UNPKG

@aokiapp/rjsf-mantine-theme

Version:

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

1 lines 3.56 kB
{"version":3,"file":"FieldTemplate.cjs","sources":["../../src/templates/FieldTemplate.tsx"],"sourcesContent":["import {\n FieldTemplateProps,\n FormContextType,\n RJSFSchema,\n StrictRJSFSchema,\n getTemplate,\n getUiOptions,\n} from '@rjsf/utils';\nimport { ReactNode, createContext, useContext } from 'react';\n\n/** `FieldContext passes the items of the `FieldTemplate` down to descendants, to avoid prop drilling.\n * It is used by the nearest descendant consumer.\n */\nexport const FieldContext = createContext<{\n description: ReactNode;\n}>(null!);\n\nexport const useFieldContext = () => {\n const context = useContext(FieldContext);\n if (!context) {\n throw new Error('FieldContext not found');\n }\n return context;\n};\n\n/** The `FieldTemplate` component is the template used by `SchemaField` to render any field. It renders the field\n * content, (label, description, children, errors and help) inside of a `WrapIfAdditional` component.\n *\n * @param props - The `FieldTemplateProps` for this component\n */\nexport default function FieldTemplate<\n T = any,\n S extends StrictRJSFSchema = RJSFSchema,\n F extends FormContextType = any,\n>(props: FieldTemplateProps<T, S, F>) {\n const {\n id,\n children,\n classNames,\n style,\n label,\n help,\n hidden,\n registry,\n schema,\n uiSchema,\n errors,\n description,\n ...otherProps\n } = props;\n const uiOptions = getUiOptions<T, S, F>(uiSchema);\n const WrapIfAdditionalTemplate = getTemplate<'WrapIfAdditionalTemplate', T, S, F>(\n 'WrapIfAdditionalTemplate',\n registry,\n uiOptions,\n );\n\n if (hidden) {\n return <div style={{ display: 'none' }}>{children}</div>;\n }\n\n // Conditions whether errors should be displayed or not is handled by the FieldErrorTemplate\n return (\n <FieldContext.Provider value={{ description: description }}>\n <WrapIfAdditionalTemplate\n classNames={classNames}\n style={style}\n id={id}\n label={label}\n registry={registry}\n schema={schema}\n uiSchema={uiSchema}\n {...otherProps}\n >\n {children}\n {errors}\n {help}\n </WrapIfAdditionalTemplate>\n </FieldContext.Provider>\n );\n}\n"],"names":["createContext","useContext","getUiOptions","getTemplate","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