import type { FocusEvent } from 'react'; import type { RadioGroupOnChangeData } from '@fluentui/react-components'; import { Label, Radio, RadioGroup } from '@fluentui/react-components'; import type { FormContextType, RJSFSchema, StrictRJSFSchema, WidgetProps } from '@rjsf/utils'; import { ariaDescribedByIds, enumOptionValueDecoder, enumOptionValueEncoder, enumOptionsIndexForValue, getOptionValueFormat, labelValue, optionId, } from '@rjsf/utils'; /** The `RadioWidget` is a widget for rendering a radio group. * It is typically used with a string property constrained with enum options. * * @param props - The `WidgetProps` for this component */ export default function RadioWidget({ id, htmlName, options, value, required, disabled, readonly, label, hideLabel, onChange, onBlur, onFocus, }: WidgetProps) { const { enumOptions, enumDisabled, emptyValue, inline } = options; const optionValueFormat = getOptionValueFormat(options); const handleChange = (_: any, data: RadioGroupOnChangeData) => onChange(enumOptionValueDecoder(data.value, enumOptions, optionValueFormat, emptyValue)); const handleBlur = ({ target }: FocusEvent) => onBlur(id, enumOptionValueDecoder(target?.value, enumOptions, optionValueFormat, emptyValue)); const handleFocus = ({ target }: FocusEvent) => onFocus(id, enumOptionValueDecoder(target?.value, enumOptions, optionValueFormat, emptyValue)); const selectedIndex = enumOptionsIndexForValue(value, enumOptions) ?? undefined; return ( <> {labelValue( , hideLabel, )} {Array.isArray(enumOptions) && enumOptions.map((option, index) => { const itemDisabled = Array.isArray(enumDisabled) && enumDisabled.includes(option.value); return ( ); })} ); }