@digigov/form 2.0.0-a32ad9b2 → 2.0.0-a402a664

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 (300) hide show
  1. package/Field/FieldBase/index.js +6 -1
  2. package/Field/FieldBase.js.map +2 -2
  3. package/Field/FieldBaseContainer/index.js +5 -3
  4. package/Field/FieldBaseContainer.js.map +2 -2
  5. package/Field/FieldConditional/index.js +4 -0
  6. package/Field/FieldConditional.js.map +2 -2
  7. package/Field/index.js +10 -4
  8. package/Field/index.js.map +2 -2
  9. package/Field/types.d.ts +10 -3
  10. package/Field/utils/index.js +3 -1
  11. package/Field/utils/index.js.map +2 -2
  12. package/Field/utils/useField/index.js +8 -1
  13. package/Field/utils/useField.js.map +2 -2
  14. package/FieldArray/FormDialog/index.js +314 -196
  15. package/FieldArray/FormDialog.d.ts +20 -7
  16. package/FieldArray/FormDialog.js.map +3 -3
  17. package/FieldArray/__stories__/Default.d.ts +1 -1
  18. package/FieldArray/__stories__/WithExactLength.d.ts +1 -1
  19. package/FieldArray/__stories__/WithModal.d.ts +1 -1
  20. package/FieldArray/index.d.ts +1 -0
  21. package/FieldArray/index.js +12 -7
  22. package/FieldArray/index.js.map +2 -2
  23. package/FieldObject/index.d.ts +3 -0
  24. package/FieldObject/index.js +26 -15
  25. package/FieldObject/index.js.map +2 -2
  26. package/FormBuilder/FormBuilder.stories.d.ts +2 -0
  27. package/FormBuilder/__stories__/AutoErrorGrouping.d.ts +1 -1
  28. package/FormBuilder/__stories__/Default.d.ts +1 -1
  29. package/FormBuilder/__stories__/ErrorGrouping.d.ts +1 -1
  30. package/FormBuilder/index.d.ts +1 -1
  31. package/FormBuilder/index.js +11 -6
  32. package/FormBuilder/index.js.map +2 -2
  33. package/FormContext/index.js +6 -2
  34. package/FormContext.d.ts +1 -0
  35. package/FormContext.js.map +2 -2
  36. package/MultiplicityField/MultiplicityField.stories.d.ts +2 -0
  37. package/MultiplicityField/__stories__/Default.d.ts +1 -1
  38. package/MultiplicityField/__stories__/PreviewDisplay.d.ts +1 -1
  39. package/MultiplicityField/__stories__/WithExactLength.d.ts +1 -1
  40. package/MultiplicityField/__stories__/WithMaxLength.d.ts +1 -1
  41. package/MultiplicityField/__stories__/WithMinAndMaxLength.d.ts +1 -1
  42. package/MultiplicityField/__stories__/WithMinLength.d.ts +1 -1
  43. package/MultiplicityField/add-objects/index.js +2 -0
  44. package/MultiplicityField/add-objects.js.map +2 -2
  45. package/MultiplicityField/index.js +4 -1
  46. package/MultiplicityField/index.js.map +2 -2
  47. package/MultiplicityField/types.d.ts +1 -0
  48. package/Questions/Questions.stories.d.ts +2 -0
  49. package/Questions/__stories__/Default.d.ts +1 -1
  50. package/cjs/Field/FieldBase/index.js +6 -1
  51. package/cjs/Field/FieldBase.js.map +2 -2
  52. package/cjs/Field/FieldBaseContainer/index.js +4 -2
  53. package/cjs/Field/FieldBaseContainer.js.map +3 -3
  54. package/cjs/Field/FieldConditional/index.js +4 -0
  55. package/cjs/Field/FieldConditional.js.map +2 -2
  56. package/cjs/Field/index.js +10 -4
  57. package/cjs/Field/index.js.map +2 -2
  58. package/cjs/Field/types.js.map +1 -1
  59. package/cjs/Field/utils/index.js +3 -1
  60. package/cjs/Field/utils/index.js.map +2 -2
  61. package/cjs/Field/utils/useField/index.js +8 -1
  62. package/cjs/Field/utils/useField.js.map +2 -2
  63. package/cjs/FieldArray/FormDialog/index.js +309 -194
  64. package/cjs/FieldArray/FormDialog.js.map +3 -3
  65. package/cjs/FieldArray/index.js +12 -7
  66. package/cjs/FieldArray/index.js.map +2 -2
  67. package/cjs/FieldObject/index.js +26 -15
  68. package/cjs/FieldObject/index.js.map +2 -2
  69. package/cjs/FormBuilder/index.js +11 -6
  70. package/cjs/FormBuilder/index.js.map +2 -2
  71. package/cjs/FormContext/index.js +7 -2
  72. package/cjs/FormContext.js.map +2 -2
  73. package/cjs/MultiplicityField/add-objects/index.js +2 -0
  74. package/cjs/MultiplicityField/add-objects.js.map +2 -2
  75. package/cjs/MultiplicityField/index.js +4 -1
  76. package/cjs/MultiplicityField/index.js.map +2 -2
  77. package/cjs/MultiplicityField/types.js.map +1 -1
  78. package/cjs/inputs/Checkboxes/index.js +1 -1
  79. package/cjs/inputs/Checkboxes/index.js.map +2 -2
  80. package/cjs/inputs/DateInput/index.js +20 -8
  81. package/cjs/inputs/DateInput/index.js.map +2 -2
  82. package/cjs/inputs/DateTimeInput/index.js +23 -10
  83. package/cjs/inputs/DateTimeInput/index.js.map +2 -2
  84. package/cjs/inputs/FileInput/index.js +26 -21
  85. package/cjs/inputs/FileInput/index.js.map +2 -2
  86. package/cjs/inputs/ImageInput/__stories__/logo.d/index.js +1 -0
  87. package/cjs/inputs/ImageInput/__stories__/logo.d.js.map +7 -0
  88. package/cjs/inputs/ImageInput/index.js +41 -10
  89. package/cjs/inputs/ImageInput/index.js.map +2 -2
  90. package/cjs/inputs/Input/index.js +4 -4
  91. package/cjs/inputs/Input/index.js.map +2 -2
  92. package/cjs/inputs/Select/index.js +4 -3
  93. package/cjs/inputs/Select/index.js.map +2 -2
  94. package/cjs/inputs/inputsScenarios/index.js +2 -2
  95. package/cjs/inputs/inputsScenarios.js.map +2 -2
  96. package/cjs/lazy/index.js +2 -1
  97. package/cjs/lazy.js.map +2 -2
  98. package/cjs/registry/index.js +6 -6
  99. package/cjs/registry.js.map +2 -2
  100. package/cjs/types.js.map +1 -1
  101. package/cjs/utils/index.js +20 -6
  102. package/cjs/utils.js.map +2 -2
  103. package/cjs/validators/index.js +10 -5
  104. package/cjs/validators/index.js.map +2 -2
  105. package/cjs/validators/utils/amka/index.js +60 -0
  106. package/cjs/validators/utils/amka.js.map +7 -0
  107. package/cjs/validators/utils/file/index.js +30 -17
  108. package/cjs/validators/utils/file.js.map +2 -2
  109. package/cjs/validators/utils/index.js +5 -1
  110. package/cjs/validators/utils/index.js.map +2 -2
  111. package/index.js +1 -1
  112. package/inputs/AutoCompleteInput/AutoComplete.stories.d.ts +2 -0
  113. package/inputs/AutoCompleteInput/__stories__/Default.d.ts +1 -1
  114. package/inputs/AutoCompleteInput/__stories__/Multiple.d.ts +1 -1
  115. package/inputs/Checkboxes/Checkboxes.stories.d.ts +2 -0
  116. package/inputs/Checkboxes/__stories__/Conditional.d.ts +1 -1
  117. package/inputs/Checkboxes/__stories__/Default.d.ts +1 -1
  118. package/inputs/Checkboxes/__stories__/WithDivider.d.ts +1 -1
  119. package/inputs/Checkboxes/index.js +1 -1
  120. package/inputs/Checkboxes/index.js.map +2 -2
  121. package/inputs/DateInput/DateInput.stories.d.ts +2 -0
  122. package/inputs/DateInput/__stories__/Default.d.ts +1 -1
  123. package/inputs/DateInput/index.js +20 -8
  124. package/inputs/DateInput/index.js.map +2 -2
  125. package/inputs/DateTimeInput/DateTimeInput.stories.d.ts +2 -0
  126. package/inputs/DateTimeInput/__stories__/Default.d.ts +1 -1
  127. package/inputs/DateTimeInput/index.js +23 -10
  128. package/inputs/DateTimeInput/index.js.map +2 -2
  129. package/inputs/FileInput/FileInput.stories.d.ts +3 -0
  130. package/inputs/FileInput/__stories__/Default.d.ts +1 -1
  131. package/inputs/FileInput/__stories__/WithBorderAndLink.d.ts +3 -0
  132. package/inputs/FileInput/index.d.ts +6 -3
  133. package/inputs/FileInput/index.js +31 -23
  134. package/inputs/FileInput/index.js.map +2 -2
  135. package/inputs/ImageInput/ImageInput.stories.d.ts +4 -1
  136. package/inputs/ImageInput/__stories__/Default.d.ts +1 -1
  137. package/inputs/ImageInput/__stories__/MaxSize.d.ts +1 -1
  138. package/inputs/ImageInput/__stories__/WithInitialValues.d.ts +3 -0
  139. package/inputs/ImageInput/__stories__/WithInvalidImageDimension.d.ts +1 -1
  140. package/inputs/ImageInput/__stories__/logo.d/index.js +1 -0
  141. package/inputs/ImageInput/__stories__/logo.d/package.json +6 -0
  142. package/inputs/ImageInput/__stories__/logo.d.js.map +7 -0
  143. package/inputs/ImageInput/index.d.ts +9 -1
  144. package/inputs/ImageInput/index.js +42 -11
  145. package/inputs/ImageInput/index.js.map +2 -2
  146. package/inputs/Input/Input.stories.d.ts +4 -0
  147. package/inputs/Input/__stories__/AFM.d.ts +1 -1
  148. package/inputs/Input/__stories__/AMKA.d.ts +3 -0
  149. package/inputs/Input/__stories__/Boolean.d.ts +1 -1
  150. package/inputs/Input/__stories__/Email.d.ts +3 -0
  151. package/inputs/Input/__stories__/IBAN.d.ts +1 -1
  152. package/inputs/Input/__stories__/Integer.d.ts +1 -1
  153. package/inputs/Input/__stories__/LandlineNumber.d.ts +1 -1
  154. package/inputs/Input/__stories__/MobilePhone.d.ts +1 -1
  155. package/inputs/Input/__stories__/PhoneNumber.d.ts +1 -1
  156. package/inputs/Input/__stories__/PostalCode.d.ts +1 -1
  157. package/inputs/Input/__stories__/String.d.ts +1 -1
  158. package/inputs/Input/__stories__/StringWithTrimValidation.d.ts +1 -1
  159. package/inputs/Input/__stories__/TextWithLimit.d.ts +1 -1
  160. package/inputs/Input/index.d.ts +2 -1
  161. package/inputs/Input/index.js +4 -4
  162. package/inputs/Input/index.js.map +2 -2
  163. package/inputs/Label/Label.stories.d.ts +2 -0
  164. package/inputs/Label/__stories__/Default.d.ts +1 -1
  165. package/inputs/OtpInput/OtpInput.stories.d.ts +2 -0
  166. package/inputs/OtpInput/__stories__/Default.d.ts +1 -1
  167. package/inputs/Radio/Radio.stories.d.ts +2 -0
  168. package/inputs/Radio/__stories__/Conditional.d.ts +1 -1
  169. package/inputs/Radio/__stories__/Default.d.ts +1 -1
  170. package/inputs/Radio/__stories__/WithDivider.d.ts +1 -1
  171. package/inputs/Select/Select.stories.d.ts +2 -0
  172. package/inputs/Select/__stories__/Default.d.ts +1 -1
  173. package/inputs/Select/index.d.ts +2 -1
  174. package/inputs/Select/index.js +4 -3
  175. package/inputs/Select/index.js.map +2 -2
  176. package/inputs/inputsScenarios/index.js +2 -2
  177. package/inputs/inputsScenarios.d.ts +1 -1
  178. package/inputs/inputsScenarios.js.map +2 -2
  179. package/lazy/index.js +2 -1
  180. package/package.json +4 -4
  181. package/registry/index.js +6 -6
  182. package/src/Field/FieldBase.tsx +5 -0
  183. package/src/Field/FieldBaseContainer.tsx +8 -4
  184. package/src/Field/FieldConditional.tsx +4 -0
  185. package/src/Field/index.tsx +15 -5
  186. package/src/Field/types.tsx +11 -3
  187. package/src/Field/utils/index.ts +2 -0
  188. package/src/Field/utils/useField.ts +9 -1
  189. package/src/FieldArray/FormDialog.tsx +430 -243
  190. package/src/FieldArray/__stories__/Default.tsx +1 -1
  191. package/src/FieldArray/__stories__/WithExactLength.tsx +1 -1
  192. package/src/FieldArray/__stories__/WithModal.tsx +4 -3
  193. package/src/FieldArray/index.tsx +26 -30
  194. package/src/FieldObject/index.tsx +33 -18
  195. package/src/FormBuilder/FormBuilder.stories.js +3 -0
  196. package/src/FormBuilder/__stories__/AutoErrorGrouping.tsx +1 -1
  197. package/src/FormBuilder/__stories__/Default.tsx +1 -1
  198. package/src/FormBuilder/__stories__/ErrorGrouping.tsx +1 -1
  199. package/src/FormBuilder/index.tsx +12 -6
  200. package/src/FormBuilder/scenarios.test.tsx +6 -6
  201. package/src/FormContext.tsx +5 -1
  202. package/src/MultiplicityField/MultiplicityField.stories.js +3 -0
  203. package/src/MultiplicityField/__stories__/Default.tsx +1 -1
  204. package/src/MultiplicityField/__stories__/PreviewDisplay.tsx +1 -1
  205. package/src/MultiplicityField/__stories__/WithExactLength.tsx +1 -1
  206. package/src/MultiplicityField/__stories__/WithMaxLength.tsx +1 -1
  207. package/src/MultiplicityField/__stories__/WithMinAndMaxLength.tsx +1 -1
  208. package/src/MultiplicityField/__stories__/WithMinLength.tsx +1 -1
  209. package/src/MultiplicityField/add-objects.tsx +2 -0
  210. package/src/MultiplicityField/index.tsx +3 -0
  211. package/src/MultiplicityField/types.ts +1 -0
  212. package/src/Questions/Questions.stories.js +3 -0
  213. package/src/Questions/__stories__/Default.tsx +1 -1
  214. package/src/inputs/AutoCompleteInput/AutoComplete.stories.js +3 -0
  215. package/src/inputs/AutoCompleteInput/__stories__/Default.tsx +1 -1
  216. package/src/inputs/AutoCompleteInput/__stories__/Multiple.tsx +1 -1
  217. package/src/inputs/Checkboxes/Checkboxes.stories.js +3 -0
  218. package/src/inputs/Checkboxes/__stories__/Conditional.tsx +1 -1
  219. package/src/inputs/Checkboxes/__stories__/Default.tsx +1 -1
  220. package/src/inputs/Checkboxes/__stories__/WithDivider.tsx +1 -1
  221. package/src/inputs/Checkboxes/index.tsx +1 -1
  222. package/src/inputs/DateInput/DateInput.stories.js +3 -0
  223. package/src/inputs/DateInput/__stories__/Default.tsx +1 -1
  224. package/src/inputs/DateInput/index.tsx +21 -7
  225. package/src/inputs/DateTimeInput/DateTimeInput.stories.js +3 -0
  226. package/src/inputs/DateTimeInput/__stories__/Default.tsx +1 -1
  227. package/src/inputs/DateTimeInput/index.tsx +24 -9
  228. package/src/inputs/FileInput/FileInput.stories.js +4 -0
  229. package/src/inputs/FileInput/__stories__/Default.tsx +1 -1
  230. package/src/inputs/FileInput/__stories__/WithBorderAndLink.tsx +34 -0
  231. package/src/inputs/FileInput/index.test.tsx +4 -0
  232. package/src/inputs/FileInput/index.tsx +41 -30
  233. package/src/inputs/ImageInput/ImageInput.stories.js +5 -1
  234. package/src/inputs/ImageInput/__stories__/Default.tsx +1 -1
  235. package/src/inputs/ImageInput/__stories__/MaxSize.tsx +3 -2
  236. package/src/inputs/ImageInput/__stories__/WithInitialValues.tsx +45 -0
  237. package/src/inputs/ImageInput/__stories__/WithInvalidImageDimension.tsx +1 -1
  238. package/src/inputs/ImageInput/__stories__/logo.d.ts +4 -0
  239. package/src/inputs/ImageInput/__stories__/logo.png +0 -0
  240. package/src/inputs/ImageInput/index.test.tsx +21 -17
  241. package/src/inputs/ImageInput/index.tsx +100 -48
  242. package/src/inputs/Input/Input.stories.js +5 -0
  243. package/src/inputs/Input/__stories__/AFM.tsx +1 -1
  244. package/src/inputs/Input/__stories__/AMKA.tsx +23 -0
  245. package/src/inputs/Input/__stories__/Boolean.tsx +1 -1
  246. package/src/inputs/Input/__stories__/Email.tsx +23 -0
  247. package/src/inputs/Input/__stories__/IBAN.tsx +1 -1
  248. package/src/inputs/Input/__stories__/Integer.tsx +1 -1
  249. package/src/inputs/Input/__stories__/LandlineNumber.tsx +1 -1
  250. package/src/inputs/Input/__stories__/MobilePhone.tsx +1 -1
  251. package/src/inputs/Input/__stories__/PhoneNumber.tsx +1 -1
  252. package/src/inputs/Input/__stories__/PostalCode.tsx +1 -1
  253. package/src/inputs/Input/__stories__/String.tsx +1 -1
  254. package/src/inputs/Input/__stories__/StringWithTrimValidation.tsx +1 -1
  255. package/src/inputs/Input/__stories__/TextWithLimit.tsx +1 -1
  256. package/src/inputs/Input/index.test.tsx +8 -0
  257. package/src/inputs/Input/index.tsx +5 -3
  258. package/src/inputs/Label/Label.stories.js +3 -0
  259. package/src/inputs/Label/__stories__/Default.tsx +1 -1
  260. package/src/inputs/OtpInput/OtpInput.stories.js +3 -0
  261. package/src/inputs/OtpInput/__stories__/Default.tsx +1 -1
  262. package/src/inputs/Radio/Radio.stories.js +3 -0
  263. package/src/inputs/Radio/__stories__/Conditional.tsx +1 -1
  264. package/src/inputs/Radio/__stories__/Default.tsx +1 -1
  265. package/src/inputs/Radio/__stories__/WithDivider.tsx +1 -1
  266. package/src/inputs/Select/Select.stories.js +3 -0
  267. package/src/inputs/Select/__stories__/Default.tsx +1 -1
  268. package/src/inputs/Select/index.tsx +7 -4
  269. package/src/inputs/inputsScenarios.ts +2 -2
  270. package/src/lazy.js +2 -1
  271. package/src/registry.js +6 -6
  272. package/src/types.tsx +2 -1
  273. package/src/utils.ts +27 -6
  274. package/src/validators/index.ts +16 -5
  275. package/src/validators/utils/amka.ts +39 -0
  276. package/src/validators/utils/file.ts +33 -19
  277. package/src/validators/utils/index.ts +4 -1
  278. package/types.d.ts +2 -1
  279. package/types.js.map +1 -1
  280. package/utils/index.js +20 -6
  281. package/utils.d.ts +2 -0
  282. package/utils.js.map +2 -2
  283. package/validators/index.d.ts +1 -1
  284. package/validators/index.js +11 -5
  285. package/validators/index.js.map +2 -2
  286. package/validators/utils/amka/index.js +36 -0
  287. package/{inputs/Input/inputsInputScenarios → validators/utils/amka}/package.json +1 -1
  288. package/validators/utils/amka.d.ts +6 -0
  289. package/validators/utils/amka.js.map +7 -0
  290. package/validators/utils/file/index.js +30 -17
  291. package/validators/utils/file.js.map +2 -2
  292. package/validators/utils/index.d.ts +1 -0
  293. package/validators/utils/index.js +4 -1
  294. package/validators/utils/index.js.map +2 -2
  295. package/cjs/inputs/Input/inputsInputScenarios/index.js +0 -439
  296. package/cjs/inputs/Input/inputsInputScenarios.js.map +0 -7
  297. package/inputs/Input/inputsInputScenarios/index.js +0 -406
  298. package/inputs/Input/inputsInputScenarios.d.ts +0 -57
  299. package/inputs/Input/inputsInputScenarios.js.map +0 -7
  300. package/src/inputs/Input/inputsInputScenarios.ts +0 -404
