@inseefr/lunatic 2.7.0-rc.5 → 2.7.2

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 (161) hide show
  1. package/README.md +45 -11
  2. package/lib/components/checkbox/checkbox-boolean/html/checkbox-boolean.js +3 -3
  3. package/lib/components/checkbox/checkbox-boolean/lunatic-checkbox-boolean.js +2 -1
  4. package/lib/components/checkbox/checkbox-group/checkbox-group-content.js +0 -2
  5. package/lib/components/checkbox/checkbox-group/html/checkbox-group-content.js +4 -2
  6. package/lib/components/checkbox/checkbox-group/html/checkbox-group.js +3 -3
  7. package/lib/components/checkbox/checkbox-group/lunatic-checkbox-group.js +2 -2
  8. package/lib/components/checkbox/checkbox-one/lunatic-checkbox-one.js +2 -1
  9. package/lib/components/checkbox/commons/checkbox-option.js +3 -1
  10. package/lib/components/commons/components/combo-box/combo-box-container.js +1 -2
  11. package/lib/components/commons/components/combo-box/combo-box.js +2 -2
  12. package/lib/components/commons/components/combo-box/selection/LabelOrInput.js +3 -1
  13. package/lib/components/commons/components/combo-box/selection/input.js +3 -1
  14. package/lib/components/commons/components/combo-box/selection/selection.js +3 -1
  15. package/lib/components/commons/components/errors/errors.js +12 -10
  16. package/lib/components/commons/components/errors/errors.spec.js +6 -6
  17. package/lib/components/component-set/html/__snapshots__/component-set.spec.tsx.snap +2 -0
  18. package/lib/components/component-set/html/component-set.js +2 -2
  19. package/lib/components/datepicker/html/DatepickerField.js +47 -0
  20. package/lib/components/datepicker/html/__snapshots__/datepicker.spec.tsx.snap +209 -17
  21. package/lib/components/datepicker/html/datepicker.js +104 -21
  22. package/lib/components/datepicker/html/datepicker.scss +19 -1
  23. package/lib/components/datepicker/html/datepicker.spec.js +71 -23
  24. package/lib/components/datepicker/lunatic-datepicker.js +5 -2
  25. package/lib/components/dropdown/lunatic-dropdown.js +2 -1
  26. package/lib/components/duration/duration.js +6 -7
  27. package/lib/components/duration/duration.scss +6 -14
  28. package/lib/components/duration/durationInput.js +14 -8
  29. package/lib/components/duration/durationUtils.js +38 -8
  30. package/lib/components/input/html/__snapshots__/input.spec.tsx.snap +2 -0
  31. package/lib/components/input/html/input.js +3 -3
  32. package/lib/components/input/lunatic-input.js +2 -1
  33. package/lib/components/input-number/html/__snapshots__/input-number.spec.tsx.snap +2 -2
  34. package/lib/components/input-number/html/input-number-thousand.js +4 -17
  35. package/lib/components/input-number/html/input-number.js +3 -5
  36. package/lib/components/input-number/lunatic-input-number.js +2 -3
  37. package/lib/components/loop/roster-for-loop/__snapshots__/roster-for-loop.spec.tsx.snap +88 -0
  38. package/lib/components/loop/roster-for-loop/roster-for-loop.js +7 -3
  39. package/lib/components/loop/roster-for-loop/roster-for-loop.spec.js +46 -0
  40. package/lib/components/lunatic-components.js +2 -11
  41. package/lib/components/radio/html/radio-group-content.js +4 -2
  42. package/lib/components/radio/html/radio-group.js +3 -3
  43. package/lib/components/radio/html/radio-option.js +3 -1
  44. package/lib/components/radio/lunatic-radio-group.js +2 -1
  45. package/lib/components/suggester/find-best-label/find-best-label.js +5 -5
  46. package/lib/components/suggester/idb-suggester/check-store.js +6 -3
  47. package/lib/components/suggester/idb-suggester/idb-suggester.js +8 -7
  48. package/lib/components/suggester/idb-suggester/suggester-status.js +1 -4
  49. package/lib/components/suggester/lunatic-suggester.js +7 -4
  50. package/lib/components/suggester/searching/create-searching.js +5 -5
  51. package/lib/components/switch/html/switch.js +2 -2
  52. package/lib/components/switch/lunatic-switch.js +2 -1
  53. package/lib/components/table/lunatic-table.js +2 -2
  54. package/lib/components/textarea/html/__snapshots__/textarea.spec.tsx.snap +2 -0
  55. package/lib/components/textarea/html/textarea.js +6 -4
  56. package/lib/components/textarea/lunatic-textarea.js +6 -3
  57. package/lib/hooks/use-auto-focus.js +26 -0
  58. package/lib/src/components/checkbox/checkbox-boolean/html/checkbox-boolean.d.ts +1 -1
  59. package/lib/src/components/checkbox/checkbox-group/html/checkbox-group-content.d.ts +2 -1
  60. package/lib/src/components/checkbox/checkbox-group/html/checkbox-group.d.ts +1 -1
  61. package/lib/src/components/checkbox/commons/checkbox-option.d.ts +1 -0
  62. package/lib/src/components/commons/components/combo-box/combo-box-container.d.ts +2 -2
  63. package/lib/src/components/commons/components/combo-box/combo-box.d.ts +2 -2
  64. package/lib/src/components/commons/components/combo-box/selection/LabelOrInput.d.ts +1 -0
  65. package/lib/src/components/commons/components/combo-box/selection/input.d.ts +1 -0
  66. package/lib/src/components/commons/components/combo-box/selection/selection.d.ts +2 -1
  67. package/lib/src/components/commons/components/errors/errors.d.ts +6 -3
  68. package/lib/src/components/datepicker/html/DatepickerField.d.ts +12 -0
  69. package/lib/src/components/datepicker/html/datepicker.d.ts +4 -3
  70. package/lib/src/components/datepicker/lunatic-datepicker.d.ts +1 -0
  71. package/lib/src/components/dropdown/html/dropdown-writable/dropdown-writable.d.ts +1 -1
  72. package/lib/src/components/dropdown/html/dropdown.d.ts +3 -1
  73. package/lib/src/components/duration/durationInput.d.ts +6 -2
  74. package/lib/src/components/duration/durationUtils.d.ts +24 -7
  75. package/lib/src/components/input/html/input.d.ts +2 -2
  76. package/lib/src/components/input-number/html/input-number-thousand.d.ts +2 -2
  77. package/lib/src/components/input-number/html/input-number.d.ts +2 -3
  78. package/lib/src/components/radio/html/radio-group-content.d.ts +2 -1
  79. package/lib/src/components/radio/html/radio-group.d.ts +1 -1
  80. package/lib/src/components/radio/html/radio-option.d.ts +1 -0
  81. package/lib/src/components/suggester/find-best-label/find-best-label.d.ts +1 -1
  82. package/lib/src/components/suggester/html/suggester.d.ts +1 -1
  83. package/lib/src/components/suggester/idb-suggester/check-store.d.ts +5 -2
  84. package/lib/src/components/suggester/idb-suggester/idb-suggester.d.ts +5 -2
  85. package/lib/src/components/suggester/idb-suggester/suggester-status.d.ts +1 -4
  86. package/lib/src/components/suggester/lunatic-suggester.d.ts +1 -1
  87. package/lib/src/components/suggester/searching/create-searching.d.ts +1 -1
  88. package/lib/src/components/switch/html/switch.d.ts +1 -1
  89. package/lib/src/components/textarea/html/textarea.d.ts +3 -2
  90. package/lib/src/components/type.d.ts +5 -3
  91. package/lib/src/hooks/use-auto-focus.d.ts +6 -0
  92. package/lib/src/use-lunatic/actions.d.ts +2 -0
  93. package/lib/src/use-lunatic/commons/fill-components/fill-component-required.d.ts +383 -0
  94. package/lib/src/use-lunatic/commons/fill-components/fill-component-value.d.ts +1 -1
  95. package/lib/src/use-lunatic/commons/fill-components/fill-component-value.spec.d.ts +1 -0
  96. package/lib/src/use-lunatic/commons/fill-components/fill-from-state.d.ts +20 -0
  97. package/lib/src/use-lunatic/commons/variables/lunatic-variables-store.d.ts +4 -0
  98. package/lib/src/use-lunatic/reducer/overview/overview-on-init.d.ts +1 -0
  99. package/lib/src/use-lunatic/type.d.ts +1 -0
  100. package/lib/src/use-lunatic/use-lunatic.d.ts +9 -5
  101. package/lib/src/use-lunatic/use-suggesters.d.ts +2 -1
  102. package/lib/src/utils/suggester-workers/append-to-index/create-append-task.d.ts +2 -2
  103. package/lib/src/utils/suggester-workers/worker-path.d.ts +1 -1
  104. package/lib/stories/behaviour/cleaning/source.json +151 -0
  105. package/lib/stories/behaviour/cleaning/test.stories.js +82 -0
  106. package/lib/stories/{questionnaires-test → behaviour}/controls/controls.stories.js +5 -5
  107. package/lib/stories/{questionnaires-test → behaviour/others}/test.stories.js +7 -7
  108. package/lib/stories/{paste-questionnaire → behaviour/paste}/test.stories.js +3 -3
  109. package/lib/stories/{resizing-questionnaire → behaviour/resizing}/test.stories.js +3 -3
  110. package/lib/stories/date-picker/datepicker.stories.js +32 -29
  111. package/lib/stories/duration/duration.stories.js +4 -4
  112. package/lib/stories/duration/{source.json → mois.json} +1 -1
  113. package/lib/stories/duration/{source1.json → time.json} +1 -1
  114. package/lib/use-lunatic/commons/fill-components/fill-component-required.js +23 -0
  115. package/lib/use-lunatic/commons/fill-components/fill-component-value.js +1 -1
  116. package/lib/use-lunatic/commons/fill-components/fill-component-value.spec.js +67 -0
  117. package/lib/use-lunatic/commons/fill-components/fill-components.js +2 -1
  118. package/lib/use-lunatic/commons/fill-components/fill-from-state.js +2 -0
  119. package/lib/use-lunatic/commons/variables/lunatic-variables-store.js +20 -0
  120. package/lib/use-lunatic/commons/variables/lunatic-variables-store.spec.js +15 -1
  121. package/lib/use-lunatic/initial-state.js +2 -1
  122. package/lib/use-lunatic/reducer/reduce-on-init.js +4 -2
  123. package/lib/use-lunatic/use-lunatic.js +12 -10
  124. package/lib/use-lunatic/use-suggesters.js +54 -37
  125. package/lib/utils/env.js +9 -1
  126. package/lib/utils/suggester-workers/append-to-index/create-append-task.js +4 -3
  127. package/lib/utils/suggester-workers/{create-worker-ts.js → create-worker.js} +10 -1
  128. package/lib/utils/suggester-workers/worker-path.js +5 -4
  129. package/package.json +20 -10
  130. package/scripts/build/add-workers-to-public.js +31 -31
  131. package/scripts/build/workers-paths.js +18 -7
  132. package/workers-release/{lunatic-append-worker-0.3.0-experimental.js → lunatic-append-worker-0.3.0.js} +1 -1
  133. package/workers-release/{lunatic-label-worker-0.3.0-experimental.js → lunatic-label-worker-0.3.0.js} +1 -1
  134. package/workers-release/{lunatic-searching-worker-0.3.0-experimental.js → lunatic-search-worker-0.3.0.js} +1 -1
  135. package/lib/components/datepicker/html/datepicker-container.js +0 -17
  136. package/lib/components/datepicker/html/datepicker-input.js +0 -35
  137. package/lib/env.d.js +0 -1
  138. package/lib/src/components/datepicker/html/datepicker-container.d.ts +0 -3
  139. package/lib/src/components/datepicker/html/datepicker-input.d.ts +0 -13
  140. package/lib/src/utils/get-component-value.d.ts +0 -5
  141. package/lib/utils/get-component-value.js +0 -34
  142. package/lib/utils/get-component-value.test.js +0 -57
  143. /package/lib/src/{utils/get-component-value.test.d.ts → components/loop/roster-for-loop/roster-for-loop.spec.d.ts} +0 -0
  144. /package/lib/src/utils/suggester-workers/{create-worker-ts.d.ts → create-worker.d.ts} +0 -0
  145. /package/lib/stories/{questionnaires-test → behaviour}/controls/V2_ControlesNonNum_horsBoucle_PasPageFin.json +0 -0
  146. /package/lib/stories/{questionnaires-test → behaviour}/controls/V2_ControlesNum_horsBoucle_PasPageFin.json +0 -0
  147. /package/lib/stories/{questionnaires-test → behaviour}/controls/V2_Controles_BouclesLiees2_PasPageFin.json +0 -0
  148. /package/lib/stories/{questionnaires-test → behaviour}/controls/V2_Controles_BouclesLiees_PasPageFin.json +0 -0
  149. /package/lib/stories/{questionnaires-test → behaviour}/controls/boucles-n.json +0 -0
  150. /package/lib/stories/{questionnaires-test → behaviour}/controls/controls-externes.json +0 -0
  151. /package/lib/stories/{questionnaires-test → behaviour}/controls/controls-externes.stories.js +0 -0
  152. /package/lib/stories/{questionnaires-test → behaviour/others}/V2_DeclarationsSimples.json +0 -0
  153. /package/lib/stories/{questionnaires-test → behaviour/others}/V2_MinMaxSum_Boucles.json +0 -0
  154. /package/lib/stories/{questionnaires-test → behaviour/others}/V2_QuestSimple_Boucles.json +0 -0
  155. /package/lib/stories/{questionnaires-test → behaviour/others}/V2_TCMRallyeGames.json +0 -0
  156. /package/lib/stories/{questionnaires-test → behaviour/others}/test-dylan.json +0 -0
  157. /package/lib/stories/{paste-questionnaire → behaviour/paste}/source.json +0 -0
  158. /package/lib/stories/{resizing-questionnaire → behaviour/resizing}/source.json +0 -0
  159. /package/workers-release/{lunatic-append-worker-0.3.0-experimental.js.LICENSE.txt → lunatic-append-worker-0.3.0.js.LICENSE.txt} +0 -0
  160. /package/workers-release/{lunatic-label-worker-0.3.0-experimental.js.LICENSE.txt → lunatic-label-worker-0.3.0.js.LICENSE.txt} +0 -0
  161. /package/workers-release/{lunatic-searching-worker-0.3.0-experimental.js.LICENSE.txt → lunatic-search-worker-0.3.0.js.LICENSE.txt} +0 -0
