UNPKG

@rjsf/material-ui

Version:

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

29 lines 2.03 kB
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import Grid from '@material-ui/core/Grid'; import TextField from '@material-ui/core/TextField'; import { ADDITIONAL_PROPERTY_FLAG, TranslatableString, } from '@rjsf/utils'; /** 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 additional = ADDITIONAL_PROPERTY_FLAG in schema; const btnStyle = { flex: 1, paddingLeft: 6, paddingRight: 6, fontWeight: 'bold', }; if (!additional) { return (_jsx("div", { className: classNames, style: style, children: children })); } const handleBlur = ({ target }) => onKeyChange(target.value); return (_jsxs(Grid, { container: true, alignItems: 'center', spacing: 2, className: classNames, style: style, children: [_jsx(Grid, { item: true, xs: true, children: _jsx(TextField, { fullWidth: true, required: required, label: keyLabel, defaultValue: label, disabled: disabled || readonly, id: `${id}-key`, name: `${id}-key`, onBlur: !readonly ? handleBlur : undefined, type: 'text' }) }), _jsx(Grid, { item: true, xs: true, children: children }), _jsx(Grid, { item: true, children: _jsx(RemoveButton, { iconType: 'default', style: btnStyle, disabled: disabled || readonly, onClick: onDropPropertyClick(label), uiSchema: uiSchema, registry: registry }) })] }, `${id}-key`)); } //# sourceMappingURL=WrapIfAdditionalTemplate.js.map