@rjsf/antd
Version:
Ant Design theme, fields and widgets for react-jsonschema-form
21 lines • 2.09 kB
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
import { ariaDescribedByIds, enumOptionSelectedValue, enumOptionValueDecoder, enumOptionValueEncoder, getOptionValueFormat, optionId, } from '@rjsf/utils';
import { Radio } from 'antd';
/** 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, }) {
const { formContext } = registry;
const { readonlyAsDisabled = true } = formContext;
const { enumOptions, enumDisabled, emptyValue } = options;
const optionValueFormat = getOptionValueFormat(options);
const handleChange = ({ target: { value: nextValue } }) => onChange(enumOptionValueDecoder(nextValue, enumOptions, optionValueFormat, emptyValue));
const handleBlur = ({ target }) => onBlur(id, enumOptionValueDecoder(target && target.value, enumOptions, optionValueFormat, emptyValue));
const handleFocus = ({ target }) => onFocus(id, enumOptionValueDecoder(target && target.value, enumOptions, optionValueFormat, emptyValue));
const selectValue = enumOptionSelectedValue(value, enumOptions, false, optionValueFormat, emptyValue);
return (_jsx(Radio.Group, { disabled: disabled || (readonlyAsDisabled && readonly), id: id, name: htmlName || id, onChange: !readonly ? handleChange : undefined, onBlur: !readonly ? handleBlur : undefined, onFocus: !readonly ? handleFocus : undefined, value: selectValue, "aria-describedby": ariaDescribedByIds(id), children: Array.isArray(enumOptions) &&
enumOptions.map((option, i) => (_jsx(Radio, { id: optionId(id, i), name: htmlName || id, autoFocus: i === 0 ? autofocus : false, disabled: disabled || (Array.isArray(enumDisabled) && enumDisabled.includes(option.value)), value: enumOptionValueEncoder(option.value, i, optionValueFormat), children: option.label }, String(option.value)))) }));
}
//# sourceMappingURL=index.js.map