@@ -1,34 +1,226 @@
1
1
  // Vitest Snapshot v1
2
2
 
3
- exports[`Datepicker > renders without crashing 1`] = `
3
+ exports[`Datepicker > should render properly with format YYYY 1`] = `
4
4
  <div>
5
5
  <div
6
6
  class="lunatic-input"
7
7
  >
8
- <input
9
- aria-labelledby="lunatic-datepicker-datepicker"
10
- class="lunatic-datepicker"
11
- id="datepicker"
12
- type="date"
13
- value="1999-01-01"
14
- />
8
+ <div
9
+ class="lunaticDatepickerFields"
10
+ >
11
+ <div
12
+ class="lunaticDatepickerField"
13
+ >
14
+ <label
15
+ for="datepickerday"
16
+ >
17
+ Jour
18
+ <span
19
+ class="lunaticDatepickerHint"
20
+ >
21
+ Exemple: 14
22
+ </span>
23
+ </label>
24
+ <input
25
+ id="datepickerday"
26
+ max="31"
27
+ min="1"
28
+ type="number"
29
+ value="1"
30
+ />
31
+ </div>
32
+ <div
33
+ class="lunaticDatepickerField"
34
+ >
35
+ <label
36
+ for="datepickermonth"
37
+ >
38
+ Mois
39
+ <span
40
+ class="lunaticDatepickerHint"
41
+ >
42
+ Exemple: 07
43
+ </span>
44
+ </label>
45
+ <input
46
+ id="datepickermonth"
47
+ max="12"
48
+ min="1"
49
+ type="number"
50
+ value="1"
51
+ />
52
+ </div>
53
+ <div
54
+ class="lunaticDatepickerField lunaticDatepickerFieldLarge"
55
+ >
56
+ <label
57
+ for="datepickeryear"
58
+ >
59
+ Année
60
+ <span
61
+ class="lunaticDatepickerHint"
62
+ >
63
+ Exemple: 2023
64
+ </span>
65
+ </label>
66
+ <input
67
+ id="datepickeryear"
68
+ min="1"
69
+ type="number"
70
+ value="1999"
71
+ />
72
+ </div>
73
+ </div>
15
74
  </div>
