@digigov/form 2.0.0-2445d5cb → 2.0.0-36b707c1

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.
Files changed (141) hide show
  1. package/Field/FieldBase/index.js +1 -0
  2. package/Field/FieldBase.js.map +2 -2
  3. package/Field/FieldBaseContainer/index.js +1 -1
  4. package/Field/FieldBaseContainer.js.map +2 -2
  5. package/Field/FieldConditional/index.js +7 -3
  6. package/Field/FieldConditional.js.map +2 -2
  7. package/Field/index.js +5 -2
  8. package/Field/index.js.map +2 -2
  9. package/Field/types.d.ts +4 -1
  10. package/Field/utils/index.d.ts +1 -0
  11. package/Field/utils/index.js +18 -1
  12. package/Field/utils/index.js.map +2 -2
  13. package/FieldArray/index.d.ts +1 -0
  14. package/FieldArray/index.js +3 -1
  15. package/FieldArray/index.js.map +2 -2
  16. package/FieldObject/index.d.ts +2 -0
  17. package/FieldObject/index.js +7 -3
  18. package/FieldObject/index.js.map +2 -2
  19. package/Fieldset/types.d.ts +0 -1
  20. package/FormBuilder/index.d.ts +8 -2
  21. package/FormBuilder/index.js +150 -6
  22. package/FormBuilder/index.js.map +3 -3
  23. package/MultiplicityField/add-objects/index.js +3 -1
  24. package/MultiplicityField/add-objects.js.map +2 -2
  25. package/MultiplicityField/index.js +4 -2
  26. package/MultiplicityField/index.js.map +2 -2
  27. package/Questions/QuestionsContext.d.ts +0 -1
  28. package/Questions/Step/StepContext.d.ts +0 -1
  29. package/Questions/Step/types.d.ts +0 -1
  30. package/Questions/types.d.ts +0 -1
  31. package/cjs/Field/FieldBase/index.js +1 -0
  32. package/cjs/Field/FieldBase.js.map +2 -2
  33. package/cjs/Field/FieldBaseContainer/index.js +3 -3
  34. package/cjs/Field/FieldBaseContainer.js.map +3 -3
  35. package/cjs/Field/FieldConditional/index.js +7 -3
  36. package/cjs/Field/FieldConditional.js.map +2 -2
  37. package/cjs/Field/index.js +5 -2
  38. package/cjs/Field/index.js.map +2 -2
  39. package/cjs/Field/types.js.map +1 -1
  40. package/cjs/Field/utils/index.js +18 -0
  41. package/cjs/Field/utils/index.js.map +2 -2
  42. package/cjs/FieldArray/index.js +3 -1
  43. package/cjs/FieldArray/index.js.map +2 -2
  44. package/cjs/FieldObject/index.js +7 -3
  45. package/cjs/FieldObject/index.js.map +2 -2
  46. package/cjs/FormBuilder/index.js +165 -5
  47. package/cjs/FormBuilder/index.js.map +3 -3
  48. package/cjs/MultiplicityField/add-objects/index.js +3 -1
  49. package/cjs/MultiplicityField/add-objects.js.map +2 -2
  50. package/cjs/MultiplicityField/index.js +4 -2
  51. package/cjs/MultiplicityField/index.js.map +2 -2
  52. package/cjs/index.js +11 -155
  53. package/cjs/index.js.map +4 -4
  54. package/cjs/inputs/AutoCompleteInput/__stories__/Multiple/index.js +0 -1
  55. package/cjs/inputs/AutoCompleteInput/__stories__/Multiple.js.map +2 -2
  56. package/cjs/inputs/AutoCompleteInput/index.js +5 -3
  57. package/cjs/inputs/AutoCompleteInput/index.js.map +2 -2
  58. package/cjs/inputs/Checkboxes/index.js +1 -1
  59. package/cjs/inputs/Checkboxes/index.js.map +2 -2
  60. package/cjs/inputs/ImageInput/ImageInput.stories/index.js +4 -4
  61. package/cjs/inputs/ImageInput/ImageInput.stories.js.map +2 -2
  62. package/cjs/inputs/ImageInput/__stories__/MaxSize/index.js +69 -0
  63. package/cjs/inputs/ImageInput/__stories__/MaxSize.js.map +7 -0
  64. package/cjs/inputs/ImageInput/index.js +3 -2
  65. package/cjs/inputs/ImageInput/index.js.map +2 -2
  66. package/cjs/inputs/Input/index.js +18 -5
  67. package/cjs/inputs/Input/index.js.map +3 -3
  68. package/cjs/inputs/Radio/__stories__/Conditional.js.map +2 -2
  69. package/cjs/inputs/Radio/index.js +52 -4
  70. package/cjs/inputs/Radio/index.js.map +2 -2
  71. package/cjs/inputs/inputsScenarios/index.js +0 -1
  72. package/cjs/inputs/inputsScenarios.js.map +2 -2
  73. package/cjs/lazy/index.js +4 -2
  74. package/cjs/lazy.js.map +2 -2
  75. package/cjs/types.js.map +1 -1
  76. package/cjs/validators/utils/file/index.js +1 -1
  77. package/cjs/validators/utils/file.js.map +2 -2
  78. package/index.d.ts +5 -8
  79. package/index.js +9 -152
  80. package/index.js.map +4 -4
  81. package/inputs/AutoCompleteInput/__stories__/Multiple/index.js +0 -1
  82. package/inputs/AutoCompleteInput/__stories__/Multiple.js.map +2 -2
  83. package/inputs/AutoCompleteInput/index.js +5 -3
  84. package/inputs/AutoCompleteInput/index.js.map +2 -2
  85. package/inputs/Checkboxes/index.js +1 -1
  86. package/inputs/Checkboxes/index.js.map +2 -2
  87. package/inputs/ImageInput/ImageInput.stories/index.js +2 -2
  88. package/inputs/ImageInput/ImageInput.stories.d.ts +1 -1
  89. package/inputs/ImageInput/ImageInput.stories.js.map +2 -2
  90. package/inputs/ImageInput/__stories__/MaxSize/index.js +36 -0
  91. package/inputs/ImageInput/__stories__/MaxSize/package.json +6 -0
  92. package/inputs/ImageInput/__stories__/MaxSize.d.ts +3 -0
  93. package/inputs/ImageInput/__stories__/MaxSize.js.map +7 -0
  94. package/inputs/ImageInput/index.js +3 -2
  95. package/inputs/ImageInput/index.js.map +2 -2
  96. package/inputs/Input/index.js +16 -3
  97. package/inputs/Input/index.js.map +3 -3
  98. package/inputs/Radio/__stories__/Conditional.js.map +2 -2
  99. package/inputs/Radio/index.d.ts +4 -0
  100. package/inputs/Radio/index.js +51 -4
  101. package/inputs/Radio/index.js.map +2 -2
  102. package/inputs/inputsScenarios/index.js +0 -1
  103. package/inputs/inputsScenarios.d.ts +0 -42
  104. package/inputs/inputsScenarios.js.map +2 -2
  105. package/lazy/index.js +4 -2
  106. package/lazy.d.ts +13 -8
  107. package/lazy.js.map +2 -2
  108. package/package.json +4 -4
  109. package/src/Field/FieldBase.tsx +1 -0
  110. package/src/Field/FieldBaseContainer.tsx +1 -1
  111. package/src/Field/FieldConditional.tsx +4 -0
  112. package/src/Field/index.tsx +4 -1
  113. package/src/Field/types.tsx +23 -20
  114. package/src/Field/utils/index.ts +18 -1
  115. package/src/FieldArray/index.tsx +6 -3
  116. package/src/FieldObject/index.tsx +6 -0
  117. package/src/FormBuilder/index.tsx +179 -7
  118. package/src/FormBuilder/scenarios.test.tsx +2 -2
  119. package/src/MultiplicityField/add-objects.tsx +2 -0
  120. package/src/MultiplicityField/index.tsx +2 -0
  121. package/src/index.ts +6 -0
  122. package/src/inputs/AutoCompleteInput/__stories__/Multiple.tsx +0 -1
  123. package/src/inputs/AutoCompleteInput/index.tsx +6 -4
  124. package/src/inputs/Checkboxes/index.test.tsx +16 -17
  125. package/src/inputs/Checkboxes/index.tsx +22 -22
  126. package/src/inputs/ImageInput/ImageInput.stories.js +2 -1
  127. package/src/inputs/ImageInput/__stories__/MaxSize.tsx +37 -0
  128. package/src/inputs/ImageInput/index.test.tsx +4 -0
  129. package/src/inputs/ImageInput/index.tsx +3 -3
  130. package/src/inputs/Input/index.tsx +24 -29
  131. package/src/inputs/Radio/__stories__/Conditional.tsx +2 -1
  132. package/src/inputs/Radio/index.tsx +69 -5
  133. package/src/inputs/inputsScenarios.ts +147 -148
  134. package/src/lazy.js +4 -2
  135. package/src/types.tsx +1 -0
  136. package/src/validators/utils/file.ts +1 -1
  137. package/types.d.ts +1 -1
  138. package/types.js.map +1 -1
  139. package/validators/utils/file/index.js +1 -1
  140. package/validators/utils/file.js.map +2 -2
  141. package/src/index.tsx +0 -178
