@rjsf/mui 6.4.1 → 6.5.0
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/README.md +25 -0
- package/dist/index.cjs +353 -214
- package/dist/index.cjs.map +4 -4
- package/dist/mui.esm.js +354 -185
- package/dist/mui.esm.js.map +4 -4
- package/dist/mui.umd.js +293 -165
- package/lib/AddButton/AddButton.js +12 -2
- package/lib/AddButton/AddButton.js.map +1 -1
- package/lib/ArrayFieldItemTemplate/ArrayFieldItemTemplate.d.ts +22 -1
- package/lib/ArrayFieldItemTemplate/ArrayFieldItemTemplate.js +3 -1
- package/lib/ArrayFieldItemTemplate/ArrayFieldItemTemplate.js.map +1 -1
- package/lib/ArrayFieldTemplate/ArrayFieldTemplate.d.ts +20 -1
- package/lib/ArrayFieldTemplate/ArrayFieldTemplate.js +3 -1
- package/lib/ArrayFieldTemplate/ArrayFieldTemplate.js.map +1 -1
- package/lib/BaseInputTemplate/BaseInputTemplate.d.ts +17 -1
- package/lib/BaseInputTemplate/BaseInputTemplate.js +9 -4
- package/lib/BaseInputTemplate/BaseInputTemplate.js.map +1 -1
- package/lib/CheckboxWidget/CheckboxWidget.d.ts +13 -1
- package/lib/CheckboxWidget/CheckboxWidget.js +3 -1
- package/lib/CheckboxWidget/CheckboxWidget.js.map +1 -1
- package/lib/CheckboxesWidget/CheckboxesWidget.d.ts +17 -2
- package/lib/CheckboxesWidget/CheckboxesWidget.js +12 -7
- package/lib/CheckboxesWidget/CheckboxesWidget.js.map +1 -1
- package/lib/DescriptionField/DescriptionField.d.ts +10 -1
- package/lib/DescriptionField/DescriptionField.js +6 -1
- package/lib/DescriptionField/DescriptionField.js.map +1 -1
- package/lib/ErrorList/ErrorList.d.ts +29 -2
- package/lib/ErrorList/ErrorList.js +7 -4
- package/lib/ErrorList/ErrorList.js.map +1 -1
- package/lib/FieldErrorTemplate/FieldErrorTemplate.d.ts +16 -1
- package/lib/FieldErrorTemplate/FieldErrorTemplate.js +8 -4
- package/lib/FieldErrorTemplate/FieldErrorTemplate.js.map +1 -1
- package/lib/FieldHelpTemplate/FieldHelpTemplate.d.ts +10 -1
- package/lib/FieldHelpTemplate/FieldHelpTemplate.js +6 -2
- package/lib/FieldHelpTemplate/FieldHelpTemplate.js.map +1 -1
- package/lib/FieldTemplate/FieldTemplate.d.ts +13 -1
- package/lib/FieldTemplate/FieldTemplate.js +3 -1
- package/lib/FieldTemplate/FieldTemplate.js.map +1 -1
- package/lib/IconButton/IconButton.js +12 -2
- package/lib/IconButton/IconButton.js.map +1 -1
- package/lib/MultiSchemaFieldTemplate/MultiSchemaFieldTemplate.d.ts +13 -1
- package/lib/MultiSchemaFieldTemplate/MultiSchemaFieldTemplate.js +6 -2
- package/lib/MultiSchemaFieldTemplate/MultiSchemaFieldTemplate.js.map +1 -1
- package/lib/ObjectFieldTemplate/ObjectFieldTemplate.d.ts +16 -1
- package/lib/ObjectFieldTemplate/ObjectFieldTemplate.js +4 -2
- package/lib/ObjectFieldTemplate/ObjectFieldTemplate.js.map +1 -1
- package/lib/OptionalDataControlsTemplate/OptionalDataControlsTemplate.js +3 -3
- package/lib/OptionalDataControlsTemplate/OptionalDataControlsTemplate.js.map +1 -1
- package/lib/RadioWidget/RadioWidget.d.ts +17 -2
- package/lib/RadioWidget/RadioWidget.js +13 -9
- package/lib/RadioWidget/RadioWidget.js.map +1 -1
- package/lib/RangeWidget/RangeWidget.d.ts +10 -1
- package/lib/RangeWidget/RangeWidget.js +3 -1
- package/lib/RangeWidget/RangeWidget.js.map +1 -1
- package/lib/SelectWidget/SelectWidget.d.ts +14 -3
- package/lib/SelectWidget/SelectWidget.js +26 -19
- package/lib/SelectWidget/SelectWidget.js.map +1 -1
- package/lib/SubmitButton/SubmitButton.d.ts +13 -1
- package/lib/SubmitButton/SubmitButton.js +5 -2
- package/lib/SubmitButton/SubmitButton.js.map +1 -1
- package/lib/TitleField/TitleField.d.ts +24 -2
- package/lib/TitleField/TitleField.js +9 -4
- package/lib/TitleField/TitleField.js.map +1 -1
- package/lib/WrapIfAdditionalTemplate/WrapIfAdditionalTemplate.d.ts +16 -1
- package/lib/WrapIfAdditionalTemplate/WrapIfAdditionalTemplate.js +7 -2
- package/lib/WrapIfAdditionalTemplate/WrapIfAdditionalTemplate.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/util.d.ts +9 -0
- package/lib/util.js +24 -0
- package/lib/util.js.map +1 -0
- package/package.json +7 -7
- package/src/AddButton/AddButton.tsx +21 -3
- package/src/ArrayFieldItemTemplate/ArrayFieldItemTemplate.tsx +39 -9
- package/src/ArrayFieldTemplate/ArrayFieldTemplate.tsx +30 -8
- package/src/BaseInputTemplate/BaseInputTemplate.tsx +29 -5
- package/src/CheckboxWidget/CheckboxWidget.tsx +20 -2
- package/src/CheckboxesWidget/CheckboxesWidget.tsx +51 -23
- package/src/DescriptionField/DescriptionField.tsx +25 -3
- package/src/ErrorList/ErrorList.tsx +52 -15
- package/src/FieldErrorTemplate/FieldErrorTemplate.tsx +34 -8
- package/src/FieldHelpTemplate/FieldHelpTemplate.tsx +30 -3
- package/src/FieldTemplate/FieldTemplate.tsx +26 -4
- package/src/IconButton/IconButton.tsx +21 -2
- package/src/MultiSchemaFieldTemplate/MultiSchemaFieldTemplate.tsx +28 -6
- package/src/ObjectFieldTemplate/ObjectFieldTemplate.tsx +25 -5
- package/src/OptionalDataControlsTemplate/OptionalDataControlsTemplate.tsx +3 -1
- package/src/RadioWidget/RadioWidget.tsx +43 -26
- package/src/RangeWidget/RangeWidget.tsx +16 -1
- package/src/SelectWidget/SelectWidget.tsx +71 -49
- package/src/SubmitButton/SubmitButton.tsx +36 -5
- package/src/TitleField/TitleField.tsx +54 -16
- package/src/WrapIfAdditionalTemplate/WrapIfAdditionalTemplate.tsx +39 -5
- package/src/util.ts +30 -0
|
@@ -1,6 +1,26 @@
|
|
|
1
|
-
import Box from '@mui/material/Box';
|
|
2
|
-
import Button from '@mui/material/Button';
|
|
3
|
-
import {
|
|
1
|
+
import Box, { BoxProps } from '@mui/material/Box';
|
|
2
|
+
import Button, { ButtonProps } from '@mui/material/Button';
|
|
3
|
+
import {
|
|
4
|
+
getSubmitButtonOptions,
|
|
5
|
+
GenericObjectType,
|
|
6
|
+
FormContextType,
|
|
7
|
+
RJSFSchema,
|
|
8
|
+
StrictRJSFSchema,
|
|
9
|
+
SubmitButtonProps,
|
|
10
|
+
getUiOptions,
|
|
11
|
+
} from '@rjsf/utils';
|
|
12
|
+
import { getMuiProps } from '../util';
|
|
13
|
+
|
|
14
|
+
/** Properties available for the `rjsfSlotProps` target of the SubmitButton. */
|
|
15
|
+
export interface SubmitButtonMuiProps extends GenericObjectType {
|
|
16
|
+
/** RJSF-specific slot props for targeting child elements of the SubmitButton. */
|
|
17
|
+
rjsfSlotProps?: {
|
|
18
|
+
/** Props applied to the `Box` wrapper. */
|
|
19
|
+
submitBox?: BoxProps;
|
|
20
|
+
/** Props applied to the `Button` element. */
|
|
21
|
+
submitButton?: ButtonProps;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
4
24
|
|
|
5
25
|
/** The `SubmitButton` renders a button that represent the `Submit` action on a form
|
|
6
26
|
*/
|
|
@@ -13,9 +33,20 @@ export default function SubmitButton<
|
|
|
13
33
|
if (norender) {
|
|
14
34
|
return null;
|
|
15
35
|
}
|
|
36
|
+
|
|
37
|
+
const uiOptions = getUiOptions<T, S, F>(uiSchema);
|
|
38
|
+
const { rjsfSlotProps: muiSlotProps, ...otherMuiProps } = getMuiProps<T, S, F, SubmitButtonMuiProps>(uiOptions);
|
|
39
|
+
|
|
16
40
|
return (
|
|
17
|
-
<Box marginTop={3}>
|
|
18
|
-
<Button
|
|
41
|
+
<Box marginTop={3} {...muiSlotProps?.submitBox}>
|
|
42
|
+
<Button
|
|
43
|
+
type='submit'
|
|
44
|
+
variant='contained'
|
|
45
|
+
color='primary'
|
|
46
|
+
{...submitButtonProps}
|
|
47
|
+
{...otherMuiProps}
|
|
48
|
+
{...muiSlotProps?.submitButton}
|
|
49
|
+
>
|
|
19
50
|
{submitText}
|
|
20
51
|
</Button>
|
|
21
52
|
</Box>
|
|
@@ -1,31 +1,69 @@
|
|
|
1
|
-
import Box from '@mui/material/Box';
|
|
2
|
-
import Divider from '@mui/material/Divider';
|
|
3
|
-
import Grid from '@mui/material/Grid';
|
|
4
|
-
import Typography from '@mui/material/Typography';
|
|
5
|
-
import {
|
|
1
|
+
import Box, { BoxProps } from '@mui/material/Box';
|
|
2
|
+
import Divider, { DividerProps } from '@mui/material/Divider';
|
|
3
|
+
import Grid, { GridProps } from '@mui/material/Grid';
|
|
4
|
+
import Typography, { TypographyProps } from '@mui/material/Typography';
|
|
5
|
+
import {
|
|
6
|
+
FormContextType,
|
|
7
|
+
GenericObjectType,
|
|
8
|
+
TitleFieldProps,
|
|
9
|
+
RJSFSchema,
|
|
10
|
+
StrictRJSFSchema,
|
|
11
|
+
getUiOptions,
|
|
12
|
+
} from '@rjsf/utils';
|
|
13
|
+
import { getMuiProps } from '../util';
|
|
14
|
+
|
|
15
|
+
/** Properties available for the `rjsfSlotProps` target of the TitleField. */
|
|
16
|
+
export interface TitleFieldMuiProps extends GenericObjectType {
|
|
17
|
+
/** RJSF-specific slot props for targeting child elements of the TitleField. */
|
|
18
|
+
rjsfSlotProps?: {
|
|
19
|
+
/** Props applied to the `Box` wrapper. */
|
|
20
|
+
titleBox?: BoxProps;
|
|
21
|
+
/** Props applied to the `Divider` element. */
|
|
22
|
+
titleDivider?: DividerProps;
|
|
23
|
+
/** Props applied to the `Typography` element used for the title. */
|
|
24
|
+
titleTypography?: TypographyProps;
|
|
25
|
+
/** Props applied to the `Grid` container used when `optionalDataControl` is present. */
|
|
26
|
+
titleGridContainer?: GridProps;
|
|
27
|
+
/** Props applied to the `Grid` item containing the title. */
|
|
28
|
+
titleGridItem?: GridProps;
|
|
29
|
+
/** Props applied to the `Grid` item containing the `optionalDataControl`. */
|
|
30
|
+
titleOptionalDataGridItem?: GridProps;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
6
33
|
|
|
7
34
|
/** The `TitleField` is the template to use to render the title of a field
|
|
8
35
|
*
|
|
9
36
|
* @param props - The `TitleFieldProps` for this component
|
|
10
37
|
*/
|
|
11
|
-
export default function TitleField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
optionalDataControl,
|
|
15
|
-
|
|
16
|
-
|
|
38
|
+
export default function TitleField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
|
|
39
|
+
props: TitleFieldProps<T, S, F>,
|
|
40
|
+
) {
|
|
41
|
+
const { id, title, optionalDataControl, uiSchema } = props;
|
|
42
|
+
|
|
43
|
+
const uiOptions = getUiOptions<T, S, F>(uiSchema);
|
|
44
|
+
const { rjsfSlotProps: muiSlotProps } = getMuiProps<T, S, F, TitleFieldMuiProps>(uiOptions);
|
|
45
|
+
|
|
46
|
+
let heading = (
|
|
47
|
+
<Typography variant='h5' {...muiSlotProps?.titleTypography}>
|
|
48
|
+
{title}
|
|
49
|
+
</Typography>
|
|
50
|
+
);
|
|
17
51
|
if (optionalDataControl) {
|
|
18
52
|
heading = (
|
|
19
|
-
<Grid container={true} spacing={0}>
|
|
20
|
-
<Grid size='grow'
|
|
21
|
-
|
|
53
|
+
<Grid container={true} spacing={0} {...muiSlotProps?.titleGridContainer}>
|
|
54
|
+
<Grid size='grow' {...muiSlotProps?.titleGridItem}>
|
|
55
|
+
{heading}
|
|
56
|
+
</Grid>
|
|
57
|
+
<Grid justifyContent='flex-end' {...muiSlotProps?.titleOptionalDataGridItem}>
|
|
58
|
+
{optionalDataControl}
|
|
59
|
+
</Grid>
|
|
22
60
|
</Grid>
|
|
23
61
|
);
|
|
24
62
|
}
|
|
25
63
|
return (
|
|
26
|
-
<Box id={id} mb={1} mt={1}>
|
|
64
|
+
<Box id={id} mb={1} mt={1} {...muiSlotProps?.titleBox}>
|
|
27
65
|
{heading}
|
|
28
|
-
<Divider />
|
|
66
|
+
<Divider {...muiSlotProps?.titleDivider} />
|
|
29
67
|
</Box>
|
|
30
68
|
);
|
|
31
69
|
}
|
|
@@ -1,15 +1,32 @@
|
|
|
1
1
|
import { CSSProperties } from 'react';
|
|
2
|
-
import Grid from '@mui/material/Grid';
|
|
2
|
+
import Grid, { GridProps } from '@mui/material/Grid';
|
|
3
3
|
import TextField from '@mui/material/TextField';
|
|
4
4
|
import {
|
|
5
5
|
ADDITIONAL_PROPERTY_FLAG,
|
|
6
|
+
GenericObjectType,
|
|
6
7
|
buttonId,
|
|
7
8
|
FormContextType,
|
|
8
9
|
RJSFSchema,
|
|
9
10
|
StrictRJSFSchema,
|
|
10
11
|
TranslatableString,
|
|
11
12
|
WrapIfAdditionalTemplateProps,
|
|
13
|
+
getUiOptions,
|
|
12
14
|
} from '@rjsf/utils';
|
|
15
|
+
import { getMuiProps } from '../util';
|
|
16
|
+
/** Properties available for the `rjsfSlotProps` target of the WrapIfAdditionalTemplate. */
|
|
17
|
+
export interface WrapIfAdditionalTemplateMuiProps extends GenericObjectType {
|
|
18
|
+
/** RJSF-specific slot props for targeting child elements of the WrapIfAdditionalTemplate. */
|
|
19
|
+
rjsfSlotProps?: {
|
|
20
|
+
/** Props applied to the outermost `Grid` container. */
|
|
21
|
+
wrapGridContainer?: GridProps;
|
|
22
|
+
/** Props applied to the `Grid` item containing the key TextField. */
|
|
23
|
+
wrapKeyGridItem?: GridProps;
|
|
24
|
+
/** Props applied to the `Grid` item containing the field children. */
|
|
25
|
+
wrapChildrenGridItem?: GridProps;
|
|
26
|
+
/** Props applied to the `Grid` item containing the remove button. */
|
|
27
|
+
wrapRemoveButtonGridItem?: GridProps;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
13
30
|
|
|
14
31
|
/** The `WrapIfAdditional` component is used by the `FieldTemplate` to rename, or remove properties that are
|
|
15
32
|
* part of an `additionalProperties` part of a schema.
|
|
@@ -49,6 +66,10 @@ export default function WrapIfAdditionalTemplate<
|
|
|
49
66
|
fontWeight: 'bold',
|
|
50
67
|
};
|
|
51
68
|
|
|
69
|
+
const uiOptions = getUiOptions<T, S, F>(uiSchema);
|
|
70
|
+
const { rjsfSlotProps } = getMuiProps<T, S, F, WrapIfAdditionalTemplateMuiProps>(uiOptions);
|
|
71
|
+
const muiSlotProps = rjsfSlotProps;
|
|
72
|
+
|
|
52
73
|
if (!additional) {
|
|
53
74
|
return (
|
|
54
75
|
<div className={classNames} style={style}>
|
|
@@ -57,10 +78,21 @@ export default function WrapIfAdditionalTemplate<
|
|
|
57
78
|
);
|
|
58
79
|
}
|
|
59
80
|
|
|
81
|
+
const { wrapGridContainer, wrapKeyGridItem, wrapChildrenGridItem, wrapRemoveButtonGridItem } = muiSlotProps || {};
|
|
82
|
+
|
|
60
83
|
return (
|
|
61
|
-
<Grid
|
|
62
|
-
|
|
84
|
+
<Grid
|
|
85
|
+
container
|
|
86
|
+
key={`${id}-key`}
|
|
87
|
+
alignItems='flex-start'
|
|
88
|
+
spacing={2}
|
|
89
|
+
className={classNames}
|
|
90
|
+
style={style}
|
|
91
|
+
{...wrapGridContainer}
|
|
92
|
+
>
|
|
93
|
+
<Grid size={5.5} {...wrapKeyGridItem}>
|
|
63
94
|
<TextField
|
|
95
|
+
key={label}
|
|
64
96
|
fullWidth={true}
|
|
65
97
|
required={required}
|
|
66
98
|
label={displayLabel ? keyLabel : undefined}
|
|
@@ -72,8 +104,10 @@ export default function WrapIfAdditionalTemplate<
|
|
|
72
104
|
type='text'
|
|
73
105
|
/>
|
|
74
106
|
</Grid>
|
|
75
|
-
<Grid size={5.5}
|
|
76
|
-
|
|
107
|
+
<Grid size={5.5} {...wrapChildrenGridItem}>
|
|
108
|
+
{children}
|
|
109
|
+
</Grid>
|
|
110
|
+
<Grid sx={{ mt: 1.5 }} {...wrapRemoveButtonGridItem}>
|
|
77
111
|
<RemoveButton
|
|
78
112
|
id={buttonId(id, 'remove')}
|
|
79
113
|
className='rjsf-object-property-remove'
|
package/src/util.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { FormContextType, RJSFSchema, StrictRJSFSchema, UIOptionsType, GenericObjectType } from '@rjsf/utils';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Extract props meant for MUI components from the `options` field of the `uiSchema`.
|
|
5
|
+
* @param {UIOptionsType} options - The options from the uiSchema
|
|
6
|
+
* @param {string[]} [propsToFilter] - An optional allowlist of props to return (used by button/icon components)
|
|
7
|
+
* @param {boolean} [rjsfSlotPropsOnly] - If true, returns only `rjsfSlotProps`, preventing root-level prop bleeding
|
|
8
|
+
* @returns {P}
|
|
9
|
+
*/
|
|
10
|
+
export function getMuiProps<
|
|
11
|
+
T = any,
|
|
12
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
13
|
+
F extends FormContextType = any,
|
|
14
|
+
P extends GenericObjectType = GenericObjectType,
|
|
15
|
+
>(options: UIOptionsType<T, S, F>, propsToFilter?: string[], rjsfSlotPropsOnly?: boolean): P {
|
|
16
|
+
const muiProps = (options?.mui as P) || ({} as P);
|
|
17
|
+
if (rjsfSlotPropsOnly) {
|
|
18
|
+
const { rjsfSlotProps } = muiProps as any;
|
|
19
|
+
return { rjsfSlotProps } as unknown as P;
|
|
20
|
+
}
|
|
21
|
+
if (propsToFilter) {
|
|
22
|
+
return Object.keys(muiProps)
|
|
23
|
+
.filter((key) => propsToFilter.includes(key))
|
|
24
|
+
.reduce((obj, key) => {
|
|
25
|
+
obj[key as keyof P] = muiProps[key as keyof P];
|
|
26
|
+
return obj;
|
|
27
|
+
}, {} as P);
|
|
28
|
+
}
|
|
29
|
+
return muiProps;
|
|
30
|
+
}
|