16
75
  </div>
17
76
  `;
18
77
 
19
- exports[`Datepicker > should handle readOnly 1`] = `
78
+ exports[`Datepicker > should render properly with format YYYY-MM 1`] = `
20
79
  <div>
21
80
  <div
22
81
  class="lunatic-input"
23
82
  >
24
- <input
25
- aria-labelledby="lunatic-datepicker-Datepicker"
26
- class="lunatic-datepicker readOnly"
27
- id="Datepicker"
28
- readonly=""
29
- type="date"
30
- value="1980-01-19"
31
- />
83
+ <div
84
+ class="lunaticDatepickerFields"
85
+ >
86
+ <div
87
+ class="lunaticDatepickerField"
88
+ >
89
+ <label
90
+ for="datepickerday"
91
+ >
92
+ Jour
93
+ <span
94
+ class="lunaticDatepickerHint"
95
+ >
96
+ Exemple: 14
97
+ </span>
98
+ </label>
99
+ <input
100
+ id="datepickerday"
101
+ max="31"
102
+ min="1"
103
+ type="number"
104
+ value="1"
105
+ />
106
+ </div>
107
+ <div
108
+ class="lunaticDatepickerField"
109
+ >
110
+ <label
111
+ for="datepickermonth"
112
+ >
113
+ Mois
114
+ <span
115
+ class="lunaticDatepickerHint"
116
+ >
117
+ Exemple: 07
118
+ </span>
119
+ </label>
120
+ <input
121
+ id="datepickermonth"
122
+ max="12"
123
+ min="1"
124
+ type="number"
125
+ value="1"
126
+ />
127
+ </div>
128
+ <div
129
+ class="lunaticDatepickerField lunaticDatepickerFieldLarge"
130
+ >
131
+ <label
132
+ for="datepickeryear"
133
+ >
134
+ Année
135
+ <span
136
+ class="lunaticDatepickerHint"
137
+ >
138
+ Exemple: 2023
139
+ </span>
140
+ </label>
141
+ <input
142
+ id="datepickeryear"
143
+ min="1"
144
+ type="number"
145
+ value="1999"
146
+ />
147
+ </div>
148
+ </div>
149
+ </div>
150
+ </div>
151
+ `;
152
+
153
+ exports[`Datepicker > should render properly with format YYYY-MM-DD 1`] = `
154
+ <div>
155
+ <div
156
+ class="lunatic-input"
157
+ >
158
+ <div
159
+ class="lunaticDatepickerFields"
160
+ >
161
+ <div
162
+ class="lunaticDatepickerField"
163
+ >
164
+ <label
165
+ for="datepickerday"
166
+ >
167
+ Jour
168
+ <span
169
+ class="lunaticDatepickerHint"
170
+ >
171
+ Exemple: 14
172
+ </span>
173
+ </label>
174
+ <input
175
+ id="datepickerday"
176
+ max="31"
177
+ min="1"
178
+ type="number"
179
+ value="1"
180
+ />
181
+ </div>
182
+ <div
183
+ class="lunaticDatepickerField"
184
+ >
185
+ <label
186
+ for="datepickermonth"
187
+ >
188
+ Mois
189
+ <span
190
+ class="lunaticDatepickerHint"
191
+ >
192
+ Exemple: 07
193
+ </span>
194
+ </label>
195
+ <input
196
+ id="datepickermonth"
197
+ max="12"
198
+ min="1"
199
+ type="number"
200
+ value="1"
201
+ />
202
+ </div>
203
+ <div
204
+ class="lunaticDatepickerField lunaticDatepickerFieldLarge"
205
+ >
206
+ <label
207
+ for="datepickeryear"
208
+ >
209
+ Année
210
+ <span
211
+ class="lunaticDatepickerHint"
212
+ >
213
+ Exemple: 2023
214
+ </span>
215
+ </label>
216
+ <input
217
+ id="datepickeryear"
218
+ min="1"
219
+ type="number"
220
+ value="1999"
221
+ />
222
+ </div>
223
+ </div>
32
224
  </div>
33
225
  </div>
34
226
  `;
