import { FormControl as MUIFormControl, FormControlLabel as MUIFormControlLabel, FormLabel as MUIFormLabel, Radio as MUIRadio, radioClasses as muiRadioClasses, RadioGroup as MUIRadioGroup, } from '@mui/material'; import { FC, useMemo } from 'react'; import { GREY } from '../lib/consts/DEFAULT_THEME'; import { BodyText } from './Text'; const RadioGroupWithLabel: FC = ({ formControlProps, formControlLabelProps, formLabelProps, id, label, onChange: onRadioGroupChange, radioItems, radioProps: { sx: radioSx, ...restRadioProps } = {}, radioGroupProps, }) => { const labelElement = useMemo( () => (typeof label === 'string' ? {label} : label), [label], ); const itemElements = useMemo(() => { const items = Object.entries(radioItems); return items.map(([itemId, { label: itemLabel, value }]) => { const itemLabelElement = typeof itemLabel === 'string' ? ( {itemLabel} ) : ( itemLabel ); return ( } key={`${id}-${itemId}`} value={value} label={itemLabelElement} {...formControlLabelProps} /> ); }); }, [formControlLabelProps, id, radioItems, radioSx, restRadioProps]); return ( {labelElement} {itemElements} ); }; export default RadioGroupWithLabel;