UNPKG

@aokiapp/rjsf-mantine-theme

Version:

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

30 lines 1.72 kB
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { getTemplate, getUiOptions, } from '@rjsf/utils'; import { createContext, useContext } from 'react'; /** `FieldContext passes the items of the `FieldTemplate` down to descendants, to avoid prop drilling. * It is used by the nearest descendant consumer. */ export const FieldContext = createContext(null); export const useFieldContext = () => { const context = useContext(FieldContext); if (!context) { throw new Error('FieldContext not found'); } return context; }; /** The `FieldTemplate` component is the template used by `SchemaField` to render any field. It renders the field * content, (label, description, children, errors and help) inside of a `WrapIfAdditional` component. * * @param props - The `FieldTemplateProps` for this component */ export default function FieldTemplate(props) { const { id, children, classNames, style, label, help, hidden, registry, schema, uiSchema, errors, description, ...otherProps } = props; const uiOptions = getUiOptions(uiSchema); const WrapIfAdditionalTemplate = getTemplate('WrapIfAdditionalTemplate', registry, uiOptions); if (hidden) { return _jsx("div", { style: { display: 'none' }, children: children }); } // Conditions whether errors should be displayed or not is handled by the FieldErrorTemplate return (_jsx(FieldContext.Provider, { value: { description: description }, children: _jsxs(WrapIfAdditionalTemplate, { classNames: classNames, style: style, id: id, label: label, registry: registry, schema: schema, uiSchema: uiSchema, ...otherProps, children: [children, errors, help] }) })); } //# sourceMappingURL=FieldTemplate.js.map