fix(striker-ui): expose id, name in radio group

main
Tsu-ba-me 11 months ago
parent 325594ef4b
commit e8ac1a9c4f
  1. 15
      striker-ui/components/RadioGroupWithLabel.tsx
  2. 15
      striker-ui/types/RadioGroupWithLabel.d.ts

@ -18,10 +18,12 @@ const RadioGroupWithLabel: FC<RadioGroupWithLabelProps> = ({
formLabelProps, formLabelProps,
id, id,
label, label,
name,
onChange: onRadioGroupChange, onChange: onRadioGroupChange,
radioItems, radioItems,
radioProps: { sx: radioSx, ...restRadioProps } = {}, radioProps: { sx: radioSx, ...restRadioProps } = {},
radioGroupProps, radioGroupProps,
value,
}) => { }) => {
const labelElement = useMemo( const labelElement = useMemo(
() => (typeof label === 'string' ? <BodyText>{label}</BodyText> : label), () => (typeof label === 'string' ? <BodyText>{label}</BodyText> : label),
@ -30,7 +32,7 @@ const RadioGroupWithLabel: FC<RadioGroupWithLabelProps> = ({
const itemElements = useMemo(() => { const itemElements = useMemo(() => {
const items = Object.entries(radioItems); const items = Object.entries(radioItems);
return items.map(([itemId, { label: itemLabel, value }]) => { return items.map(([itemId, { label: itemLabel, value: itemValue }]) => {
const itemLabelElement = const itemLabelElement =
typeof itemLabel === 'string' ? ( typeof itemLabel === 'string' ? (
<BodyText>{itemLabel}</BodyText> <BodyText>{itemLabel}</BodyText>
@ -53,7 +55,7 @@ const RadioGroupWithLabel: FC<RadioGroupWithLabelProps> = ({
/> />
} }
key={`${id}-${itemId}`} key={`${id}-${itemId}`}
value={value} value={itemValue}
label={itemLabelElement} label={itemLabelElement}
{...formControlLabelProps} {...formControlLabelProps}
/> />
@ -64,7 +66,14 @@ const RadioGroupWithLabel: FC<RadioGroupWithLabelProps> = ({
return ( return (
<MUIFormControl {...formControlProps}> <MUIFormControl {...formControlProps}>
<MUIFormLabel {...formLabelProps}>{labelElement}</MUIFormLabel> <MUIFormLabel {...formLabelProps}>{labelElement}</MUIFormLabel>
<MUIRadioGroup onChange={onRadioGroupChange} row {...radioGroupProps}> <MUIRadioGroup
id={id}
name={name}
onChange={onRadioGroupChange}
row
value={value}
{...radioGroupProps}
>
{itemElements} {itemElements}
</MUIRadioGroup> </MUIRadioGroup>
</MUIFormControl> </MUIFormControl>

@ -3,18 +3,23 @@ type RadioItem<RadioItemValue> = {
value: RadioItemValue; value: RadioItemValue;
}; };
type RadioItemList<Value = string> = Record<string, RadioItem<Value>>;
type RadioGroupWithLabelOptionalProps = { type RadioGroupWithLabelOptionalProps = {
formControlProps?: import('@mui/material').FormControlProps; formControlProps?: import('@mui/material').FormControlProps;
formControlLabelProps?: import('@mui/material').FormControlLabelProps; formControlLabelProps?: import('@mui/material').FormControlLabelProps;
formLabelProps?: import('@mui/material').FormLabelProps; formLabelProps?: import('@mui/material').FormLabelProps;
label?: import('react').ReactNode; label?: import('react').ReactNode;
onChange?: import('@mui/material').RadioGroupProps['onChange'];
radioProps?: import('@mui/material').RadioProps; radioProps?: import('@mui/material').RadioProps;
radioGroupProps?: import('@mui/material').RadioGroupProps; radioGroupProps?: import('@mui/material').RadioGroupProps;
}; };
type RadioGroupWithLabelProps<RadioItemValue = string> = type RadioGroupWithLabelProps<RadioItemValue = string> =
RadioGroupWithLabelOptionalProps & { RadioGroupWithLabelOptionalProps &
id: string; Pick<
radioItems: { [id: string]: RadioItem<RadioItemValue> }; import('@mui/material').RadioGroupProps,
}; 'name' | 'onChange' | 'value'
> & {
id: string;
radioItems: RadioItemList<RadioItemValue>;
};

Loading…
Cancel
Save