@@ -1,52 +1,135 @@
1
1
  "use strict";
2
2
 
3
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
3
4
  Object.defineProperty(exports, "__esModule", {
4
5
  value: true
5
6
  });
6
7
  exports["default"] = void 0;
7
8
  var _react = require("react");
8
9
  var _commons = require("../../commons");
9
- var _datepickerInput = _interopRequireDefault(require("./datepicker-input"));
10
- var _datepickerContainer = _interopRequireDefault(require("./datepicker-container"));
10
+ var _DatepickerField = require("./DatepickerField");
11
11
  require("./datepicker.scss");
12
12
  var _jsxRuntime = require("react/jsx-runtime");
13
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
13
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
14
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
15
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
16
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
17
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
18
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
19
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
20
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
21
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
22
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
23
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
24
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
25
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
26
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
27
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
14
28
  function Datepicker(_ref) {
15
29
  var disabled = _ref.disabled,
16
30
  readOnly = _ref.readOnly,
17
31
  _ref$value = _ref.value,
18
32
  value = _ref$value === void 0 ? '' : _ref$value,
33
+ _ref$format = _ref.format,
34
+ format = _ref$format === void 0 ? 'YYYY-MM-DD' : _ref$format,
19
35
  onChange = _ref.onChange,
20
36
  id = _ref.id,
21
- min = _ref.min,
22
- max = _ref.max,
23
37
  label = _ref.label,
24
38
  errors = _ref.errors,
25
39
  description = _ref.description;
26
40
  var labelId = "lunatic-datepicker-".concat(id);
27
- var handleChange = (0, _react.useCallback)(function (e) {
28
- var value = e.target.value;
29
- onChange(value);
30
- }, [onChange]);
31
- return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_datepickerContainer["default"], {
41
+ var showDay = format.includes('DD');
42
+ var showMonth = format.includes('MM');
43
+
44
+ // Raw state, we allow invalid dates to be typed
45
+ var _useState = (0, _react.useState)(function () {
46
+ return numbersFromDateString(value);
47
+ }),
48
+ _useState2 = _slicedToArray(_useState, 2),
49
+ numbers = _useState2[0],
50
+ setNumbers = _useState2[1];
51
+ var setNumber = function setNumber(index) {
52
+ return function (value) {
53
+ var newNumbers = _toConsumableArray(numbers);
54
+ newNumbers[index] = value;
55
+ setNumbers(newNumbers);
56
+ handleChange(newNumbers);
57
+ };
58
+ };
59
+ var handleChange = function handleChange(numbers) {
60
+ var formatParts = format.split('-');
61
+ var hasNaNIndex = numbers.findIndex(function (v) {
62
+ return Number.isNaN(v);
63
+ });
64
+
65
+ // Date has a missing part
66
+ if (hasNaNIndex > -1 && hasNaNIndex <= formatParts.length - 1) {
67
+ onChange(null);
68
+ return;
69
+ }
70
+
71
+ // Date is not valid
72
+ if (format === 'YYYY-MM-DD' && !isDateValid(numbers)) {
73
+ onChange(null);
74
+ return;
75
+ }
76
+ var result = formatParts.map(function (v, k) {
77
+ return numbers[k].toString().padStart(v.length, '0');
78
+ }).join('-');
79
+ onChange(result);
80
+ };
81
+ var extraProps = {
82
+ readOnly: readOnly,
83
+ disabled: disabled
84
+ };
85
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
86
+ className: "lunatic-input",
32
87
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_commons.Label, {
33
88
  htmlFor: id,
34
89
  id: labelId,
35
90
  description: description,
36
91
  children: label
37
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_datepickerInput["default"], {
38
- id: id,
39
- labelId: labelId,
40
- readOnly: readOnly,
41
- disabled: disabled,
42
- value: value,
43
- onChange: handleChange,
44
- min: min,
45
- max: max
92
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
93
+ className: "lunaticDatepickerFields",
94
+ children: [showDay && /*#__PURE__*/(0, _jsxRuntime.jsx)(_DatepickerField.DatepickerField, _objectSpread({
95
+ id: id + 'day',
96
+ label: "Jour",
97
+ description: "Exemple: 14",
98
+ max: 31,
99
+ value: numbers[2],
100
+ onChange: setNumber(2)
101
+ }, extraProps)), showMonth && /*#__PURE__*/(0, _jsxRuntime.jsx)(_DatepickerField.DatepickerField, _objectSpread({
102
+ id: id + 'month',
103
+ label: "Mois",
104
+ description: "Exemple: 07",
105
+ max: 12,
106
+ value: numbers[1],
107
+ onChange: setNumber(1)
108
+ }, extraProps)), /*#__PURE__*/(0, _jsxRuntime.jsx)(_DatepickerField.DatepickerField, _objectSpread({
109
+ id: id + 'year',
110
+ label: "Ann\xE9e",
111
+ description: "Exemple: 2023",
112
+ value: numbers[0],
113
+ onChange: setNumber(0)
114
+ }, extraProps))]
46
115
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_commons.Errors, {
47
- errors: errors,
48
- activeId: id
116
+ errors: errors
49
117
  })]
50
118
  });
