@rjsf/primereact 6.0.0-beta.19 → 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 +143 -84
- package/dist/index.cjs.map +4 -4
- package/dist/primereact.esm.js +135 -76
- package/dist/primereact.esm.js.map +4 -4
- package/dist/primereact.umd.js +89 -33
- package/lib/ArrayFieldTemplate/ArrayFieldTemplate.js +5 -5
- 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/AutoCompleteWidget/AutoCompleteWidget.js.map +1 -1
- package/lib/BaseInputTemplate/BaseInputTemplate.js.map +1 -1
- package/lib/CheckboxWidget/CheckboxWidget.js.map +1 -1
- package/lib/CheckboxesWidget/CheckboxesWidget.js.map +1 -1
- package/lib/ColorWidget/ColorWidget.js.map +1 -1
- package/lib/FieldErrorTemplate/FieldErrorTemplate.d.ts +1 -1
- package/lib/FieldErrorTemplate/FieldErrorTemplate.js +2 -2
- package/lib/FieldErrorTemplate/FieldErrorTemplate.js.map +1 -1
- package/lib/FieldHelpTemplate/FieldHelpTemplate.js +2 -2
- package/lib/FieldHelpTemplate/FieldHelpTemplate.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/PasswordWidget/PasswordWidget.js.map +1 -1
- package/lib/RadioWidget/RadioWidget.js.map +1 -1
- package/lib/RangeWidget/RangeWidget.js.map +1 -1
- package/lib/SelectWidget/SelectWidget.js.map +1 -1
- 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/UpDownWidget/UpDownWidget.js.map +1 -1
- package/lib/WrapIfAdditionalTemplate/WrapIfAdditionalTemplate.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +7 -7
- package/src/ArrayFieldTemplate/ArrayFieldTemplate.tsx +19 -16
- package/src/ArrayFieldTitleTemplate/ArrayFieldTitleTemplate.tsx +12 -3
- package/src/AutoCompleteWidget/AutoCompleteWidget.tsx +1 -1
- package/src/BaseInputTemplate/BaseInputTemplate.tsx +2 -2
- package/src/CheckboxWidget/CheckboxWidget.tsx +2 -2
- package/src/CheckboxesWidget/CheckboxesWidget.tsx +2 -2
- package/src/ColorWidget/ColorWidget.tsx +1 -1
- package/src/FieldErrorTemplate/FieldErrorTemplate.tsx +2 -2
- package/src/FieldHelpTemplate/FieldHelpTemplate.tsx +2 -2
- package/src/IconButton/IconButton.tsx +13 -9
- package/src/ObjectFieldTemplate/ObjectFieldTemplate.tsx +8 -4
- package/src/OptionalDataControlsTemplate/OptionalDataControlsTemplate.tsx +44 -0
- package/src/OptionalDataControlsTemplate/index.ts +2 -0
- package/src/PasswordWidget/PasswordWidget.tsx +1 -1
- package/src/RadioWidget/RadioWidget.tsx +1 -1
- package/src/RangeWidget/RangeWidget.tsx +1 -1
- package/src/SelectWidget/SelectWidget.tsx +2 -2
- package/src/Templates/Templates.ts +2 -0
- package/src/TitleField/TitleField.tsx +15 -3
- package/src/UpDownWidget/UpDownWidget.tsx +1 -1
- package/src/WrapIfAdditionalTemplate/WrapIfAdditionalTemplate.tsx +1 -1
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",
|
|
@@ -24,11 +24,12 @@ export default function ArrayFieldTemplate<
|
|
|
24
24
|
>(props: ArrayFieldTemplateProps<T, S, F>) {
|
|
25
25
|
const {
|
|
26
26
|
uiSchema,
|
|
27
|
-
|
|
27
|
+
fieldPathId,
|
|
28
28
|
canAdd,
|
|
29
29
|
className,
|
|
30
30
|
disabled,
|
|
31
31
|
items,
|
|
32
|
+
optionalDataControl,
|
|
32
33
|
onAddClick,
|
|
33
34
|
readonly,
|
|
34
35
|
schema,
|
|
@@ -54,41 +55,43 @@ export default function ArrayFieldTemplate<
|
|
|
54
55
|
registry,
|
|
55
56
|
uiOptions,
|
|
56
57
|
);
|
|
58
|
+
const showOptionalDataControlInTitle = !readonly && !disabled;
|
|
57
59
|
|
|
58
60
|
return (
|
|
59
61
|
<>
|
|
60
62
|
<ArrayFieldTitleTemplate
|
|
61
|
-
|
|
63
|
+
fieldPathId={fieldPathId}
|
|
62
64
|
title={uiOptions.title || title}
|
|
63
65
|
schema={schema}
|
|
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}
|
|
70
|
-
id={
|
|
73
|
+
id={fieldPathId.$id}
|
|
71
74
|
className={`${className}${isFixedItems<S>(schema) ? '' : ' sortable-form-fields'}`}
|
|
72
75
|
>
|
|
73
76
|
<ArrayFieldDescriptionTemplate
|
|
74
|
-
|
|
77
|
+
fieldPathId={fieldPathId}
|
|
75
78
|
description={uiOptions.description || schema.description}
|
|
76
79
|
schema={schema}
|
|
77
80
|
uiSchema={uiSchema}
|
|
78
81
|
registry={registry}
|
|
79
82
|
/>
|
|
80
|
-
<div key={`array-item-list-${
|
|
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
|
|
@@ -99,7 +102,7 @@ export default function ArrayFieldTemplate<
|
|
|
99
102
|
}}
|
|
100
103
|
>
|
|
101
104
|
<AddButton
|
|
102
|
-
id={buttonId
|
|
105
|
+
id={buttonId(fieldPathId, 'add')}
|
|
103
106
|
className='rjsf-array-item-add'
|
|
104
107
|
onClick={onAddClick}
|
|
105
108
|
disabled={disabled || readonly}
|
|
@@ -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,
|
|
18
|
+
>({ title, uiSchema, required, fieldPathId, optionalDataControl }: ArrayFieldTitleProps<T, S, F>) {
|
|
19
19
|
const uiOptions = getUiOptions<T, S, F>(uiSchema);
|
|
20
|
-
|
|
21
|
-
<h5 id={titleId(
|
|
20
|
+
let heading = (
|
|
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
|
}
|
|
@@ -74,7 +74,7 @@ export default function AutoCompleteWidget<
|
|
|
74
74
|
onChange={(onChangeOverride as any) || _onChange}
|
|
75
75
|
onBlur={_onBlur}
|
|
76
76
|
onFocus={_onFocus}
|
|
77
|
-
aria-describedby={ariaDescribedByIds
|
|
77
|
+
aria-describedby={ariaDescribedByIds(id, !!schema.examples)}
|
|
78
78
|
/* Make autocomplete look like a dropdown, which looks much nicer */
|
|
79
79
|
pt={{
|
|
80
80
|
root: {
|
|
@@ -59,13 +59,13 @@ export default function BaseInputTemplate<
|
|
|
59
59
|
required={required}
|
|
60
60
|
autoFocus={autofocus}
|
|
61
61
|
disabled={disabled || readonly}
|
|
62
|
-
list={schema.examples ? examplesId
|
|
62
|
+
list={schema.examples ? examplesId(id) : undefined}
|
|
63
63
|
value={value || value === 0 ? value : ''}
|
|
64
64
|
invalid={rawErrors.length > 0}
|
|
65
65
|
onChange={onChangeOverride || _onChange}
|
|
66
66
|
onBlur={_onBlur}
|
|
67
67
|
onFocus={_onFocus}
|
|
68
|
-
aria-describedby={ariaDescribedByIds
|
|
68
|
+
aria-describedby={ariaDescribedByIds(id, !!schema.examples)}
|
|
69
69
|
/>
|
|
70
70
|
);
|
|
71
71
|
}
|
|
@@ -58,7 +58,7 @@ export default function CheckboxWidget<
|
|
|
58
58
|
<>
|
|
59
59
|
{!hideLabel && !!description && (
|
|
60
60
|
<DescriptionFieldTemplate
|
|
61
|
-
id={descriptionId
|
|
61
|
+
id={descriptionId(id)}
|
|
62
62
|
description={description}
|
|
63
63
|
schema={schema}
|
|
64
64
|
uiSchema={uiSchema}
|
|
@@ -77,7 +77,7 @@ export default function CheckboxWidget<
|
|
|
77
77
|
onBlur={_onBlur}
|
|
78
78
|
onFocus={_onFocus}
|
|
79
79
|
required={required}
|
|
80
|
-
aria-describedby={ariaDescribedByIds
|
|
80
|
+
aria-describedby={ariaDescribedByIds(id)}
|
|
81
81
|
/>
|
|
82
82
|
{labelValue(<Label id={id} text={label} />, hideLabel, false)}
|
|
83
83
|
</div>
|
|
@@ -70,7 +70,7 @@ export default function CheckboxesWidget<
|
|
|
70
70
|
>
|
|
71
71
|
{!hideLabel && !!description && (
|
|
72
72
|
<DescriptionFieldTemplate
|
|
73
|
-
id={descriptionId
|
|
73
|
+
id={descriptionId(id)}
|
|
74
74
|
description={description}
|
|
75
75
|
schema={schema}
|
|
76
76
|
uiSchema={uiSchema}
|
|
@@ -94,7 +94,7 @@ export default function CheckboxesWidget<
|
|
|
94
94
|
onChange={_onChange(index)}
|
|
95
95
|
onBlur={_onBlur}
|
|
96
96
|
onFocus={_onFocus}
|
|
97
|
-
aria-describedby={ariaDescribedByIds
|
|
97
|
+
aria-describedby={ariaDescribedByIds(id)}
|
|
98
98
|
/>
|
|
99
99
|
<Label id={optionId(id, index)} text={option.label} />
|
|
100
100
|
</div>
|
|
@@ -56,7 +56,7 @@ export default function ColorWidget<T = any, S extends StrictRJSFSchema = RJSFSc
|
|
|
56
56
|
onChange={onChangeOverride || _onChange}
|
|
57
57
|
onBlur={_onBlur}
|
|
58
58
|
onFocus={_onFocus}
|
|
59
|
-
aria-describedby={ariaDescribedByIds
|
|
59
|
+
aria-describedby={ariaDescribedByIds(id, !!schema.examples)}
|
|
60
60
|
/>
|
|
61
61
|
);
|
|
62
62
|
}
|
|
@@ -9,9 +9,9 @@ export default function FieldErrorTemplate<
|
|
|
9
9
|
T = any,
|
|
10
10
|
S extends StrictRJSFSchema = RJSFSchema,
|
|
11
11
|
F extends FormContextType = any,
|
|
12
|
-
>({ errors,
|
|
12
|
+
>({ errors, fieldPathId }: FieldErrorProps<T, S, F>) {
|
|
13
13
|
if (errors && errors.length > 0) {
|
|
14
|
-
const id = errorId
|
|
14
|
+
const id = errorId(fieldPathId);
|
|
15
15
|
const content = errors.map((error, i: number) => {
|
|
16
16
|
return <div key={i}>{error}</div>;
|
|
17
17
|
});
|
|
@@ -9,9 +9,9 @@ export default function FieldHelpTemplate<
|
|
|
9
9
|
S extends StrictRJSFSchema = RJSFSchema,
|
|
10
10
|
F extends FormContextType = any,
|
|
11
11
|
>(props: FieldHelpProps<T, S, F>) {
|
|
12
|
-
const {
|
|
12
|
+
const { fieldPathId, help } = props;
|
|
13
13
|
if (help) {
|
|
14
|
-
const id = helpId
|
|
14
|
+
const id = helpId(fieldPathId);
|
|
15
15
|
return <small id={id}>{help}</small>;
|
|
16
16
|
}
|
|
17
17
|
return null;
|
|
@@ -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,
|
|
@@ -33,7 +34,7 @@ export default function ObjectFieldTemplate<
|
|
|
33
34
|
uiSchema,
|
|
34
35
|
schema,
|
|
35
36
|
formData,
|
|
36
|
-
|
|
37
|
+
fieldPathId,
|
|
37
38
|
registry,
|
|
38
39
|
} = props;
|
|
39
40
|
const uiOptions = getUiOptions<T, S, F>(uiSchema);
|
|
@@ -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 },
|
|
@@ -51,18 +53,19 @@ export default function ObjectFieldTemplate<
|
|
|
51
53
|
<>
|
|
52
54
|
{title && (
|
|
53
55
|
<TitleFieldTemplate
|
|
54
|
-
id={titleId
|
|
56
|
+
id={titleId(fieldPathId)}
|
|
55
57
|
title={title}
|
|
56
58
|
required={required}
|
|
57
59
|
schema={schema}
|
|
58
60
|
uiSchema={uiSchema}
|
|
59
61
|
registry={registry}
|
|
62
|
+
optionalDataControl={showOptionalDataControlInTitle ? optionalDataControl : undefined}
|
|
60
63
|
/>
|
|
61
64
|
)}
|
|
62
65
|
{description && (
|
|
63
66
|
<div style={{ marginBottom: '1rem' }}>
|
|
64
67
|
<DescriptionFieldTemplate
|
|
65
|
-
id={descriptionId
|
|
68
|
+
id={descriptionId(fieldPathId)}
|
|
66
69
|
description={description}
|
|
67
70
|
schema={schema}
|
|
68
71
|
uiSchema={uiSchema}
|
|
@@ -70,11 +73,12 @@ 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' }}>
|
|
76
80
|
<AddButton
|
|
77
|
-
id={buttonId
|
|
81
|
+
id={buttonId(fieldPathId, 'add')}
|
|
78
82
|
className='rjsf-object-property-expand'
|
|
79
83
|
icon='pi pi-plus'
|
|
80
84
|
onClick={onAddClick(schema)}
|
|
@@ -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
|
+
}
|
|
@@ -58,7 +58,7 @@ export default function PasswordWidget<
|
|
|
58
58
|
onChange={onChangeOverride || _onChange}
|
|
59
59
|
onBlur={_onBlur}
|
|
60
60
|
onFocus={_onFocus}
|
|
61
|
-
aria-describedby={ariaDescribedByIds
|
|
61
|
+
aria-describedby={ariaDescribedByIds(id, !!schema.examples)}
|
|
62
62
|
pt={{ root: { style: { display: 'flex', flexDirection: 'column' } } }}
|
|
63
63
|
/>
|
|
64
64
|
);
|
|
@@ -47,7 +47,7 @@ export default function RadioWidget<T = any, S extends StrictRJSFSchema = RJSFSc
|
|
|
47
47
|
value={String(index)}
|
|
48
48
|
checked={checked}
|
|
49
49
|
disabled={disabled || itemDisabled || readonly}
|
|
50
|
-
aria-describedby={ariaDescribedByIds
|
|
50
|
+
aria-describedby={ariaDescribedByIds(id)}
|
|
51
51
|
/>
|
|
52
52
|
<label htmlFor={optionId(id, index)} style={{ marginLeft: '8px' }}>
|
|
53
53
|
{option.label}
|
|
@@ -82,7 +82,7 @@ function SingleSelectWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F
|
|
|
82
82
|
placeholder={placeholder}
|
|
83
83
|
disabled={disabled || readonly}
|
|
84
84
|
autoFocus={autofocus}
|
|
85
|
-
aria-describedby={ariaDescribedByIds
|
|
85
|
+
aria-describedby={ariaDescribedByIds(id)}
|
|
86
86
|
{...dropdownRemainingProps}
|
|
87
87
|
/>
|
|
88
88
|
);
|
|
@@ -132,7 +132,7 @@ function MultiSelectWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F e
|
|
|
132
132
|
disabled={disabled || readonly}
|
|
133
133
|
autoFocus={autofocus}
|
|
134
134
|
display={options.display === 'chip' ? 'chip' : 'comma'}
|
|
135
|
-
aria-describedby={ariaDescribedByIds
|
|
135
|
+
aria-describedby={ariaDescribedByIds(id)}
|
|
136
136
|
pt={{ root: { style: { position: 'relative' } } }}
|
|
137
137
|
/>
|
|
138
138
|
);
|
|
@@ -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
|
);
|
|
@@ -64,7 +64,7 @@ export default function UpDownWidget<T = any, S extends StrictRJSFSchema = RJSFS
|
|
|
64
64
|
onChange={(onChangeOverride as any) || _onChange}
|
|
65
65
|
onBlur={_onBlur}
|
|
66
66
|
onFocus={_onFocus}
|
|
67
|
-
aria-describedby={ariaDescribedByIds
|
|
67
|
+
aria-describedby={ariaDescribedByIds(id, !!schema.examples)}
|
|
68
68
|
/>
|
|
69
69
|
);
|
|
70
70
|
}
|
|
@@ -71,7 +71,7 @@ export default function WrapIfAdditionalTemplate<
|
|
|
71
71
|
<div style={{ flex: 1 }}>{children}</div>
|
|
72
72
|
<div>
|
|
73
73
|
<RemoveButton
|
|
74
|
-
id={buttonId
|
|
74
|
+
id={buttonId(id, 'remove')}
|
|
75
75
|
className='rjsf-object-property-remove'
|
|
76
76
|
disabled={disabled || readonly}
|
|
77
77
|
onClick={onDropPropertyClick(label)}
|