import { FocusEvent } from 'react'; import { Radio, RadioChangeEvent } from 'antd'; import { ariaDescribedByIds, enumOptionSelectedValue, enumOptionValueDecoder, enumOptionValueEncoder, getOptionValueFormat, optionId, FormContextType, GenericObjectType, RJSFSchema, StrictRJSFSchema, WidgetProps, } 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({ autofocus, disabled, registry, id, htmlName, onBlur, onChange, onFocus, options, readonly, value, }: WidgetProps) { const { formContext } = registry; const { readonlyAsDisabled = true } = formContext as GenericObjectType; const { enumOptions, enumDisabled, emptyValue } = options; const optionValueFormat = getOptionValueFormat(options); const handleChange = ({ target: { value: nextValue } }: RadioChangeEvent) => onChange(enumOptionValueDecoder(nextValue, enumOptions, optionValueFormat, emptyValue)); const handleBlur = ({ target }: FocusEvent) => onBlur(id, enumOptionValueDecoder(target && target.value, enumOptions, optionValueFormat, emptyValue)); const handleFocus = ({ target }: FocusEvent) => onFocus(id, enumOptionValueDecoder(target && target.value, enumOptions, optionValueFormat, emptyValue)); const selectValue = enumOptionSelectedValue(value, enumOptions, false, optionValueFormat, emptyValue); return ( {Array.isArray(enumOptions) && enumOptions.map((option, i) => ( {option.label} ))} ); }