51
119
  }
120
+ function numbersFromDateString(s) {
121
+ if (!s) {
122
+ return [NaN, NaN, NaN];
123
+ }
124
+ var parts = s.split('-');
125
+ return [parseInt(parts[0], 10), parseInt(parts[1], 10), parseInt(parts[2], 10)];
126
+ }
127
+ function isDateValid(dateArray) {
128
+ var _dateArray = _slicedToArray(dateArray, 3),
129
+ year = _dateArray[0],
130
+ month = _dateArray[1],
131
+ day = _dateArray[2];
132
+ var date = new Date(year, month - 1, day);
133
+ return date.getFullYear() === year && date.getMonth() === month - 1 && date.getDate() === day;
134
+ }
52
135
  var _default = exports["default"] = (0, _commons.createCustomizableLunaticField)(Datepicker, 'Datepicker');
@@ -1 +1,19 @@
1
- // see input.scss
1
+ .lunaticDatepickerFields {
2
+ display: flex;
3
+ align-items: flex-end;
4
+ gap: 1rem;
5
+ }
6
+
7
+ .lunaticDatepickerField input {
8
+ width: 3.5em;
9
+ }
10
+
11
+ .lunaticDatepickerFieldLarge input {
12
+ width: 4.5em;
13
+ }
14
+
15
+ .lunaticDatepickerHint {
16
+ display: block;
17
+ font-weight: 400;
18
+ font-size: .9em;
19
+ }
@@ -10,29 +10,77 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "d
10
10
  (0, _vitest.beforeEach)(function () {
11
11
  mockOnChange.mockClear();
12
12
  });
