UNPKG

@rjsf/mui

Version:

Material UI 5 theme, fields and widgets for react-jsonschema-form

22 lines 2.27 kB
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime"; import Grid from '@mui/material/Grid/index.js'; import { canExpand, descriptionId, getTemplate, getUiOptions, titleId, } from '@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 { description, title, properties, required, disabled, readonly, uiSchema, idSchema, schema, formData, onAddClick, 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; return (_jsxs(_Fragment, { 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 })), _jsxs(Grid, { container: true, spacing: 2, style: { marginTop: '10px' }, children: [properties.map((element, index) => // Remove the <Grid> if the inner element is hidden as the <Grid> // itself would otherwise still take up space. element.hidden ? (element.content) : (_jsx(Grid, { item: true, xs: 12, style: { marginBottom: '10px' }, children: element.content }, index))), canExpand(schema, uiSchema, formData) && (_jsx(Grid, { container: true, justifyContent: 'flex-end', children: _jsx(Grid, { item: true, children: _jsx(AddButton, { className: 'object-property-expand', onClick: onAddClick(schema), disabled: disabled || readonly, uiSchema: uiSchema, registry: registry }) }) }))] })] })); } //# sourceMappingURL=ObjectFieldTemplate.js.map