Refactor radio group buttons
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Eric NGUYEN 2022-08-16 13:46:54 +02:00
parent 9ce184df26
commit 6d56ea49cf
4 changed files with 80 additions and 68 deletions

View file

@ -0,0 +1,53 @@
import * as React from 'react';
import { IInputGroup } from '../../Interfaces/IInputGroup';
interface IRadioGroupButtonsProps {
name: string
value?: string
defaultValue?: string
labelText: string
inputGroups: IInputGroup[]
onChange?: (event: React.ChangeEvent<HTMLInputElement>) => void
}
export const RadioGroupButtons: React.FunctionComponent<IRadioGroupButtonsProps> = (props) => {
let inputGroups;
if (props.value !== undefined) {
inputGroups = props.inputGroups.map((inputGroup) => (
<label key={inputGroup.value}>
<input
type='radio'
name={props.name}
value={inputGroup.value}
checked={props.value === inputGroup.value}
onChange={props.onChange}
/>
{inputGroup.text}
</label>
));
} else {
inputGroups = props.inputGroups.map((inputGroup) => (
<label key={inputGroup.value}>
<input
type='radio'
name={props.name}
value={inputGroup.value}
defaultChecked={props.defaultValue === inputGroup.value}
onChange={props.onChange}
/>
{inputGroup.text}
</label>
));
}
return (
<>
<label>
{props.labelText}
</label>
<div id='XPositionReference'>
{ inputGroups }
</div>
</>
);
};