@rjsf/mui 5.11.2 → 5.12.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1003 -5
- package/dist/index.js.map +7 -0
- package/dist/mui.esm.js +650 -824
- package/dist/mui.esm.js.map +7 -1
- package/dist/mui.umd.js +852 -0
- package/lib/AddButton/AddButton.d.ts +5 -0
- package/lib/AddButton/AddButton.js +13 -0
- package/lib/AddButton/AddButton.js.map +1 -0
- package/lib/AddButton/index.d.ts +2 -0
- package/lib/AddButton/index.js +3 -0
- package/lib/AddButton/index.js.map +1 -0
- package/lib/ArrayFieldItemTemplate/ArrayFieldItemTemplate.d.ts +7 -0
- package/lib/ArrayFieldItemTemplate/ArrayFieldItemTemplate.js +21 -0
- package/lib/ArrayFieldItemTemplate/ArrayFieldItemTemplate.js.map +1 -0
- package/lib/ArrayFieldItemTemplate/index.d.ts +2 -0
- package/lib/ArrayFieldItemTemplate/index.js +3 -0
- package/lib/ArrayFieldItemTemplate/index.js.map +1 -0
- package/lib/ArrayFieldTemplate/ArrayFieldTemplate.d.ts +7 -0
- package/lib/ArrayFieldTemplate/ArrayFieldTemplate.js +25 -0
- package/lib/ArrayFieldTemplate/ArrayFieldTemplate.js.map +1 -0
- package/lib/ArrayFieldTemplate/index.d.ts +2 -0
- package/lib/ArrayFieldTemplate/index.js +3 -0
- package/lib/ArrayFieldTemplate/index.js.map +1 -0
- package/lib/BaseInputTemplate/BaseInputTemplate.d.ts +9 -0
- package/lib/BaseInputTemplate/BaseInputTemplate.js +32 -0
- package/lib/BaseInputTemplate/BaseInputTemplate.js.map +1 -0
- package/lib/BaseInputTemplate/index.d.ts +2 -0
- package/lib/BaseInputTemplate/index.js +3 -0
- package/lib/BaseInputTemplate/index.js.map +1 -0
- package/lib/CheckboxWidget/CheckboxWidget.d.ts +8 -0
- package/lib/CheckboxWidget/CheckboxWidget.js +24 -0
- package/lib/CheckboxWidget/CheckboxWidget.js.map +1 -0
- package/lib/CheckboxWidget/index.d.ts +2 -0
- package/lib/CheckboxWidget/index.js +3 -0
- package/lib/CheckboxWidget/index.js.map +1 -0
- package/lib/CheckboxesWidget/CheckboxesWidget.d.ts +8 -0
- package/lib/CheckboxesWidget/CheckboxesWidget.js +33 -0
- package/lib/CheckboxesWidget/CheckboxesWidget.js.map +1 -0
- package/lib/CheckboxesWidget/index.d.ts +2 -0
- package/lib/CheckboxesWidget/index.js +3 -0
- package/lib/CheckboxesWidget/index.js.map +1 -0
- package/lib/DescriptionField/DescriptionField.d.ts +7 -0
- package/lib/DescriptionField/DescriptionField.js +14 -0
- package/lib/DescriptionField/DescriptionField.js.map +1 -0
- package/lib/DescriptionField/index.d.ts +2 -0
- package/lib/DescriptionField/index.js +3 -0
- package/lib/DescriptionField/index.js.map +1 -0
- package/lib/ErrorList/ErrorList.d.ts +7 -0
- package/lib/ErrorList/ErrorList.js +21 -0
- package/lib/ErrorList/ErrorList.js.map +1 -0
- package/lib/ErrorList/index.d.ts +2 -0
- package/lib/ErrorList/index.js +3 -0
- package/lib/ErrorList/index.js.map +1 -0
- package/lib/FieldErrorTemplate/FieldErrorTemplate.d.ts +7 -0
- package/lib/FieldErrorTemplate/FieldErrorTemplate.js +20 -0
- package/lib/FieldErrorTemplate/FieldErrorTemplate.js.map +1 -0
- package/lib/FieldErrorTemplate/index.d.ts +2 -0
- package/lib/FieldErrorTemplate/index.js +3 -0
- package/lib/FieldErrorTemplate/index.js.map +1 -0
- package/lib/FieldHelpTemplate/FieldHelpTemplate.d.ts +7 -0
- package/lib/FieldHelpTemplate/FieldHelpTemplate.js +16 -0
- package/lib/FieldHelpTemplate/FieldHelpTemplate.js.map +1 -0
- package/lib/FieldHelpTemplate/index.d.ts +2 -0
- package/lib/FieldHelpTemplate/index.js +3 -0
- package/lib/FieldHelpTemplate/index.js.map +1 -0
- package/lib/FieldTemplate/FieldTemplate.d.ts +8 -0
- package/lib/FieldTemplate/FieldTemplate.js +19 -0
- package/lib/FieldTemplate/FieldTemplate.js.map +1 -0
- package/lib/FieldTemplate/index.d.ts +2 -0
- package/lib/FieldTemplate/index.js +3 -0
- package/lib/FieldTemplate/index.js.map +1 -0
- package/lib/IconButton/IconButton.d.ts +7 -0
- package/lib/IconButton/IconButton.js +30 -0
- package/lib/IconButton/IconButton.js.map +1 -0
- package/lib/IconButton/index.d.ts +2 -0
- package/lib/IconButton/index.js +3 -0
- package/lib/IconButton/index.js.map +1 -0
- package/lib/MuiForm/MuiForm.d.ts +6 -0
- package/lib/MuiForm/MuiForm.js +7 -0
- package/lib/MuiForm/MuiForm.js.map +1 -0
- package/lib/MuiForm/index.d.ts +2 -0
- package/lib/MuiForm/index.js +3 -0
- package/lib/MuiForm/index.js.map +1 -0
- package/lib/ObjectFieldTemplate/ObjectFieldTemplate.d.ts +9 -0
- package/lib/ObjectFieldTemplate/ObjectFieldTemplate.js +22 -0
- package/lib/ObjectFieldTemplate/ObjectFieldTemplate.js.map +1 -0
- package/lib/ObjectFieldTemplate/index.d.ts +2 -0
- package/lib/ObjectFieldTemplate/index.js +3 -0
- package/lib/ObjectFieldTemplate/index.js.map +1 -0
- package/lib/RadioWidget/RadioWidget.d.ts +8 -0
- package/lib/RadioWidget/RadioWidget.js +27 -0
- package/lib/RadioWidget/RadioWidget.js.map +1 -0
- package/lib/RadioWidget/index.d.ts +2 -0
- package/lib/RadioWidget/index.js +3 -0
- package/lib/RadioWidget/index.js.map +1 -0
- package/lib/RangeWidget/RangeWidget.d.ts +8 -0
- package/lib/RangeWidget/RangeWidget.js +20 -0
- package/lib/RangeWidget/RangeWidget.js.map +1 -0
- package/lib/RangeWidget/index.d.ts +2 -0
- package/lib/RangeWidget/index.js +3 -0
- package/lib/RangeWidget/index.js.map +1 -0
- package/lib/SelectWidget/SelectWidget.d.ts +9 -0
- package/lib/SelectWidget/SelectWidget.js +29 -0
- package/lib/SelectWidget/SelectWidget.js.map +1 -0
- package/lib/SelectWidget/index.d.ts +2 -0
- package/lib/SelectWidget/index.js +3 -0
- package/lib/SelectWidget/index.js.map +1 -0
- package/lib/SubmitButton/SubmitButton.d.ts +5 -0
- package/lib/SubmitButton/SubmitButton.js +14 -0
- package/lib/SubmitButton/SubmitButton.js.map +1 -0
- package/lib/SubmitButton/index.d.ts +2 -0
- package/lib/SubmitButton/index.js +3 -0
- package/lib/SubmitButton/index.js.map +1 -0
- package/lib/Templates/Templates.d.ts +4 -0
- package/lib/Templates/Templates.js +39 -0
- package/lib/Templates/Templates.js.map +1 -0
- package/lib/Templates/index.d.ts +2 -0
- package/lib/Templates/index.js +3 -0
- package/lib/Templates/index.js.map +1 -0
- package/lib/TextareaWidget/TextareaWidget.d.ts +7 -0
- package/lib/TextareaWidget/TextareaWidget.js +16 -0
- package/lib/TextareaWidget/TextareaWidget.js.map +1 -0
- package/lib/TextareaWidget/index.d.ts +2 -0
- package/lib/TextareaWidget/index.js +3 -0
- package/lib/TextareaWidget/index.js.map +1 -0
- package/lib/Theme/Theme.d.ts +5 -0
- package/lib/Theme/Theme.js +10 -0
- package/lib/Theme/Theme.js.map +1 -0
- package/lib/Theme/index.d.ts +2 -0
- package/lib/Theme/index.js +3 -0
- package/lib/Theme/index.js.map +1 -0
- package/lib/TitleField/TitleField.d.ts +7 -0
- package/lib/TitleField/TitleField.js +12 -0
- package/lib/TitleField/TitleField.js.map +1 -0
- package/lib/TitleField/index.d.ts +2 -0
- package/lib/TitleField/index.js +3 -0
- package/lib/TitleField/index.js.map +1 -0
- package/lib/Widgets/Widgets.d.ts +4 -0
- package/lib/Widgets/Widgets.js +18 -0
- package/lib/Widgets/Widgets.js.map +1 -0
- package/lib/Widgets/index.d.ts +2 -0
- package/lib/Widgets/index.js +3 -0
- package/lib/Widgets/index.js.map +1 -0
- package/lib/WrapIfAdditionalTemplate/WrapIfAdditionalTemplate.d.ts +8 -0
- package/lib/WrapIfAdditionalTemplate/WrapIfAdditionalTemplate.js +29 -0
- package/lib/WrapIfAdditionalTemplate/WrapIfAdditionalTemplate.js.map +1 -0
- package/lib/WrapIfAdditionalTemplate/index.d.ts +2 -0
- package/lib/WrapIfAdditionalTemplate/index.js +3 -0
- package/lib/WrapIfAdditionalTemplate/index.js.map +1 -0
- package/lib/index.d.ts +6 -0
- package/lib/index.js +7 -0
- package/lib/index.js.map +1 -0
- package/package.json +24 -16
- package/src/AddButton/AddButton.tsx +18 -0
- package/src/AddButton/index.ts +2 -0
- package/src/ArrayFieldItemTemplate/ArrayFieldItemTemplate.tsx +91 -0
- package/src/ArrayFieldItemTemplate/index.ts +2 -0
- package/src/ArrayFieldTemplate/ArrayFieldTemplate.tsx +87 -0
- package/src/ArrayFieldTemplate/index.ts +2 -0
- package/src/BaseInputTemplate/BaseInputTemplate.tsx +106 -0
- package/src/BaseInputTemplate/index.ts +2 -0
- package/src/CheckboxWidget/CheckboxWidget.tsx +87 -0
- package/src/CheckboxWidget/index.ts +2 -0
- package/src/CheckboxesWidget/CheckboxesWidget.tsx +92 -0
- package/src/CheckboxesWidget/index.ts +2 -0
- package/src/DescriptionField/DescriptionField.tsx +23 -0
- package/src/DescriptionField/index.ts +2 -0
- package/src/ErrorList/ErrorList.tsx +39 -0
- package/src/ErrorList/index.ts +2 -0
- package/src/FieldErrorTemplate/FieldErrorTemplate.tsx +32 -0
- package/src/FieldErrorTemplate/index.ts +2 -0
- package/src/FieldHelpTemplate/FieldHelpTemplate.tsx +19 -0
- package/src/FieldHelpTemplate/index.ts +2 -0
- package/src/FieldTemplate/FieldTemplate.tsx +81 -0
- package/src/FieldTemplate/index.ts +2 -0
- package/src/IconButton/IconButton.tsx +81 -0
- package/src/IconButton/index.ts +2 -0
- package/src/MuiForm/MuiForm.tsx +15 -0
- package/src/MuiForm/index.ts +2 -0
- package/src/ObjectFieldTemplate/ObjectFieldTemplate.tsx +99 -0
- package/src/ObjectFieldTemplate/index.ts +2 -0
- package/src/RadioWidget/RadioWidget.tsx +83 -0
- package/src/RadioWidget/index.ts +2 -0
- package/src/RangeWidget/RangeWidget.tsx +51 -0
- package/src/RangeWidget/index.ts +2 -0
- package/src/SelectWidget/SelectWidget.tsx +100 -0
- package/src/SelectWidget/index.ts +2 -0
- package/src/SubmitButton/SubmitButton.tsx +23 -0
- package/src/SubmitButton/index.ts +2 -0
- package/src/Templates/Templates.ts +46 -0
- package/src/Templates/index.ts +2 -0
- package/src/TextareaWidget/TextareaWidget.tsx +21 -0
- package/src/TextareaWidget/index.ts +2 -0
- package/src/Theme/Theme.tsx +18 -0
- package/src/Theme/index.ts +2 -0
- package/src/TitleField/TitleField.tsx +20 -0
- package/src/TitleField/index.ts +2 -0
- package/src/Widgets/Widgets.ts +25 -0
- package/src/Widgets/index.ts +2 -0
- package/src/WrapIfAdditionalTemplate/WrapIfAdditionalTemplate.tsx +90 -0
- package/src/WrapIfAdditionalTemplate/index.ts +2 -0
- package/src/index.ts +8 -0
- package/dist/index.d.ts +0 -17
- package/dist/mui.cjs.development.js +0 -1239
- package/dist/mui.cjs.development.js.map +0 -1
- package/dist/mui.cjs.production.min.js +0 -2
- package/dist/mui.cjs.production.min.js.map +0 -1
- package/dist/mui.umd.development.js +0 -1213
- package/dist/mui.umd.development.js.map +0 -1
- package/dist/mui.umd.production.min.js +0 -2
- package/dist/mui.umd.production.min.js.map +0 -1
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import Grid from '@mui/material/Grid';
|
|
3
|
+
import TextField from '@mui/material/TextField';
|
|
4
|
+
import { ADDITIONAL_PROPERTY_FLAG, TranslatableString, } from '@rjsf/utils';
|
|
5
|
+
/** The `WrapIfAdditional` component is used by the `FieldTemplate` to rename, or remove properties that are
|
|
6
|
+
* part of an `additionalProperties` part of a schema.
|
|
7
|
+
*
|
|
8
|
+
* @param props - The `WrapIfAdditionalProps` for this component
|
|
9
|
+
*/
|
|
10
|
+
export default function WrapIfAdditionalTemplate(props) {
|
|
11
|
+
const { children, classNames, style, disabled, id, label, onDropPropertyClick, onKeyChange, readonly, required, schema, uiSchema, registry, } = props;
|
|
12
|
+
const { templates, translateString } = registry;
|
|
13
|
+
// Button templates are not overridden in the uiSchema
|
|
14
|
+
const { RemoveButton } = templates.ButtonTemplates;
|
|
15
|
+
const keyLabel = translateString(TranslatableString.KeyLabel, [label]);
|
|
16
|
+
const additional = ADDITIONAL_PROPERTY_FLAG in schema;
|
|
17
|
+
const btnStyle = {
|
|
18
|
+
flex: 1,
|
|
19
|
+
paddingLeft: 6,
|
|
20
|
+
paddingRight: 6,
|
|
21
|
+
fontWeight: 'bold',
|
|
22
|
+
};
|
|
23
|
+
if (!additional) {
|
|
24
|
+
return (_jsx("div", Object.assign({ className: classNames, style: style }, { children: children })));
|
|
25
|
+
}
|
|
26
|
+
const handleBlur = ({ target }) => onKeyChange(target.value);
|
|
27
|
+
return (_jsxs(Grid, Object.assign({ container: true, alignItems: 'center', spacing: 2, className: classNames, style: style }, { children: [_jsx(Grid, Object.assign({ 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, Object.assign({ item: true, xs: true }, { children: children })), _jsx(Grid, Object.assign({ item: true }, { children: _jsx(RemoveButton, { iconType: 'default', style: btnStyle, disabled: disabled || readonly, onClick: onDropPropertyClick(label), uiSchema: uiSchema, registry: registry }) }))] }), `${id}-key`));
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=WrapIfAdditionalTemplate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WrapIfAdditionalTemplate.js","sourceRoot":"","sources":["../../src/WrapIfAdditionalTemplate/WrapIfAdditionalTemplate.tsx"],"names":[],"mappings":";AACA,OAAO,IAAI,MAAM,oBAAoB,CAAC;AACtC,OAAO,SAAS,MAAM,yBAAyB,CAAC;AAChD,OAAO,EACL,wBAAwB,EAIxB,kBAAkB,GAEnB,MAAM,aAAa,CAAC;AAErB;;;;GAIG;AACH,MAAM,CAAC,OAAO,UAAU,wBAAwB,CAI9C,KAA6C;IAC7C,MAAM,EACJ,QAAQ,EACR,UAAU,EACV,KAAK,EACL,QAAQ,EACR,EAAE,EACF,KAAK,EACL,mBAAmB,EACnB,WAAW,EACX,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,QAAQ,EACR,QAAQ,GACT,GAAG,KAAK,CAAC;IACV,MAAM,EAAE,SAAS,EAAE,eAAe,EAAE,GAAG,QAAQ,CAAC;IAChD,sDAAsD;IACtD,MAAM,EAAE,YAAY,EAAE,GAAG,SAAS,CAAC,eAAe,CAAC;IACnD,MAAM,QAAQ,GAAG,eAAe,CAAC,kBAAkB,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;IACvE,MAAM,UAAU,GAAG,wBAAwB,IAAI,MAAM,CAAC;IACtD,MAAM,QAAQ,GAAkB;QAC9B,IAAI,EAAE,CAAC;QACP,WAAW,EAAE,CAAC;QACd,YAAY,EAAE,CAAC;QACf,UAAU,EAAE,MAAM;KACnB,CAAC;IAEF,IAAI,CAAC,UAAU,EAAE;QACf,OAAO,CACL,4BAAK,SAAS,EAAE,UAAU,EAAE,KAAK,EAAE,KAAK,gBACrC,QAAQ,IACL,CACP,CAAC;KACH;IAED,MAAM,UAAU,GAAG,CAAC,EAAE,MAAM,EAAgC,EAAE,EAAE,CAAC,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAE3F,OAAO,CACL,MAAC,IAAI,kBAAC,SAAS,QAAmB,UAAU,EAAC,QAAQ,EAAC,OAAO,EAAE,CAAC,EAAE,SAAS,EAAE,UAAU,EAAE,KAAK,EAAE,KAAK,iBACnG,KAAC,IAAI,kBAAC,IAAI,QAAC,EAAE,sBACX,KAAC,SAAS,IACR,SAAS,EAAE,IAAI,EACf,QAAQ,EAAE,QAAQ,EAClB,KAAK,EAAE,QAAQ,EACf,YAAY,EAAE,KAAK,EACnB,QAAQ,EAAE,QAAQ,IAAI,QAAQ,EAC9B,EAAE,EAAE,GAAG,EAAE,MAAM,EACf,IAAI,EAAE,GAAG,EAAE,MAAM,EACjB,MAAM,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,EAC1C,IAAI,EAAC,MAAM,GACX,IACG,EACP,KAAC,IAAI,kBAAC,IAAI,EAAE,IAAI,EAAE,EAAE,sBACjB,QAAQ,IACJ,EACP,KAAC,IAAI,kBAAC,IAAI,EAAE,IAAI,gBACd,KAAC,YAAY,IACX,QAAQ,EAAC,SAAS,EAClB,KAAK,EAAE,QAAQ,EACf,QAAQ,EAAE,QAAQ,IAAI,QAAQ,EAC9B,OAAO,EAAE,mBAAmB,CAAC,KAAK,CAAC,EACnC,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,QAAQ,GAClB,IACG,MA1BY,GAAG,EAAE,MAAM,CA2BzB,CACR,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/WrapIfAdditionalTemplate/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AACrD,cAAc,4BAA4B,CAAC"}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import MuiForm from './MuiForm/MuiForm';
|
|
2
|
+
export { default as Form, generateForm } from './MuiForm';
|
|
3
|
+
export { default as Templates, generateTemplates } from './Templates';
|
|
4
|
+
export { default as Theme, generateTheme } from './Theme';
|
|
5
|
+
export { default as Widgets, generateWidgets } from './Widgets';
|
|
6
|
+
export default MuiForm;
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import MuiForm from './MuiForm/MuiForm';
|
|
2
|
+
export { default as Form, generateForm } from './MuiForm';
|
|
3
|
+
export { default as Templates, generateTemplates } from './Templates';
|
|
4
|
+
export { default as Theme, generateTheme } from './Theme';
|
|
5
|
+
export { default as Widgets, generateWidgets } from './Widgets';
|
|
6
|
+
export default MuiForm;
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,mBAAmB,CAAC;AAExC,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAC1D,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACtE,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC1D,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAEhE,eAAe,OAAO,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rjsf/mui",
|
|
3
|
-
"version": "5.
|
|
4
|
-
"module": "./dist/mui.esm.js",
|
|
3
|
+
"version": "5.12.1",
|
|
5
4
|
"main": "./dist/index.js",
|
|
6
|
-
"
|
|
5
|
+
"module": "./lib/index.js",
|
|
6
|
+
"types": "./lib/index.d.ts",
|
|
7
7
|
"description": "Material UI 5 theme, fields and widgets for react-jsonschema-form",
|
|
8
8
|
"files": [
|
|
9
|
-
"dist"
|
|
9
|
+
"dist",
|
|
10
|
+
"lib",
|
|
11
|
+
"src"
|
|
10
12
|
],
|
|
11
13
|
"scripts": {
|
|
12
|
-
"build": "rimraf
|
|
14
|
+
"build:ts": "rimraf lib && tsc",
|
|
15
|
+
"build:cjs": "esbuild ./src/index.ts --bundle --outfile=dist/index.js --sourcemap --packages=external --format=cjs",
|
|
16
|
+
"build:esm": "esbuild ./src/index.ts --bundle --outfile=dist/mui.esm.js --sourcemap --packages=external --format=esm",
|
|
17
|
+
"build:umd": "rollup dist/mui.esm.js --format=umd --file=dist/mui.umd.js --name=@rjsf/mui",
|
|
18
|
+
"build": "rimraf dist && npm run build:ts && npm run build:cjs && npm run build:esm && npm run build:umd",
|
|
13
19
|
"cs-check": "prettier -l \"{src,test}/**/*.ts?(x)\"",
|
|
14
20
|
"cs-format": "prettier \"{src,test}/**/*.ts?(x)\" --write",
|
|
15
21
|
"lint": "eslint src test",
|
|
@@ -45,24 +51,26 @@
|
|
|
45
51
|
"@emotion/jest": "^11.11.0",
|
|
46
52
|
"@emotion/react": "^11.11.1",
|
|
47
53
|
"@emotion/styled": "^11.11.0",
|
|
48
|
-
"@mui/icons-material": "^5.14.
|
|
49
|
-
"@mui/material": "^5.14.
|
|
50
|
-
"@rjsf/core": "^5.
|
|
51
|
-
"@rjsf/utils": "^5.
|
|
52
|
-
"@rjsf/validator-ajv8": "^5.
|
|
54
|
+
"@mui/icons-material": "^5.14.3",
|
|
55
|
+
"@mui/material": "^5.14.3",
|
|
56
|
+
"@rjsf/core": "^5.12.1",
|
|
57
|
+
"@rjsf/utils": "^5.12.1",
|
|
58
|
+
"@rjsf/validator-ajv8": "^5.12.1",
|
|
53
59
|
"@types/react": "^17.0.62",
|
|
54
60
|
"@types/react-dom": "^17.0.20",
|
|
55
61
|
"@types/react-test-renderer": "^17.0.2",
|
|
56
|
-
"babel-jest": "^29.6.
|
|
57
|
-
"
|
|
58
|
-
"eslint": "^8.
|
|
59
|
-
"jest": "^29.6.
|
|
62
|
+
"babel-jest": "^29.6.2",
|
|
63
|
+
"esbuild": "^0.18.19",
|
|
64
|
+
"eslint": "^8.46.0",
|
|
65
|
+
"jest": "^29.6.2",
|
|
60
66
|
"jest-environment-jsdom": "^29.6.1",
|
|
61
67
|
"jest-watch-typeahead": "^2.2.2",
|
|
62
68
|
"react": "^17.0.2",
|
|
63
69
|
"react-dom": "^17.0.2",
|
|
64
70
|
"react-test-renderer": "^17.0.2",
|
|
65
|
-
"rimraf": "^5.0.1"
|
|
71
|
+
"rimraf": "^5.0.1",
|
|
72
|
+
"rollup": "^3.27.2",
|
|
73
|
+
"typescript": "^4.9.5"
|
|
66
74
|
},
|
|
67
75
|
"publishConfig": {
|
|
68
76
|
"access": "public"
|
|
@@ -90,5 +98,5 @@
|
|
|
90
98
|
"url": "git+https://github.com/rjsf-team/react-jsonschema-form.git"
|
|
91
99
|
},
|
|
92
100
|
"license": "Apache-2.0",
|
|
93
|
-
"gitHead": "
|
|
101
|
+
"gitHead": "de6477730fd16a07def501c2cb761af9c3f4c247"
|
|
94
102
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import AddIcon from '@mui/icons-material/Add';
|
|
2
|
+
import IconButton from '@mui/material/IconButton';
|
|
3
|
+
import { FormContextType, IconButtonProps, RJSFSchema, StrictRJSFSchema, TranslatableString } from '@rjsf/utils';
|
|
4
|
+
|
|
5
|
+
/** The `AddButton` renders a button that represent the `Add` action on a form
|
|
6
|
+
*/
|
|
7
|
+
export default function AddButton<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>({
|
|
8
|
+
uiSchema,
|
|
9
|
+
registry,
|
|
10
|
+
...props
|
|
11
|
+
}: IconButtonProps<T, S, F>) {
|
|
12
|
+
const { translateString } = registry;
|
|
13
|
+
return (
|
|
14
|
+
<IconButton title={translateString(TranslatableString.AddItemButton)} {...props} color='primary'>
|
|
15
|
+
<AddIcon />
|
|
16
|
+
</IconButton>
|
|
17
|
+
);
|
|
18
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { CSSProperties } from 'react';
|
|
2
|
+
import Box from '@mui/material/Box';
|
|
3
|
+
import Grid from '@mui/material/Grid';
|
|
4
|
+
import Paper from '@mui/material/Paper';
|
|
5
|
+
import { ArrayFieldTemplateItemType, FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
|
|
6
|
+
|
|
7
|
+
/** The `ArrayFieldItemTemplate` component is the template used to render an items of an array.
|
|
8
|
+
*
|
|
9
|
+
* @param props - The `ArrayFieldTemplateItemType` props for the component
|
|
10
|
+
*/
|
|
11
|
+
export default function ArrayFieldItemTemplate<
|
|
12
|
+
T = any,
|
|
13
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
14
|
+
F extends FormContextType = any
|
|
15
|
+
>(props: ArrayFieldTemplateItemType<T, S, F>) {
|
|
16
|
+
const {
|
|
17
|
+
children,
|
|
18
|
+
disabled,
|
|
19
|
+
hasToolbar,
|
|
20
|
+
hasCopy,
|
|
21
|
+
hasMoveDown,
|
|
22
|
+
hasMoveUp,
|
|
23
|
+
hasRemove,
|
|
24
|
+
index,
|
|
25
|
+
onCopyIndexClick,
|
|
26
|
+
onDropIndexClick,
|
|
27
|
+
onReorderClick,
|
|
28
|
+
readonly,
|
|
29
|
+
uiSchema,
|
|
30
|
+
registry,
|
|
31
|
+
} = props;
|
|
32
|
+
const { CopyButton, MoveDownButton, MoveUpButton, RemoveButton } = registry.templates.ButtonTemplates;
|
|
33
|
+
const btnStyle: CSSProperties = {
|
|
34
|
+
flex: 1,
|
|
35
|
+
paddingLeft: 6,
|
|
36
|
+
paddingRight: 6,
|
|
37
|
+
fontWeight: 'bold',
|
|
38
|
+
minWidth: 0,
|
|
39
|
+
};
|
|
40
|
+
return (
|
|
41
|
+
<Grid container={true} alignItems='center'>
|
|
42
|
+
<Grid item={true} xs style={{ overflow: 'auto' }}>
|
|
43
|
+
<Box mb={2}>
|
|
44
|
+
<Paper elevation={2}>
|
|
45
|
+
<Box p={2}>{children}</Box>
|
|
46
|
+
</Paper>
|
|
47
|
+
</Box>
|
|
48
|
+
</Grid>
|
|
49
|
+
{hasToolbar && (
|
|
50
|
+
<Grid item={true}>
|
|
51
|
+
{(hasMoveUp || hasMoveDown) && (
|
|
52
|
+
<MoveUpButton
|
|
53
|
+
style={btnStyle}
|
|
54
|
+
disabled={disabled || readonly || !hasMoveUp}
|
|
55
|
+
onClick={onReorderClick(index, index - 1)}
|
|
56
|
+
uiSchema={uiSchema}
|
|
57
|
+
registry={registry}
|
|
58
|
+
/>
|
|
59
|
+
)}
|
|
60
|
+
{(hasMoveUp || hasMoveDown) && (
|
|
61
|
+
<MoveDownButton
|
|
62
|
+
style={btnStyle}
|
|
63
|
+
disabled={disabled || readonly || !hasMoveDown}
|
|
64
|
+
onClick={onReorderClick(index, index + 1)}
|
|
65
|
+
uiSchema={uiSchema}
|
|
66
|
+
registry={registry}
|
|
67
|
+
/>
|
|
68
|
+
)}
|
|
69
|
+
{hasCopy && (
|
|
70
|
+
<CopyButton
|
|
71
|
+
style={btnStyle}
|
|
72
|
+
disabled={disabled || readonly}
|
|
73
|
+
onClick={onCopyIndexClick(index)}
|
|
74
|
+
uiSchema={uiSchema}
|
|
75
|
+
registry={registry}
|
|
76
|
+
/>
|
|
77
|
+
)}
|
|
78
|
+
{hasRemove && (
|
|
79
|
+
<RemoveButton
|
|
80
|
+
style={btnStyle}
|
|
81
|
+
disabled={disabled || readonly}
|
|
82
|
+
onClick={onDropIndexClick(index)}
|
|
83
|
+
uiSchema={uiSchema}
|
|
84
|
+
registry={registry}
|
|
85
|
+
/>
|
|
86
|
+
)}
|
|
87
|
+
</Grid>
|
|
88
|
+
)}
|
|
89
|
+
</Grid>
|
|
90
|
+
);
|
|
91
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import Box from '@mui/material/Box';
|
|
2
|
+
import Grid from '@mui/material/Grid';
|
|
3
|
+
import Paper from '@mui/material/Paper';
|
|
4
|
+
import {
|
|
5
|
+
getTemplate,
|
|
6
|
+
getUiOptions,
|
|
7
|
+
ArrayFieldTemplateProps,
|
|
8
|
+
ArrayFieldTemplateItemType,
|
|
9
|
+
FormContextType,
|
|
10
|
+
RJSFSchema,
|
|
11
|
+
StrictRJSFSchema,
|
|
12
|
+
} from '@rjsf/utils';
|
|
13
|
+
|
|
14
|
+
/** The `ArrayFieldTemplate` component is the template used to render all items in an array.
|
|
15
|
+
*
|
|
16
|
+
* @param props - The `ArrayFieldTemplateItemType` props for the component
|
|
17
|
+
*/
|
|
18
|
+
export default function ArrayFieldTemplate<
|
|
19
|
+
T = any,
|
|
20
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
21
|
+
F extends FormContextType = any
|
|
22
|
+
>(props: ArrayFieldTemplateProps<T, S, F>) {
|
|
23
|
+
const { canAdd, disabled, idSchema, uiSchema, items, onAddClick, readonly, registry, required, schema, title } =
|
|
24
|
+
props;
|
|
25
|
+
const uiOptions = getUiOptions<T, S, F>(uiSchema);
|
|
26
|
+
const ArrayFieldDescriptionTemplate = getTemplate<'ArrayFieldDescriptionTemplate', T, S, F>(
|
|
27
|
+
'ArrayFieldDescriptionTemplate',
|
|
28
|
+
registry,
|
|
29
|
+
uiOptions
|
|
30
|
+
);
|
|
31
|
+
const ArrayFieldItemTemplate = getTemplate<'ArrayFieldItemTemplate', T, S, F>(
|
|
32
|
+
'ArrayFieldItemTemplate',
|
|
33
|
+
registry,
|
|
34
|
+
uiOptions
|
|
35
|
+
);
|
|
36
|
+
const ArrayFieldTitleTemplate = getTemplate<'ArrayFieldTitleTemplate', T, S, F>(
|
|
37
|
+
'ArrayFieldTitleTemplate',
|
|
38
|
+
registry,
|
|
39
|
+
uiOptions
|
|
40
|
+
);
|
|
41
|
+
// Button templates are not overridden in the uiSchema
|
|
42
|
+
const {
|
|
43
|
+
ButtonTemplates: { AddButton },
|
|
44
|
+
} = registry.templates;
|
|
45
|
+
return (
|
|
46
|
+
<Paper elevation={2}>
|
|
47
|
+
<Box p={2}>
|
|
48
|
+
<ArrayFieldTitleTemplate
|
|
49
|
+
idSchema={idSchema}
|
|
50
|
+
title={uiOptions.title || title}
|
|
51
|
+
schema={schema}
|
|
52
|
+
uiSchema={uiSchema}
|
|
53
|
+
required={required}
|
|
54
|
+
registry={registry}
|
|
55
|
+
/>
|
|
56
|
+
<ArrayFieldDescriptionTemplate
|
|
57
|
+
idSchema={idSchema}
|
|
58
|
+
description={uiOptions.description || schema.description}
|
|
59
|
+
schema={schema}
|
|
60
|
+
uiSchema={uiSchema}
|
|
61
|
+
registry={registry}
|
|
62
|
+
/>
|
|
63
|
+
<Grid container={true} key={`array-item-list-${idSchema.$id}`}>
|
|
64
|
+
{items &&
|
|
65
|
+
items.map(({ key, ...itemProps }: ArrayFieldTemplateItemType<T, S, F>) => (
|
|
66
|
+
<ArrayFieldItemTemplate key={key} {...itemProps} />
|
|
67
|
+
))}
|
|
68
|
+
{canAdd && (
|
|
69
|
+
<Grid container justifyContent='flex-end'>
|
|
70
|
+
<Grid item={true}>
|
|
71
|
+
<Box mt={2}>
|
|
72
|
+
<AddButton
|
|
73
|
+
className='array-item-add'
|
|
74
|
+
onClick={onAddClick}
|
|
75
|
+
disabled={disabled || readonly}
|
|
76
|
+
uiSchema={uiSchema}
|
|
77
|
+
registry={registry}
|
|
78
|
+
/>
|
|
79
|
+
</Box>
|
|
80
|
+
</Grid>
|
|
81
|
+
</Grid>
|
|
82
|
+
)}
|
|
83
|
+
</Grid>
|
|
84
|
+
</Box>
|
|
85
|
+
</Paper>
|
|
86
|
+
);
|
|
87
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { ChangeEvent, FocusEvent } from 'react';
|
|
2
|
+
import TextField, { TextFieldProps } from '@mui/material/TextField';
|
|
3
|
+
import {
|
|
4
|
+
ariaDescribedByIds,
|
|
5
|
+
BaseInputTemplateProps,
|
|
6
|
+
examplesId,
|
|
7
|
+
getInputProps,
|
|
8
|
+
labelValue,
|
|
9
|
+
FormContextType,
|
|
10
|
+
RJSFSchema,
|
|
11
|
+
StrictRJSFSchema,
|
|
12
|
+
} from '@rjsf/utils';
|
|
13
|
+
|
|
14
|
+
const TYPES_THAT_SHRINK_LABEL = ['date', 'datetime-local', 'file', 'time'];
|
|
15
|
+
|
|
16
|
+
/** The `BaseInputTemplate` is the template to use to render the basic `<input>` component for the `core` theme.
|
|
17
|
+
* It is used as the template for rendering many of the <input> based widgets that differ by `type` and callbacks only.
|
|
18
|
+
* It can be customized/overridden for other themes or individual implementations as needed.
|
|
19
|
+
*
|
|
20
|
+
* @param props - The `WidgetProps` for this template
|
|
21
|
+
*/
|
|
22
|
+
export default function BaseInputTemplate<
|
|
23
|
+
T = any,
|
|
24
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
25
|
+
F extends FormContextType = any
|
|
26
|
+
>(props: BaseInputTemplateProps<T, S, F>) {
|
|
27
|
+
const {
|
|
28
|
+
id,
|
|
29
|
+
name, // remove this from textFieldProps
|
|
30
|
+
placeholder,
|
|
31
|
+
required,
|
|
32
|
+
readonly,
|
|
33
|
+
disabled,
|
|
34
|
+
type,
|
|
35
|
+
label,
|
|
36
|
+
hideLabel,
|
|
37
|
+
value,
|
|
38
|
+
onChange,
|
|
39
|
+
onChangeOverride,
|
|
40
|
+
onBlur,
|
|
41
|
+
onFocus,
|
|
42
|
+
autofocus,
|
|
43
|
+
options,
|
|
44
|
+
schema,
|
|
45
|
+
uiSchema,
|
|
46
|
+
rawErrors = [],
|
|
47
|
+
formContext,
|
|
48
|
+
registry,
|
|
49
|
+
InputLabelProps,
|
|
50
|
+
...textFieldProps
|
|
51
|
+
} = props;
|
|
52
|
+
const inputProps = getInputProps<T, S, F>(schema, type, options);
|
|
53
|
+
// Now we need to pull out the step, min, max into an inner `inputProps` for material-ui
|
|
54
|
+
const { step, min, max, ...rest } = inputProps;
|
|
55
|
+
const otherProps = {
|
|
56
|
+
inputProps: {
|
|
57
|
+
step,
|
|
58
|
+
min,
|
|
59
|
+
max,
|
|
60
|
+
...(schema.examples ? { list: examplesId<T>(id) } : undefined),
|
|
61
|
+
},
|
|
62
|
+
...rest,
|
|
63
|
+
};
|
|
64
|
+
const _onChange = ({ target: { value } }: ChangeEvent<HTMLInputElement>) =>
|
|
65
|
+
onChange(value === '' ? options.emptyValue : value);
|
|
66
|
+
const _onBlur = ({ target: { value } }: FocusEvent<HTMLInputElement>) => onBlur(id, value);
|
|
67
|
+
const _onFocus = ({ target: { value } }: FocusEvent<HTMLInputElement>) => onFocus(id, value);
|
|
68
|
+
const DisplayInputLabelProps = TYPES_THAT_SHRINK_LABEL.includes(type)
|
|
69
|
+
? {
|
|
70
|
+
...InputLabelProps,
|
|
71
|
+
shrink: true,
|
|
72
|
+
}
|
|
73
|
+
: InputLabelProps;
|
|
74
|
+
|
|
75
|
+
return (
|
|
76
|
+
<>
|
|
77
|
+
<TextField
|
|
78
|
+
id={id}
|
|
79
|
+
name={id}
|
|
80
|
+
placeholder={placeholder}
|
|
81
|
+
label={labelValue(label || undefined, hideLabel, false)}
|
|
82
|
+
autoFocus={autofocus}
|
|
83
|
+
required={required}
|
|
84
|
+
disabled={disabled || readonly}
|
|
85
|
+
{...otherProps}
|
|
86
|
+
value={value || value === 0 ? value : ''}
|
|
87
|
+
error={rawErrors.length > 0}
|
|
88
|
+
onChange={onChangeOverride || _onChange}
|
|
89
|
+
onBlur={_onBlur}
|
|
90
|
+
onFocus={_onFocus}
|
|
91
|
+
InputLabelProps={DisplayInputLabelProps}
|
|
92
|
+
{...(textFieldProps as TextFieldProps)}
|
|
93
|
+
aria-describedby={ariaDescribedByIds<T>(id, !!schema.examples)}
|
|
94
|
+
/>
|
|
95
|
+
{Array.isArray(schema.examples) && (
|
|
96
|
+
<datalist id={examplesId<T>(id)}>
|
|
97
|
+
{(schema.examples as string[])
|
|
98
|
+
.concat(schema.default && !schema.examples.includes(schema.default) ? ([schema.default] as string[]) : [])
|
|
99
|
+
.map((example: any) => {
|
|
100
|
+
return <option key={example} value={example} />;
|
|
101
|
+
})}
|
|
102
|
+
</datalist>
|
|
103
|
+
)}
|
|
104
|
+
</>
|
|
105
|
+
);
|
|
106
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { FocusEvent } from 'react';
|
|
2
|
+
import Checkbox from '@mui/material/Checkbox';
|
|
3
|
+
import FormControlLabel from '@mui/material/FormControlLabel';
|
|
4
|
+
import {
|
|
5
|
+
ariaDescribedByIds,
|
|
6
|
+
descriptionId,
|
|
7
|
+
getTemplate,
|
|
8
|
+
labelValue,
|
|
9
|
+
schemaRequiresTrueValue,
|
|
10
|
+
FormContextType,
|
|
11
|
+
RJSFSchema,
|
|
12
|
+
StrictRJSFSchema,
|
|
13
|
+
WidgetProps,
|
|
14
|
+
} from '@rjsf/utils';
|
|
15
|
+
|
|
16
|
+
/** The `CheckBoxWidget` is a widget for rendering boolean properties.
|
|
17
|
+
* It is typically used to represent a boolean.
|
|
18
|
+
*
|
|
19
|
+
* @param props - The `WidgetProps` for this component
|
|
20
|
+
*/
|
|
21
|
+
export default function CheckboxWidget<
|
|
22
|
+
T = any,
|
|
23
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
24
|
+
F extends FormContextType = any
|
|
25
|
+
>(props: WidgetProps<T, S, F>) {
|
|
26
|
+
const {
|
|
27
|
+
schema,
|
|
28
|
+
id,
|
|
29
|
+
value,
|
|
30
|
+
disabled,
|
|
31
|
+
readonly,
|
|
32
|
+
label = '',
|
|
33
|
+
hideLabel,
|
|
34
|
+
autofocus,
|
|
35
|
+
onChange,
|
|
36
|
+
onBlur,
|
|
37
|
+
onFocus,
|
|
38
|
+
registry,
|
|
39
|
+
options,
|
|
40
|
+
uiSchema,
|
|
41
|
+
} = props;
|
|
42
|
+
const DescriptionFieldTemplate = getTemplate<'DescriptionFieldTemplate', T, S, F>(
|
|
43
|
+
'DescriptionFieldTemplate',
|
|
44
|
+
registry,
|
|
45
|
+
options
|
|
46
|
+
);
|
|
47
|
+
// Because an unchecked checkbox will cause html5 validation to fail, only add
|
|
48
|
+
// the "required" attribute if the field value must be "true", due to the
|
|
49
|
+
// "const" or "enum" keywords
|
|
50
|
+
const required = schemaRequiresTrueValue<S>(schema);
|
|
51
|
+
|
|
52
|
+
const _onChange = (_: any, checked: boolean) => onChange(checked);
|
|
53
|
+
const _onBlur = ({ target: { value } }: FocusEvent<HTMLButtonElement>) => onBlur(id, value);
|
|
54
|
+
const _onFocus = ({ target: { value } }: FocusEvent<HTMLButtonElement>) => onFocus(id, value);
|
|
55
|
+
const description = options.description ?? schema.description;
|
|
56
|
+
|
|
57
|
+
return (
|
|
58
|
+
<>
|
|
59
|
+
{!hideLabel && !!description && (
|
|
60
|
+
<DescriptionFieldTemplate
|
|
61
|
+
id={descriptionId<T>(id)}
|
|
62
|
+
description={description}
|
|
63
|
+
schema={schema}
|
|
64
|
+
uiSchema={uiSchema}
|
|
65
|
+
registry={registry}
|
|
66
|
+
/>
|
|
67
|
+
)}
|
|
68
|
+
<FormControlLabel
|
|
69
|
+
control={
|
|
70
|
+
<Checkbox
|
|
71
|
+
id={id}
|
|
72
|
+
name={id}
|
|
73
|
+
checked={typeof value === 'undefined' ? false : Boolean(value)}
|
|
74
|
+
required={required}
|
|
75
|
+
disabled={disabled || readonly}
|
|
76
|
+
autoFocus={autofocus}
|
|
77
|
+
onChange={_onChange}
|
|
78
|
+
onBlur={_onBlur}
|
|
79
|
+
onFocus={_onFocus}
|
|
80
|
+
aria-describedby={ariaDescribedByIds<T>(id)}
|
|
81
|
+
/>
|
|
82
|
+
}
|
|
83
|
+
label={labelValue(label, hideLabel, false)}
|
|
84
|
+
/>
|
|
85
|
+
</>
|
|
86
|
+
);
|
|
87
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { ChangeEvent, FocusEvent } from 'react';
|
|
2
|
+
import Checkbox from '@mui/material/Checkbox';
|
|
3
|
+
import FormControlLabel from '@mui/material/FormControlLabel';
|
|
4
|
+
import FormGroup from '@mui/material/FormGroup';
|
|
5
|
+
import FormLabel from '@mui/material/FormLabel';
|
|
6
|
+
import {
|
|
7
|
+
ariaDescribedByIds,
|
|
8
|
+
enumOptionsDeselectValue,
|
|
9
|
+
enumOptionsIsSelected,
|
|
10
|
+
enumOptionsSelectValue,
|
|
11
|
+
enumOptionsValueForIndex,
|
|
12
|
+
labelValue,
|
|
13
|
+
optionId,
|
|
14
|
+
FormContextType,
|
|
15
|
+
WidgetProps,
|
|
16
|
+
RJSFSchema,
|
|
17
|
+
StrictRJSFSchema,
|
|
18
|
+
} from '@rjsf/utils';
|
|
19
|
+
|
|
20
|
+
/** The `CheckboxesWidget` is a widget for rendering checkbox groups.
|
|
21
|
+
* It is typically used to represent an array of enums.
|
|
22
|
+
*
|
|
23
|
+
* @param props - The `WidgetProps` for this component
|
|
24
|
+
*/
|
|
25
|
+
export default function CheckboxesWidget<
|
|
26
|
+
T = any,
|
|
27
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
28
|
+
F extends FormContextType = any
|
|
29
|
+
>({
|
|
30
|
+
label,
|
|
31
|
+
hideLabel,
|
|
32
|
+
id,
|
|
33
|
+
disabled,
|
|
34
|
+
options,
|
|
35
|
+
value,
|
|
36
|
+
autofocus,
|
|
37
|
+
readonly,
|
|
38
|
+
required,
|
|
39
|
+
onChange,
|
|
40
|
+
onBlur,
|
|
41
|
+
onFocus,
|
|
42
|
+
}: WidgetProps<T, S, F>) {
|
|
43
|
+
const { enumOptions, enumDisabled, inline, emptyValue } = options;
|
|
44
|
+
const checkboxesValues = Array.isArray(value) ? value : [value];
|
|
45
|
+
|
|
46
|
+
const _onChange =
|
|
47
|
+
(index: number) =>
|
|
48
|
+
({ target: { checked } }: ChangeEvent<HTMLInputElement>) => {
|
|
49
|
+
if (checked) {
|
|
50
|
+
onChange(enumOptionsSelectValue(index, checkboxesValues, enumOptions));
|
|
51
|
+
} else {
|
|
52
|
+
onChange(enumOptionsDeselectValue(index, checkboxesValues, enumOptions));
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const _onBlur = ({ target: { value } }: FocusEvent<HTMLButtonElement>) =>
|
|
57
|
+
onBlur(id, enumOptionsValueForIndex<S>(value, enumOptions, emptyValue));
|
|
58
|
+
const _onFocus = ({ target: { value } }: FocusEvent<HTMLButtonElement>) =>
|
|
59
|
+
onFocus(id, enumOptionsValueForIndex<S>(value, enumOptions, emptyValue));
|
|
60
|
+
|
|
61
|
+
return (
|
|
62
|
+
<>
|
|
63
|
+
{labelValue(
|
|
64
|
+
<FormLabel required={required} htmlFor={id}>
|
|
65
|
+
{label || undefined}
|
|
66
|
+
</FormLabel>,
|
|
67
|
+
hideLabel
|
|
68
|
+
)}
|
|
69
|
+
<FormGroup id={id} row={!!inline}>
|
|
70
|
+
{Array.isArray(enumOptions) &&
|
|
71
|
+
enumOptions.map((option, index: number) => {
|
|
72
|
+
const checked = enumOptionsIsSelected<S>(option.value, checkboxesValues);
|
|
73
|
+
const itemDisabled = Array.isArray(enumDisabled) && enumDisabled.indexOf(option.value) !== -1;
|
|
74
|
+
const checkbox = (
|
|
75
|
+
<Checkbox
|
|
76
|
+
id={optionId(id, index)}
|
|
77
|
+
name={id}
|
|
78
|
+
checked={checked}
|
|
79
|
+
disabled={disabled || itemDisabled || readonly}
|
|
80
|
+
autoFocus={autofocus && index === 0}
|
|
81
|
+
onChange={_onChange(index)}
|
|
82
|
+
onBlur={_onBlur}
|
|
83
|
+
onFocus={_onFocus}
|
|
84
|
+
aria-describedby={ariaDescribedByIds<T>(id)}
|
|
85
|
+
/>
|
|
86
|
+
);
|
|
87
|
+
return <FormControlLabel control={checkbox} key={index} label={option.label} />;
|
|
88
|
+
})}
|
|
89
|
+
</FormGroup>
|
|
90
|
+
</>
|
|
91
|
+
);
|
|
92
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import Typography from '@mui/material/Typography';
|
|
2
|
+
import { DescriptionFieldProps, FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
|
|
3
|
+
|
|
4
|
+
/** The `DescriptionField` is the template to use to render the description of a field
|
|
5
|
+
*
|
|
6
|
+
* @param props - The `DescriptionFieldProps` for this component
|
|
7
|
+
*/
|
|
8
|
+
export default function DescriptionField<
|
|
9
|
+
T = any,
|
|
10
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
11
|
+
F extends FormContextType = any
|
|
12
|
+
>(props: DescriptionFieldProps<T, S, F>) {
|
|
13
|
+
const { id, description } = props;
|
|
14
|
+
if (description) {
|
|
15
|
+
return (
|
|
16
|
+
<Typography id={id} variant='subtitle2' style={{ marginTop: '5px' }}>
|
|
17
|
+
{description}
|
|
18
|
+
</Typography>
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return null;
|
|
23
|
+
}
|