@digigov/form 2.0.0-2445d5cb → 2.0.0-298cfc51
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/Field/FieldBase/index.js +1 -0
- package/Field/FieldBase.js.map +2 -2
- package/Field/FieldBaseContainer/index.js +2 -2
- package/Field/FieldBaseContainer.js.map +2 -2
- package/Field/FieldConditional/index.js +7 -3
- package/Field/FieldConditional.js.map +2 -2
- package/Field/index.js +5 -2
- package/Field/index.js.map +2 -2
- package/Field/types.d.ts +5 -1
- package/Field/utils/index.d.ts +1 -0
- package/Field/utils/index.js +18 -1
- package/Field/utils/index.js.map +2 -2
- package/FieldArray/index.d.ts +1 -0
- package/FieldArray/index.js +7 -5
- package/FieldArray/index.js.map +2 -2
- package/FieldObject/index.d.ts +2 -0
- package/FieldObject/index.js +9 -5
- package/FieldObject/index.js.map +2 -2
- package/Fieldset/index.d.ts +1 -1
- package/Fieldset/index.js +5 -5
- package/Fieldset/index.js.map +2 -2
- package/Fieldset/types.d.ts +2 -3
- package/FormBuilder/index.d.ts +8 -2
- package/FormBuilder/index.js +150 -6
- package/FormBuilder/index.js.map +3 -3
- package/MultiplicityField/add-objects/index.js +7 -5
- package/MultiplicityField/add-objects.js.map +2 -2
- package/MultiplicityField/index.js +16 -12
- package/MultiplicityField/index.js.map +2 -2
- package/Questions/QuestionsContext.d.ts +0 -1
- package/Questions/Step/StepContext.d.ts +0 -1
- package/Questions/Step/StepTitle/index.js +4 -3
- package/Questions/Step/StepTitle.d.ts +1 -1
- package/Questions/Step/StepTitle.js.map +2 -2
- package/Questions/Step/types.d.ts +0 -1
- package/Questions/types.d.ts +0 -1
- package/cjs/Field/FieldBase/index.js +1 -0
- package/cjs/Field/FieldBase.js.map +2 -2
- package/cjs/Field/FieldBaseContainer/index.js +4 -4
- package/cjs/Field/FieldBaseContainer.js.map +3 -3
- package/cjs/Field/FieldConditional/index.js +7 -3
- package/cjs/Field/FieldConditional.js.map +2 -2
- package/cjs/Field/index.js +5 -2
- package/cjs/Field/index.js.map +2 -2
- package/cjs/Field/types.js.map +1 -1
- package/cjs/Field/utils/index.js +18 -0
- package/cjs/Field/utils/index.js.map +2 -2
- package/cjs/FieldArray/index.js +9 -7
- package/cjs/FieldArray/index.js.map +3 -3
- package/cjs/FieldObject/index.js +10 -6
- package/cjs/FieldObject/index.js.map +3 -3
- package/cjs/Fieldset/index.js +10 -10
- package/cjs/Fieldset/index.js.map +3 -3
- package/cjs/Fieldset/types.js.map +1 -1
- package/cjs/FormBuilder/index.js +165 -5
- package/cjs/FormBuilder/index.js.map +3 -3
- package/cjs/MultiplicityField/add-objects/index.js +11 -9
- package/cjs/MultiplicityField/add-objects.js.map +3 -3
- package/cjs/MultiplicityField/index.js +15 -16
- package/cjs/MultiplicityField/index.js.map +3 -3
- package/cjs/Questions/Step/StepTitle/index.js +5 -5
- package/cjs/Questions/Step/StepTitle.js.map +3 -3
- package/cjs/index.js +11 -155
- package/cjs/index.js.map +4 -4
- package/cjs/inputs/AutoCompleteInput/__stories__/Multiple/index.js +0 -1
- package/cjs/inputs/AutoCompleteInput/__stories__/Multiple.js.map +2 -2
- package/cjs/inputs/AutoCompleteInput/index.js +8 -6
- package/cjs/inputs/AutoCompleteInput/index.js.map +3 -3
- package/cjs/inputs/Checkboxes/index.js +7 -9
- package/cjs/inputs/Checkboxes/index.js.map +3 -3
- package/cjs/inputs/DateInput/index.js +3 -4
- package/cjs/inputs/DateInput/index.js.map +3 -3
- package/cjs/inputs/FileInput/index.js +7 -8
- package/cjs/inputs/FileInput/index.js.map +3 -3
- package/cjs/inputs/ImageInput/ImageInput.stories/index.js +4 -4
- package/cjs/inputs/ImageInput/ImageInput.stories.js.map +2 -2
- package/cjs/inputs/ImageInput/__stories__/MaxSize/index.js +69 -0
- package/cjs/inputs/ImageInput/__stories__/MaxSize.js.map +7 -0
- package/cjs/inputs/ImageInput/__stories__/WithInvalidImageDimension/index.js +2 -1
- package/cjs/inputs/ImageInput/__stories__/WithInvalidImageDimension.js.map +2 -2
- package/cjs/inputs/ImageInput/index.js +8 -8
- package/cjs/inputs/ImageInput/index.js.map +3 -3
- package/cjs/inputs/Input/__stories__/LandlineNumber/index.js +1 -0
- package/cjs/inputs/Input/__stories__/LandlineNumber.js.map +2 -2
- package/cjs/inputs/Input/__stories__/MobilePhone/index.js +1 -0
- package/cjs/inputs/Input/__stories__/MobilePhone.js.map +2 -2
- package/cjs/inputs/Input/__stories__/PhoneNumber/index.js +1 -0
- package/cjs/inputs/Input/__stories__/PhoneNumber.js.map +2 -2
- package/cjs/inputs/Input/__stories__/PostalCode/index.js +1 -0
- package/cjs/inputs/Input/__stories__/PostalCode.js.map +2 -2
- package/cjs/inputs/Input/index.js +20 -7
- package/cjs/inputs/Input/index.js.map +3 -3
- package/cjs/inputs/Label/index.js +3 -3
- package/cjs/inputs/Label/index.js.map +3 -3
- package/cjs/inputs/Radio/__stories__/Conditional.js.map +2 -2
- package/cjs/inputs/Radio/index.js +56 -10
- package/cjs/inputs/Radio/index.js.map +3 -3
- package/cjs/inputs/Select/index.js +3 -4
- package/cjs/inputs/Select/index.js.map +3 -3
- package/cjs/inputs/inputsScenarios/index.js +0 -1
- package/cjs/inputs/inputsScenarios.js.map +2 -2
- package/cjs/lazy/index.js +7 -2
- package/cjs/lazy.js.map +2 -2
- package/cjs/registry/index.js +2 -0
- package/cjs/registry.js.map +2 -2
- package/cjs/types.js.map +1 -1
- package/cjs/validators/index.js +16 -66
- package/cjs/validators/index.js.map +3 -3
- package/cjs/validators/utils/date/index.js +138 -0
- package/cjs/validators/utils/date.js.map +7 -0
- package/cjs/validators/utils/file/index.js +1 -1
- package/cjs/validators/utils/file.js.map +2 -2
- package/cjs/validators/utils/index.js +3 -1
- package/cjs/validators/utils/index.js.map +2 -2
- package/index.d.ts +5 -8
- package/index.js +9 -152
- package/index.js.map +4 -4
- package/inputs/AutoCompleteInput/__stories__/Multiple/index.js +0 -1
- package/inputs/AutoCompleteInput/__stories__/Multiple.js.map +2 -2
- package/inputs/AutoCompleteInput/index.js +10 -6
- package/inputs/AutoCompleteInput/index.js.map +2 -2
- package/inputs/Checkboxes/index.js +8 -6
- package/inputs/Checkboxes/index.js.map +2 -2
- package/inputs/DateInput/index.js +5 -3
- package/inputs/DateInput/index.js.map +2 -2
- package/inputs/FileInput/index.js +5 -6
- package/inputs/FileInput/index.js.map +2 -2
- package/inputs/ImageInput/ImageInput.stories/index.js +2 -2
- package/inputs/ImageInput/ImageInput.stories.d.ts +1 -1
- package/inputs/ImageInput/ImageInput.stories.js.map +2 -2
- package/inputs/ImageInput/__stories__/MaxSize/index.js +36 -0
- package/inputs/ImageInput/__stories__/MaxSize/package.json +6 -0
- package/inputs/ImageInput/__stories__/MaxSize.d.ts +3 -0
- package/inputs/ImageInput/__stories__/MaxSize.js.map +7 -0
- package/inputs/ImageInput/__stories__/WithInvalidImageDimension/index.js +2 -1
- package/inputs/ImageInput/__stories__/WithInvalidImageDimension.js.map +2 -2
- package/inputs/ImageInput/index.js +7 -7
- package/inputs/ImageInput/index.js.map +2 -2
- package/inputs/Input/__stories__/LandlineNumber/index.js +1 -0
- package/inputs/Input/__stories__/LandlineNumber.js.map +2 -2
- package/inputs/Input/__stories__/MobilePhone/index.js +1 -0
- package/inputs/Input/__stories__/MobilePhone.js.map +2 -2
- package/inputs/Input/__stories__/PhoneNumber/index.js +1 -0
- package/inputs/Input/__stories__/PhoneNumber.js.map +2 -2
- package/inputs/Input/__stories__/PostalCode/index.js +1 -0
- package/inputs/Input/__stories__/PostalCode.js.map +2 -2
- package/inputs/Input/index.js +18 -5
- package/inputs/Input/index.js.map +3 -3
- package/inputs/Label/index.js +2 -2
- package/inputs/Label/index.js.map +2 -2
- package/inputs/Radio/__stories__/Conditional.js.map +2 -2
- package/inputs/Radio/index.d.ts +4 -0
- package/inputs/Radio/index.js +57 -8
- package/inputs/Radio/index.js.map +2 -2
- package/inputs/Select/index.js +1 -2
- package/inputs/Select/index.js.map +2 -2
- package/inputs/inputsScenarios/index.js +0 -1
- package/inputs/inputsScenarios.d.ts +0 -42
- package/inputs/inputsScenarios.js.map +2 -2
- package/lazy/index.js +7 -2
- package/lazy.d.ts +16 -8
- package/lazy.js.map +2 -2
- package/package.json +4 -4
- package/registry/index.js +2 -0
- package/registry.d.ts +1 -0
- package/registry.js.map +2 -2
- package/src/Field/FieldBase.tsx +1 -0
- package/src/Field/FieldBaseContainer.tsx +2 -2
- package/src/Field/FieldConditional.tsx +4 -0
- package/src/Field/index.tsx +4 -1
- package/src/Field/types.tsx +24 -20
- package/src/Field/utils/index.ts +18 -1
- package/src/FieldArray/index.tsx +9 -5
- package/src/FieldObject/index.tsx +8 -2
- package/src/Fieldset/index.tsx +5 -5
- package/src/Fieldset/types.tsx +2 -2
- package/src/FormBuilder/{FormBuilder.mdx → doc.mdx} +20 -33
- package/src/FormBuilder/index.tsx +179 -7
- package/src/FormBuilder/scenarios.test.tsx +2 -2
- package/src/MultiplicityField/add-objects.tsx +6 -5
- package/src/MultiplicityField/{MultiplicityField.mdx → doc.mdx} +12 -16
- package/src/MultiplicityField/index.tsx +15 -12
- package/src/Questions/Step/StepTitle.tsx +4 -3
- package/src/Questions/__snapshots__/index.spec.tsx.snap +8 -4
- package/src/Questions/{index.mdx → doc.mdx} +9 -12
- package/src/create-simple-form.mdx +2 -6
- package/src/{index.mdx → doc.mdx} +4 -8
- package/src/index.ts +6 -0
- package/src/inputs/AutoCompleteInput/__stories__/Multiple.tsx +0 -1
- package/src/inputs/AutoCompleteInput/{index.mdx → doc.mdx} +2 -13
- package/src/inputs/AutoCompleteInput/index.tsx +36 -29
- package/src/inputs/Checkboxes/{index.mdx → doc.mdx} +5 -15
- package/src/inputs/Checkboxes/index.test.tsx +16 -17
- package/src/inputs/Checkboxes/index.tsx +9 -7
- package/src/inputs/DateInput/{index.mdx → doc.mdx} +1 -8
- package/src/inputs/DateInput/index.tsx +5 -3
- package/src/inputs/FileInput/{index.mdx → doc.mdx} +1 -5
- package/src/inputs/FileInput/index.tsx +5 -6
- package/src/inputs/ImageInput/ImageInput.stories.js +2 -1
- package/src/inputs/ImageInput/__stories__/MaxSize.tsx +37 -0
- package/src/inputs/ImageInput/__stories__/WithInvalidImageDimension.tsx +2 -0
- package/src/inputs/ImageInput/doc.mdx +23 -0
- package/src/inputs/ImageInput/index.test.tsx +4 -0
- package/src/inputs/ImageInput/index.tsx +9 -11
- package/src/inputs/Input/__stories__/LandlineNumber.tsx +2 -1
- package/src/inputs/Input/__stories__/MobilePhone.tsx +1 -0
- package/src/inputs/Input/__stories__/PhoneNumber.tsx +1 -0
- package/src/inputs/Input/__stories__/PostalCode.tsx +1 -0
- package/src/inputs/Input/doc.mdx +56 -0
- package/src/inputs/Input/index.tsx +33 -30
- package/src/inputs/Label/doc.mdx +14 -0
- package/src/inputs/Label/index.tsx +2 -3
- package/src/inputs/OtpInput/{index.mdx → doc.mdx} +1 -8
- package/src/inputs/Radio/__stories__/Conditional.tsx +2 -1
- package/src/inputs/Radio/{index.mdx → doc.mdx} +5 -15
- package/src/inputs/Radio/index.tsx +75 -9
- package/src/inputs/Select/{index.mdx → doc.mdx} +1 -5
- package/src/inputs/Select/index.tsx +1 -2
- package/src/inputs/inputsScenarios.ts +147 -148
- package/src/installation.mdx +2 -5
- package/src/lazy.js +7 -2
- package/src/registry.js +2 -0
- package/src/types.tsx +1 -0
- package/src/validators/index.ts +33 -71
- package/src/validators/utils/date.ts +107 -0
- package/src/validators/utils/file.ts +1 -1
- package/src/validators/utils/index.ts +1 -0
- package/types.d.ts +1 -1
- package/types.js.map +1 -1
- package/validators/index.js +20 -67
- package/validators/index.js.map +2 -2
- package/validators/utils/date/index.js +103 -0
- package/validators/utils/date/package.json +6 -0
- package/validators/utils/date.d.ts +9 -0
- package/validators/utils/date.js.map +7 -0
- package/validators/utils/file/index.js +1 -1
- package/validators/utils/file.js.map +2 -2
- package/validators/utils/index.d.ts +1 -0
- package/validators/utils/index.js +1 -0
- package/validators/utils/index.js.map +2 -2
- package/src/index.tsx +0 -178
- package/src/inputs/ImageInput/index.mdx +0 -19
- package/src/inputs/Input/index.mdx +0 -95
- package/src/inputs/Label/index.mdx +0 -0
- /package/src/Field/{index.mdx → doc.mdx} +0 -0
package/src/Field/index.tsx
CHANGED
|
@@ -56,6 +56,7 @@ export const Field: React.FC<FieldProps> = ({
|
|
|
56
56
|
register={register}
|
|
57
57
|
field={calculatedField as FieldWithCondition}
|
|
58
58
|
error={error}
|
|
59
|
+
Field={Field}
|
|
59
60
|
/>
|
|
60
61
|
);
|
|
61
62
|
}
|
|
@@ -67,6 +68,7 @@ export const Field: React.FC<FieldProps> = ({
|
|
|
67
68
|
register={register}
|
|
68
69
|
error={error}
|
|
69
70
|
formState={formState}
|
|
71
|
+
Field={Field}
|
|
70
72
|
{...calculatedField}
|
|
71
73
|
/>
|
|
72
74
|
);
|
|
@@ -87,6 +89,7 @@ export const Field: React.FC<FieldProps> = ({
|
|
|
87
89
|
setValue={setValue}
|
|
88
90
|
getValues={getValues}
|
|
89
91
|
unregister={unregister}
|
|
92
|
+
Field={Field}
|
|
90
93
|
{...calculatedField}
|
|
91
94
|
/>
|
|
92
95
|
);
|
|
@@ -100,7 +103,7 @@ export const Field: React.FC<FieldProps> = ({
|
|
|
100
103
|
register={register}
|
|
101
104
|
reset={reset}
|
|
102
105
|
error={error}
|
|
103
|
-
|
|
106
|
+
Field={Field}
|
|
104
107
|
/>
|
|
105
108
|
);
|
|
106
109
|
};
|
package/src/Field/types.tsx
CHANGED
|
@@ -11,26 +11,27 @@ export type FieldLabelProps = {
|
|
|
11
11
|
export interface FieldSpec {
|
|
12
12
|
key: string; // !TODO rename key to name;
|
|
13
13
|
type?:
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
14
|
+
| 'int'
|
|
15
|
+
| 'string'
|
|
16
|
+
| 'text'
|
|
17
|
+
| 'boolean'
|
|
18
|
+
| 'email'
|
|
19
|
+
| 'uuid4'
|
|
20
|
+
| 'choice:multiple'
|
|
21
|
+
| 'choice:single'
|
|
22
|
+
| 'mobile_phone'
|
|
23
|
+
| 'date'
|
|
24
|
+
| 'otp'
|
|
25
|
+
| 'afm'
|
|
26
|
+
| 'iban'
|
|
27
|
+
| 'file'
|
|
28
|
+
| 'image'
|
|
29
|
+
| 'postal_code'
|
|
30
|
+
| 'phone_number'
|
|
31
|
+
| 'array'
|
|
32
|
+
| 'object';
|
|
33
33
|
component?: any;
|
|
34
|
+
autoComplete?: string;
|
|
34
35
|
maxLength?: number;
|
|
35
36
|
condition?: Record<string, FieldCondition>;
|
|
36
37
|
controlled?: boolean;
|
|
@@ -77,6 +78,7 @@ export interface FieldConditionalProps {
|
|
|
77
78
|
register: UseFormReturn['register'];
|
|
78
79
|
reset: UseFormReturn['reset'];
|
|
79
80
|
error?: ErrorOption;
|
|
81
|
+
Field: React.FC<FieldProps>;
|
|
80
82
|
}
|
|
81
83
|
|
|
82
84
|
export type FieldComponentItem = {
|
|
@@ -111,6 +113,7 @@ export interface ControlledFieldProps {
|
|
|
111
113
|
error?: boolean;
|
|
112
114
|
name?: string;
|
|
113
115
|
disabled?: boolean;
|
|
116
|
+
Field: React.FC<FieldProps>;
|
|
114
117
|
}
|
|
115
118
|
|
|
116
119
|
export interface UncontrolledFieldProps {
|
|
@@ -121,6 +124,7 @@ export interface UncontrolledFieldProps {
|
|
|
121
124
|
extra?: Record<string, never>;
|
|
122
125
|
type?: string;
|
|
123
126
|
disabled?: boolean;
|
|
127
|
+
Field: React.FC<FieldProps>;
|
|
124
128
|
}
|
|
125
129
|
|
|
126
130
|
export interface CalculatedField extends OmittedFieldSpec {
|
|
@@ -137,7 +141,7 @@ export interface FieldBaseProps extends CalculatedField {
|
|
|
137
141
|
control: UseFormReturn['control'];
|
|
138
142
|
register: UseFormReturn['register'];
|
|
139
143
|
reset: UseFormReturn['reset'];
|
|
140
|
-
|
|
144
|
+
Field: React.FC<FieldProps>;
|
|
141
145
|
}
|
|
142
146
|
|
|
143
147
|
export interface FieldProps extends FieldSpec {
|
package/src/Field/utils/index.ts
CHANGED
|
@@ -6,7 +6,7 @@ import FileInput from '@digigov/form/inputs/FileInput';
|
|
|
6
6
|
import ImageInput from '@digigov/form/inputs/ImageInput';
|
|
7
7
|
import Input from '@digigov/form/inputs/Input';
|
|
8
8
|
import OtpInput from '@digigov/form/inputs/OtpInput';
|
|
9
|
-
import Radio from '@digigov/form/inputs/Radio';
|
|
9
|
+
import Radio, { ControlledRadioButtonsGroup } from '@digigov/form/inputs/Radio';
|
|
10
10
|
import Select from '@digigov/form/inputs/Select';
|
|
11
11
|
|
|
12
12
|
export const FIELD_COMPONENTS: FieldComponentRegistry = {
|
|
@@ -57,3 +57,20 @@ export const ALTERNATIVE_COMPONENTS: FieldComponentRegistry = {
|
|
|
57
57
|
wrapper: 'fieldset',
|
|
58
58
|
},
|
|
59
59
|
};
|
|
60
|
+
|
|
61
|
+
export const CONTROLLED_FIELD_COMPONENTS: FieldComponentRegistry = {
|
|
62
|
+
...FIELD_COMPONENTS,
|
|
63
|
+
'choice:single': {
|
|
64
|
+
wrapper: 'fieldset',
|
|
65
|
+
controlled: true,
|
|
66
|
+
component: ControlledRadioButtonsGroup,
|
|
67
|
+
},
|
|
68
|
+
text: {
|
|
69
|
+
component: Input,
|
|
70
|
+
controlled: true,
|
|
71
|
+
},
|
|
72
|
+
string: {
|
|
73
|
+
component: Input,
|
|
74
|
+
controlled: true,
|
|
75
|
+
},
|
|
76
|
+
};
|
package/src/FieldArray/index.tsx
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { ErrorOption, useFieldArray, UseFormReturn } from 'react-hook-form';
|
|
3
|
-
import
|
|
3
|
+
import { FieldBaseContainer } from '@digigov/form/Field/FieldBaseContainer';
|
|
4
4
|
import { FieldProps } from '@digigov/form/Field/types';
|
|
5
|
-
import FieldObject from '@digigov/form/FieldObject';
|
|
5
|
+
import { FieldObject } from '@digigov/form/FieldObject';
|
|
6
6
|
import { FieldsetLabel } from '@digigov/form/Fieldset';
|
|
7
|
-
import Fieldset from '@digigov/
|
|
7
|
+
import { Fieldset } from '@digigov/form/Fieldset';
|
|
8
8
|
import { Card } from '@digigov/ui/content/Card';
|
|
9
9
|
import { Button } from '@digigov/ui/form/Button';
|
|
10
10
|
import { Hint } from '@digigov/ui/typography/Hint';
|
|
11
|
+
|
|
11
12
|
export interface FieldArrayProps extends FieldProps {
|
|
12
13
|
control: UseFormReturn['control'];
|
|
13
14
|
register: UseFormReturn['register'];
|
|
14
15
|
formState: UseFormReturn['formState'];
|
|
15
16
|
error?: ErrorOption;
|
|
17
|
+
Field: React.FC<FieldProps>;
|
|
16
18
|
}
|
|
17
19
|
export const FieldArray: React.FC<FieldArrayProps> = ({
|
|
18
20
|
name,
|
|
@@ -22,6 +24,7 @@ export const FieldArray: React.FC<FieldArrayProps> = ({
|
|
|
22
24
|
error,
|
|
23
25
|
layout,
|
|
24
26
|
label,
|
|
27
|
+
Field,
|
|
25
28
|
...customField
|
|
26
29
|
}) => {
|
|
27
30
|
const { fields, append, remove } = useFieldArray({
|
|
@@ -30,7 +33,7 @@ export const FieldArray: React.FC<FieldArrayProps> = ({
|
|
|
30
33
|
});
|
|
31
34
|
|
|
32
35
|
return (
|
|
33
|
-
<
|
|
36
|
+
<FieldBaseContainer
|
|
34
37
|
label={label}
|
|
35
38
|
layout={layout}
|
|
36
39
|
error={
|
|
@@ -60,6 +63,7 @@ export const FieldArray: React.FC<FieldArrayProps> = ({
|
|
|
60
63
|
register={register}
|
|
61
64
|
control={control}
|
|
62
65
|
{...customField.extra?.of}
|
|
66
|
+
Field={Field}
|
|
63
67
|
/>
|
|
64
68
|
<Button
|
|
65
69
|
name={`${name}-object-remove`}
|
|
@@ -84,7 +88,7 @@ export const FieldArray: React.FC<FieldArrayProps> = ({
|
|
|
84
88
|
>
|
|
85
89
|
{customField.extra?.label.object?.add}
|
|
86
90
|
</Button>
|
|
87
|
-
</
|
|
91
|
+
</FieldBaseContainer>
|
|
88
92
|
);
|
|
89
93
|
};
|
|
90
94
|
|
|
@@ -7,9 +7,9 @@ import {
|
|
|
7
7
|
ALTERNATIVE_COMPONENTS,
|
|
8
8
|
} from '@digigov/form/Field/utils';
|
|
9
9
|
import { calculateField } from '@digigov/form/Field/utils/calculateField';
|
|
10
|
-
import Fieldset,
|
|
10
|
+
import { Fieldset, FieldsetCaption } from '@digigov/form/Fieldset';
|
|
11
11
|
import { FieldSpec } from '@digigov/form/types';
|
|
12
|
-
import { FieldsetLegend } from '@digigov/
|
|
12
|
+
import { FieldsetLegend } from '@digigov/ui/form/FieldContainer';
|
|
13
13
|
import { useTranslation } from '@digigov/ui/i18n';
|
|
14
14
|
|
|
15
15
|
export interface FieldObjectProps extends Omit<FieldProps, 'key'> {
|
|
@@ -18,6 +18,7 @@ export interface FieldObjectProps extends Omit<FieldProps, 'key'> {
|
|
|
18
18
|
reset: UseFormReturn['reset'];
|
|
19
19
|
formState: UseFormReturn['formState'];
|
|
20
20
|
error?: ErrorOption;
|
|
21
|
+
Field: React.FC<FieldProps>;
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
export const FieldObject: React.FC<FieldObjectProps> = ({
|
|
@@ -29,6 +30,7 @@ export const FieldObject: React.FC<FieldObjectProps> = ({
|
|
|
29
30
|
reset,
|
|
30
31
|
formState,
|
|
31
32
|
error,
|
|
33
|
+
Field,
|
|
32
34
|
}) => {
|
|
33
35
|
const { t } = useTranslation();
|
|
34
36
|
|
|
@@ -50,6 +52,7 @@ export const FieldObject: React.FC<FieldObjectProps> = ({
|
|
|
50
52
|
field={field}
|
|
51
53
|
error={error && error[field.key]}
|
|
52
54
|
formState={formState}
|
|
55
|
+
Field={Field}
|
|
53
56
|
/>
|
|
54
57
|
))}
|
|
55
58
|
</Fieldset>
|
|
@@ -65,6 +68,7 @@ export interface FieldObjectItemProps {
|
|
|
65
68
|
formState: UseFormReturn['formState'];
|
|
66
69
|
error?: ErrorOption;
|
|
67
70
|
children?: React.ReactNode;
|
|
71
|
+
Field: React.FC<FieldProps>;
|
|
68
72
|
}
|
|
69
73
|
|
|
70
74
|
const FieldObjectItem: React.FC<FieldObjectItemProps> = ({
|
|
@@ -76,6 +80,7 @@ const FieldObjectItem: React.FC<FieldObjectItemProps> = ({
|
|
|
76
80
|
formState,
|
|
77
81
|
reset,
|
|
78
82
|
register,
|
|
83
|
+
Field,
|
|
79
84
|
}) => {
|
|
80
85
|
const calculatedField: CalculatedField = useMemo(
|
|
81
86
|
() =>
|
|
@@ -88,6 +93,7 @@ const FieldObjectItem: React.FC<FieldObjectItemProps> = ({
|
|
|
88
93
|
<FieldBase
|
|
89
94
|
{...calculatedField}
|
|
90
95
|
name={name}
|
|
96
|
+
Field={Field}
|
|
91
97
|
control={control}
|
|
92
98
|
reset={reset}
|
|
93
99
|
register={register}
|
package/src/Fieldset/index.tsx
CHANGED
|
@@ -4,11 +4,11 @@ import {
|
|
|
4
4
|
FieldsetCaptionProps,
|
|
5
5
|
FieldsetBodyProps,
|
|
6
6
|
} from '@digigov/form/Fieldset/types';
|
|
7
|
-
import Fieldset from '@digigov/react-core/Fieldset';
|
|
8
|
-
import FieldsetLegend from '@digigov/
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import NormalText from '@digigov/ui/typography/NormalText';
|
|
7
|
+
import { Fieldset } from '@digigov/react-core/Fieldset';
|
|
8
|
+
import { FieldsetLegend } from '@digigov/ui/form/FieldContainer';
|
|
9
|
+
import { Grid } from '@digigov/ui/layouts/Grid';
|
|
10
|
+
import { Hint } from '@digigov/ui/typography/Hint';
|
|
11
|
+
import { NormalText } from '@digigov/ui/typography/NormalText';
|
|
12
12
|
|
|
13
13
|
export const FieldsetLabel: React.FC<FieldsetLabelProps> = ({
|
|
14
14
|
children,
|
package/src/Fieldset/types.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { FieldsetLegendProps } from '@digigov/
|
|
2
|
-
import { HintProps } from '@digigov/
|
|
1
|
+
import { FieldsetLegendProps } from '@digigov/ui/form/FieldContainer';
|
|
2
|
+
import { HintProps } from '@digigov/ui/typography/Hint';
|
|
3
3
|
|
|
4
4
|
export interface FieldsetLabelProps extends FieldsetLegendProps {}
|
|
5
5
|
export interface FieldsetCaptionProps extends HintProps {}
|
|
@@ -8,11 +8,8 @@ sidebar_label: FormBuilder
|
|
|
8
8
|
|
|
9
9
|
`stepForm` component:
|
|
10
10
|
|
|
11
|
-
<
|
|
12
|
-
|
|
13
|
-
component="FormBuilder"
|
|
14
|
-
story="Default.tsx"
|
|
15
|
-
/>
|
|
11
|
+
<code src="@digigov/form/FormBuilder/__stories__/Default.tsx" />
|
|
12
|
+
|
|
16
13
|
|
|
17
14
|
### Importing and using FormBuilder Component
|
|
18
15
|
|
|
@@ -34,18 +31,14 @@ import BasicLayout, {
|
|
|
34
31
|
import {FormBuilder} from '@digigov/form';
|
|
35
32
|
|
|
36
33
|
export default function MyComponent({ props }) {
|
|
37
|
-
|
|
38
34
|
return (
|
|
39
35
|
<BasicLayout>
|
|
40
|
-
|
|
41
|
-
.
|
|
36
|
+
/* code */
|
|
42
37
|
<Container>
|
|
43
38
|
<Main>
|
|
44
|
-
|
|
45
|
-
.
|
|
39
|
+
/* code */
|
|
46
40
|
<FormBuilder></FormBuilder>
|
|
47
|
-
|
|
48
|
-
.
|
|
41
|
+
/* code */
|
|
49
42
|
</Main>
|
|
50
43
|
</Container>
|
|
51
44
|
<Bottom>
|
|
@@ -54,7 +47,6 @@ export default function MyComponent({ props }) {
|
|
|
54
47
|
</BasicLayout>
|
|
55
48
|
);
|
|
56
49
|
}
|
|
57
|
-
}
|
|
58
50
|
```
|
|
59
51
|
|
|
60
52
|
### Props
|
|
@@ -83,7 +75,7 @@ Below are demostrated some examples for each type of field
|
|
|
83
75
|
|
|
84
76
|
The examples above are implemented by using the code below
|
|
85
77
|
|
|
86
|
-
```
|
|
78
|
+
```jsx
|
|
87
79
|
import React, { useState } from 'react';
|
|
88
80
|
import BasicLayout, {
|
|
89
81
|
Top,
|
|
@@ -91,7 +83,7 @@ import BasicLayout, {
|
|
|
91
83
|
Main,
|
|
92
84
|
Bottom,
|
|
93
85
|
} from '@digigov/ui/layouts/Basic';
|
|
94
|
-
import Header, { HeaderTitle } from '@digigov/ui/app/Header';
|
|
86
|
+
import Header, { HeaderTitle, HeaderContent, HeaderSection } from '@digigov/ui/app/Header';
|
|
95
87
|
import GovGRLogo from '@digigov/ui/govgr/GovGRLogo';
|
|
96
88
|
import GovGRFooter from '@digigov/ui/govgr/Footer';
|
|
97
89
|
import Button from '@digigov/ui/form/Button';
|
|
@@ -99,8 +91,9 @@ import PageTitleContainer, {
|
|
|
99
91
|
PageTitleCaption,
|
|
100
92
|
PageTitleHeading,
|
|
101
93
|
} from '@digigov/ui/app/PageTitleContainer';
|
|
102
|
-
import
|
|
103
|
-
import FormBuilder, { Fieldset,
|
|
94
|
+
import BackLink from '@digigov/ui/navigation/BackLink';
|
|
95
|
+
import FormBuilder, { Fieldset, Field } from '@digigov/form';
|
|
96
|
+
import { FieldsetLabel } from '@digigov/form/Fieldset';
|
|
104
97
|
import { useTranslation } from '@digigov/ui/i18n';
|
|
105
98
|
|
|
106
99
|
const FIELDS = [
|
|
@@ -203,30 +196,24 @@ const initialValues = {
|
|
|
203
196
|
string: 'default content',
|
|
204
197
|
};
|
|
205
198
|
|
|
206
|
-
const useStyles = makeStyles(
|
|
207
|
-
{
|
|
208
|
-
top: { minHeight: '75px' },
|
|
209
|
-
main: {},
|
|
210
|
-
side: {},
|
|
211
|
-
},
|
|
212
|
-
{ name: 'MuiSite' }
|
|
213
|
-
);
|
|
214
|
-
|
|
215
199
|
export default function Index() {
|
|
216
|
-
const styles = useStyles();
|
|
217
200
|
const [data, setData] = useState(null);
|
|
218
201
|
const { t } = useTranslation();
|
|
219
202
|
return (
|
|
220
203
|
<BasicLayout>
|
|
221
|
-
<Top
|
|
204
|
+
<Top>
|
|
222
205
|
<Header>
|
|
223
|
-
<
|
|
224
|
-
|
|
206
|
+
<HeaderContent>
|
|
207
|
+
<HeaderSection>
|
|
208
|
+
<GovGRLogo />
|
|
209
|
+
<HeaderTitle>Service name</HeaderTitle>
|
|
210
|
+
</HeaderSection>
|
|
211
|
+
</HeaderContent>
|
|
225
212
|
</Header>
|
|
226
213
|
</Top>
|
|
227
214
|
<Container>
|
|
228
|
-
<Main
|
|
229
|
-
<
|
|
215
|
+
<Main>
|
|
216
|
+
<BackLink>Back</BackLink>
|
|
230
217
|
<PageTitleContainer>
|
|
231
218
|
<PageTitleCaption>Before we start</PageTitleCaption>
|
|
232
219
|
<PageTitleHeading>Submit a form</PageTitleHeading>
|
|
@@ -237,7 +224,7 @@ export default function Index() {
|
|
|
237
224
|
initial={initialValues}
|
|
238
225
|
>
|
|
239
226
|
<Fieldset>
|
|
240
|
-
<FieldsetLabel>This is a fieldset</FieldsetLabel>
|
|
227
|
+
<FieldsetLabel size="lg">This is a fieldset</FieldsetLabel>
|
|
241
228
|
{FIELDS.map((field) => (
|
|
242
229
|
<Field key={field.key} name={field.key} />
|
|
243
230
|
))}
|
|
@@ -1,8 +1,180 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
} from '@digigov/form';
|
|
7
|
-
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
import React, { useCallback, useContext, useRef } from 'react';
|
|
3
|
+
import { useForm } from 'react-hook-form';
|
|
4
|
+
import { Field } from '@digigov/form/Field';
|
|
5
|
+
import { CONTROLLED_FIELD_COMPONENTS } from '@digigov/form/Field/utils';
|
|
6
|
+
import { Fieldset } from '@digigov/form/Fieldset';
|
|
7
|
+
import { FormContext } from '@digigov/form/FormContext';
|
|
8
|
+
import { FormBaseProps, FormData, FormBuilderProps } from '@digigov/form/types';
|
|
9
|
+
import { yupResolver } from '@digigov/form/utils';
|
|
10
|
+
import { useValidationSchema } from '@digigov/form/validators';
|
|
11
|
+
import { Button } from '@digigov/ui/form/Button';
|
|
12
|
+
import { Form } from '@digigov/ui/form/Form';
|
|
13
|
+
|
|
14
|
+
const FormBase = React.forwardRef(function FormBase(
|
|
15
|
+
{
|
|
16
|
+
onSubmit,
|
|
17
|
+
children,
|
|
18
|
+
registerField,
|
|
19
|
+
fieldsMap,
|
|
20
|
+
fieldsetsMap,
|
|
21
|
+
resolver,
|
|
22
|
+
mode,
|
|
23
|
+
initial,
|
|
24
|
+
reValidateMode,
|
|
25
|
+
shouldFocusError,
|
|
26
|
+
criteriaMode,
|
|
27
|
+
componentRegistry,
|
|
28
|
+
grid,
|
|
29
|
+
...props
|
|
30
|
+
}: FormBaseProps,
|
|
31
|
+
ref: React.Ref<HTMLFormElement>
|
|
32
|
+
) {
|
|
33
|
+
const form = useForm({
|
|
34
|
+
resolver,
|
|
35
|
+
mode,
|
|
36
|
+
defaultValues: initial,
|
|
37
|
+
reValidateMode,
|
|
38
|
+
shouldFocusError,
|
|
39
|
+
criteriaMode,
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
const handleSubmit = useCallback(
|
|
43
|
+
(data: FormData): void => {
|
|
44
|
+
onSubmit && onSubmit(data);
|
|
45
|
+
},
|
|
46
|
+
[onSubmit]
|
|
47
|
+
);
|
|
48
|
+
const submit = form.handleSubmit(handleSubmit);
|
|
49
|
+
const ctx = {
|
|
50
|
+
fieldsMap,
|
|
51
|
+
fieldsetsMap,
|
|
52
|
+
control: form.control,
|
|
53
|
+
register: form.register,
|
|
54
|
+
watch: form.watch,
|
|
55
|
+
resetField: form.resetField,
|
|
56
|
+
registerField: registerField,
|
|
57
|
+
errors: form.formState.errors,
|
|
58
|
+
formState: form.formState,
|
|
59
|
+
reset: form.reset,
|
|
60
|
+
trigger: form.trigger,
|
|
61
|
+
getFieldState: form.getFieldState,
|
|
62
|
+
setValue: form.setValue,
|
|
63
|
+
clearErrors: form.clearErrors,
|
|
64
|
+
getValues: form.getValues,
|
|
65
|
+
unregister: form.unregister,
|
|
66
|
+
componentRegistry,
|
|
67
|
+
setError: form.setError,
|
|
68
|
+
formRef: ref,
|
|
69
|
+
submit,
|
|
70
|
+
};
|
|
71
|
+
return (
|
|
72
|
+
<FormContext.Provider value={ctx}>
|
|
73
|
+
<Form grid={grid} onSubmit={submit} ref={ref} {...props}>
|
|
74
|
+
{children}
|
|
75
|
+
</Form>
|
|
76
|
+
</FormContext.Provider>
|
|
77
|
+
);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
const useFormContext = () => {
|
|
81
|
+
return useContext(FormContext);
|
|
82
|
+
};
|
|
83
|
+
const useFormValues = () => {
|
|
84
|
+
const ctx = useFormContext();
|
|
85
|
+
return ctx.getValues();
|
|
86
|
+
};
|
|
87
|
+
const FormBuilder = React.forwardRef(function FormBuilder(
|
|
88
|
+
{
|
|
89
|
+
fields = [],
|
|
90
|
+
fieldsets,
|
|
91
|
+
initial = {},
|
|
92
|
+
onSubmit,
|
|
93
|
+
children,
|
|
94
|
+
reValidateMode = 'onSubmit',
|
|
95
|
+
mode = 'onSubmit',
|
|
96
|
+
shouldFocusError = true,
|
|
97
|
+
criteriaMode = 'all',
|
|
98
|
+
auto = false,
|
|
99
|
+
validatorRegistry,
|
|
100
|
+
componentRegistry,
|
|
101
|
+
grid = false,
|
|
102
|
+
...props
|
|
103
|
+
}: FormBuilderProps,
|
|
104
|
+
ref: React.Ref<HTMLFormElement>
|
|
105
|
+
): React.ReactElement {
|
|
106
|
+
const fieldsState = useRef(fields);
|
|
107
|
+
const setFieldsState = useCallback((newFields) => {
|
|
108
|
+
fieldsState.current = newFields;
|
|
109
|
+
}, []);
|
|
110
|
+
const schema = useValidationSchema(fieldsState, validatorRegistry);
|
|
111
|
+
const registerField = useCallback((field) => {
|
|
112
|
+
const fieldIndex = fieldsState.current.findIndex(
|
|
113
|
+
(f) => f.key === field.key
|
|
114
|
+
);
|
|
115
|
+
if (fieldIndex > -1) {
|
|
116
|
+
fieldsState.current[fieldIndex] = field;
|
|
117
|
+
} else {
|
|
118
|
+
fieldsState.current.push(field);
|
|
119
|
+
}
|
|
120
|
+
setFieldsState(fieldsState.current);
|
|
121
|
+
}, []);
|
|
122
|
+
let resolver;
|
|
123
|
+
let fieldsMap;
|
|
124
|
+
let fieldsetsMap;
|
|
125
|
+
let fieldChildren;
|
|
126
|
+
if (schema) {
|
|
127
|
+
resolver = yupResolver(schema);
|
|
128
|
+
fieldsMap = fields
|
|
129
|
+
? fields.reduce((map, field) => ({ ...map, [field.key]: field }), {})
|
|
130
|
+
: {};
|
|
131
|
+
fieldsetsMap =
|
|
132
|
+
fieldsets &&
|
|
133
|
+
fieldsets.reduce(
|
|
134
|
+
(map, fieldset) => ({ ...map, [fieldset.key]: fieldset }),
|
|
135
|
+
{}
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
if (auto) {
|
|
139
|
+
if (fieldsets) {
|
|
140
|
+
fieldChildren = fieldsets.map((fieldset) => (
|
|
141
|
+
<Fieldset key={fieldset.key} />
|
|
142
|
+
));
|
|
143
|
+
} else if (fields) {
|
|
144
|
+
fieldChildren = fields.map((field) => (
|
|
145
|
+
<Field key={field.key} name={field.key} />
|
|
146
|
+
));
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return (
|
|
151
|
+
<FormBase
|
|
152
|
+
resolver={resolver}
|
|
153
|
+
fieldsetsMap={fieldsetsMap}
|
|
154
|
+
fieldsMap={fieldsMap}
|
|
155
|
+
registerField={registerField}
|
|
156
|
+
initial={initial}
|
|
157
|
+
reValidateMode={reValidateMode}
|
|
158
|
+
mode={mode}
|
|
159
|
+
shouldFocusError={shouldFocusError}
|
|
160
|
+
criteriaMode={criteriaMode}
|
|
161
|
+
onSubmit={onSubmit}
|
|
162
|
+
componentRegistry={componentRegistry}
|
|
163
|
+
ref={ref}
|
|
164
|
+
grid={grid}
|
|
165
|
+
{...props}
|
|
166
|
+
>
|
|
167
|
+
{fieldChildren}
|
|
168
|
+
{auto && <Button type="submit">Συνέχεια</Button>}
|
|
169
|
+
{children}
|
|
170
|
+
</FormBase>
|
|
171
|
+
);
|
|
172
|
+
});
|
|
173
|
+
export const ControlledFormBuilder = (props) => {
|
|
174
|
+
return (
|
|
175
|
+
<FormBuilder {...props} componentRegistry={CONTROLLED_FIELD_COMPONENTS} />
|
|
176
|
+
);
|
|
177
|
+
};
|
|
8
178
|
export default FormBuilder;
|
|
179
|
+
|
|
180
|
+
export { useFormContext, useFormValues, FormBase };
|
|
@@ -1120,7 +1120,7 @@ const inputsScenarios = [
|
|
|
1120
1120
|
args: {
|
|
1121
1121
|
maxSizeToMb: 0.0003,
|
|
1122
1122
|
},
|
|
1123
|
-
text: el.form.error.
|
|
1123
|
+
text: el.form.error.image_size,
|
|
1124
1124
|
},
|
|
1125
1125
|
{
|
|
1126
1126
|
type: 'error',
|
|
@@ -1847,7 +1847,7 @@ for (const scenario of scenarios) {
|
|
|
1847
1847
|
test(scenario.title, async ({ mount, page }) => {
|
|
1848
1848
|
const formBuilder = await mount(
|
|
1849
1849
|
// @ts-ignore
|
|
1850
|
-
<FormBuilder auto={true} fields={scenario.fields} onSubmit={() => {}} />
|
|
1850
|
+
<FormBuilder auto={true} fields={scenario.fields} onSubmit={() => { }} />
|
|
1851
1851
|
);
|
|
1852
1852
|
await fillFields(page, formBuilder, scenario);
|
|
1853
1853
|
await submitForm(formBuilder);
|
|
@@ -14,16 +14,15 @@ import {
|
|
|
14
14
|
} from '@digigov/form/Field/utils';
|
|
15
15
|
import { calculateField } from '@digigov/form/Field/utils/calculateField';
|
|
16
16
|
import { useField } from '@digigov/form/Field/utils/useField';
|
|
17
|
-
|
|
18
|
-
import
|
|
17
|
+
import { FieldObject } from '@digigov/form/FieldObject';
|
|
18
|
+
import { Fieldset } from '@digigov/form/Fieldset';
|
|
19
19
|
import type {
|
|
20
20
|
MultiplicityProps,
|
|
21
21
|
StashedObject,
|
|
22
22
|
} from '@digigov/form/MultiplicityField/types';
|
|
23
23
|
import { FieldSpec } from '@digigov/form/types';
|
|
24
|
-
import
|
|
25
|
-
import RadioConditional from '@digigov/
|
|
26
|
-
import Button from '@digigov/ui/form/Button';
|
|
24
|
+
import { Button } from '@digigov/ui/form/Button';
|
|
25
|
+
import { RadioConditional } from '@digigov/ui/form/RadioContainer';
|
|
27
26
|
|
|
28
27
|
export interface AddObjectsProps
|
|
29
28
|
extends Omit<MultiplicityProps, 'key' | 'component'> {
|
|
@@ -51,6 +50,7 @@ export const AddObjects: React.FC<AddObjectsProps> = ({
|
|
|
51
50
|
getValues,
|
|
52
51
|
onStash,
|
|
53
52
|
error,
|
|
53
|
+
Field,
|
|
54
54
|
}) => {
|
|
55
55
|
const currentIndex = fields.length > 0 ? fields.length - 1 : fields.length;
|
|
56
56
|
const currentName = `${name}.${currentIndex}`;
|
|
@@ -186,6 +186,7 @@ export const AddObjects: React.FC<AddObjectsProps> = ({
|
|
|
186
186
|
control={control}
|
|
187
187
|
register={register}
|
|
188
188
|
reset={reset}
|
|
189
|
+
Field={Field}
|
|
189
190
|
error={
|
|
190
191
|
extra?.max - stashedObjects.length === 0 ||
|
|
191
192
|
extra?.length - stashedObjects.length === 0
|