import { useMemo, type ChangeEvent } from 'react'; import { Radio as MuiRadio, RadioGroup, FormControl, FormControlLabel, FormLabel, type RadioProps, type RadioGroupProps, Box, Typography } from '@mui/material'; import clsx from 'clsx'; import './rds-radio.scss'; export interface RdsRadioOption { value: string; text: string; disabled?: boolean; } export interface RdsRadioProps extends Omit { options: RdsRadioOption[]; label?: string; direction?: 'row' | 'column'; radioProps?: RadioProps; layout?: 'icon' | 'icon with label' | 'icon with bottom label'; state?: 'default' | 'hover' | 'disabled'; selected?: boolean; } const RdsRadio= ({ options, label, direction = 'column', radioProps, layout = 'icon with label', state = 'default', selected, ...props }:RdsRadioProps) => { const radioRow = direction === 'row'; const effectiveValue: string | undefined = useMemo(() => { if (typeof selected === 'undefined') return props.value as string | undefined; if (selected === false) return undefined; if (props.value) return props.value as string; const first = options.find(o => !o.disabled); return first ? first.value : undefined; }, [selected, props.value, options]); const renderOption = (option: RdsRadioOption) => { const optionDisabled = option.disabled ?? false; const finalDisabled = optionDisabled || state === 'disabled'; const commonProps = { value: option.value, control: , disabled: finalDisabled, }; if (layout === 'icon') { return ; } if (layout === 'icon with bottom label') { const radioId = `rds-radio-${option.value}`; return ( ); } return ( ); }; const { value: _ignoredValue, ...restProps } = props; return ( {label && {label}} {layout === 'icon with bottom label' ? ( {options.map(renderOption)} ) : ( { if (typeof selected === 'undefined' && props.onChange) { props.onChange(e as ChangeEvent, val); } }} {...restProps} > {options.map(renderOption)} )} ); }; RdsRadio.displayName = 'RdsRadio'; export default RdsRadio;