@@ -2,6 +2,7 @@ import React from 'react';
2
2
  import { useWatch } from 'react-hook-form';
3
3
  import { UncontrolledFieldProps } from '@digigov/form/Field/types';
4
4
  import { FieldOptionProps } from '@digigov/form/inputs/Label';
5
+ import { Base } from '@digigov/react-core/Base';
5
6
  import Hint from '@digigov/react-core/Hint';
6
7
  import { RadioConditional } from '@digigov/react-core/RadioConditional';
7
8
  import RadioContainer from '@digigov/react-core/RadioContainer';
@@ -24,13 +25,13 @@ export const RadioButtonsGroup: React.FC<RadioButtonsGroupProps> = ({
24
25
  register,
25
26
  extra: { options, className },
26
27
  disabled,
27
- fieldComponent: Field,
28
+ Field,
28
29
  ...props
29
30
  }) => {
30
31
  const currentValue: string | undefined = useWatch({ control, name });
31
32
  const { t } = useTranslation();
32
33
  return (
33
- <RadioContainer className={className} defaultValue={currentValue} id={name}>
34
+ <RadioContainer className={className} id={name}>
34
35
  {options.map(
35
36
  ({
36
37
  label,
@@ -40,7 +41,7 @@ export const RadioButtonsGroup: React.FC<RadioButtonsGroupProps> = ({
40
41
  selected,
41
42
  ...option
42
43
  }) => (
43
- <div key={`${name}.${v}`}>
44
+ <Base as="div" key={`${name}.${v}`}>
44
45
  <RadioItem
45
46
  {...register(name)}
46
47
  id={`${name}.${v}`}
@@ -56,7 +57,9 @@ export const RadioButtonsGroup: React.FC<RadioButtonsGroupProps> = ({
56
57
  type: 'radio',
57
58
  }}
58
59
  >
59
- {(label && label.primary && t(label.primary)) || v}
60
+ {label && label.primary && (
61
+ <Base as="span">{t(label.primary) || v}</Base>
62
+ )}
60
63
  {label && label.secondary && <Hint>{t(label.secondary)}</Hint>}
61
64
  </RadioItem>
62
65
  {selected && selected()}
@@ -67,11 +70,72 @@ export const RadioButtonsGroup: React.FC<RadioButtonsGroupProps> = ({
67
70
  ))}
68
71
  </RadioConditional>
69
72
  )}
70
- </div>
73
+ </Base>
71
74
  )
72
75
  )}
73
76
  </RadioContainer>
74
77
  );
