UNPKG

@aokiapp/rjsf-mantine-theme

Version:

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

31 lines 1.89 kB
import { jsx as _jsx } from "react/jsx-runtime"; import { useEffect } from 'react'; import { getUiOptions, getWidget } from '@rjsf/utils'; /** The `NullField` component is used to render a field in the schema is null. It also ensures that the `formData` is * also set to null if it has no value. * * Differences from the original: * - Traverse the widget and use it * - By default, use `NullWidget`, which is not present in the original * - Hence, null fields can be replaced with custom ones * * @param props - The `FieldProps` for this template */ function NullField(props) { var _a; const { schema, name, uiSchema, idSchema, formData, required, disabled = false, readonly = false, autofocus = false, onChange, onBlur, onFocus, registry, rawErrors, hideError, } = props; const { title } = schema; const { widgets, formContext, schemaUtils, globalUiOptions } = registry; const { widget = 'NullWidget', placeholder = '', title: uiTitle, ...options } = getUiOptions(uiSchema); const displayLabel = schemaUtils.getDisplayLabel(schema, uiSchema, globalUiOptions); const label = (_a = uiTitle !== null && uiTitle !== void 0 ? uiTitle : title) !== null && _a !== void 0 ? _a : name; const Widget = getWidget(schema, widget, widgets); useEffect(() => { if (formData === undefined) { onChange(null); } }, [formData, onChange]); return (_jsx(Widget, { options: options, schema: schema, uiSchema: uiSchema, id: idSchema.$id, name: name, label: label, hideLabel: !displayLabel, hideError: hideError, value: formData, onChange: onChange, onBlur: onBlur, onFocus: onFocus, required: required, disabled: disabled, readonly: readonly, formContext: formContext, autofocus: autofocus, registry: registry, placeholder: placeholder, rawErrors: rawErrors })); } export default NullField; //# sourceMappingURL=NullField.js.map