UNPKG

@snups/rjsf-mantine

Version:

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

24 lines 2.56 kB
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { Box, Container, Group, SimpleGrid } from '@mantine/core'; import { buttonId, canExpand, descriptionId, getTemplate, getUiOptions, titleId, } from '@snups/rjsf-utils'; /** The `ObjectFieldTemplate` is the template to use to render all the inner properties of an object along with the * title and description if available. If the object is expandable, then an `AddButton` is also rendered after all * the properties. * * @param props - The `ObjectFieldTemplateProps` for this component */ export default function ObjectFieldTemplate(props) { const { title, description, disabled, properties, onAddClick, readonly, required, schema, uiSchema, idSchema, formData, registry, } = props; const uiOptions = getUiOptions(uiSchema); const TitleFieldTemplate = getTemplate('TitleFieldTemplate', registry, uiOptions); const DescriptionFieldTemplate = getTemplate('DescriptionFieldTemplate', registry, uiOptions); // Button templates are not overridden in the uiSchema const { ButtonTemplates: { AddButton }, } = registry.templates; const gridCols = (typeof (uiOptions === null || uiOptions === void 0 ? void 0 : uiOptions.gridCols) === 'number' && (uiOptions === null || uiOptions === void 0 ? void 0 : uiOptions.gridCols)) || undefined; const gridSpacing = uiOptions === null || uiOptions === void 0 ? void 0 : uiOptions.gridSpacing; const gridVerticalSpacing = uiOptions === null || uiOptions === void 0 ? void 0 : uiOptions.gridVerticalSpacing; return (_jsxs(Container, { id: idSchema.$id, p: 0, children: [title && (_jsx(TitleFieldTemplate, { id: titleId(idSchema), title: title, required: required, schema: schema, uiSchema: uiSchema, registry: registry })), description && (_jsx(DescriptionFieldTemplate, { id: descriptionId(idSchema), description: description, schema: schema, uiSchema: uiSchema, registry: registry })), _jsx(SimpleGrid, { cols: gridCols, spacing: gridSpacing, verticalSpacing: gridVerticalSpacing, mb: 'sm', children: properties .filter((e) => !e.hidden) .map((element) => (_jsx(Box, { children: element.content }, element.name))) }), canExpand(schema, uiSchema, formData) && (_jsx(Group, { mt: 'xs', justify: 'flex-end', children: _jsx(AddButton, { id: buttonId(idSchema, 'add'), disabled: disabled || readonly, onClick: onAddClick(schema), className: 'rjsf-object-property-expand', uiSchema: uiSchema, registry: registry }) }))] })); } //# sourceMappingURL=ObjectFieldTemplate.js.map