Improve XPositionReference radio input group
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing

This commit is contained in:
Eric NGUYEN 2022-08-16 14:47:13 +02:00
parent f0bfa39f33
commit 658b9d9cc7
5 changed files with 74 additions and 16 deletions

View file

@ -5,6 +5,7 @@ interface IRadioGroupButtonsProps {
name: string
value?: string
defaultValue?: string
inputClassName: string
labelText: string
inputGroups: IInputGroup[]
onChange?: (event: React.ChangeEvent<HTMLInputElement>) => void
@ -13,32 +14,40 @@ interface IRadioGroupButtonsProps {
export const RadioGroupButtons: React.FunctionComponent<IRadioGroupButtonsProps> = (props) => {
let inputGroups;
if (props.value !== undefined) {
// dynamic
inputGroups = props.inputGroups.map((inputGroup) => (
<label key={inputGroup.value}>
<div key={inputGroup.value}>
<input
id={inputGroup.value}
type='radio'
name={props.name}
className='m-2'
className={`peer m-2 ${props.inputClassName}`}
value={inputGroup.value}
checked={props.value === inputGroup.value}
onChange={props.onChange}
/>
{inputGroup.text}
</label>
<label htmlFor={inputGroup.value} className='text-gray-400 peer-checked:text-blue-500'>
{inputGroup.text}
</label>
</div>
));
} else {
// static
inputGroups = props.inputGroups.map((inputGroup) => (
<label key={inputGroup.value}>
<div key={inputGroup.value}>
<input
id={inputGroup.value}
type='radio'
name={props.name}
className='m-2'
className={`peer m-2 ${props.inputClassName}`}
value={inputGroup.value}
defaultChecked={props.defaultValue === inputGroup.value}
onChange={props.onChange}
/>
{inputGroup.text}
</label>
<label htmlFor={inputGroup.value} className='text-gray-400 peer-checked:text-blue-500'>
{inputGroup.text}
</label>
</div>
));
}