@rjsf/primereact 6.0.0-beta.20 → 6.0.0-beta.21
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 +129 -70
- package/dist/index.cjs.map +4 -4
- package/dist/primereact.esm.js +121 -62
- package/dist/primereact.esm.js.map +4 -4
- package/dist/primereact.umd.js +75 -19
- package/lib/ArrayFieldTemplate/ArrayFieldTemplate.js +4 -4
- package/lib/ArrayFieldTemplate/ArrayFieldTemplate.js.map +1 -1
- package/lib/ArrayFieldTitleTemplate/ArrayFieldTitleTemplate.d.ts +1 -1
- package/lib/ArrayFieldTitleTemplate/ArrayFieldTitleTemplate.js +7 -3
- package/lib/ArrayFieldTitleTemplate/ArrayFieldTitleTemplate.js.map +1 -1
- package/lib/IconButton/IconButton.d.ts +7 -6
- package/lib/IconButton/IconButton.js +1 -2
- package/lib/IconButton/IconButton.js.map +1 -1
- package/lib/ObjectFieldTemplate/ObjectFieldTemplate.js +3 -2
- package/lib/ObjectFieldTemplate/ObjectFieldTemplate.js.map +1 -1
- package/lib/OptionalDataControlsTemplate/OptionalDataControlsTemplate.d.ts +10 -0
- package/lib/OptionalDataControlsTemplate/OptionalDataControlsTemplate.js +21 -0
- package/lib/OptionalDataControlsTemplate/OptionalDataControlsTemplate.js.map +1 -0
- package/lib/OptionalDataControlsTemplate/index.d.ts +2 -0
- package/lib/OptionalDataControlsTemplate/index.js +3 -0
- package/lib/OptionalDataControlsTemplate/index.js.map +1 -0
- package/lib/Templates/Templates.js +2 -0
- package/lib/Templates/Templates.js.map +1 -1
- package/lib/TitleField/TitleField.d.ts +1 -1
- package/lib/TitleField/TitleField.js +6 -2
- package/lib/TitleField/TitleField.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +7 -7
- package/src/ArrayFieldTemplate/ArrayFieldTemplate.tsx +13 -10
- package/src/ArrayFieldTitleTemplate/ArrayFieldTitleTemplate.tsx +11 -2
- package/src/IconButton/IconButton.tsx +13 -9
- package/src/ObjectFieldTemplate/ObjectFieldTemplate.tsx +4 -0
- package/src/OptionalDataControlsTemplate/OptionalDataControlsTemplate.tsx +44 -0
- package/src/OptionalDataControlsTemplate/index.ts +2 -0
- package/src/Templates/Templates.ts +2 -0
- package/src/TitleField/TitleField.tsx +15 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rjsf/primereact",
|
|
3
|
-
"version": "6.0.0-beta.
|
|
3
|
+
"version": "6.0.0-beta.21",
|
|
4
4
|
"description": "PrimeReact theme, fields and widgets for react-jsonschema-form",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "lib/index.js",
|
|
@@ -61,17 +61,17 @@
|
|
|
61
61
|
"node": ">=20"
|
|
62
62
|
},
|
|
63
63
|
"peerDependencies": {
|
|
64
|
-
"@rjsf/core": "^6.0.0-beta.
|
|
65
|
-
"@rjsf/utils": "^6.0.0-beta.
|
|
64
|
+
"@rjsf/core": "^6.0.0-beta.21",
|
|
65
|
+
"@rjsf/utils": "^6.0.0-beta.21",
|
|
66
66
|
"primeicons": ">=6.0.0",
|
|
67
67
|
"primereact": ">=8.0.0",
|
|
68
68
|
"react": ">=18"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
|
-
"@rjsf/core": "^6.0.0-beta.
|
|
72
|
-
"@rjsf/snapshot-tests": "^6.0.0-beta.
|
|
73
|
-
"@rjsf/utils": "^6.0.0-beta.
|
|
74
|
-
"@rjsf/validator-ajv8": "^6.0.0-beta.
|
|
71
|
+
"@rjsf/core": "^6.0.0-beta.21",
|
|
72
|
+
"@rjsf/snapshot-tests": "^6.0.0-beta.21",
|
|
73
|
+
"@rjsf/utils": "^6.0.0-beta.21",
|
|
74
|
+
"@rjsf/validator-ajv8": "^6.0.0-beta.21",
|
|
75
75
|
"@rollup/plugin-replace": "^6.0.2",
|
|
76
76
|
"eslint": "^8.57.1",
|
|
77
77
|
"primeflex": "^4.0.0",
|
|
@@ -29,6 +29,7 @@ export default function ArrayFieldTemplate<
|
|
|
29
29
|
className,
|
|
30
30
|
disabled,
|
|
31
31
|
items,
|
|
32
|
+
optionalDataControl,
|
|
32
33
|
onAddClick,
|
|
33
34
|
readonly,
|
|
34
35
|
schema,
|
|
@@ -54,6 +55,7 @@ export default function ArrayFieldTemplate<
|
|
|
54
55
|
registry,
|
|
55
56
|
uiOptions,
|
|
56
57
|
);
|
|
58
|
+
const showOptionalDataControlInTitle = !readonly && !disabled;
|
|
57
59
|
|
|
58
60
|
return (
|
|
59
61
|
<>
|
|
@@ -64,6 +66,7 @@ export default function ArrayFieldTemplate<
|
|
|
64
66
|
uiSchema={uiSchema}
|
|
65
67
|
required={required}
|
|
66
68
|
registry={registry}
|
|
69
|
+
optionalDataControl={showOptionalDataControlInTitle ? optionalDataControl : undefined}
|
|
67
70
|
/>
|
|
68
71
|
<Fieldset
|
|
69
72
|
{...rest}
|
|
@@ -79,16 +82,16 @@ export default function ArrayFieldTemplate<
|
|
|
79
82
|
/>
|
|
80
83
|
<div key={`array-item-list-${fieldPathId.$id}`}>
|
|
81
84
|
<div>
|
|
82
|
-
{
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
85
|
+
{!showOptionalDataControlInTitle ? optionalDataControl : undefined}
|
|
86
|
+
{items.map(({ key, uiSchema: itemUiSchema = {}, ...props }: ArrayFieldItemTemplateType<T, S, F>) => {
|
|
87
|
+
const mergedUiSchema = {
|
|
88
|
+
...itemUiSchema,
|
|
89
|
+
[UI_OPTIONS_KEY]: {
|
|
90
|
+
...itemUiSchema[UI_OPTIONS_KEY],
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
return <ArrayFieldItemTemplate key={key} {...props} uiSchema={mergedUiSchema} />;
|
|
94
|
+
})}
|
|
92
95
|
</div>
|
|
93
96
|
{canAdd && (
|
|
94
97
|
<div
|
|
@@ -15,11 +15,20 @@ export default function ArrayFieldTitleTemplate<
|
|
|
15
15
|
T = any,
|
|
16
16
|
S extends StrictRJSFSchema = RJSFSchema,
|
|
17
17
|
F extends FormContextType = any,
|
|
18
|
-
>({ title, uiSchema, required, fieldPathId }: ArrayFieldTitleProps<T, S, F>) {
|
|
18
|
+
>({ title, uiSchema, required, fieldPathId, optionalDataControl }: ArrayFieldTitleProps<T, S, F>) {
|
|
19
19
|
const uiOptions = getUiOptions<T, S, F>(uiSchema);
|
|
20
|
-
|
|
20
|
+
let heading = (
|
|
21
21
|
<h5 id={titleId(fieldPathId)} style={{ margin: 0, fontSize: '1.5rem', marginBottom: '0.2rem' }}>
|
|
22
22
|
{uiOptions.title || title} {required ? '*' : ''}
|
|
23
23
|
</h5>
|
|
24
24
|
);
|
|
25
|
+
if (optionalDataControl) {
|
|
26
|
+
heading = (
|
|
27
|
+
<div style={{ display: 'flex' }}>
|
|
28
|
+
<div style={{ flexGrow: 1 }}>{heading}</div>
|
|
29
|
+
<div>{optionalDataControl}</div>
|
|
30
|
+
</div>
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
return heading;
|
|
25
34
|
}
|
|
@@ -1,17 +1,21 @@
|
|
|
1
|
-
import { Button } from 'primereact/button';
|
|
1
|
+
import { Button, ButtonProps } from 'primereact/button';
|
|
2
2
|
import { FormContextType, IconButtonProps, RJSFSchema, StrictRJSFSchema, TranslatableString } from '@rjsf/utils';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
export type PrimeIconButtonProps<
|
|
5
|
+
T = any,
|
|
6
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
7
|
+
F extends FormContextType = any,
|
|
8
|
+
> = IconButtonProps<T, S, F> & Omit<ButtonProps, 'onClick'>;
|
|
9
|
+
|
|
10
|
+
export default function IconButton<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
|
|
11
|
+
props: PrimeIconButtonProps<T, S, F>,
|
|
6
12
|
) {
|
|
7
13
|
const { icon, iconType, uiSchema, registry, ...otherProps } = props;
|
|
8
14
|
return <Button icon={`pi pi-${icon}`} rounded text severity='secondary' {...otherProps} />;
|
|
9
15
|
}
|
|
10
16
|
|
|
11
|
-
export default IconButton;
|
|
12
|
-
|
|
13
17
|
export function CopyButton<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
|
|
14
|
-
props:
|
|
18
|
+
props: PrimeIconButtonProps<T, S, F>,
|
|
15
19
|
) {
|
|
16
20
|
const {
|
|
17
21
|
registry: { translateString },
|
|
@@ -20,7 +24,7 @@ export function CopyButton<T = any, S extends StrictRJSFSchema = RJSFSchema, F e
|
|
|
20
24
|
}
|
|
21
25
|
|
|
22
26
|
export function MoveDownButton<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
|
|
23
|
-
props:
|
|
27
|
+
props: PrimeIconButtonProps<T, S, F>,
|
|
24
28
|
) {
|
|
25
29
|
const {
|
|
26
30
|
registry: { translateString },
|
|
@@ -29,7 +33,7 @@ export function MoveDownButton<T = any, S extends StrictRJSFSchema = RJSFSchema,
|
|
|
29
33
|
}
|
|
30
34
|
|
|
31
35
|
export function MoveUpButton<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
|
|
32
|
-
props:
|
|
36
|
+
props: PrimeIconButtonProps<T, S, F>,
|
|
33
37
|
) {
|
|
34
38
|
const {
|
|
35
39
|
registry: { translateString },
|
|
@@ -38,7 +42,7 @@ export function MoveUpButton<T = any, S extends StrictRJSFSchema = RJSFSchema, F
|
|
|
38
42
|
}
|
|
39
43
|
|
|
40
44
|
export function RemoveButton<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
|
|
41
|
-
props:
|
|
45
|
+
props: PrimeIconButtonProps<T, S, F>,
|
|
42
46
|
) {
|
|
43
47
|
const {
|
|
44
48
|
registry: { translateString },
|
|
@@ -24,6 +24,7 @@ export default function ObjectFieldTemplate<
|
|
|
24
24
|
>(props: ObjectFieldTemplateProps<T, S, F>) {
|
|
25
25
|
const {
|
|
26
26
|
description,
|
|
27
|
+
optionalDataControl,
|
|
27
28
|
onAddClick,
|
|
28
29
|
title,
|
|
29
30
|
properties,
|
|
@@ -43,6 +44,7 @@ export default function ObjectFieldTemplate<
|
|
|
43
44
|
registry,
|
|
44
45
|
uiOptions,
|
|
45
46
|
);
|
|
47
|
+
const showOptionalDataControlInTitle = !readonly && !disabled;
|
|
46
48
|
// Button templates are not overridden in the uiSchema
|
|
47
49
|
const {
|
|
48
50
|
ButtonTemplates: { AddButton },
|
|
@@ -57,6 +59,7 @@ export default function ObjectFieldTemplate<
|
|
|
57
59
|
schema={schema}
|
|
58
60
|
uiSchema={uiSchema}
|
|
59
61
|
registry={registry}
|
|
62
|
+
optionalDataControl={showOptionalDataControlInTitle ? optionalDataControl : undefined}
|
|
60
63
|
/>
|
|
61
64
|
)}
|
|
62
65
|
{description && (
|
|
@@ -70,6 +73,7 @@ export default function ObjectFieldTemplate<
|
|
|
70
73
|
/>
|
|
71
74
|
</div>
|
|
72
75
|
)}
|
|
76
|
+
{!showOptionalDataControlInTitle ? optionalDataControl : undefined}
|
|
73
77
|
{properties.map((prop) => prop.content)}
|
|
74
78
|
{canExpand<T, S, F>(schema, uiSchema, formData) && (
|
|
75
79
|
<div style={{ marginTop: '1rem', textAlign: 'right' }}>
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { FormContextType, OptionalDataControlsTemplateProps, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
|
|
2
|
+
|
|
3
|
+
import IconButton, { RemoveButton } from '../IconButton';
|
|
4
|
+
|
|
5
|
+
/** The OptionalDataControlsTemplate renders one of three different states. If
|
|
6
|
+
* there is an `onAddClick()` function, it renders the "Add" button. If there is
|
|
7
|
+
* an `onRemoveClick()` function, it renders the "Remove" button. Otherwise it
|
|
8
|
+
* renders the "No data found" section. All of them use the `label` as either
|
|
9
|
+
* the `title` of buttons or simply outputting it.
|
|
10
|
+
*
|
|
11
|
+
* @param props - The `OptionalDataControlsTemplateProps` for the template
|
|
12
|
+
*/
|
|
13
|
+
export default function OptionalDataControlsTemplate<
|
|
14
|
+
T = any,
|
|
15
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
16
|
+
F extends FormContextType = any,
|
|
17
|
+
>(props: OptionalDataControlsTemplateProps<T, S, F>) {
|
|
18
|
+
const { id, registry, label, onAddClick, onRemoveClick } = props;
|
|
19
|
+
if (onAddClick) {
|
|
20
|
+
return (
|
|
21
|
+
<IconButton
|
|
22
|
+
id={id}
|
|
23
|
+
registry={registry}
|
|
24
|
+
className='rjsf-add-optional-data'
|
|
25
|
+
onClick={onAddClick}
|
|
26
|
+
title={label}
|
|
27
|
+
icon='pi pi-plus'
|
|
28
|
+
style={{ height: '1.5rem', width: '1.5rem' }} // Shrink the button
|
|
29
|
+
/>
|
|
30
|
+
);
|
|
31
|
+
} else if (onRemoveClick) {
|
|
32
|
+
return (
|
|
33
|
+
<RemoveButton
|
|
34
|
+
id={id}
|
|
35
|
+
registry={registry}
|
|
36
|
+
className='rjsf-remove-optional-data'
|
|
37
|
+
onClick={onRemoveClick}
|
|
38
|
+
title={label}
|
|
39
|
+
style={{ height: '1.5rem', width: '1.5rem' }} // Shrink the button
|
|
40
|
+
/>
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
return <em id={id}>{label}</em>;
|
|
44
|
+
}
|
|
@@ -12,6 +12,7 @@ import FieldHelpTemplate from '../FieldHelpTemplate';
|
|
|
12
12
|
import FieldTemplate from '../FieldTemplate';
|
|
13
13
|
import MultiSchemaFieldTemplate from '../MultiSchemaFieldTemplate';
|
|
14
14
|
import ObjectFieldTemplate from '../ObjectFieldTemplate';
|
|
15
|
+
import OptionalDataControlsTemplate from '../OptionalDataControlsTemplate';
|
|
15
16
|
import SubmitButton from '../SubmitButton';
|
|
16
17
|
import TitleField from '../TitleField';
|
|
17
18
|
import WrapIfAdditionalTemplate from '../WrapIfAdditionalTemplate';
|
|
@@ -43,6 +44,7 @@ export function generateTemplates<
|
|
|
43
44
|
FieldTemplate,
|
|
44
45
|
MultiSchemaFieldTemplate,
|
|
45
46
|
ObjectFieldTemplate,
|
|
47
|
+
OptionalDataControlsTemplate,
|
|
46
48
|
TitleFieldTemplate: TitleField,
|
|
47
49
|
WrapIfAdditionalTemplate,
|
|
48
50
|
GridTemplate,
|
|
@@ -10,13 +10,25 @@ export default function TitleField<T = any, S extends StrictRJSFSchema = RJSFSch
|
|
|
10
10
|
title,
|
|
11
11
|
uiSchema,
|
|
12
12
|
required,
|
|
13
|
+
optionalDataControl,
|
|
13
14
|
}: TitleFieldProps<T, S, F>) {
|
|
14
15
|
const uiOptions = getUiOptions<T, S, F>(uiSchema);
|
|
16
|
+
let heading = (
|
|
17
|
+
<h5 style={{ margin: 0, fontSize: id === titleId('root') ? '1.5rem' : '1.2rem' }}>
|
|
18
|
+
{uiOptions.title || title} {required ? '*' : ''}
|
|
19
|
+
</h5>
|
|
20
|
+
);
|
|
21
|
+
if (optionalDataControl) {
|
|
22
|
+
heading = (
|
|
23
|
+
<div style={{ display: 'flex' }}>
|
|
24
|
+
<div style={{ flexGrow: 1 }}>{heading}</div>
|
|
25
|
+
<div style={{ marginLeft: '-5px' }}>{optionalDataControl}</div>
|
|
26
|
+
</div>
|
|
27
|
+
);
|
|
28
|
+
}
|
|
15
29
|
return (
|
|
16
30
|
<div id={id}>
|
|
17
|
-
|
|
18
|
-
{uiOptions.title || title} {required ? '*' : ''}
|
|
19
|
-
</h5>
|
|
31
|
+
{heading}
|
|
20
32
|
<Divider pt={{ root: { style: { marginTop: '0.5rem' } } }} />
|
|
21
33
|
</div>
|
|
22
34
|
);
|