75
78
  };
79
+ export const ControlledRadioButtonsGroup: React.FC<
80
+ RadioButtonsGroupProps & { onChange: (e: any) => void; value: any }
81
+ > = ({
82
+ name,
83
+ extra: { options, className },
84
+ disabled,
85
+ onChange,
86
+ value,
87
+ Field,
88
+ ...props
89
+ }) => {
90
+ const currentValue: string | undefined = value;
91
+ const { t } = useTranslation();
92
+ return (
93
+ <RadioContainer className={className} id={name}>
94
+ {options.map(
95
+ ({
96
+ label,
97
+ value: v,
98
+ show,
99
+ disabled: optionDisabled,
100
+ selected,
101
+ ...option
102
+ }) => (
103
+ <React.Fragment key={`${name}.${v}`}>
104
+ <RadioItem
105
+ onChange={(e) => {
106
+ console.log(e);
107
+ onChange(e);
108
+ }}
109
+ id={`${name}.${v}`}
110
+ value={v}
111
+ checked={currentValue === v}
112
+ disabled={disabled || optionDisabled}
113
+ {...option}
114
+ {...{
115
+ ...props,
116
+ reset: undefined,
117
+ required: undefined,
118
+ error: undefined,
119
+ 'aria-describedby': undefined,
120
+ type: 'radio',
121
+ }}
122
+ >
123
+ {(label && label.primary && t(label.primary)) || v}
124
+ {label && label.secondary && <Hint>{t(label.secondary)}</Hint>}
125
+ </RadioItem>
126
+ {selected && selected()}
127
+ {currentValue === v && show && (
128
+ <RadioConditional>
129
+ {show.map((fieldName) => (
130
+ <Field name={fieldName} key={fieldName} />
131
+ ))}
132
+ </RadioConditional>
133
+ )}
134
+ </React.Fragment>
135
+ )
136
+ )}
137
+ </RadioContainer>
138
+ );
139
+ };
76
140
 
77
141
  export default RadioButtonsGroup;
@@ -1,160 +1,159 @@
1
1
  import el from '@digigov/form/locales/el';
2
2
 
