@lonli-lokli/dynamic-forms-mui
Version:
Material UI 5 theme, fields and widgets for react-jsonschema-form
29 lines • 2.13 kB
JavaScript
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import Grid2 from '@mui/material/Grid2/index.js';
import TextField from '@mui/material/TextField/index.js';
import { ADDITIONAL_PROPERTY_FLAG, buttonId, TranslatableString, } from '@lonli-lokli/dynamic-forms-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 && target.value);
return (_jsxs(Grid2, { container: true, alignItems: 'center', spacing: 2, className: classNames, style: style, children: [_jsx(Grid2, { size: 'auto', 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(Grid2, { size: 'auto', children: children }), _jsx(Grid2, { children: _jsx(RemoveButton, { id: buttonId(id, 'remove'), className: 'rjsf-object-property-remove', iconType: 'default', style: btnStyle, disabled: disabled || readonly, onClick: onDropPropertyClick(label), uiSchema: uiSchema, registry: registry }) })] }, `${id}-key`));
}
//# sourceMappingURL=WrapIfAdditionalTemplate.js.map