13
- (0, _vitest.it)('renders without crashing', function () {
14
- var _render = (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_datepicker["default"], {
15
- value: '1999-01-01',
16
- id: "datepicker",
17
- "aria-labelledby": "datepicker",
18
- onChange: mockOnChange
19
- })),
20
- container = _render.container;
21
- (0, _vitest.expect)(container).toMatchSnapshot();
13
+ ['YYYY-MM-DD', 'YYYY-MM', 'YYYY'].forEach(function (format) {
14
+ (0, _vitest.it)('should render properly with format ' + format, function () {
15
+ var _render = (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_datepicker["default"], {
16
+ value: '1999-01-01',
17
+ id: "datepicker",
18
+ "aria-labelledby": "datepicker",
19
+ onChange: mockOnChange
20
+ })),
21
+ container = _render.container;
22
+ (0, _vitest.expect)(container).toMatchSnapshot();
23
+ });
22
24
  });
23
- (0, _vitest.it)('should handle readOnly', function () {
24
- var _render2 = (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_datepicker["default"], {
25
- id: "Datepicker",
26
- value: '1980-01-19',
27
- readOnly: true,
28
- onChange: mockOnChange
29
- })),
30
- container = _render2.container;
31
- (0, _vitest.expect)(container).toMatchSnapshot();
32
- var input = container.querySelector('input[type="date"]');
33
- (0, _vitest.expect)(input).toHaveAttribute('readonly');
34
- input.focus();
35
- (0, _vitest.expect)(input).toHaveFocus();
36
- (0, _vitest.expect)(input).toHaveValue('1980-01-19');
25
+ (0, _vitest.it)('handle change correctly for format YYYY-MM-DD', function () {
26
+ (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_datepicker["default"], {
27
+ value: '1999-01-01',
28
+ id: "datepicker",
29
+ "aria-labelledby": "datepicker",
30
+ onChange: mockOnChange
31
+ }));
32
+ _react.fireEvent.change(_react.screen.getByLabelText(/Année/), {
33
+ target: {
34
+ valueAsNumber: 2023
35
+ }
36
+ });
37
+ (0, _vitest.expect)(mockOnChange).toHaveBeenLastCalledWith('2023-01-01');
38
+ _react.fireEvent.change(_react.screen.getByLabelText(/Mois/), {
39
+ target: {
40
+ valueAsNumber: 2
41
+ }
42
+ });
43
+ _react.fireEvent.change(_react.screen.getByLabelText(/Jour/), {
44
+ target: {
45
+ valueAsNumber: 30
46
+ }
47
+ });
48
+ (0, _vitest.expect)(mockOnChange).toHaveBeenLastCalledWith(null);
49
+ });
50
+ (0, _vitest.it)('handle change correctly for format YYYY-MM', function () {
51
+ (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_datepicker["default"], {
52
+ format: "YYYY-MM",
53
+ value: "1999-01",
54
+ id: "datepicker",
55
+ "aria-labelledby": "datepicker",
56
+ onChange: mockOnChange
57
+ }));
58
+ _react.fireEvent.change(_react.screen.getByLabelText(/Année/), {
59
+ target: {
60
+ valueAsNumber: 2023
61
+ }
62
+ });
63
+ (0, _vitest.expect)(mockOnChange).toHaveBeenLastCalledWith('2023-01');
64
+ _react.fireEvent.change(_react.screen.getByLabelText(/Mois/), {
65
+ target: {
66
+ valueAsNumber: 10
67
+ }
68
+ });
69
+ (0, _vitest.expect)(mockOnChange).toHaveBeenLastCalledWith('2023-10');
70
+ });
71
+ (0, _vitest.it)('handle change correctly for year YYYY', function () {
72
+ (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_datepicker["default"], {
73
+ format: "YYYY",
74
+ value: "1999",
75
+ id: "datepicker",
76
+ "aria-labelledby": "datepicker",
77
+ onChange: mockOnChange
78
+ }));
79
+ _react.fireEvent.change(_react.screen.getByLabelText(/Année/), {
80
+ target: {
81
+ valueAsNumber: 2023
82
+ }
83
+ });
84
+ (0, _vitest.expect)(mockOnChange).toHaveBeenLastCalledWith('2023');
37
85
  });
