UNPKG

@aokiapp/rjsf-mantine-theme

Version:

Mantine theme, fields and widgets for react-jsonschema-form

25 lines 2.08 kB
import { jsx as _jsx } from "react/jsx-runtime"; import { ariaDescribedByIds, enumOptionsValueForIndex, optionId, enumOptionsIndexForValue, labelValue, } from '@rjsf/utils'; import { Flex, Radio } from '@mantine/core'; import { createErrors } from '../utils/createErrors'; /** 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(props) { const { id, value, required, disabled, readonly, hideLabel, label, onChange, onBlur, onFocus, options, rawErrors, hideError, schema, } = props; const { enumOptions, enumDisabled, emptyValue, inline } = options; const _onChange = (nextValue) => { onChange(enumOptionsValueForIndex(nextValue, enumOptions, emptyValue)); }; const _onBlur = () => onBlur(id, value); const _onFocus = () => onFocus(id, value); const description = options.description || schema.description; return (_jsx(Radio.Group, { name: id, label: labelValue(label || undefined, hideLabel, false), description: description, required: required, value: enumOptionsIndexForValue(value, enumOptions, false), onChange: _onChange, onBlur: _onBlur, onFocus: _onFocus, error: createErrors(rawErrors, hideError), className: 'armt-widget-radio', children: _jsx(Flex, { direction: inline ? 'row' : 'column', m: 'xs', gap: 'sm', children: enumOptions === null || enumOptions === void 0 ? void 0 : enumOptions.map((option, index) => { var _a; const itemDisabled = enumDisabled && enumDisabled.indexOf(option.value) !== -1; return (_jsx(Radio, { id: optionId(id, index), name: id, label: option.label, value: enumOptionsIndexForValue(option.value, enumOptions, false), disabled: disabled || itemDisabled || readonly, "aria-describedby": ariaDescribedByIds(id), description: (_a = option.schema) === null || _a === void 0 ? void 0 : _a.description }, index)); }) }) })); } //# sourceMappingURL=RadioWidget.js.map