3
3
  export const INPUTS_FIELDS = [
4
- {
5
- key: 'date-example',
6
- type: 'date',
7
- required: true,
8
- label: {
9
- primary: 'Ποιά είναι η ημερομηνία γέννησής σας;',
10
- secondary:
11
- 'Για παράδειγμα, 05 11 2020',
12
- },
13
- },
14
- {
15
- key: 'otp',
16
- type: 'otp',
17
- maxLength: 6,
18
- label: {
19
- primary: 'Συμπληρώστε τον κωδικό επιβεβαίωσης',
20
- },
21
- required: true,
22
- },
23
- {
24
- key: 'checkbox',
25
- type: 'choice:multiple',
26
- required: true,
27
- label: { primary: 'Πώς αισθάνεστε αυτή τη στιγμή;' },
28
- extra: {
29
- options: [
30
- {
31
- label: { primary: 'Έχω συνάχι' },
32
- value: 'runny-nose',
33
- },
34
- {
35
- label: { primary: 'Έχω πυρετό' },
36
- value: 'fever',
37
- },
38
- {
39
- label: { primary: 'Αισθάνομαι κούραση' },
40
- value: 'fatigue',
41
- },
42
- ],
43
- }
44
- },
45
- {
46
- key: 'autocomplete_multiple',
47
- required: true,
48
- type: 'choice:multiple',
49
- label: { primary: 'Πώς αισθάνεστε αυτή τη στιγμή;' },
50
- extra: {
51
- component: 'AutoComplete',
52
- multiple: true,
53
- options: [
54
- {
55
- label: { primary: 'Έχω συνάχι' },
56
- value: 'runny-nose',
57
- },
58
- {
59
- label: { primary: 'Έχω πυρετό' },
60
- value: 'fever',
61
- },
62
- {
63
- label: { primary: 'Αισθάνομαι κούραση' },
64
- value: 'fatigue',
65
- },
66
- ],
67
- },
4
+ {
5
+ key: 'date-example',
6
+ type: 'date',
7
+ required: true,
8
+ label: {
9
+ primary: 'Ποιά είναι η ημερομηνία γέννησής σας;',
10
+ secondary:
11
+ 'Για παράδειγμα, 05 11 2020',
68
12
  },
69
- {
70
- key: 'radio',
71
- type: 'choice:single',
72
- required: true,
73
- label: { primary: 'Πώς αισθάνεστε αυτή τη στιγμή;' },
74
- extra: {
75
- options: [
76
- {
77
- label: { primary: 'Έχω συνάχι' },
78
- value: 'runny-nose',
79
- },
80
- {
81
- label: { primary: 'Έχω πυρετό' },
82
- value: 'fever',
83
- },
84
- {
85
- label: { primary: 'Αισθάνομαι κούραση' },
86
- value: 'fatigue',
87
- },
88
- ],
89
- }
13
+ },
14
+ {
15
+ key: 'otp',
16
+ type: 'otp',
17
+ maxLength: 6,
18
+ label: {
19
+ primary: 'Συμπληρώστε τον κωδικό επιβεβαίωσης',
90
20
  },
91
- {
92
- key: 'select',
93
- type: 'choice:single',
94
- required: true,
95
- label: { primary: 'Πώς αισθάνεστε αυτή τη στιγμή;' },
96
- extra: {
97
- component: 'Select',
98
- options: [
99
- {
100
- label: { primary: '' },
101
- value: '',
102
- },
103
- {
104
- label: { primary: 'Έχω συνάχι' },
105
- value: 'runny-nose',
106
- },
107
- {
108
- label: { primary: 'Έχω πυρετό' },
109
- value: 'fever',
110
- },
111
- {
112
- label: { primary: 'Αισθάνομαι κούραση' },
113
- value: 'fatigue',
114
- },
115
- ],
116
- }
21
+ required: true,
22
+ },
23
+ {
24
+ key: 'checkbox',
25
+ type: 'choice:multiple',
26
+ required: true,
27
+ label: { primary: 'Πώς αισθάνεστε αυτή τη στιγμή;' },
28
+ extra: {
29
+ options: [
30
+ {
31
+ label: { primary: 'Έχω συνάχι' },
32
+ value: 'runny-nose',
33
+ },
34
+ {
35
+ label: { primary: 'Έχω πυρετό' },
36
+ value: 'fever',
37
+ },
38
+ {
39
+ label: { primary: 'Αισθάνομαι κούραση' },
40
+ value: 'fatigue',
41
+ },
42
+ ],
43
+ }
44
+ },
45
+ {
46
+ key: 'autocomplete_multiple',
47
+ required: true,
48
+ type: 'choice:multiple',
49
+ label: { primary: 'Πώς αισθάνεστε αυτή τη στιγμή;' },
50
+ extra: {
51
+ component: 'AutoComplete',
52
+ options: [
53
+ {
54
+ label: { primary: 'Έχω συνάχι' },
55
+ value: 'runny-nose',
56
+ },
57
+ {
58
+ label: { primary: 'Έχω πυρετό' },
59
+ value: 'fever',
60
+ },
61
+ {
62
+ label: { primary: 'Αισθάνομαι κούραση' },
63
+ value: 'fatigue',
64
+ },
65
+ ],
117
66
  },
118
- {
119
- key: 'autocomplete_single',
120
- required: true,
121
- type: 'choice:single',
122
- label: { primary: 'Πώς αισθάνεστε αυτή τη στιγμή;' },
123
- extra: {
124
- component: 'AutoComplete',
125
- options: [
126
- {
127
- label: { primary: 'Έχω συνάχι' },
128
- value: 'runny-nose',
129
- },
130
- {
131
- label: { primary: 'Έχω πυρετό' },
132
- value: 'fever',
133
- },
134
- {
135
- label: { primary: 'Αισθάνομαι κούραση' },
136
- value: 'fatigue',
137
- },
138
- ],
139
- },
67
+ },
68
+ {
69
+ key: 'radio',
70
+ type: 'choice:single',
71
+ required: true,
72
+ label: { primary: 'Πώς αισθάνεστε αυτή τη στιγμή;' },
73
+ extra: {
74
+ options: [
75
+ {
76
+ label: { primary: 'Έχω συνάχι' },
77
+ value: 'runny-nose',
78
+ },
79
+ {
80
+ label: { primary: 'Έχω πυρετό' },
81
+ value: 'fever',
82
+ },
83
+ {
84
+ label: { primary: 'Αισθάνομαι κούραση' },
85
+ value: 'fatigue',
86
+ },
87
+ ],
88
+ }
89
+ },
90
+ {
91
+ key: 'select',
92
+ type: 'choice:single',
93
+ required: true,
94
+ label: { primary: 'Πώς αισθάνεστε αυτή τη στιγμή;' },
95
+ extra: {
96
+ component: 'Select',
97
+ options: [
98
+ {
99
+ label: { primary: '' },
100
+ value: '',
101
+ },
102
+ {
103
+ label: { primary: 'Έχω συνάχι' },
104
+ value: 'runny-nose',
105
+ },
106
+ {
107
+ label: { primary: 'Έχω πυρετό' },
108
+ value: 'fever',
109
+ },
110
+ {
111
+ label: { primary: 'Αισθάνομαι κούραση' },
112
+ value: 'fatigue',
113
+ },
114
+ ],
115
+ }
116
+ },
117
+ {
118
+ key: 'autocomplete_single',
119
+ required: true,
120
+ type: 'choice:single',
121
+ label: { primary: 'Πώς αισθάνεστε αυτή τη στιγμή;' },
122
+ extra: {
123
+ component: 'AutoComplete',
124
+ options: [
125
+ {
126
+ label: { primary: 'Έχω συνάχι' },
127
+ value: 'runny-nose',
128
+ },
129
+ {
130
+ label: { primary: 'Έχω πυρετό' },
131
+ value: 'fever',
132
+ },
133
+ {
134
+ label: { primary: 'Αισθάνομαι κούραση' },
135
+ value: 'fatigue',
136
+ },
137
+ ],
140
138
  },
141
- {
142
- key: 'image',
143
- type: 'image',
144
- required: true,
145
- label: {
146
- primary: 'Ανεβάστε τη φωτογραφία του προστίμου',
147
- },
139
+ },
140
+ {
141
+ key: 'image',
142
+ type: 'image',
143
+ required: true,
144
+ label: {
145
+ primary: 'Ανεβάστε τη φωτογραφία του προστίμου',
148
146
  },
149
- {
150
- key: 'file',
151
- type: 'file',
152
- label: {
153
- primary: 'Ανεβάστε το αρχείο της απόδειξης',
154
- },
155
- required: true,
147
+ },
148
+ {
149
+ key: 'file',
150
+ type: 'file',
151
+ label: {
152
+ primary: 'Ανεβάστε το αρχείο της απόδειξης',
156
153
  },
157
- ]
154
+ required: true,
155
+ },
156
+ ]
158
157
 
159
158
  export const scenarios = [
160
159
  {
package/src/lazy.js CHANGED
@@ -5,6 +5,7 @@ export default {
5
5
  'FieldConditional': lazy(() => import('@digigov/form/Field/FieldConditional').then((module)=> ({default: module['FieldConditional']}))),
6
6
  'Field': lazy(() => import('@digigov/form/internal').then((module)=> ({default: module['Field']}))),
7
7
  'ALTERNATIVE_COMPONENTS': lazy(() => import('@digigov/form/Field/utils').then((module)=> ({default: module['ALTERNATIVE_COMPONENTS']}))),
8
+ 'CONTROLLED_FIELD_COMPONENTS': lazy(() => import('@digigov/form/Field/utils').then((module)=> ({default: module['CONTROLLED_FIELD_COMPONENTS']}))),
8
9
  'FIELD_COMPONENTS': lazy(() => import('@digigov/form/Field/utils').then((module)=> ({default: module['FIELD_COMPONENTS']}))),
9
10
  'FieldArray': lazy(() => import('@digigov/form/FieldArray').then((module)=> ({default: module['FieldArray']}))),
10
11
  'FieldObject': lazy(() => import('@digigov/form/FieldObject').then((module)=> ({default: module['FieldObject']}))),
@@ -13,9 +14,10 @@ export default {
13
14
  'FieldsetBody': lazy(() => import('@digigov/form/Fieldset').then((module)=> ({default: module['FieldsetBody']}))),
14
15
  'FieldsetCaption': lazy(() => import('@digigov/form/Fieldset').then((module)=> ({default: module['FieldsetCaption']}))),
15
16
  'FieldsetLabel': lazy(() => import('@digigov/form/Fieldset').then((module)=> ({default: module['FieldsetLabel']}))),
17
+ 'ControlledFormBuilder': lazy(() => import('@digigov/form/FormBuilder').then((module)=> ({default: module['ControlledFormBuilder']}))),
16
18
  'FormBase': lazy(() => import('@digigov/form/FormBuilder').then((module)=> ({default: module['FormBase']}))),
17
19
  'FormContext': lazy(() => import('@digigov/form/FormContext').then((module)=> ({default: module['FormContext']}))),
18
- 'FormBuilder': lazy(() => import('@digigov/form').then((module)=> ({default: module['FormBuilder']}))),
20
+ 'Label': lazy(() => import('@digigov/form/inputs/Label').then((module)=> ({default: module['Label']}))),
19
21
  'AutoCompleteInput': lazy(() => import('@digigov/form/inputs/AutoCompleteInput').then((module)=> ({default: module['AutoCompleteInput']}))),
20
22
  'Checkboxes': lazy(() => import('@digigov/form/inputs/Checkboxes').then((module)=> ({default: module['Checkboxes']}))),
21
23
  'DateInput': lazy(() => import('@digigov/form/inputs/DateInput').then((module)=> ({default: module['DateInput']}))),
@@ -23,13 +25,13 @@ export default {
23
25
  'Image': lazy(() => import('@digigov/form/inputs/ImageInput').then((module)=> ({default: module['Image']}))),
24
26
  'ImageInput': lazy(() => import('@digigov/form/inputs/ImageInput').then((module)=> ({default: module['ImageInput']}))),
25
27
  'Input': lazy(() => import('@digigov/form/inputs/Input').then((module)=> ({default: module['Input']}))),
26
- 'Label': lazy(() => import('@digigov/form/inputs/Label').then((module)=> ({default: module['Label']}))),
27
28
  'OtpInput': lazy(() => import('@digigov/form/inputs/OtpInput').then((module)=> ({default: module['OtpInput']}))),
28
29
  'Radio': lazy(() => import('@digigov/form/inputs').then((module)=> ({default: module['Radio']}))),
29
30
  'Select': lazy(() => import('@digigov/form/inputs/Select').then((module)=> ({default: module['Select']}))),
30
31
  'INPUTS_FIELDS': lazy(() => import('@digigov/form/inputs/inputsScenarios').then((module)=> ({default: module['INPUTS_FIELDS']}))),
31
32
  'REMOVE_SPACES': lazy(() => import('@digigov/form/inputs/OtpInput').then((module)=> ({default: module['REMOVE_SPACES']}))),
32
33
  'RE_DIGIT': lazy(() => import('@digigov/form/inputs/OtpInput').then((module)=> ({default: module['RE_DIGIT']}))),
34
+ 'ControlledRadioButtonsGroup': lazy(() => import('@digigov/form/inputs/Radio').then((module)=> ({default: module['ControlledRadioButtonsGroup']}))),
33
35
  'RadioButtonsGroup': lazy(() => import('@digigov/form/inputs/Radio').then((module)=> ({default: module['RadioButtonsGroup']}))),
34
36
  'AddObjects': lazy(() => import('@digigov/form/MultiplicityField/add-objects').then((module)=> ({default: module['AddObjects']}))),
35
37
  'ListObject': lazy(() => import('@digigov/form/MultiplicityField').then((module)=> ({default: module['ListObject']}))),
package/src/types.tsx CHANGED
@@ -53,6 +53,7 @@ export interface FormBuilderProps {
53
53
  validatorRegistry?: Record<string, ValidatorSchema[]>;
54
54
  componentRegistry?: FieldComponentRegistry;
55
55
  grid?: boolean;
56
+ controlledFieldsOnly?: boolean;
56
57
  }
57
58
 
58
59
  export interface FormBaseProps
@@ -6,7 +6,7 @@ const DEFAULT_FILE_MAX_SIZE = 10000000;
6
6
  export const FILE_MAX_SIZE_VALIDATOR = (field: FieldSpec): ValidatorSchema => ({
7
7
  name: 'file-max-size-validator',
8
8
  message: {
9
- key: 'form.error.file_size',
9
+ key: field.type === 'file' ? 'form.error.file_size' : 'form.error.image_size',
10
10
  context: {
11
11
  maxSizeToMb: (field?.extra?.limit.maxSize || DEFAULT_FILE_MAX_SIZE) / 1000000,
12
12
  },
package/types.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { UseFormReturn, UseFormProps } from 'react-hook-form';
3
2
  import { FieldComponentRegistry, FieldLabelProps, FieldSpec, FormData } from '@digigov/form/Field/types';
4
3
  import { ValidatorSchema } from '@digigov/form/validators/types';
@@ -46,6 +45,7 @@ export interface FormBuilderProps {
46
45
  validatorRegistry?: Record<string, ValidatorSchema[]>;
47
46
  componentRegistry?: FieldComponentRegistry;
48
47
  grid?: boolean;
48
+ controlledFieldsOnly?: boolean;
49
49
  }
50
50
  export interface FormBaseProps extends Omit<FormBuilderProps, 'fields' | 'fieldsets' | 'auto'> {
51
51
  fieldsetsMap?: Record<string, FieldsetSpec>;
package/types.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/types.tsx"],
4
- "sourcesContent": ["import { UseFormReturn, UseFormProps } from 'react-hook-form';\nimport {\n FieldComponentRegistry,\n FieldLabelProps,\n FieldSpec,\n FormData,\n} from '@digigov/form/Field/types';\nimport { ValidatorSchema } from '@digigov/form/validators/types';\nexport * from '@digigov/form/Field/types';\nexport type FieldError = {\n message: string;\n};\n\nexport interface FieldsetSpec {\n key: string;\n fields: string[];\n label?: FieldLabelProps;\n body?: React.ReactNode;\n}\n\nexport interface FormContextProps {\n fieldsetsMap?: Record<string, FieldsetSpec>;\n fieldsMap: Record<string, FieldSpec>;\n control: UseFormReturn['control'];\n register: UseFormReturn['register'];\n trigger: UseFormReturn['trigger'];\n clearErrors: UseFormReturn['clearErrors'];\n watch: UseFormReturn['watch'];\n getFieldState: UseFormReturn['getFieldState'];\n setValue: UseFormReturn['setValue'];\n getValues: UseFormReturn['getValues'];\n unregister: UseFormReturn['unregister'];\n formState: UseFormReturn['formState'];\n reset: UseFormReturn['reset'];\n resetField: UseFormReturn['resetField'];\n registerField: (field: FieldSpec) => void;\n errors: UseFormReturn['formState']['errors'];\n componentRegistry?: FieldComponentRegistry;\n submit: () => Promise<void>;\n}\n\nexport interface FormBuilderProps {\n fields?: FieldSpec[];\n fieldsets?: FieldsetSpec[];\n initial?: FormData;\n onSubmit?: (data: FormData) => void | null | FieldError[];\n mode?: UseFormProps['mode'];\n reValidateMode?: UseFormProps['reValidateMode'];\n criteriaMode?: UseFormProps['criteriaMode'];\n children?: React.ReactNode;\n shouldFocusError?: boolean;\n auto?: boolean;\n validatorRegistry?: Record<string, ValidatorSchema[]>;\n componentRegistry?: FieldComponentRegistry;\n grid?: boolean;\n}\n\nexport interface FormBaseProps\n extends Omit<FormBuilderProps, 'fields' | 'fieldsets' | 'auto'> {\n fieldsetsMap?: Record<string, FieldsetSpec>;\n fieldsMap: Record<string, FieldSpec>;\n registerField: (field: FieldSpec) => void;\n resolver: any;\n}\n"],
4
+ "sourcesContent": ["import { UseFormReturn, UseFormProps } from 'react-hook-form';\nimport {\n FieldComponentRegistry,\n FieldLabelProps,\n FieldSpec,\n FormData,\n} from '@digigov/form/Field/types';\nimport { ValidatorSchema } from '@digigov/form/validators/types';\nexport * from '@digigov/form/Field/types';\nexport type FieldError = {\n message: string;\n};\n\nexport interface FieldsetSpec {\n key: string;\n fields: string[];\n label?: FieldLabelProps;\n body?: React.ReactNode;\n}\n\nexport interface FormContextProps {\n fieldsetsMap?: Record<string, FieldsetSpec>;\n fieldsMap: Record<string, FieldSpec>;\n control: UseFormReturn['control'];\n register: UseFormReturn['register'];\n trigger: UseFormReturn['trigger'];\n clearErrors: UseFormReturn['clearErrors'];\n watch: UseFormReturn['watch'];\n getFieldState: UseFormReturn['getFieldState'];\n setValue: UseFormReturn['setValue'];\n getValues: UseFormReturn['getValues'];\n unregister: UseFormReturn['unregister'];\n formState: UseFormReturn['formState'];\n reset: UseFormReturn['reset'];\n resetField: UseFormReturn['resetField'];\n registerField: (field: FieldSpec) => void;\n errors: UseFormReturn['formState']['errors'];\n componentRegistry?: FieldComponentRegistry;\n submit: () => Promise<void>;\n}\n\nexport interface FormBuilderProps {\n fields?: FieldSpec[];\n fieldsets?: FieldsetSpec[];\n initial?: FormData;\n onSubmit?: (data: FormData) => void | null | FieldError[];\n mode?: UseFormProps['mode'];\n reValidateMode?: UseFormProps['reValidateMode'];\n criteriaMode?: UseFormProps['criteriaMode'];\n children?: React.ReactNode;\n shouldFocusError?: boolean;\n auto?: boolean;\n validatorRegistry?: Record<string, ValidatorSchema[]>;\n componentRegistry?: FieldComponentRegistry;\n grid?: boolean;\n controlledFieldsOnly?: boolean;\n}\n\nexport interface FormBaseProps\n extends Omit<FormBuilderProps, 'fields' | 'fieldsets' | 'auto'> {\n fieldsetsMap?: Record<string, FieldsetSpec>;\n fieldsMap: Record<string, FieldSpec>;\n registerField: (field: FieldSpec) => void;\n resolver: any;\n}\n"],
5
5
  "mappings": "AAQA,cAAc;",
6
6
  "names": []
7
7
  }
@@ -2,7 +2,7 @@ const DEFAULT_FILE_MAX_SIZE = 1e7;
2
2
  const FILE_MAX_SIZE_VALIDATOR = (field) => ({
3
3
  name: "file-max-size-validator",
4
4
  message: {
5
- key: "form.error.file_size",
5
+ key: field.type === "file" ? "form.error.file_size" : "form.error.image_size",
6
6
  context: {
7
7
  maxSizeToMb: (field?.extra?.limit.maxSize || DEFAULT_FILE_MAX_SIZE) / 1e6
8
8
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/validators/utils/file.ts"],
4
- "sourcesContent": ["import { FieldSpec } from '@digigov/form/types';\nimport { ValidatorSchema } from '@digigov/form/validators/types';\n\nconst DEFAULT_FILE_MAX_SIZE = 10000000;\n\nexport const FILE_MAX_SIZE_VALIDATOR = (field: FieldSpec): ValidatorSchema => ({\n name: 'file-max-size-validator',\n message: {\n key: 'form.error.file_size',\n context: {\n maxSizeToMb: (field?.extra?.limit.maxSize || DEFAULT_FILE_MAX_SIZE) / 1000000,\n },\n },\n test: (value: File[]): boolean => {\n if (value) {\n for (const file of value) {\n const maxSize = field?.extra?.limit?.maxSize || DEFAULT_FILE_MAX_SIZE\n if (file.size > maxSize) {\n return false;\n }\n }\n }\n return true;\n },\n});\n"],
5
- "mappings": "AAGA,MAAM,wBAAwB;AAEvB,MAAM,0BAA0B,CAAC,WAAuC;AAAA,EAC7E,MAAM;AAAA,EACN,SAAS;AAAA,IACP,KAAK;AAAA,IACL,SAAS;AAAA,MACP,cAAc,OAAO,OAAO,MAAM,WAAW,yBAAyB;AAAA,IACxE;AAAA,EACF;AAAA,EACA,MAAM,CAAC,UAA2B;AAChC,QAAI,OAAO;AACT,iBAAW,QAAQ,OAAO;AACxB,cAAM,UAAU,OAAO,OAAO,OAAO,WAAW;AAChD,YAAI,KAAK,OAAO,SAAS;AACvB,iBAAO;AAAA,QACT;AAAA,MACF;AAAA,IACF;AACA,WAAO;AAAA,EACT;AACF;",
4
+ "sourcesContent": ["import { FieldSpec } from '@digigov/form/types';\nimport { ValidatorSchema } from '@digigov/form/validators/types';\n\nconst DEFAULT_FILE_MAX_SIZE = 10000000;\n\nexport const FILE_MAX_SIZE_VALIDATOR = (field: FieldSpec): ValidatorSchema => ({\n name: 'file-max-size-validator',\n message: {\n key: field.type === 'file' ? 'form.error.file_size' : 'form.error.image_size',\n context: {\n maxSizeToMb: (field?.extra?.limit.maxSize || DEFAULT_FILE_MAX_SIZE) / 1000000,\n },\n },\n test: (value: File[]): boolean => {\n if (value) {\n for (const file of value) {\n const maxSize = field?.extra?.limit?.maxSize || DEFAULT_FILE_MAX_SIZE\n if (file.size > maxSize) {\n return false;\n }\n }\n }\n return true;\n },\n});\n"],
5
+ "mappings": "AAGA,MAAM,wBAAwB;AAEvB,MAAM,0BAA0B,CAAC,WAAuC;AAAA,EAC7E,MAAM;AAAA,EACN,SAAS;AAAA,IACP,KAAK,MAAM,SAAS,SAAS,yBAAyB;AAAA,IACtD,SAAS;AAAA,MACP,cAAc,OAAO,OAAO,MAAM,WAAW,yBAAyB;AAAA,IACxE;AAAA,EACF;AAAA,EACA,MAAM,CAAC,UAA2B;AAChC,QAAI,OAAO;AACT,iBAAW,QAAQ,OAAO;AACxB,cAAM,UAAU,OAAO,OAAO,OAAO,WAAW;AAChD,YAAI,KAAK,OAAO,SAAS;AACvB,iBAAO;AAAA,QACT;AAAA,MACF;AAAA,IACF;AACA,WAAO;AAAA,EACT;AACF;",
6
6
  "names": []
7
7
  }