38
86
  });
@@ -8,6 +8,7 @@ var _datepicker = _interopRequireDefault(require("./html/datepicker"));
8
8
  var _commons = require("../commons");
9
9
  var _lunaticComponentWithoutLabel = _interopRequireDefault(require("../commons/components/lunatic-component-without-label"));
10
10
  var _useOnHandleChange = _interopRequireDefault(require("../commons/use-on-handle-change"));
11
+ var _errors = require("../commons/components/errors/errors");
11
12
  var _jsxRuntime = require("react/jsx-runtime");
12
13
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
13
14
  var LunaticDatepicker = function LunaticDatepicker(props) {
@@ -26,7 +27,8 @@ var LunaticDatepicker = function LunaticDatepicker(props) {
26
27
  declarations = props.declarations,
27
28
  missing = props.missing,
28
29
  missingResponse = props.missingResponse,
29
- management = props.management;
30
+ management = props.management,
31
+ format = props.format;
30
32
  var onChange = (0, _useOnHandleChange["default"])({
31
33
  handleChange: handleChange,
32
34
  response: response,
@@ -43,6 +45,7 @@ var LunaticDatepicker = function LunaticDatepicker(props) {
43
45
  description: description,
44
46
  handleChange: handleChange,
45
47
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_datepicker["default"], {
48
+ format: format,
46
49
  disabled: disabled,
47
50
  readOnly: readOnly,
48
51
  value: value !== null && value !== void 0 ? value : '',
@@ -52,7 +55,7 @@ var LunaticDatepicker = function LunaticDatepicker(props) {
52
55
  max: max,
53
56
  label: label,
54
57
  description: description,
55
- errors: errors
58
+ errors: (0, _errors.getComponentErrors)(errors, id)
56
59
  })
57
60
  });
58
61
  };
@@ -8,6 +8,7 @@ var _lunaticComponentWithoutLabel = _interopRequireDefault(require("../commons/c
8
8
  var _useOnHandleChange = _interopRequireDefault(require("../commons/use-on-handle-change"));
9
9
  var _dropdown = _interopRequireDefault(require("./html/dropdown"));
10
10
  var _classnames = _interopRequireDefault(require("classnames"));
11
+ var _errors = require("../commons/components/errors/errors");
11
12
  var _jsxRuntime = require("react/jsx-runtime");
12
13
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
13
14
  function LunaticDropdown(_ref) {
@@ -51,7 +52,7 @@ function LunaticDropdown(_ref) {
51
52
  onSelect: onChange,
52
53
  value: value,
53
54
  className: (0, _classnames["default"])(className, 'lunatic-dropdown'),
54
- errors: errors,
55
+ errors: (0, _errors.getComponentErrors)(errors, id),
55
56
  label: label,
56
57
  readOnly: readOnly
57
58
  })
@@ -38,13 +38,12 @@ function Duration(props) {
38
38
  management: management,
39
39
  description: description,
40
40
  handleChange: handleChange,
41
- children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
42
- className: "container",
43
- children: [label, /*#__PURE__*/(0, _jsxRuntime.jsx)(_durationInput["default"], {
44
- value: value,
45
- format: format,
46
- onChange: onChange
47
- })]
41
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_durationInput["default"], {
42
+ id: id,
43
+ label: label,
44
+ value: value,
45
+ format: format,
46
+ onChange: onChange
48
47
  })
49
48
  });
50
49
  }
@@ -1,17 +1,9 @@
1
- .input-field {
2
- width: 100px;
3
- margin-right: 10px
4
- }
5
- .field-group {
1
+ .duration-fields,
2
+ .duration-field {
6
3
  display: flex;
4
+ align-items: center;
5
+ gap: 1rem;
7
6
  }
8
-
9
- .input-field-group {
10
- display: flex;
11
- align-items: first baseline;
12
- margin: 5px;
7
+ .duration-field {
8
+ gap: .5rem;
13
9
  }
14
-
15
- .input-label {
16
- margin-right: 5px;
17
- }