@rjsf/core 6.0.0-beta.2 → 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/core.umd.js +705 -471
- package/dist/{index.js → index.cjs} +1094 -844
- package/dist/index.cjs.map +7 -0
- package/dist/index.esm.js +1053 -774
- package/dist/index.esm.js.map +4 -4
- package/lib/components/Form.d.ts +88 -23
- package/lib/components/Form.d.ts.map +1 -1
- package/lib/components/Form.js +213 -151
- package/lib/components/fields/ArrayField.d.ts +17 -7
- package/lib/components/fields/ArrayField.d.ts.map +1 -1
- package/lib/components/fields/ArrayField.js +116 -70
- package/lib/components/fields/BooleanField.d.ts.map +1 -1
- package/lib/components/fields/BooleanField.js +7 -2
- package/lib/components/fields/LayoutGridField.d.ts +27 -25
- package/lib/components/fields/LayoutGridField.d.ts.map +1 -1
- package/lib/components/fields/LayoutGridField.js +83 -59
- package/lib/components/fields/LayoutHeaderField.d.ts +1 -1
- package/lib/components/fields/LayoutHeaderField.js +3 -3
- package/lib/components/fields/LayoutMultiSchemaField.js +6 -5
- package/lib/components/fields/MultiSchemaField.d.ts.map +1 -1
- package/lib/components/fields/MultiSchemaField.js +13 -9
- package/lib/components/fields/NullField.js +3 -3
- package/lib/components/fields/NumberField.d.ts.map +1 -1
- package/lib/components/fields/NumberField.js +3 -3
- package/lib/components/fields/ObjectField.d.ts +3 -3
- package/lib/components/fields/ObjectField.d.ts.map +1 -1
- package/lib/components/fields/ObjectField.js +34 -34
- package/lib/components/fields/OptionalDataControlsField.d.ts +8 -0
- package/lib/components/fields/OptionalDataControlsField.d.ts.map +1 -0
- package/lib/components/fields/OptionalDataControlsField.js +43 -0
- package/lib/components/fields/SchemaField.d.ts.map +1 -1
- package/lib/components/fields/SchemaField.js +17 -17
- package/lib/components/fields/StringField.d.ts.map +1 -1
- package/lib/components/fields/StringField.js +7 -2
- package/lib/components/fields/index.d.ts.map +1 -1
- package/lib/components/fields/index.js +2 -0
- package/lib/components/templates/ArrayFieldDescriptionTemplate.d.ts +1 -1
- package/lib/components/templates/ArrayFieldDescriptionTemplate.js +3 -3
- package/lib/components/templates/ArrayFieldItemButtonsTemplate.js +2 -2
- package/lib/components/templates/ArrayFieldTemplate.d.ts.map +1 -1
- package/lib/components/templates/ArrayFieldTemplate.js +4 -3
- package/lib/components/templates/ArrayFieldTitleTemplate.d.ts +1 -1
- package/lib/components/templates/ArrayFieldTitleTemplate.d.ts.map +1 -1
- package/lib/components/templates/ArrayFieldTitleTemplate.js +3 -3
- package/lib/components/templates/ButtonTemplates/AddButton.d.ts +1 -1
- package/lib/components/templates/ButtonTemplates/AddButton.d.ts.map +1 -1
- package/lib/components/templates/ButtonTemplates/AddButton.js +2 -2
- package/lib/components/templates/FieldErrorTemplate.js +2 -2
- package/lib/components/templates/FieldHelpTemplate.js +2 -2
- package/lib/components/templates/MultiSchemaFieldTemplate.d.ts +8 -0
- package/lib/components/templates/MultiSchemaFieldTemplate.d.ts.map +1 -0
- package/lib/components/templates/MultiSchemaFieldTemplate.js +10 -0
- package/lib/components/templates/ObjectFieldTemplate.d.ts.map +1 -1
- package/lib/components/templates/ObjectFieldTemplate.js +3 -2
- package/lib/components/templates/OptionalDataControlsTemplate.d.ts +11 -0
- package/lib/components/templates/OptionalDataControlsTemplate.d.ts.map +1 -0
- package/lib/components/templates/OptionalDataControlsTemplate.js +20 -0
- package/lib/components/templates/TitleField.d.ts.map +1 -1
- package/lib/components/templates/TitleField.js +2 -2
- package/lib/components/templates/UnsupportedField.js +3 -3
- package/lib/components/templates/index.d.ts.map +1 -1
- package/lib/components/templates/index.js +4 -0
- package/lib/components/widgets/AltDateWidget.d.ts.map +1 -1
- package/lib/components/widgets/AltDateWidget.js +15 -18
- package/lib/components/widgets/CheckboxesWidget.js +2 -2
- package/lib/getDefaultRegistry.d.ts.map +1 -1
- package/lib/getDefaultRegistry.js +2 -1
- package/lib/getTestRegistry.d.ts +5 -0
- package/lib/getTestRegistry.d.ts.map +1 -0
- package/lib/getTestRegistry.js +19 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +18 -19
- package/src/components/Form.tsx +306 -177
- package/src/components/fields/ArrayField.tsx +127 -80
- package/src/components/fields/BooleanField.tsx +12 -3
- package/src/components/fields/LayoutGridField.tsx +95 -88
- package/src/components/fields/LayoutHeaderField.tsx +3 -3
- package/src/components/fields/LayoutMultiSchemaField.tsx +5 -5
- package/src/components/fields/MultiSchemaField.tsx +51 -35
- package/src/components/fields/NullField.tsx +3 -3
- package/src/components/fields/NumberField.tsx +11 -3
- package/src/components/fields/ObjectField.tsx +47 -53
- package/src/components/fields/OptionalDataControlsField.tsx +84 -0
- package/src/components/fields/SchemaField.tsx +24 -30
- package/src/components/fields/StringField.tsx +12 -3
- package/src/components/fields/index.ts +2 -0
- package/src/components/templates/ArrayFieldDescriptionTemplate.tsx +3 -3
- package/src/components/templates/ArrayFieldItemButtonsTemplate.tsx +5 -5
- package/src/components/templates/ArrayFieldTemplate.tsx +9 -5
- package/src/components/templates/ArrayFieldTitleTemplate.tsx +4 -3
- package/src/components/templates/BaseInputTemplate.tsx +3 -3
- package/src/components/templates/ButtonTemplates/AddButton.tsx +2 -0
- package/src/components/templates/FieldErrorTemplate.tsx +2 -2
- package/src/components/templates/FieldHelpTemplate.tsx +2 -2
- package/src/components/templates/MultiSchemaFieldTemplate.tsx +20 -0
- package/src/components/templates/ObjectFieldTemplate.tsx +10 -5
- package/src/components/templates/OptionalDataControlsTemplate.tsx +43 -0
- package/src/components/templates/TitleField.tsx +6 -1
- package/src/components/templates/UnsupportedField.tsx +3 -3
- package/src/components/templates/WrapIfAdditionalTemplate.tsx +1 -1
- package/src/components/templates/index.ts +4 -0
- package/src/components/widgets/AltDateWidget.tsx +21 -23
- package/src/components/widgets/CheckboxWidget.tsx +2 -2
- package/src/components/widgets/CheckboxesWidget.tsx +3 -3
- package/src/components/widgets/RadioWidget.tsx +1 -1
- package/src/components/widgets/SelectWidget.tsx +1 -1
- package/src/components/widgets/TextareaWidget.tsx +1 -1
- package/src/getDefaultRegistry.ts +10 -1
- package/src/getTestRegistry.tsx +34 -0
- package/src/index.ts +2 -1
- package/dist/index.js.map +0 -7
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
} from '@rjsf/utils';
|
|
11
11
|
|
|
12
12
|
/** The `ArrayFieldTitleTemplate` component renders a `TitleFieldTemplate` with an `id` derived from
|
|
13
|
-
* the `
|
|
13
|
+
* the `fieldPathId`.
|
|
14
14
|
*
|
|
15
15
|
* @param props - The `ArrayFieldTitleProps` for the component
|
|
16
16
|
*/
|
|
@@ -19,7 +19,7 @@ export default function ArrayFieldTitleTemplate<
|
|
|
19
19
|
S extends StrictRJSFSchema = RJSFSchema,
|
|
20
20
|
F extends FormContextType = any,
|
|
21
21
|
>(props: ArrayFieldTitleProps<T, S, F>) {
|
|
22
|
-
const {
|
|
22
|
+
const { fieldPathId, title, schema, uiSchema, required, registry, optionalDataControl } = props;
|
|
23
23
|
const options = getUiOptions<T, S, F>(uiSchema, registry.globalUiOptions);
|
|
24
24
|
const { label: displayLabel = true } = options;
|
|
25
25
|
if (!title || !displayLabel) {
|
|
@@ -32,12 +32,13 @@ export default function ArrayFieldTitleTemplate<
|
|
|
32
32
|
);
|
|
33
33
|
return (
|
|
34
34
|
<TitleFieldTemplate
|
|
35
|
-
id={titleId
|
|
35
|
+
id={titleId(fieldPathId)}
|
|
36
36
|
title={title}
|
|
37
37
|
required={required}
|
|
38
38
|
schema={schema}
|
|
39
39
|
uiSchema={uiSchema}
|
|
40
40
|
registry={registry}
|
|
41
|
+
optionalDataControl={optionalDataControl}
|
|
41
42
|
/>
|
|
42
43
|
);
|
|
43
44
|
}
|
|
@@ -85,14 +85,14 @@ export default function BaseInputTemplate<
|
|
|
85
85
|
autoFocus={autofocus}
|
|
86
86
|
value={inputValue}
|
|
87
87
|
{...inputProps}
|
|
88
|
-
list={schema.examples ? examplesId
|
|
88
|
+
list={schema.examples ? examplesId(id) : undefined}
|
|
89
89
|
onChange={onChangeOverride || _onChange}
|
|
90
90
|
onBlur={_onBlur}
|
|
91
91
|
onFocus={_onFocus}
|
|
92
|
-
aria-describedby={ariaDescribedByIds
|
|
92
|
+
aria-describedby={ariaDescribedByIds(id, !!schema.examples)}
|
|
93
93
|
/>
|
|
94
94
|
{Array.isArray(schema.examples) && (
|
|
95
|
-
<datalist key={`datalist_${id}`} id={examplesId
|
|
95
|
+
<datalist key={`datalist_${id}`} id={examplesId(id)}>
|
|
96
96
|
{(schema.examples as string[])
|
|
97
97
|
.concat(schema.default && !schema.examples.includes(schema.default) ? ([schema.default] as string[]) : [])
|
|
98
98
|
.map((example: any) => {
|
|
@@ -5,6 +5,7 @@ import IconButton from './IconButton';
|
|
|
5
5
|
/** The `AddButton` renders a button that represent the `Add` action on a form
|
|
6
6
|
*/
|
|
7
7
|
export default function AddButton<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>({
|
|
8
|
+
id,
|
|
8
9
|
className,
|
|
9
10
|
onClick,
|
|
10
11
|
disabled,
|
|
@@ -15,6 +16,7 @@ export default function AddButton<T = any, S extends StrictRJSFSchema = RJSFSche
|
|
|
15
16
|
<div className='row'>
|
|
16
17
|
<p className={`col-xs-3 col-xs-offset-9 text-right ${className}`}>
|
|
17
18
|
<IconButton
|
|
19
|
+
id={id}
|
|
18
20
|
iconType='info'
|
|
19
21
|
icon='plus'
|
|
20
22
|
className='btn-add col-xs-12'
|
|
@@ -9,11 +9,11 @@ export default function FieldErrorTemplate<
|
|
|
9
9
|
S extends StrictRJSFSchema = RJSFSchema,
|
|
10
10
|
F extends FormContextType = any,
|
|
11
11
|
>(props: FieldErrorProps<T, S, F>) {
|
|
12
|
-
const { errors = [],
|
|
12
|
+
const { errors = [], fieldPathId } = props;
|
|
13
13
|
if (errors.length === 0) {
|
|
14
14
|
return null;
|
|
15
15
|
}
|
|
16
|
-
const id = errorId
|
|
16
|
+
const id = errorId(fieldPathId);
|
|
17
17
|
|
|
18
18
|
return (
|
|
19
19
|
<div>
|
|
@@ -9,11 +9,11 @@ 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
14
|
return null;
|
|
15
15
|
}
|
|
16
|
-
const id = helpId
|
|
16
|
+
const id = helpId(fieldPathId);
|
|
17
17
|
if (typeof help === 'string') {
|
|
18
18
|
return (
|
|
19
19
|
<p id={id} className='help-block'>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { FormContextType, MultiSchemaFieldTemplateProps, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
|
|
2
|
+
|
|
3
|
+
/** The `MultiSchemaFieldTemplate` component renders the layout for the MultiSchemaField, which supports choosing
|
|
4
|
+
* a schema from a list of schemas defined using `anyOf` or `oneOf`.
|
|
5
|
+
*
|
|
6
|
+
* @param props - The `MultiSchemaFieldTemplate` to be rendered
|
|
7
|
+
*/
|
|
8
|
+
export default function MultiSchemaFieldTemplate<
|
|
9
|
+
T = any,
|
|
10
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
11
|
+
F extends FormContextType = any,
|
|
12
|
+
>(props: MultiSchemaFieldTemplateProps<T, S, F>) {
|
|
13
|
+
const { selector, optionSchemaField } = props;
|
|
14
|
+
return (
|
|
15
|
+
<div className='panel panel-default panel-body'>
|
|
16
|
+
<div className='form-group'>{selector}</div>
|
|
17
|
+
{optionSchemaField}
|
|
18
|
+
</div>
|
|
19
|
+
);
|
|
20
|
+
}
|
|
@@ -24,11 +24,13 @@ export default function ObjectFieldTemplate<
|
|
|
24
24
|
F extends FormContextType = any,
|
|
25
25
|
>(props: ObjectFieldTemplateProps<T, S, F>) {
|
|
26
26
|
const {
|
|
27
|
+
className,
|
|
27
28
|
description,
|
|
28
29
|
disabled,
|
|
29
30
|
formData,
|
|
30
|
-
|
|
31
|
+
fieldPathId,
|
|
31
32
|
onAddClick,
|
|
33
|
+
optionalDataControl,
|
|
32
34
|
properties,
|
|
33
35
|
readonly,
|
|
34
36
|
registry,
|
|
@@ -44,35 +46,38 @@ export default function ObjectFieldTemplate<
|
|
|
44
46
|
registry,
|
|
45
47
|
options,
|
|
46
48
|
);
|
|
49
|
+
const showOptionalDataControlInTitle = !readonly && !disabled;
|
|
47
50
|
// Button templates are not overridden in the uiSchema
|
|
48
51
|
const {
|
|
49
52
|
ButtonTemplates: { AddButton },
|
|
50
53
|
} = registry.templates;
|
|
51
54
|
return (
|
|
52
|
-
<fieldset id={
|
|
55
|
+
<fieldset className={className} id={fieldPathId.$id}>
|
|
53
56
|
{title && (
|
|
54
57
|
<TitleFieldTemplate
|
|
55
|
-
id={titleId
|
|
58
|
+
id={titleId(fieldPathId)}
|
|
56
59
|
title={title}
|
|
57
60
|
required={required}
|
|
58
61
|
schema={schema}
|
|
59
62
|
uiSchema={uiSchema}
|
|
60
63
|
registry={registry}
|
|
64
|
+
optionalDataControl={showOptionalDataControlInTitle ? optionalDataControl : undefined}
|
|
61
65
|
/>
|
|
62
66
|
)}
|
|
63
67
|
{description && (
|
|
64
68
|
<DescriptionFieldTemplate
|
|
65
|
-
id={descriptionId
|
|
69
|
+
id={descriptionId(fieldPathId)}
|
|
66
70
|
description={description}
|
|
67
71
|
schema={schema}
|
|
68
72
|
uiSchema={uiSchema}
|
|
69
73
|
registry={registry}
|
|
70
74
|
/>
|
|
71
75
|
)}
|
|
76
|
+
{!showOptionalDataControlInTitle ? optionalDataControl : undefined}
|
|
72
77
|
{properties.map((prop: ObjectFieldTemplatePropertyType) => prop.content)}
|
|
73
78
|
{canExpand<T, S, F>(schema, uiSchema, formData) && (
|
|
74
79
|
<AddButton
|
|
75
|
-
id={buttonId
|
|
80
|
+
id={buttonId(fieldPathId, 'add')}
|
|
76
81
|
className='rjsf-object-property-expand'
|
|
77
82
|
onClick={onAddClick(schema)}
|
|
78
83
|
disabled={disabled || readonly}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { FormContextType, OptionalDataControlsTemplateProps, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
|
|
2
|
+
|
|
3
|
+
import IconButton from './ButtonTemplates/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
|
+
icon='plus'
|
|
25
|
+
className='rjsf-add-optional-data btn-sm'
|
|
26
|
+
onClick={onAddClick}
|
|
27
|
+
title={label}
|
|
28
|
+
/>
|
|
29
|
+
);
|
|
30
|
+
} else if (onRemoveClick) {
|
|
31
|
+
return (
|
|
32
|
+
<IconButton
|
|
33
|
+
id={id}
|
|
34
|
+
registry={registry}
|
|
35
|
+
icon='remove'
|
|
36
|
+
className='rjsf-remove-optional-data btn-sm'
|
|
37
|
+
onClick={onRemoveClick}
|
|
38
|
+
title={label}
|
|
39
|
+
/>
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
return <em id={id}>{label}</em>;
|
|
43
|
+
}
|
|
@@ -9,11 +9,16 @@ const REQUIRED_FIELD_SYMBOL = '*';
|
|
|
9
9
|
export default function TitleField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
|
|
10
10
|
props: TitleFieldProps<T, S, F>,
|
|
11
11
|
) {
|
|
12
|
-
const { id, title, required } = props;
|
|
12
|
+
const { id, title, required, optionalDataControl } = props;
|
|
13
13
|
return (
|
|
14
14
|
<legend id={id}>
|
|
15
15
|
{title}
|
|
16
16
|
{required && <span className='required'>{REQUIRED_FIELD_SYMBOL}</span>}
|
|
17
|
+
{optionalDataControl && (
|
|
18
|
+
<span className='pull-right' style={{ marginBottom: '2px' }}>
|
|
19
|
+
{optionalDataControl}
|
|
20
|
+
</span>
|
|
21
|
+
)}
|
|
17
22
|
</legend>
|
|
18
23
|
);
|
|
19
24
|
}
|
|
@@ -9,13 +9,13 @@ import Markdown from 'markdown-to-jsx';
|
|
|
9
9
|
function UnsupportedField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
|
|
10
10
|
props: UnsupportedFieldProps<T, S, F>,
|
|
11
11
|
) {
|
|
12
|
-
const { schema,
|
|
12
|
+
const { schema, fieldPathId, reason, registry } = props;
|
|
13
13
|
const { translateString } = registry;
|
|
14
14
|
let translateEnum: TranslatableString = TranslatableString.UnsupportedField;
|
|
15
15
|
const translateParams: string[] = [];
|
|
16
|
-
if (
|
|
16
|
+
if (fieldPathId && fieldPathId.$id) {
|
|
17
17
|
translateEnum = TranslatableString.UnsupportedFieldWithId;
|
|
18
|
-
translateParams.push(
|
|
18
|
+
translateParams.push(fieldPathId.$id);
|
|
19
19
|
}
|
|
20
20
|
if (reason) {
|
|
21
21
|
translateEnum =
|
|
@@ -75,7 +75,7 @@ export default function WrapIfAdditionalTemplate<
|
|
|
75
75
|
<div className='form-additional form-group col-xs-5'>{children}</div>
|
|
76
76
|
<div className='col-xs-2'>
|
|
77
77
|
<RemoveButton
|
|
78
|
-
id={buttonId
|
|
78
|
+
id={buttonId(id, 'remove')}
|
|
79
79
|
className='rjsf-object-property-remove btn-block'
|
|
80
80
|
style={{ border: '0' }}
|
|
81
81
|
disabled={disabled || readonly}
|
|
@@ -13,7 +13,9 @@ import FieldTemplate from './FieldTemplate';
|
|
|
13
13
|
import FieldErrorTemplate from './FieldErrorTemplate';
|
|
14
14
|
import FieldHelpTemplate from './FieldHelpTemplate';
|
|
15
15
|
import GridTemplate from './GridTemplate';
|
|
16
|
+
import MultiSchemaFieldTemplate from './MultiSchemaFieldTemplate';
|
|
16
17
|
import ObjectFieldTemplate from './ObjectFieldTemplate';
|
|
18
|
+
import OptionalDataControlsTemplate from './OptionalDataControlsTemplate';
|
|
17
19
|
import TitleField from './TitleField';
|
|
18
20
|
import UnsupportedField from './UnsupportedField';
|
|
19
21
|
import WrapIfAdditionalTemplate from './WrapIfAdditionalTemplate';
|
|
@@ -37,7 +39,9 @@ function templates<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends F
|
|
|
37
39
|
FieldErrorTemplate,
|
|
38
40
|
FieldHelpTemplate,
|
|
39
41
|
GridTemplate,
|
|
42
|
+
MultiSchemaFieldTemplate,
|
|
40
43
|
ObjectFieldTemplate,
|
|
44
|
+
OptionalDataControlsTemplate,
|
|
41
45
|
TitleFieldTemplate: TitleField,
|
|
42
46
|
UnsupportedFieldTemplate: UnsupportedField,
|
|
43
47
|
WrapIfAdditionalTemplate,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MouseEvent, useCallback, useEffect,
|
|
1
|
+
import { MouseEvent, useCallback, useEffect, useState } from 'react';
|
|
2
2
|
import {
|
|
3
3
|
ariaDescribedByIds,
|
|
4
4
|
dateRangeOptions,
|
|
@@ -61,7 +61,7 @@ function DateElement<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends
|
|
|
61
61
|
onFocus={onFocus}
|
|
62
62
|
registry={registry}
|
|
63
63
|
label=''
|
|
64
|
-
aria-describedby={ariaDescribedByIds
|
|
64
|
+
aria-describedby={ariaDescribedByIds(rootId)}
|
|
65
65
|
/>
|
|
66
66
|
);
|
|
67
67
|
}
|
|
@@ -84,29 +84,27 @@ function AltDateWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F exten
|
|
|
84
84
|
value,
|
|
85
85
|
}: WidgetProps<T, S, F>) {
|
|
86
86
|
const { translateString } = registry;
|
|
87
|
-
const [
|
|
88
|
-
const [state, setState] = useReducer(
|
|
89
|
-
(state: DateObject, action: Partial<DateObject>) => {
|
|
90
|
-
return { ...state, ...action };
|
|
91
|
-
},
|
|
92
|
-
parseDateString(value, time),
|
|
93
|
-
);
|
|
87
|
+
const [state, setState] = useState(parseDateString(value, time));
|
|
94
88
|
|
|
95
89
|
useEffect(() => {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}, [time, value, onChange, state, lastValue]);
|
|
90
|
+
setState(parseDateString(value, time));
|
|
91
|
+
}, [time, value]);
|
|
92
|
+
|
|
93
|
+
const handleChange = useCallback(
|
|
94
|
+
(property: keyof DateObject, value: string) => {
|
|
95
|
+
const nextState = {
|
|
96
|
+
...state,
|
|
97
|
+
[property]: typeof value === 'undefined' ? -1 : value,
|
|
98
|
+
};
|
|
106
99
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
100
|
+
if (readyForChange(nextState)) {
|
|
101
|
+
onChange(toDateString(nextState, time));
|
|
102
|
+
} else {
|
|
103
|
+
setState(nextState);
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
[state, onChange, time],
|
|
107
|
+
);
|
|
110
108
|
|
|
111
109
|
const handleSetNow = useCallback(
|
|
112
110
|
(event: MouseEvent<HTMLAnchorElement>) => {
|
|
@@ -117,7 +115,7 @@ function AltDateWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F exten
|
|
|
117
115
|
const nextState = parseDateString(new Date().toJSON(), time);
|
|
118
116
|
onChange(toDateString(nextState, time));
|
|
119
117
|
},
|
|
120
|
-
[disabled, readonly, time],
|
|
118
|
+
[disabled, readonly, time, onChange],
|
|
121
119
|
);
|
|
122
120
|
|
|
123
121
|
const handleClear = useCallback(
|
|
@@ -62,7 +62,7 @@ function CheckboxWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F exte
|
|
|
62
62
|
<div className={`checkbox ${disabled || readonly ? 'disabled' : ''}`}>
|
|
63
63
|
{!hideLabel && description && (
|
|
64
64
|
<DescriptionFieldTemplate
|
|
65
|
-
id={descriptionId
|
|
65
|
+
id={descriptionId(id)}
|
|
66
66
|
description={description}
|
|
67
67
|
schema={schema}
|
|
68
68
|
uiSchema={uiSchema}
|
|
@@ -81,7 +81,7 @@ function CheckboxWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F exte
|
|
|
81
81
|
onChange={handleChange}
|
|
82
82
|
onBlur={handleBlur}
|
|
83
83
|
onFocus={handleFocus}
|
|
84
|
-
aria-describedby={ariaDescribedByIds
|
|
84
|
+
aria-describedby={ariaDescribedByIds(id)}
|
|
85
85
|
/>
|
|
86
86
|
{labelValue(<span>{label}</span>, hideLabel)}
|
|
87
87
|
</label>
|
|
@@ -33,13 +33,13 @@ function CheckboxesWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F ex
|
|
|
33
33
|
const handleBlur = useCallback(
|
|
34
34
|
({ target }: FocusEvent<HTMLInputElement>) =>
|
|
35
35
|
onBlur(id, enumOptionsValueForIndex<S>(target && target.value, enumOptions, emptyValue)),
|
|
36
|
-
[onBlur, id],
|
|
36
|
+
[onBlur, id, enumOptions, emptyValue],
|
|
37
37
|
);
|
|
38
38
|
|
|
39
39
|
const handleFocus = useCallback(
|
|
40
40
|
({ target }: FocusEvent<HTMLInputElement>) =>
|
|
41
41
|
onFocus(id, enumOptionsValueForIndex<S>(target && target.value, enumOptions, emptyValue)),
|
|
42
|
-
[onFocus, id],
|
|
42
|
+
[onFocus, id, enumOptions, emptyValue],
|
|
43
43
|
);
|
|
44
44
|
return (
|
|
45
45
|
<div className='checkboxes' id={id}>
|
|
@@ -70,7 +70,7 @@ function CheckboxesWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F ex
|
|
|
70
70
|
onChange={handleChange}
|
|
71
71
|
onBlur={handleBlur}
|
|
72
72
|
onFocus={handleFocus}
|
|
73
|
-
aria-describedby={ariaDescribedByIds
|
|
73
|
+
aria-describedby={ariaDescribedByIds(id)}
|
|
74
74
|
/>
|
|
75
75
|
<span>{option.label}</span>
|
|
76
76
|
</span>
|
|
@@ -65,7 +65,7 @@ function RadioWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends
|
|
|
65
65
|
onChange={handleChange}
|
|
66
66
|
onBlur={handleBlur}
|
|
67
67
|
onFocus={handleFocus}
|
|
68
|
-
aria-describedby={ariaDescribedByIds
|
|
68
|
+
aria-describedby={ariaDescribedByIds(id)}
|
|
69
69
|
/>
|
|
70
70
|
<span>{option.label}</span>
|
|
71
71
|
</span>
|
|
@@ -83,7 +83,7 @@ function SelectWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F extend
|
|
|
83
83
|
onBlur={handleBlur}
|
|
84
84
|
onFocus={handleFocus}
|
|
85
85
|
onChange={handleChange}
|
|
86
|
-
aria-describedby={ariaDescribedByIds
|
|
86
|
+
aria-describedby={ariaDescribedByIds(id)}
|
|
87
87
|
>
|
|
88
88
|
{showPlaceholderOption && <option value=''>{placeholder}</option>}
|
|
89
89
|
{Array.isArray(enumOptions) &&
|
|
@@ -48,7 +48,7 @@ function TextareaWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F exte
|
|
|
48
48
|
onBlur={handleBlur}
|
|
49
49
|
onFocus={handleFocus}
|
|
50
50
|
onChange={handleChange}
|
|
51
|
-
aria-describedby={ariaDescribedByIds
|
|
51
|
+
aria-describedby={ariaDescribedByIds(id)}
|
|
52
52
|
/>
|
|
53
53
|
);
|
|
54
54
|
}
|
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_ID_PREFIX,
|
|
3
|
+
DEFAULT_ID_SEPARATOR,
|
|
4
|
+
englishStringTranslator,
|
|
5
|
+
FormContextType,
|
|
6
|
+
Registry,
|
|
7
|
+
RJSFSchema,
|
|
8
|
+
StrictRJSFSchema,
|
|
9
|
+
} from '@rjsf/utils';
|
|
2
10
|
|
|
3
11
|
import fields from './components/fields';
|
|
4
12
|
import templates from './components/templates';
|
|
@@ -20,5 +28,6 @@ export default function getDefaultRegistry<
|
|
|
20
28
|
rootSchema: {} as S,
|
|
21
29
|
formContext: {} as F,
|
|
22
30
|
translateString: englishStringTranslator,
|
|
31
|
+
globalFormOptions: { idPrefix: DEFAULT_ID_PREFIX, idSeparator: DEFAULT_ID_SEPARATOR },
|
|
23
32
|
};
|
|
24
33
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_ID_PREFIX,
|
|
3
|
+
DEFAULT_ID_SEPARATOR,
|
|
4
|
+
createSchemaUtils,
|
|
5
|
+
englishStringTranslator,
|
|
6
|
+
Registry,
|
|
7
|
+
} from '@rjsf/utils';
|
|
8
|
+
import validator from '@rjsf/validator-ajv8';
|
|
9
|
+
|
|
10
|
+
import getDefaultRegistry from './getDefaultRegistry';
|
|
11
|
+
|
|
12
|
+
/** Use for react testing library tests where we directly test the component rather than testing inside a Form
|
|
13
|
+
*/
|
|
14
|
+
export default function getTestRegistry(
|
|
15
|
+
rootSchema: Registry['rootSchema'],
|
|
16
|
+
fields: Registry['fields'] = {},
|
|
17
|
+
templates: Partial<Registry['templates']> = {},
|
|
18
|
+
widgets: Registry['widgets'] = {},
|
|
19
|
+
formContext: Registry['formContext'] = {},
|
|
20
|
+
globalFormOptions: Registry['globalFormOptions'] = { idPrefix: DEFAULT_ID_PREFIX, idSeparator: DEFAULT_ID_SEPARATOR },
|
|
21
|
+
): Registry {
|
|
22
|
+
const defaults = getDefaultRegistry();
|
|
23
|
+
const schemaUtils = createSchemaUtils(validator, rootSchema);
|
|
24
|
+
return {
|
|
25
|
+
fields: { ...defaults.fields, ...fields },
|
|
26
|
+
templates: { ...defaults.templates, ...templates },
|
|
27
|
+
widgets: { ...defaults.widgets, ...widgets },
|
|
28
|
+
formContext,
|
|
29
|
+
rootSchema,
|
|
30
|
+
schemaUtils,
|
|
31
|
+
translateString: englishStringTranslator,
|
|
32
|
+
globalFormOptions,
|
|
33
|
+
};
|
|
34
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -2,8 +2,9 @@ import Form, { FormProps, FormState, IChangeEvent } from './components/Form';
|
|
|
2
2
|
import RichDescription, { RichDescriptionProps } from './components/RichDescription';
|
|
3
3
|
import withTheme, { ThemeProps } from './withTheme';
|
|
4
4
|
import getDefaultRegistry from './getDefaultRegistry';
|
|
5
|
+
import getTestRegistry from './getTestRegistry';
|
|
5
6
|
|
|
6
7
|
export type { FormProps, FormState, IChangeEvent, ThemeProps, RichDescriptionProps };
|
|
7
8
|
|
|
8
|
-
export { withTheme, getDefaultRegistry, RichDescription };
|
|
9
|
+
export { withTheme, getDefaultRegistry, getTestRegistry, RichDescription };
|
|
9
10
|
export default Form;
|