UNPKG

@aokiapp/rjsf-mantine-theme

Version:

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

25 lines 2.13 kB
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { ADDITIONAL_PROPERTY_FLAG, TranslatableString, } from '@rjsf/utils'; import { Group, TextInput, Box } from '@mantine/core'; /** The `WrapIfAdditional` component is used by the `FieldTemplate` to rename, or remove properties that are * part of an `additionalProperties` part of a schema. * * @param props - The `WrapIfAdditionalProps` for this component */ export default function WrapIfAdditionalTemplate(props) { const { children, classNames, style, disabled, id, label, onDropPropertyClick, onKeyChange, readonly, required, schema, uiSchema, registry, } = props; const { templates, translateString } = registry; // Button templates are not overridden in the uiSchema const { RemoveButton } = templates.ButtonTemplates; const keyLabel = translateString(TranslatableString.KeyLabel, [label]); const { readonlyAsDisabled = true, wrapperStyle } = registry.formContext; const additional = ADDITIONAL_PROPERTY_FLAG in schema; if (!additional) { return (_jsx("div", { className: `${classNames !== null && classNames !== void 0 ? classNames : ''} armt-template-wia`, style: style, children: children })); } const handleBlur = ({ target }) => onKeyChange(target.value); // the reason that wraps the children in a div is to match the result of additional=false return (_jsx("div", { className: `${classNames !== null && classNames !== void 0 ? classNames : ''} armt-template-wia`, style: style, children: _jsxs(Group, { align: 'center', children: [_jsx(TextInput // key input , { label: keyLabel, required: required, defaultValue: label, disabled: disabled || (readonlyAsDisabled && readonly), id: id, name: id, onBlur: !readonly ? handleBlur : undefined, style: wrapperStyle, type: 'text' }), _jsx(Box, { style: { flexGrow: 1 }, children: children }), _jsx(RemoveButton, { className: 'array-item-remove', disabled: disabled || readonly, onClick: onDropPropertyClick(label), uiSchema: uiSchema, registry: registry })] }) }, `${id}-key`)); } //# sourceMappingURL=WrapIfAdditionalTemplate.js.map