@rjsf/mui 6.5.1 → 6.5.2
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.cjs +181 -73
- package/dist/index.cjs.map +2 -2
- package/dist/mui.esm.js +181 -73
- package/dist/mui.esm.js.map +2 -2
- package/dist/mui.umd.js +181 -73
- package/lib/ArrayFieldItemTemplate/ArrayFieldItemTemplate.js +3 -3
- package/lib/ArrayFieldItemTemplate/ArrayFieldItemTemplate.js.map +1 -1
- package/lib/ArrayFieldTemplate/ArrayFieldTemplate.js +3 -3
- package/lib/ArrayFieldTemplate/ArrayFieldTemplate.js.map +1 -1
- package/lib/DescriptionField/DescriptionField.js +3 -4
- package/lib/DescriptionField/DescriptionField.js.map +1 -1
- package/lib/ErrorList/ErrorList.js +4 -4
- package/lib/ErrorList/ErrorList.js.map +1 -1
- package/lib/FieldHelpTemplate/FieldHelpTemplate.js +3 -4
- package/lib/FieldHelpTemplate/FieldHelpTemplate.js.map +1 -1
- package/lib/ObjectFieldTemplate/ObjectFieldTemplate.js +4 -4
- package/lib/ObjectFieldTemplate/ObjectFieldTemplate.js.map +1 -1
- package/lib/SubmitButton/SubmitButton.js +3 -3
- package/lib/SubmitButton/SubmitButton.js.map +1 -1
- package/lib/TitleField/TitleField.js +5 -5
- package/lib/TitleField/TitleField.js.map +1 -1
- package/lib/WrapIfAdditionalTemplate/WrapIfAdditionalTemplate.js +3 -5
- package/lib/WrapIfAdditionalTemplate/WrapIfAdditionalTemplate.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/util.d.ts +19 -0
- package/lib/util.js +9 -0
- package/lib/util.js.map +1 -1
- package/package.json +9 -9
- package/src/ArrayFieldItemTemplate/ArrayFieldItemTemplate.tsx +25 -9
- package/src/ArrayFieldTemplate/ArrayFieldTemplate.tsx +19 -7
- package/src/DescriptionField/DescriptionField.tsx +8 -4
- package/src/ErrorList/ErrorList.tsx +19 -9
- package/src/FieldHelpTemplate/FieldHelpTemplate.tsx +4 -5
- package/src/ObjectFieldTemplate/ObjectFieldTemplate.tsx +22 -6
- package/src/SubmitButton/SubmitButton.tsx +9 -4
- package/src/TitleField/TitleField.tsx +20 -8
- package/src/WrapIfAdditionalTemplate/WrapIfAdditionalTemplate.tsx +5 -7
- package/src/util.ts +36 -0
package/lib/util.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { FormContextType, RJSFSchema, StrictRJSFSchema, UIOptionsType, GenericObjectType } from '@rjsf/utils';
|
|
2
|
+
import { BoxProps, FormHelperTextProps, GridProps, PaperProps, SxProps, TypographyProps } from '@mui/material';
|
|
2
3
|
/**
|
|
3
4
|
* Extract props meant for MUI components from the `options` field of the `uiSchema`.
|
|
4
5
|
* @param {UIOptionsType} options - The options from the uiSchema
|
|
@@ -7,3 +8,21 @@ import { FormContextType, RJSFSchema, StrictRJSFSchema, UIOptionsType, GenericOb
|
|
|
7
8
|
* @returns {P}
|
|
8
9
|
*/
|
|
9
10
|
export declare function getMuiProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any, P extends GenericObjectType = GenericObjectType>(options: UIOptionsType<T, S, F>, propsToFilter?: string[], rjsfSlotPropsOnly?: boolean): P;
|
|
11
|
+
/**
|
|
12
|
+
* Merges default `sx` props with any `sx` provided on a MUI component's props, returning a value
|
|
13
|
+
* suitable for passing directly to the MUI `sx` prop.
|
|
14
|
+
*
|
|
15
|
+
* When `muiProps.sx` is an array (only valid for `GridProps`), the default sx object is prepended
|
|
16
|
+
* to produce an `sx` array, preserving MUI's array-merge semantics. Otherwise the two objects are
|
|
17
|
+
* shallow-merged, with `muiProps.sx` taking precedence over the `sxProps`.
|
|
18
|
+
*
|
|
19
|
+
* If `muiProps` is omitted the `sxProps`` are returned as-is.
|
|
20
|
+
*
|
|
21
|
+
* @param sxProps - The default sx styles to apply
|
|
22
|
+
* @param [muiProps] - The MUI component props that may contain a user-supplied `sx`
|
|
23
|
+
* @returns - The merged sx value
|
|
24
|
+
*/
|
|
25
|
+
export declare function computeSxProps<MuiProps extends GridProps>(sxProps: SxProps, muiProps: MuiProps & {
|
|
26
|
+
sx: any[];
|
|
27
|
+
}): MuiProps['sx'] | MuiProps['sx'][];
|
|
28
|
+
export declare function computeSxProps<MuiProps extends BoxProps | FormHelperTextProps | PaperProps | TypographyProps>(sxProps: SxProps, muiProps?: MuiProps): MuiProps['sx'];
|
package/lib/util.js
CHANGED
|
@@ -21,4 +21,13 @@ export function getMuiProps(options, propsToFilter, rjsfSlotPropsOnly) {
|
|
|
21
21
|
}
|
|
22
22
|
return muiProps;
|
|
23
23
|
}
|
|
24
|
+
export function computeSxProps(sxProps, muiProps) {
|
|
25
|
+
if (!muiProps) {
|
|
26
|
+
return sxProps;
|
|
27
|
+
}
|
|
28
|
+
if (Array.isArray(muiProps === null || muiProps === void 0 ? void 0 : muiProps.sx)) {
|
|
29
|
+
return [sxProps, ...muiProps.sx];
|
|
30
|
+
}
|
|
31
|
+
return { ...sxProps, ...muiProps === null || muiProps === void 0 ? void 0 : muiProps.sx };
|
|
32
|
+
}
|
|
24
33
|
//# sourceMappingURL=util.js.map
|
package/lib/util.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAIA;;;;;;GAMG;AACH,MAAM,UAAU,WAAW,CAKzB,OAA+B,EAAE,aAAwB,EAAE,iBAA2B;IACtF,MAAM,QAAQ,GAAG,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,GAAS,KAAK,EAAQ,CAAC;IAClD,IAAI,iBAAiB,EAAE,CAAC;QACtB,MAAM,EAAE,aAAa,EAAE,GAAG,QAAe,CAAC;QAC1C,OAAO,EAAE,aAAa,EAAkB,CAAC;IAC3C,CAAC;IACD,IAAI,aAAa,EAAE,CAAC;QAClB,OAAO,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC;aACzB,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,aAAa,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;aAC5C,MAAM,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;YACnB,GAAG,CAAC,GAAc,CAAC,GAAG,QAAQ,CAAC,GAAc,CAAC,CAAC;YAC/C,OAAO,GAAG,CAAC;QACb,CAAC,EAAE,EAAO,CAAC,CAAC;IAChB,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC;AAwBD,MAAM,UAAU,cAAc,CAE5B,OAAgB,EAAE,QAAmB;IACrC,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,OAAO,OAAO,CAAC;IACjB,CAAC;IACD,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,EAAE,CAAC,EAAE,CAAC;QAChC,OAAO,CAAC,OAAO,EAAE,GAAG,QAAQ,CAAC,EAAE,CAAC,CAAC;IACnC,CAAC;IACD,OAAO,EAAE,GAAG,OAAO,EAAE,GAAG,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,EAAE,EAAoB,CAAC;AAC3D,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rjsf/mui",
|
|
3
|
-
"version": "6.5.
|
|
3
|
+
"version": "6.5.2",
|
|
4
4
|
"main": "./dist/index.cjs",
|
|
5
5
|
"module": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -62,8 +62,8 @@
|
|
|
62
62
|
"peerDependencies": {
|
|
63
63
|
"@emotion/react": "^11.7.0",
|
|
64
64
|
"@emotion/styled": "^11.6.0",
|
|
65
|
-
"@mui/icons-material": "^7.0.0",
|
|
66
|
-
"@mui/material": "^7.0.0",
|
|
65
|
+
"@mui/icons-material": "^7.0.0 || ^9.0.0",
|
|
66
|
+
"@mui/material": "^7.0.0 || ^9.0.0",
|
|
67
67
|
"@rjsf/core": "^6.5.x",
|
|
68
68
|
"@rjsf/utils": "^6.5.x",
|
|
69
69
|
"react": ">=18"
|
|
@@ -72,12 +72,12 @@
|
|
|
72
72
|
"@emotion/jest": "^11.14.2",
|
|
73
73
|
"@emotion/react": "^11.14.0",
|
|
74
74
|
"@emotion/styled": "^11.14.1",
|
|
75
|
-
"@mui/icons-material": "^
|
|
76
|
-
"@mui/material": "^
|
|
77
|
-
"@rjsf/core": "6.5.
|
|
78
|
-
"@rjsf/snapshot-tests": "6.5.
|
|
79
|
-
"@rjsf/utils": "6.5.
|
|
80
|
-
"@rjsf/validator-ajv8": "6.5.
|
|
75
|
+
"@mui/icons-material": "^9.0.0",
|
|
76
|
+
"@mui/material": "^9.0.0",
|
|
77
|
+
"@rjsf/core": "6.5.2",
|
|
78
|
+
"@rjsf/snapshot-tests": "6.5.2",
|
|
79
|
+
"@rjsf/utils": "6.5.2",
|
|
80
|
+
"@rjsf/validator-ajv8": "6.5.2",
|
|
81
81
|
"eslint": "^8.57.1"
|
|
82
82
|
},
|
|
83
83
|
"publishConfig": {
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
StrictRJSFSchema,
|
|
12
12
|
GenericObjectType,
|
|
13
13
|
} from '@rjsf/utils';
|
|
14
|
-
import { getMuiProps } from '../util';
|
|
14
|
+
import { computeSxProps, getMuiProps } from '../util';
|
|
15
15
|
|
|
16
16
|
/** Properties available for the `rjsfSlotProps` target of the ArrayFieldItemTemplate. */
|
|
17
17
|
export interface ArrayFieldItemTemplateMuiProps extends GenericObjectType {
|
|
@@ -56,25 +56,41 @@ export default function ArrayFieldItemTemplate<
|
|
|
56
56
|
minWidth: 0,
|
|
57
57
|
};
|
|
58
58
|
|
|
59
|
-
const {
|
|
59
|
+
const {
|
|
60
|
+
rjsfSlotProps: {
|
|
61
|
+
arrayItemGridContainer,
|
|
62
|
+
arrayItemGridItem,
|
|
63
|
+
arrayItemInnerBox,
|
|
64
|
+
arrayItemOuterBox,
|
|
65
|
+
arrayItemPaper,
|
|
66
|
+
arrayItemToolbarGrid,
|
|
67
|
+
} = {},
|
|
68
|
+
} = getMuiProps<T, S, F, ArrayFieldItemTemplateMuiProps>(uiOptions);
|
|
60
69
|
|
|
61
70
|
return (
|
|
62
|
-
<Grid
|
|
71
|
+
<Grid
|
|
72
|
+
container
|
|
73
|
+
{...arrayItemGridContainer}
|
|
74
|
+
sx={computeSxProps<GridProps>({ alignItems: 'center' }, arrayItemGridContainer)}
|
|
75
|
+
>
|
|
63
76
|
<Grid
|
|
64
77
|
size={{ xs: 8, sm: 9, md: 10, lg: 11, xl: 11.25 }}
|
|
65
|
-
|
|
66
|
-
{
|
|
78
|
+
{...arrayItemGridItem}
|
|
79
|
+
sx={computeSxProps({ overflow: 'auto' }, arrayItemGridItem)}
|
|
67
80
|
>
|
|
68
|
-
<Box
|
|
69
|
-
<Paper elevation={2} {...
|
|
70
|
-
<Box
|
|
81
|
+
<Box {...arrayItemOuterBox} sx={computeSxProps<BoxProps>({ mb: 2 }, arrayItemOuterBox)}>
|
|
82
|
+
<Paper elevation={2} {...arrayItemPaper}>
|
|
83
|
+
<Box {...arrayItemInnerBox} sx={computeSxProps<BoxProps>({ p: 2 }, arrayItemInnerBox)}>
|
|
71
84
|
{children}
|
|
72
85
|
</Box>
|
|
73
86
|
</Paper>
|
|
74
87
|
</Box>
|
|
75
88
|
</Grid>
|
|
76
89
|
{hasToolbar && (
|
|
77
|
-
<Grid
|
|
90
|
+
<Grid
|
|
91
|
+
{...arrayItemToolbarGrid}
|
|
92
|
+
sx={computeSxProps<GridProps>({ mt: hasDescription ? -5 : -1.5 }, arrayItemToolbarGrid)}
|
|
93
|
+
>
|
|
78
94
|
<ArrayFieldItemButtonsTemplate {...buttonsProps} style={btnStyle} />
|
|
79
95
|
</Grid>
|
|
80
96
|
)}
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
buttonId,
|
|
12
12
|
GenericObjectType,
|
|
13
13
|
} from '@rjsf/utils';
|
|
14
|
-
import { getMuiProps } from '../util';
|
|
14
|
+
import { computeSxProps, getMuiProps } from '../util';
|
|
15
15
|
|
|
16
16
|
/** Properties available for the `rjsfSlotProps` target of the ArrayFieldTemplate. */
|
|
17
17
|
export interface ArrayFieldTemplateMuiProps extends GenericObjectType {
|
|
@@ -70,11 +70,19 @@ export default function ArrayFieldTemplate<
|
|
|
70
70
|
ButtonTemplates: { AddButton },
|
|
71
71
|
} = registry.templates;
|
|
72
72
|
|
|
73
|
-
const {
|
|
73
|
+
const {
|
|
74
|
+
rjsfSlotProps: {
|
|
75
|
+
arrayPaper,
|
|
76
|
+
arrayBox,
|
|
77
|
+
arrayAddButtonGridContainer,
|
|
78
|
+
arrayAddButtonGridItem,
|
|
79
|
+
arrayAddButtonBox,
|
|
80
|
+
} = {},
|
|
81
|
+
} = getMuiProps<T, S, F, ArrayFieldTemplateMuiProps>(uiOptions);
|
|
74
82
|
|
|
75
83
|
return (
|
|
76
|
-
<Paper elevation={2} {...
|
|
77
|
-
<Box
|
|
84
|
+
<Paper elevation={2} {...arrayPaper}>
|
|
85
|
+
<Box {...arrayBox} sx={computeSxProps<BoxProps>({ p: 2 }, arrayBox)}>
|
|
78
86
|
<ArrayFieldTitleTemplate
|
|
79
87
|
fieldPathId={fieldPathId}
|
|
80
88
|
title={uiOptions.title || title}
|
|
@@ -94,9 +102,13 @@ export default function ArrayFieldTemplate<
|
|
|
94
102
|
{!showOptionalDataControlInTitle ? optionalDataControl : undefined}
|
|
95
103
|
{items}
|
|
96
104
|
{canAdd && (
|
|
97
|
-
<Grid
|
|
98
|
-
|
|
99
|
-
|
|
105
|
+
<Grid
|
|
106
|
+
container
|
|
107
|
+
{...arrayAddButtonGridContainer}
|
|
108
|
+
sx={computeSxProps<GridProps>({ justifyContent: 'flex-end' }, arrayAddButtonGridContainer)}
|
|
109
|
+
>
|
|
110
|
+
<Grid {...arrayAddButtonGridItem}>
|
|
111
|
+
<Box {...arrayAddButtonBox} sx={computeSxProps<BoxProps>({ mt: 2 }, arrayAddButtonBox)}>
|
|
100
112
|
<AddButton
|
|
101
113
|
id={buttonId(fieldPathId, 'add')}
|
|
102
114
|
className='rjsf-array-item-add'
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
getUiOptions,
|
|
9
9
|
} from '@rjsf/utils';
|
|
10
10
|
import { RichDescription } from '@rjsf/core';
|
|
11
|
-
import { getMuiProps } from '../util';
|
|
11
|
+
import { computeSxProps, getMuiProps } from '../util';
|
|
12
12
|
|
|
13
13
|
/** Properties available for the `rjsfSlotProps` target of the DescriptionField. */
|
|
14
14
|
export interface DescriptionFieldMuiProps extends GenericObjectType {
|
|
@@ -31,12 +31,16 @@ export default function DescriptionField<
|
|
|
31
31
|
const { id, description, registry, uiSchema } = props;
|
|
32
32
|
|
|
33
33
|
const uiOptions = getUiOptions<T, S, F>(uiSchema);
|
|
34
|
-
const
|
|
35
|
-
const { rjsfSlotProps: muiSlotProps } = muiProps;
|
|
34
|
+
const { rjsfSlotProps: { descTypography } = {} } = getMuiProps<T, S, F, DescriptionFieldMuiProps>(uiOptions);
|
|
36
35
|
|
|
37
36
|
if (description) {
|
|
38
37
|
return (
|
|
39
|
-
<Typography
|
|
38
|
+
<Typography
|
|
39
|
+
id={id}
|
|
40
|
+
variant='subtitle2'
|
|
41
|
+
{...descTypography}
|
|
42
|
+
sx={computeSxProps<TypographyProps>({ mt: 0.625 }, descTypography)}
|
|
43
|
+
>
|
|
40
44
|
<RichDescription description={description} registry={registry} uiSchema={uiSchema} />
|
|
41
45
|
</Typography>
|
|
42
46
|
);
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
TranslatableString,
|
|
16
16
|
getUiOptions,
|
|
17
17
|
} from '@rjsf/utils';
|
|
18
|
-
import { getMuiProps } from '../util';
|
|
18
|
+
import { computeSxProps, getMuiProps } from '../util';
|
|
19
19
|
|
|
20
20
|
/** Properties available for the `rjsfSlotProps` target of the ErrorList. */
|
|
21
21
|
export interface ErrorListMuiProps extends GenericObjectType {
|
|
@@ -50,22 +50,32 @@ export default function ErrorList<T = any, S extends StrictRJSFSchema = RJSFSche
|
|
|
50
50
|
const { translateString } = registry;
|
|
51
51
|
|
|
52
52
|
const uiOptions = getUiOptions<T, S, F>(uiSchema);
|
|
53
|
-
const {
|
|
53
|
+
const {
|
|
54
|
+
rjsfSlotProps: {
|
|
55
|
+
errorPaper,
|
|
56
|
+
errorBox,
|
|
57
|
+
errorTypography,
|
|
58
|
+
errorList,
|
|
59
|
+
errorListItem,
|
|
60
|
+
errorListItemIcon,
|
|
61
|
+
errorListItemText,
|
|
62
|
+
} = {},
|
|
63
|
+
} = getMuiProps<T, S, F, ErrorListMuiProps>(uiOptions);
|
|
54
64
|
|
|
55
65
|
return (
|
|
56
|
-
<Paper elevation={2} {...
|
|
57
|
-
<Box
|
|
58
|
-
<Typography variant='h6' {...
|
|
66
|
+
<Paper elevation={2} {...errorPaper}>
|
|
67
|
+
<Box {...errorBox} sx={computeSxProps<BoxProps>({ mb: 2, p: 2 }, errorBox)}>
|
|
68
|
+
<Typography variant='h6' {...errorTypography}>
|
|
59
69
|
{translateString(TranslatableString.ErrorsLabel)}
|
|
60
70
|
</Typography>
|
|
61
|
-
<List dense={true} {...
|
|
71
|
+
<List dense={true} {...errorList}>
|
|
62
72
|
{errors.map((error, i: number) => {
|
|
63
73
|
return (
|
|
64
|
-
<ListItem key={i} {...
|
|
65
|
-
<ListItemIcon {...
|
|
74
|
+
<ListItem key={i} {...errorListItem}>
|
|
75
|
+
<ListItemIcon {...errorListItemIcon}>
|
|
66
76
|
<ErrorIcon color='error' />
|
|
67
77
|
</ListItemIcon>
|
|
68
|
-
<ListItemText primary={error.stack} {...
|
|
78
|
+
<ListItemText primary={error.stack} {...errorListItemText} />
|
|
69
79
|
</ListItem>
|
|
70
80
|
);
|
|
71
81
|
})}
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
GenericObjectType,
|
|
10
10
|
} from '@rjsf/utils';
|
|
11
11
|
import FormHelperText, { FormHelperTextProps } from '@mui/material/FormHelperText';
|
|
12
|
-
import { getMuiProps } from '../util';
|
|
12
|
+
import { computeSxProps, getMuiProps } from '../util';
|
|
13
13
|
|
|
14
14
|
/** Properties available for the `rjsfSlotProps` target of the FieldHelpTemplate. */
|
|
15
15
|
export interface FieldHelpTemplateMuiProps extends GenericObjectType {
|
|
@@ -35,15 +35,14 @@ export default function FieldHelpTemplate<
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
const uiOptions = getUiOptions<T, S, F>(uiSchema);
|
|
38
|
-
const
|
|
39
|
-
const { rjsfSlotProps: muiSlotProps } = muiProps;
|
|
38
|
+
const { rjsfSlotProps: { helpFormHelperText } = {} } = getMuiProps<T, S, F, FieldHelpTemplateMuiProps>(uiOptions);
|
|
40
39
|
|
|
41
40
|
return (
|
|
42
41
|
<FormHelperText
|
|
43
42
|
component='div'
|
|
44
43
|
id={helpId(fieldPathId)}
|
|
45
|
-
|
|
46
|
-
{
|
|
44
|
+
{...helpFormHelperText}
|
|
45
|
+
sx={computeSxProps<FormHelperTextProps>({ mt: 0.625 }, helpFormHelperText)}
|
|
47
46
|
>
|
|
48
47
|
<RichHelp help={help} registry={registry} uiSchema={uiSchema} />
|
|
49
48
|
</FormHelperText>
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
titleId,
|
|
13
13
|
buttonId,
|
|
14
14
|
} from '@rjsf/utils';
|
|
15
|
-
import { getMuiProps } from '../util';
|
|
15
|
+
import { computeSxProps, getMuiProps } from '../util';
|
|
16
16
|
|
|
17
17
|
/** Properties available for the `rjsfSlotProps` target of the ObjectFieldTemplate. */
|
|
18
18
|
export interface ObjectFieldTemplateMuiProps extends GenericObjectType {
|
|
@@ -68,7 +68,9 @@ export default function ObjectFieldTemplate<
|
|
|
68
68
|
ButtonTemplates: { AddButton },
|
|
69
69
|
} = registry.templates;
|
|
70
70
|
|
|
71
|
-
const {
|
|
71
|
+
const {
|
|
72
|
+
rjsfSlotProps: { objectGridContainer, objectGridItem, objectAddButtonGridContainer, objectAddButtonGridItem } = {},
|
|
73
|
+
} = getMuiProps<T, S, F, ObjectFieldTemplateMuiProps>(uiOptions);
|
|
72
74
|
|
|
73
75
|
return (
|
|
74
76
|
<>
|
|
@@ -92,7 +94,12 @@ export default function ObjectFieldTemplate<
|
|
|
92
94
|
registry={registry}
|
|
93
95
|
/>
|
|
94
96
|
)}
|
|
95
|
-
<Grid
|
|
97
|
+
<Grid
|
|
98
|
+
container
|
|
99
|
+
spacing={2}
|
|
100
|
+
{...objectGridContainer}
|
|
101
|
+
sx={computeSxProps<GridProps>({ mt: 1.25 }, objectGridContainer)}
|
|
102
|
+
>
|
|
96
103
|
{!showOptionalDataControlInTitle ? optionalDataControl : undefined}
|
|
97
104
|
{properties.map((element, index) =>
|
|
98
105
|
// Remove the <Grid> if the inner element is hidden as the <Grid>
|
|
@@ -100,15 +107,24 @@ export default function ObjectFieldTemplate<
|
|
|
100
107
|
element.hidden ? (
|
|
101
108
|
element.content
|
|
102
109
|
) : (
|
|
103
|
-
<Grid
|
|
110
|
+
<Grid
|
|
111
|
+
size={{ xs: 12 }}
|
|
112
|
+
key={index}
|
|
113
|
+
{...objectGridItem}
|
|
114
|
+
sx={computeSxProps<GridProps>({ mb: 1.25 }, objectGridItem)}
|
|
115
|
+
>
|
|
104
116
|
{element.content}
|
|
105
117
|
</Grid>
|
|
106
118
|
),
|
|
107
119
|
)}
|
|
108
120
|
</Grid>
|
|
109
121
|
{canExpand<T, S, F>(schema, uiSchema, formData) && (
|
|
110
|
-
<Grid
|
|
111
|
-
|
|
122
|
+
<Grid
|
|
123
|
+
container
|
|
124
|
+
{...objectAddButtonGridContainer}
|
|
125
|
+
sx={computeSxProps<GridProps>({ justifyContent: 'flex-end' }, objectAddButtonGridContainer)}
|
|
126
|
+
>
|
|
127
|
+
<Grid {...objectAddButtonGridItem}>
|
|
112
128
|
<AddButton
|
|
113
129
|
id={buttonId(fieldPathId, 'add')}
|
|
114
130
|
className='rjsf-object-property-expand'
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
SubmitButtonProps,
|
|
10
10
|
getUiOptions,
|
|
11
11
|
} from '@rjsf/utils';
|
|
12
|
-
import { getMuiProps } from '../util';
|
|
12
|
+
import { computeSxProps, getMuiProps } from '../util';
|
|
13
13
|
|
|
14
14
|
/** Properties available for the `rjsfSlotProps` target of the SubmitButton. */
|
|
15
15
|
export interface SubmitButtonMuiProps extends GenericObjectType {
|
|
@@ -35,17 +35,22 @@ export default function SubmitButton<
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
const uiOptions = getUiOptions<T, S, F>(uiSchema);
|
|
38
|
-
const { rjsfSlotProps:
|
|
38
|
+
const { rjsfSlotProps: { submitBox, submitButton } = {}, ...otherMuiProps } = getMuiProps<
|
|
39
|
+
T,
|
|
40
|
+
S,
|
|
41
|
+
F,
|
|
42
|
+
SubmitButtonMuiProps
|
|
43
|
+
>(uiOptions);
|
|
39
44
|
|
|
40
45
|
return (
|
|
41
|
-
<Box
|
|
46
|
+
<Box {...submitBox} sx={computeSxProps<BoxProps>({ mt: 3 }, submitBox)}>
|
|
42
47
|
<Button
|
|
43
48
|
type='submit'
|
|
44
49
|
variant='contained'
|
|
45
50
|
color='primary'
|
|
46
51
|
{...submitButtonProps}
|
|
47
52
|
{...otherMuiProps}
|
|
48
|
-
{...
|
|
53
|
+
{...submitButton}
|
|
49
54
|
>
|
|
50
55
|
{submitText}
|
|
51
56
|
</Button>
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
StrictRJSFSchema,
|
|
11
11
|
getUiOptions,
|
|
12
12
|
} from '@rjsf/utils';
|
|
13
|
-
import { getMuiProps } from '../util';
|
|
13
|
+
import { computeSxProps, getMuiProps } from '../util';
|
|
14
14
|
|
|
15
15
|
/** Properties available for the `rjsfSlotProps` target of the TitleField. */
|
|
16
16
|
export interface TitleFieldMuiProps extends GenericObjectType {
|
|
@@ -41,29 +41,41 @@ export default function TitleField<T = any, S extends StrictRJSFSchema = RJSFSch
|
|
|
41
41
|
const { id, title, optionalDataControl, uiSchema } = props;
|
|
42
42
|
|
|
43
43
|
const uiOptions = getUiOptions<T, S, F>(uiSchema);
|
|
44
|
-
const {
|
|
44
|
+
const {
|
|
45
|
+
rjsfSlotProps: {
|
|
46
|
+
titleBox,
|
|
47
|
+
titleDivider,
|
|
48
|
+
titleTypography,
|
|
49
|
+
titleGridContainer,
|
|
50
|
+
titleGridItem,
|
|
51
|
+
titleOptionalDataGridItem,
|
|
52
|
+
} = {},
|
|
53
|
+
} = getMuiProps<T, S, F, TitleFieldMuiProps>(uiOptions);
|
|
45
54
|
|
|
46
55
|
let heading = (
|
|
47
|
-
<Typography variant='h5' {...
|
|
56
|
+
<Typography variant='h5' {...titleTypography}>
|
|
48
57
|
{title}
|
|
49
58
|
</Typography>
|
|
50
59
|
);
|
|
51
60
|
if (optionalDataControl) {
|
|
52
61
|
heading = (
|
|
53
|
-
<Grid container={true} spacing={0} {...
|
|
54
|
-
<Grid size='grow' {...
|
|
62
|
+
<Grid container={true} spacing={0} {...titleGridContainer}>
|
|
63
|
+
<Grid size='grow' {...titleGridItem}>
|
|
55
64
|
{heading}
|
|
56
65
|
</Grid>
|
|
57
|
-
<Grid
|
|
66
|
+
<Grid
|
|
67
|
+
{...titleOptionalDataGridItem}
|
|
68
|
+
sx={computeSxProps<GridProps>({ justifyContent: 'flex-end' }, titleOptionalDataGridItem)}
|
|
69
|
+
>
|
|
58
70
|
{optionalDataControl}
|
|
59
71
|
</Grid>
|
|
60
72
|
</Grid>
|
|
61
73
|
);
|
|
62
74
|
}
|
|
63
75
|
return (
|
|
64
|
-
<Box id={id}
|
|
76
|
+
<Box id={id} {...titleBox} sx={computeSxProps<BoxProps>({ mb: 1, mt: 1 }, titleBox)}>
|
|
65
77
|
{heading}
|
|
66
|
-
<Divider {...
|
|
78
|
+
<Divider {...titleDivider} />
|
|
67
79
|
</Box>
|
|
68
80
|
);
|
|
69
81
|
}
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
WrapIfAdditionalTemplateProps,
|
|
13
13
|
getUiOptions,
|
|
14
14
|
} from '@rjsf/utils';
|
|
15
|
-
import { getMuiProps } from '../util';
|
|
15
|
+
import { computeSxProps, getMuiProps } from '../util';
|
|
16
16
|
/** Properties available for the `rjsfSlotProps` target of the WrapIfAdditionalTemplate. */
|
|
17
17
|
export interface WrapIfAdditionalTemplateMuiProps extends GenericObjectType {
|
|
18
18
|
/** RJSF-specific slot props for targeting child elements of the WrapIfAdditionalTemplate. */
|
|
@@ -67,8 +67,8 @@ export default function WrapIfAdditionalTemplate<
|
|
|
67
67
|
};
|
|
68
68
|
|
|
69
69
|
const uiOptions = getUiOptions<T, S, F>(uiSchema);
|
|
70
|
-
const { rjsfSlotProps
|
|
71
|
-
|
|
70
|
+
const { rjsfSlotProps: { wrapGridContainer, wrapKeyGridItem, wrapChildrenGridItem, wrapRemoveButtonGridItem } = {} } =
|
|
71
|
+
getMuiProps<T, S, F, WrapIfAdditionalTemplateMuiProps>(uiOptions);
|
|
72
72
|
|
|
73
73
|
if (!additional) {
|
|
74
74
|
return (
|
|
@@ -78,17 +78,15 @@ export default function WrapIfAdditionalTemplate<
|
|
|
78
78
|
);
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
const { wrapGridContainer, wrapKeyGridItem, wrapChildrenGridItem, wrapRemoveButtonGridItem } = muiSlotProps || {};
|
|
82
|
-
|
|
83
81
|
return (
|
|
84
82
|
<Grid
|
|
85
83
|
container
|
|
86
84
|
key={`${id}-key`}
|
|
87
|
-
alignItems='flex-start'
|
|
88
85
|
spacing={2}
|
|
89
86
|
className={classNames}
|
|
90
87
|
style={style}
|
|
91
88
|
{...wrapGridContainer}
|
|
89
|
+
sx={computeSxProps<GridProps>({ alignItems: 'flex-start' }, wrapGridContainer)}
|
|
92
90
|
>
|
|
93
91
|
<Grid size={5.5} {...wrapKeyGridItem}>
|
|
94
92
|
<TextField
|
|
@@ -107,7 +105,7 @@ export default function WrapIfAdditionalTemplate<
|
|
|
107
105
|
<Grid size={5.5} {...wrapChildrenGridItem}>
|
|
108
106
|
{children}
|
|
109
107
|
</Grid>
|
|
110
|
-
<Grid sx={{ mt: 1.5 }
|
|
108
|
+
<Grid {...wrapRemoveButtonGridItem} sx={computeSxProps<GridProps>({ mt: 1.5 }, wrapRemoveButtonGridItem)}>
|
|
111
109
|
<RemoveButton
|
|
112
110
|
id={buttonId(id, 'remove')}
|
|
113
111
|
className='rjsf-object-property-remove'
|
package/src/util.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { FormContextType, RJSFSchema, StrictRJSFSchema, UIOptionsType, GenericObjectType } from '@rjsf/utils';
|
|
2
2
|
|
|
3
|
+
import { BoxProps, FormHelperTextProps, GridProps, PaperProps, SxProps, TypographyProps } from '@mui/material';
|
|
4
|
+
|
|
3
5
|
/**
|
|
4
6
|
* Extract props meant for MUI components from the `options` field of the `uiSchema`.
|
|
5
7
|
* @param {UIOptionsType} options - The options from the uiSchema
|
|
@@ -28,3 +30,37 @@ export function getMuiProps<
|
|
|
28
30
|
}
|
|
29
31
|
return muiProps;
|
|
30
32
|
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Merges default `sx` props with any `sx` provided on a MUI component's props, returning a value
|
|
36
|
+
* suitable for passing directly to the MUI `sx` prop.
|
|
37
|
+
*
|
|
38
|
+
* When `muiProps.sx` is an array (only valid for `GridProps`), the default sx object is prepended
|
|
39
|
+
* to produce an `sx` array, preserving MUI's array-merge semantics. Otherwise the two objects are
|
|
40
|
+
* shallow-merged, with `muiProps.sx` taking precedence over the `sxProps`.
|
|
41
|
+
*
|
|
42
|
+
* If `muiProps` is omitted the `sxProps`` are returned as-is.
|
|
43
|
+
*
|
|
44
|
+
* @param sxProps - The default sx styles to apply
|
|
45
|
+
* @param [muiProps] - The MUI component props that may contain a user-supplied `sx`
|
|
46
|
+
* @returns - The merged sx value
|
|
47
|
+
*/
|
|
48
|
+
export function computeSxProps<MuiProps extends GridProps>(
|
|
49
|
+
sxProps: SxProps,
|
|
50
|
+
muiProps: MuiProps & { sx: any[] },
|
|
51
|
+
): MuiProps['sx'] | MuiProps['sx'][];
|
|
52
|
+
export function computeSxProps<MuiProps extends BoxProps | FormHelperTextProps | PaperProps | TypographyProps>(
|
|
53
|
+
sxProps: SxProps,
|
|
54
|
+
muiProps?: MuiProps,
|
|
55
|
+
): MuiProps['sx'];
|
|
56
|
+
export function computeSxProps<
|
|
57
|
+
MuiProps extends BoxProps | FormHelperTextProps | GridProps | PaperProps | TypographyProps,
|
|
58
|
+
>(sxProps: SxProps, muiProps?: MuiProps): MuiProps['sx'] | MuiProps['sx'][] {
|
|
59
|
+
if (!muiProps) {
|
|
60
|
+
return sxProps;
|
|
61
|
+
}
|
|
62
|
+
if (Array.isArray(muiProps?.sx)) {
|
|
63
|
+
return [sxProps, ...muiProps.sx];
|
|
64
|
+
}
|
|
65
|
+
return { ...sxProps, ...muiProps?.sx } as MuiProps['sx'];
|
|
66
|
+
}
|