@aokiapp/rjsf-mantine-theme
Version:
Mantine theme, fields and widgets for react-jsonschema-form
65 lines (62 loc) • 2.02 kB
JavaScript
import { jsx } from 'react/jsx-runtime';
import { labelValue, enumOptionsIndexForValue, optionId, ariaDescribedByIds, enumOptionsValueForIndex } from '@rjsf/utils';
import { Radio, Flex } from '@mantine/core';
import { createErrors } from '../utils/createErrors.mjs';
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 /* @__PURE__ */ jsx(
Radio.Group,
{
name: id,
label: labelValue(label || void 0, hideLabel, false),
description,
required,
value: enumOptionsIndexForValue(value, enumOptions, false),
onChange: _onChange,
onBlur: _onBlur,
onFocus: _onFocus,
error: createErrors(rawErrors, hideError),
className: "armt-widget-radio",
children: /* @__PURE__ */ jsx(Flex, { direction: inline ? "row" : "column", m: "xs", gap: "sm", children: enumOptions?.map((option, index) => {
const itemDisabled = enumDisabled && enumDisabled.indexOf(option.value) !== -1;
return /* @__PURE__ */ 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: option.schema?.description
},
index
);
}) })
}
);
}
export { RadioWidget as default };
//# sourceMappingURL=RadioWidget.mjs.map