@@ -85,9 +85,9 @@ export const Checkboxes: React.FC<CheckboxesProps> = ({
85
85
  ...props,
86
86
  reset: undefined,
87
87
  defaultValue: undefined,
88
+ error: undefined,
88
89
  onBlur: undefined,
89
90
  required: undefined,
90
- Field: undefined,
91
91
  'aria-describedby': undefined,
92
92
  type: 'checkbox',
93
93
  }}
@@ -1,7 +1,10 @@
1
1
  import DateInput from '@digigov/form/inputs/DateInput';
2
+ import doc from './doc.mdx?raw';
2
3
  export default {
3
4
  title: 'Digigov Form/inputs/DateInput',
4
5
  component: DateInput,
6
+ tags: ['autodocs'],
7
+ markdown: doc,
5
8
  displayName: 'DateInput',
6
9
  };
7
10
  export { Default } from '@digigov/form/inputs/DateInput/__stories__/Default';
@@ -14,7 +14,7 @@ const fields = [
14
14
  } as const,
15
15
  ];
16
16
 
17
- export const Default = () => (
17
+ export const Default = (_: any) => (
18
18
  <FormBuilder onSubmit={() => console.log('kati')}>
19
19
  {fields.map(({ key, ...field }) => {
20
20
  return <Field {...field} name={key} key={key} />;
@@ -2,6 +2,7 @@ import React, { useMemo, useState } from 'react';
2
2
  import dayjs from 'dayjs';
3
3
  import customParseFormat from 'dayjs/plugin/customParseFormat';
4
4
  import { UncontrolledFieldProps } from '@digigov/form/Field/types';
5
+ import { useFormContext } from '@digigov/form/FormContext';
5
6
  import {
6
7
  DateInputContainer,
7
8
  DateInputItem,
@@ -16,22 +17,26 @@ export interface DateInputProps extends Omit<UncontrolledFieldProps, 'extra'> {
16
17
  };
17
18
  }
18
19
 
19
- function useDate(value, onChange) {
20
+ function useDate(name, value, form) {
20
21
  const [year, month, day] = useMemo(() => {
21
22
  if (!value || value.length === 0) {
22
- onChange('');
23
+ update('');
23
24
  return ['', '', ''];
24
25
  }
25
26
  const [day, month, year] = value.split('/');
26
27
  return [year, month, day];
27
28
  }, [value]);
28
29
 
30
+ function update(value) {
31
+ form.setValue(name, value, { shouldValidate: false });
32
+ }
33
+
29
34
  function set(year, month, day) {
30
35
  const value = `${day || ''}/${month || ''}/${year || ''}`;
31
36
  if (!year && !month && !day) {
32
- onChange(null);
37
+ update('');
33
38
  } else {
34
- onChange(value);
39
+ update(value);
35
40
  }
36
41
  }
37
42
 
@@ -56,6 +61,12 @@ function useDate(value, onChange) {
56
61
  set(year, month, val);
57
62
  }
58
63
 
64
+ function trigger() {
65
+ if (form.formState.isSubmitted) {
66
+ form.trigger(name);
67
+ }
68
+ }
69
+
59
70
  return {
60
71
  day,
61
72
  month,
@@ -63,6 +74,7 @@ function useDate(value, onChange) {
63
74
  setYear,
64
75
  setMonth,
65
76
  setDay,
77
+ trigger,
66
78
  };
67
79
  }
68
80
 
@@ -90,14 +102,15 @@ export const DateInput = ({ name, ...props }) => {
90
102
  return props.value;
91
103
  }, [props.value, initial]);
92
104
 
93
- const date = useDate(value || makeDate(props.defaultValue), props.onChange);
105
+ const form = useFormContext();
106
+ const date = useDate(name, value || makeDate(props.defaultValue), form);
94
107
 
95
108
  return (
96
109
  <DateInputContainer>
97
110
  <DatePart
98
111
  label={t('form.label.day')}
99
112
  onChange={date.setDay}
100
- onBlur={(e) => date.setDay(e, true)}
113
+ onBlur={date.trigger}
101
114
  value={date.day}
102
115
  width={2}
103
116
  name={`${name}-day`}
@@ -110,7 +123,7 @@ export const DateInput = ({ name, ...props }) => {
110
123
  <DatePart
111
124
  label={t('form.label.month')}
112
125
  onChange={date.setMonth}
113
- onBlur={(e) => date.setMonth(e, true)}
126
+ onBlur={date.trigger}
114
127
  value={date.month}
115
128
  width={2}
116
129
  name={`${name}-month`}
@@ -123,6 +136,7 @@ export const DateInput = ({ name, ...props }) => {
123
136
  <DatePart
124
137
  label={t('form.label.year')}
125
138
  onChange={date.setYear}
139
+ onBlur={date.trigger}
126
140
  value={date.year}
127
141
  width={4}
128
142
  name={`${name}-year`}
@@ -1,8 +1,11 @@
1
1
  import { Default } from './__stories__/Default';
2
+ import doc from './doc.mdx?raw';
2
3
 
3
4
  export default {
4
5
  title: 'Form/Inputs/DateTimeInput',
5
6
  component: Default,
7
+ tags: ['autodocs'],
8
+ markdown: doc,
6
9
  };
7
10
 
8
11
  export { Default };
@@ -14,7 +14,7 @@ const fields = [
14
14
  } as const,
15
15
  ];
16
16
 
17
- export const Default = () => (
17
+ export const Default = (_: any) => (
18
18
  <FormBuilder onSubmit={() => console.log('kati')}>
19
19
  {fields.map(({ key, ...field }) => {
20
20
  return <Field {...field} name={key} key={key} />;
@@ -2,6 +2,7 @@ import React, { useMemo, useState } from 'react';
2
2
  import dayjs from 'dayjs';
3
3
  import customParseFormat from 'dayjs/plugin/customParseFormat';
4
4
  import { UncontrolledFieldProps } from '@digigov/form/Field/types';
5
+ import { useFormContext } from '@digigov/form/FormContext';
5
6
  import {
6
7
  DateInputContainer,
7
8
  DateInputItem,
@@ -17,10 +18,10 @@ export interface DateTimeInputProps
17
18
  };
18
19
  }
19
20
 
20
- function useDateTime(value, onChange) {
21
+ function useDateTime(name, value, form) {
21
22
  const [year, month, day, hours, minutes] = useMemo(() => {
22
23
  if (!value || value.length === 0) {
23
- onChange('');
24
+ update('');
24
25
  return ['', '', '', '', ''];
25
26
  }
26
27
  const [datePart, timePart] = value.split(' ');
@@ -29,15 +30,19 @@ function useDateTime(value, onChange) {
29
30
  return [year, month, day, hours, minutes];
30
31
  }, [value]);
31
32
 
33
+ function update(value) {
34
+ form.setValue(name, value, { shouldValidate: false });
35
+ }
36
+
32
37
  function set(year, month, day, hours, minutes) {
33
38
  const datePart = `${day || ''}/${month || ''}/${year || ''}`;
34
39
  const timePart = hours || minutes ? `${hours || ''}:${minutes || ''}` : '';
35
40
  const value = timePart ? `${datePart} ${timePart}` : datePart;
36
41
 
37
42
  if (!year && !month && !day && !hours && !minutes) {
38
- onChange(null);
43
+ update('');
39
44
  } else {
40
- onChange(value);
45
+ update(value);
41
46
  }
42
47
  }
43
48
 
@@ -78,6 +83,12 @@ function useDateTime(value, onChange) {
78
83
  set(year, month, day, hours, val);
79
84
  }
80
85
 
86
+ function trigger() {
87
+ if (form.formState.isSubmitted) {
88
+ form.trigger(name);
89
+ }
90
+ }
91
+
81
92
  return {
82
93
  day,
83
94
  month,
@@ -89,6 +100,7 @@ function useDateTime(value, onChange) {
89
100
  setDay,
90
101
  setHours,
91
102
  setMinutes,
103
+ trigger,
92
104
  };
93
105
  }
94
106
 
@@ -116,9 +128,11 @@ export const DateTimeInput = ({ name, ...props }) => {
116
128
  return props.value;
117
129
  }, [props.value, initial]);
118
130
 
131
+ const form = useFormContext();
119
132
  const datetime = useDateTime(
133
+ name,
120
134
  value || makeDateTime(props.defaultValue),
121
- props.onChange
135
+ form
122
136
  );
123
137
 
124
138
  return (
@@ -126,7 +140,7 @@ export const DateTimeInput = ({ name, ...props }) => {
126
140
  <DateTimePart
127
141
  label={t('form.label.day')}
128
142
  onChange={datetime.setDay}
129
- onBlur={(e) => datetime.setDay(e, true)}
143
+ onBlur={datetime.trigger}
130
144
  value={datetime.day}
131
145
  width={2}
132
146
  name={`${name}-day`}
@@ -139,7 +153,7 @@ export const DateTimeInput = ({ name, ...props }) => {
139
153
  <DateTimePart
140
154
  label={t('form.label.month')}
141
155
  onChange={datetime.setMonth}
142
- onBlur={(e) => datetime.setMonth(e, true)}
156
+ onBlur={datetime.trigger}
143
157
  value={datetime.month}
144
158
  width={2}
145
159
  name={`${name}-month`}
@@ -152,6 +166,7 @@ export const DateTimeInput = ({ name, ...props }) => {
152
166
  <DateTimePart
153
167
  label={t('form.label.year')}
154
168
  onChange={datetime.setYear}
169
+ onBlur={datetime.trigger}
155
170
  value={datetime.year}
156
171
  width={4}
157
172
  name={`${name}-year`}
@@ -164,7 +179,7 @@ export const DateTimeInput = ({ name, ...props }) => {
164
179
  <DateTimePart
165
180
  label={t('form.label.hours')}
166
181
  onChange={datetime.setHours}
167
- onBlur={(e) => datetime.setHours(e, true)}
182
+ onBlur={datetime.trigger}
168
183
  value={datetime.hours}
169
184
  width={2}
170
185
  name={`${name}-hours`}
@@ -177,7 +192,7 @@ export const DateTimeInput = ({ name, ...props }) => {
177
192
  <DateTimePart
178
193
  label={t('form.label.minutes')}
179
194
  onChange={datetime.setMinutes}
180
- onBlur={(e) => datetime.setMinutes(e, true)}
195
+ onBlur={datetime.trigger}
181
196
  value={datetime.minutes}
182
197
  width={2}
183
198
  name={`${name}-minutes`}
@@ -1,7 +1,11 @@
1
1
  import FileInput from '@digigov/form/inputs/FileInput';
2
+ import doc from './doc.mdx?raw';
2
3
  export default {
3
4
  title: 'Digigov Form/inputs/FileInput',
4
5
  component: FileInput,
6
+ tags: ['autodocs'],
7
+ markdown: doc,
5
8
  displayName: 'FileInput',
6
9
  };
7
10
  export { Default } from '@digigov/form/inputs/FileInput/__stories__/Default';
11
+ export { WithBorderAndLink } from '@digigov/form/inputs/FileInput/__stories__/WithBorderAndLink';
@@ -2,7 +2,7 @@ import React from 'react';
2
2
  import FormBuilder, { Field } from '@digigov/form';
3
3
  import { Button } from '@digigov/ui/form/Button';
4
4
 
5
- export const Default = () => (
5
+ export const Default = (_: any) => (
6
6
  <FormBuilder
7
7
  onSubmit={(data) => {
8
8
  console.log(data);
@@ -0,0 +1,34 @@
1
+ import React from 'react';
2
+ import FormBuilder, { Field } from '@digigov/form';
3
+ import { Button } from '@digigov/ui/form/Button';
4
+
5
+ export const WithBorderAndLink = () => (
6
+ <FormBuilder
7
+ onSubmit={(data) => {
8
+ console.log(data);
9
+ }}
10
+ >
11
+ <Field
12
+ key={'string'}
13
+ name="file"
14
+ type="file"
15
+ required
16
+ extra={{
17
+ containerProps: {
18
+ variant: 'border',
19
+ },
20
+ uploadButtonProps: {
21
+ variant: 'link',
22
+ },
23
+ resetButtonProps: {
24
+ variant: 'link',
25
+ color: 'warning',
26
+ },
27
+ }}
28
+ label={{ primary: 'Βιογραφικό σημείωμα' }}
29
+ />
30
+ <Button>Συνέχεια</Button>
31
+ </FormBuilder>
32
+ );
33
+
34
+ export default WithBorderAndLink;
@@ -2,6 +2,7 @@ import React from 'react';
2
2
  import { test, expect } from '@playwright/experimental-ct-react';
3
3
  import TestVariant from '@digigov/ui/utils/TestVariant'
4
4
  import { Default } from '@digigov/form/inputs/FileInput/__stories__/Default';
5
+ import { WithBorderAndLink } from '@digigov/form/inputs/FileInput/__stories__/WithBorderAndLink';
5
6
 
6
7
  test('renders the All FileInput variants', async ({ mount, page }) => {
7
8
  await mount(
@@ -10,6 +11,9 @@ test('renders the All FileInput variants', async ({ mount, page }) => {
10
11
  <TestVariant title="Default">
11
12
  <Default />
12
13
  </TestVariant>
14
+ <TestVariant title="WithBorderAndLink">
15
+ <WithBorderAndLink />
16
+ </TestVariant>
13
17
  </div>
14
18
  )
15
19
  await page.evaluate(() => document.fonts.ready);
@@ -1,10 +1,17 @@
1
- import React, { useState } from 'react';
1
+ import React, { useEffect, useState } from 'react';
2
+ import { useWatch } from 'react-hook-form';
2
3
  import { UncontrolledFieldProps } from '@digigov/form/Field/types';
3
- import { Button } from '@digigov/ui/form/Button';
4
- import { FileUpload, FileUploadContainer } from '@digigov/ui/form/FileUpload';
4
+ import { Button, ButtonProps } from '@digigov/ui/form/Button';
5
+ import {
6
+ FileUpload,
7
+ FileUploadContainer,
8
+ FileUploadContainerProps,
9
+ FileUploadProps,
10
+ } from '@digigov/ui/form/FileUpload';
5
11
  import { useTranslation } from '@digigov/ui/i18n';
6
12
  import { Hint } from '@digigov/ui/typography/Hint';
7
13
  import { Paragraph } from '@digigov/ui/typography/Paragraph';
14
+
8
15
  export interface FileInputProps extends Omit<UncontrolledFieldProps, 'extra'> {
9
16
  extra?: {
10
17
  className?: string;
@@ -13,9 +20,10 @@ export interface FileInputProps extends Omit<UncontrolledFieldProps, 'extra'> {
13
20
  limit: {
14
21
  maxSize?: number;
15
22
  };
16
- variant?: 'border' | 'none';
17
- buttonVariant?: 'link' | 'button';
18
- resetButtonColor?: 'primary' | 'secondary' | 'warning';
23
+ containerProps?: FileUploadContainerProps;
24
+ uploadButtonProps?: FileUploadProps;
25
+ noResetButton?: boolean;
26
+ resetButtonProps?: ButtonProps;
19
27
  locales?: {
20
28
  file?: string;
21
29
  chooseFile?: string;
@@ -25,30 +33,26 @@ export interface FileInputProps extends Omit<UncontrolledFieldProps, 'extra'> {
25
33
  };
26
34
  }
27
35
 
28
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
29
36
  export const FileInput: React.FC<any> = React.forwardRef(function FileInput(
30
- { name, disabled, reset, onChange, extra, ...props },
37
+ { name, disabled, resetField, extra, control, onChange, ...props },
31
38
  ref: any
32
39
  ) {
40
+ delete props.Field;
41
+ delete props.reset;
33
42
  const { t } = useTranslation();
34
- const variant = extra?.variant || 'none';
35
- const buttonVariant = extra?.buttonVariant;
36
- const resetButtonColor = extra?.resetButtonColor;
37
- const [files, setFiles] = useState<string[] | undefined>([]);
38
- const handleChange = (e) => {
39
- const target = e.target as HTMLInputElement;
40
- const selectedFiles = Array.from(
41
- target.files as ArrayLike<{ name: string }>
42
- ).map(({ name }) => name);
43
- setFiles(selectedFiles);
44
- // proceed calling the onChange provided
45
- // by react-hook-form
46
- onChange(e);
47
- };
43
+ const value: any = useWatch({ control, name });
44
+
45
+ const [files, setFiles] = useState<string[] | undefined>(
46
+ Object.values(value || {})?.map?.(({ name }) => name) || []
47
+ );
48
+ useEffect(() => {
49
+ setFiles(Object.values(value || {})?.map?.(({ name }) => name));
50
+ }, [value]);
51
+
48
52
  return (
49
53
  <>
50
54
  <FileUploadContainer
51
- variant={variant}
55
+ variant={extra?.containerProps?.variant || 'default'}
52
56
  hasFiles={files && files.length > 0}
53
57
  >
54
58
  {files?.length ? (
@@ -70,24 +74,31 @@ export const FileInput: React.FC<any> = React.forwardRef(function FileInput(
70
74
  ref={ref}
71
75
  hasFiles={!!files?.length}
72
76
  name={name}
73
- variant={buttonVariant}
77
+ variant={extra?.uploadButtonProps?.variant}
74
78
  disabled={disabled}
75
- onChange={handleChange}
76
79
  id={name}
77
- {...{ ...props, required: undefined, Field: undefined }}
80
+ onChange={(event) => {
81
+ event.preventDefault();
82
+ const target = event?.target as HTMLInputElement;
83
+ if (target?.files && target?.files.length > 0) {
84
+ setFiles(Object.values(target?.files)?.map?.(({ name }) => name));
85
+ }
86
+ onChange(event);
87
+ }}
88
+ {...{ ...props, required: undefined }}
78
89
  >
79
90
  {files?.length ? t('upload.change_file') : t('upload.choose_file')}
80
91
  </FileUpload>
81
- {files !== undefined && files.length > 0 && (
92
+ {files !== undefined && files?.length > 0 && !extra?.noResetButton && (
82
93
  <>
83
94
  <Button
84
- variant="link"
95
+ variant={extra?.resetButtonProps?.variant || 'link'}
85
96
  onClick={(event) => {
86
97
  event.preventDefault();
87
- reset({ [name]: '' });
98
+ resetField(name);
88
99
  setFiles(undefined);
89
100
  }}
90
- color={resetButtonColor}
101
+ color={extra?.resetButtonProps?.color || 'secondary'}
91
102
  >
92
103
  {t('upload.reset_file')}
93
104
  </Button>
@@ -1,9 +1,13 @@
1
1
  import ImageInput from '@digigov/form/inputs/ImageInput';
2
+ import doc from './doc.mdx?raw';
2
3
  export default {
3
4
  title: 'Digigov Form/inputs/ImageInput',
4
5
  component: ImageInput,
6
+ tags: ['autodocs'],
7
+ markdown: doc,
5
8
  displayName: 'ImageInput',
6
9
  };
7
10
  export { Default } from '@digigov/form/inputs/ImageInput/__stories__/Default';
8
- export { WithInvalidImageDimension } from '@digigov/form/inputs/ImageInput/__stories__/WithInvalidImageDimension';
9
11
  export { MaxSize } from '@digigov/form/inputs/ImageInput/__stories__/MaxSize';
12
+ export { WithInvalidImageDimension } from '@digigov/form/inputs/ImageInput/__stories__/WithInvalidImageDimension';
13
+ export { WithInitialValues } from '@digigov/form/inputs/ImageInput/__stories__/WithInitialValues';
@@ -13,7 +13,7 @@ const FIELDS: FieldSpec[] = [
13
13
  },
14
14
  ];
15
15
 
16
- export const Default = () => (
16
+ export const Default = (_: any) => (
17
17
  <FormBuilder
18
18
  fields={FIELDS}
19
19
  onSubmit={(data) => {
@@ -9,17 +9,18 @@ const FIELDS: FieldSpec[] = [
9
9
  required: true,
10
10
  label: {
11
11
  primary: 'Ανέβασμα φωτογραφίας',
12
- secondary: 'Μέγιστο μέγεθος φωτογραφίας: 10KB.',
12
+ secondary: 'Μέγιστο μέγεθος φωτογραφίας: 1KB.',
13
13
  },
14
14
  extra: {
15
15
  limit: {
16
+ // bytes
16
17
  maxSize: 1000,
17
18
  },
18
19
  },
19
20
  },
20
21
  ];
21
22
 
22
- export const MaxSize = () => (
23
+ export const MaxSize = (_: any) => (
23
24
  <FormBuilder
24
25
  fields={FIELDS}
25
26
  onSubmit={(data) => {
@@ -0,0 +1,45 @@
1
+ import React from 'react';
2
+ import FormBuilder, { Field, Fieldset } from '@digigov/form';
3
+ import logo from '@digigov/form/inputs/ImageInput/__stories__/logo.png';
4
+ import { FieldSpec } from '@digigov/form/types';
5
+ import { Button } from '@digigov/ui/form/Button';
6
+ const FIELDS: FieldSpec[] = [
7
+ {
8
+ key: 'image',
9
+ type: 'image',
10
+ required: true,
11
+ label: {
12
+ primary: 'Ανέβασμα φωτογραφίας',
13
+ secondary:
14
+ 'Οι επιτρεπόμενες διαστάσεις είναι για το ύψος από 100 μέχρι 400 και για το πλάτος από 100 μέχρι 400.',
15
+ },
16
+ extra: {
17
+ limit: {
18
+ maxHeight: 400,
19
+ maxWidth: 400,
20
+ minHeight: 100,
21
+ minWidth: 100,
22
+ },
23
+ },
24
+ },
25
+ ];
26
+
27
+ export const WithInitialValues = (_: any) => (
28
+ <FormBuilder
29
+ fields={FIELDS}
30
+ initial={{
31
+ image: { src: logo, filename: 'logo.png' },
32
+ }}
33
+ onSubmit={(data) => {
34
+ console.log(data);
35
+ }}
36
+ >
37
+ <Fieldset>
38
+ {FIELDS.map((field) => (
39
+ <Field key={field.key} name={field.key} />
40
+ ))}
41
+ </Fieldset>
42
+ <Button type="submit">Συνέχεια</Button>
43
+ </FormBuilder>
44
+ );
45
+ export default WithInitialValues;
@@ -23,7 +23,7 @@ const FIELDS: FieldSpec[] = [
23
23
  },
24
24
  ];
25
25
 
26
- export const WithInvalidImageDimension = () => (
26
+ export const WithInvalidImageDimension = (_: any) => (
27
27
  <FormBuilder
28
28
  fields={FIELDS}
29
29
  onSubmit={(data) => {
@@ -0,0 +1,4 @@
1
+ declare module '*.png' {
2
+ const value: any;
3
+ export default value;
4
+ }
@@ -1,32 +1,36 @@
1
1
  import React from 'react';
2
2
  import { test, expect } from '@playwright/experimental-ct-react';
3
- import TestVariant from '@digigov/ui/utils/TestVariant';
3
+ import TestVariant from '@digigov/ui/utils/TestVariant'
4
4
  import { Default } from '@digigov/form/inputs/ImageInput/__stories__/Default';
5
5
  import { MaxSize } from '@digigov/form/inputs/ImageInput/__stories__/MaxSize';
6
+ import { WithInitialValues } from '@digigov/form/inputs/ImageInput/__stories__/WithInitialValues';
6
7
  import { WithInvalidImageDimension } from '@digigov/form/inputs/ImageInput/__stories__/WithInvalidImageDimension';
7
8
 
8
9
  test('renders the All ImageInput variants', async ({ mount, page }) => {
9
10
  await mount(
10
- <div>
11
- <TestVariant title="Default">
12
- <Default />
13
- </TestVariant>
14
- <TestVariant title="MaxSize">
15
- <MaxSize />
16
- </TestVariant>
17
- <TestVariant title="WithInvalidImageDimension">
18
- <WithInvalidImageDimension />
19
- </TestVariant>
20
- </div>
21
- );
11
+
12
+ <div>
13
+ <TestVariant title="Default">
14
+ <Default />
15
+ </TestVariant>
16
+ <TestVariant title="MaxSize">
17
+ <MaxSize />
18
+ </TestVariant>
19
+ <TestVariant title="WithInitialValues">
20
+ <WithInitialValues />
21
+ </TestVariant>
22
+ <TestVariant title="WithInvalidImageDimension">
23
+ <WithInvalidImageDimension />
24
+ </TestVariant>
25
+ </div>
26
+ )
22
27
  await page.evaluate(() => document.fonts.ready);
23
28
 
24
29
  // Move the mouse to the top-left corner to avoid random hover issues
25
30
  await page.mouse.move(0, 0);
26
31
 
27
- const screenshot = await page.screenshot({
28
- fullPage: true,
29
- animations: 'disabled',
30
- });
32
+
33
+ const screenshot = await page.screenshot({ fullPage: true, animations: 'disabled' });
31
34
  expect(screenshot).toMatchSnapshot();
32
35
  });
36
+