@developer-overheid-nl/don-register-components 1.3.1 → 1.6.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.
- package/CHANGELOG.md +176 -130
- package/LICENSE.md +291 -291
- package/README.md +20 -20
- package/package.json +10 -8
- package/src/Introduction.mdx +52 -0
- package/src/alert/Alert.stories.tsx +57 -0
- package/src/alert/Alert.tsx +19 -19
- package/src/alert/styles.module.css +3 -3
- package/src/alignBox/AlignBox.stories.tsx +84 -0
- package/src/alignBox/AlignBox.tsx +114 -114
- package/src/alignBox/styles.module.css +110 -110
- package/src/amountLabel/AmountLabel.stories.tsx +28 -0
- package/src/amountLabel/AmountLabel.tsx +21 -16
- package/src/amountLabel/styles.module.css +11 -11
- package/src/analytics/PiwikPro.tsx +94 -94
- package/src/analytics/index.ts +1 -1
- package/src/article/Article.stories.tsx +53 -0
- package/src/article/Article.tsx +10 -10
- package/src/badgeList/BadgeList.tsx +34 -34
- package/src/badgeList/styles.module.css +37 -37
- package/src/block/Block.stories.tsx +58 -0
- package/src/block/Block.tsx +35 -35
- package/src/block/styles.module.css +29 -29
- package/src/button/Button.stories.tsx +56 -0
- package/src/button/Button.tsx +3 -3
- package/src/button/ButtonAction.stories.tsx +62 -0
- package/src/button/ButtonAction.tsx +51 -0
- package/src/cardAsLink/CardAsLink.stories.tsx +81 -0
- package/src/cardAsLink/CardAsLink.tsx +21 -21
- package/src/cardAsLink/styles.module.css +23 -23
- package/src/cardsList/CardsList.tsx +56 -56
- package/src/cardsList/styles.module.css +18 -19
- package/src/client.ts +7 -7
- package/src/container/Container.stories.tsx +21 -0
- package/src/container/Container.tsx +10 -10
- package/src/container/styles.module.css +28 -28
- package/src/copyButton/CopyButton.stories.tsx +41 -0
- package/src/copyButton/CopyButton.tsx +45 -39
- package/src/copyButton/styles.module.css +13 -13
- package/src/dataBadgeLink/DataBadgeLink.stories.tsx +137 -0
- package/src/dataBadgeLink/DataBadgeLink.tsx +59 -53
- package/src/dataBadgeLink/styles.module.css +89 -89
- package/src/dataSummary/DataSummary.tsx +22 -22
- package/src/dataSummary/DataSummaryItem.tsx +21 -21
- package/src/dataSummary/styles.module.css +75 -75
- package/src/facetFilters/FacetFilters.stories.tsx +93 -0
- package/src/facetFilters/FacetFilters.tsx +424 -419
- package/src/facetFilters/styles.module.css +3 -3
- package/src/fieldset/FieldSet.stories.tsx +45 -0
- package/src/fieldset/FieldSet.tsx +3 -3
- package/src/filters/Filters.stories.tsx +45 -0
- package/src/filters/Filters.tsx +116 -116
- package/src/filters/styles.module.css +26 -26
- package/src/footer/Footer.stories.tsx +127 -0
- package/src/footer/Footer.tsx +81 -76
- package/src/footer/styles.module.css +103 -103
- package/src/formFieldCheckboxGroup/FormFieldCheckboxGroup.stories.tsx +48 -0
- package/src/formFieldCheckboxGroup/FormFieldCheckboxGroup.tsx +16 -16
- package/src/formFieldCheckboxGroup/styles.module.css +5 -5
- package/src/formFieldCheckboxOption/FormFieldCheckboxOption.stories.tsx +61 -0
- package/src/formFieldCheckboxOption/FormFieldCheckboxOption.tsx +26 -26
- package/src/formFieldCheckboxOption/styles.module.css +22 -22
- package/src/formFieldLabel/FormFieldLabel.stories.tsx +21 -0
- package/src/formFieldLabel/FormFieldLabel.tsx +23 -23
- package/src/formFieldRadioGroup/FormFieldRadioGroup.stories.tsx +57 -0
- package/src/formFieldRadioGroup/FormFieldRadioGroup.tsx +13 -13
- package/src/formFieldRadioGroup/styles.module.css +5 -5
- package/src/formFieldRadioOption/FormFieldRadioOption.stories.tsx +48 -0
- package/src/formFieldRadioOption/FormFieldRadioOption.tsx +75 -75
- package/src/formFieldRadioOption/styles.module.css +49 -49
- package/src/formFieldSwitch/FormFieldSwitch.stories.tsx +61 -0
- package/src/formFieldSwitch/FormFieldSwitch.tsx +82 -79
- package/src/formFieldSwitch/styles.module.css +32 -32
- package/src/formFieldTextInput/FormFieldTextInput.stories.tsx +45 -0
- package/src/formFieldTextInput/FormFieldTextInput.tsx +3 -3
- package/src/grid/Grid.stories.tsx +37 -0
- package/src/grid/Grid.tsx +48 -0
- package/src/grid/styles.module.css +24 -0
- package/src/header/Header.stories.tsx +54 -0
- package/src/header/Header.tsx +137 -137
- package/src/header/styles.module.css +71 -71
- package/src/heading/Heading.stories.tsx +60 -0
- package/src/heading/Heading.tsx +15 -15
- package/src/headingGroup/HeadingGroup.stories.tsx +57 -0
- package/src/headingGroup/HeadingGroup.tsx +48 -48
- package/src/headingGroup/styles.module.css +3 -3
- package/src/i18n.ts +24 -25
- package/src/iconBadge/IconBadge.stories.tsx +46 -0
- package/src/iconBadge/IconBadge.tsx +35 -35
- package/src/iconBadge/getAppearance.ts +53 -53
- package/src/iconBadge/styles.module.css +19 -19
- package/src/iconsSprite/Icon.stories.tsx +73 -0
- package/src/iconsSprite/Icon.tsx +17 -17
- package/src/iconsSprite/IconsSprite.tsx +5 -5
- package/src/index.ts +117 -107
- package/src/infoButton/InfoButton.stories.tsx +52 -0
- package/src/infoButton/InfoButton.tsx +45 -45
- package/src/infoButton/styles.module.css +43 -43
- package/src/link/Link.stories.tsx +49 -0
- package/src/link/Link.tsx +10 -10
- package/src/markdown/Markdown.stories.tsx +48 -0
- package/src/markdown/Markdown.tsx +42 -42
- package/src/overlay/Overlay.stories.tsx +38 -0
- package/src/overlay/Overlay.tsx +18 -18
- package/src/overlay/styles.module.css +15 -15
- package/src/pagination/Pagination.stories.tsx +91 -0
- package/src/pagination/Pagination.tsx +267 -267
- package/src/pagination/styles.module.css +28 -28
- package/src/paragraph/Paragraph.stories.tsx +45 -0
- package/src/paragraph/Paragraph.tsx +24 -24
- package/src/paragraph/styles.module.css +6 -6
- package/src/pillBadge/PillBadge.examples.tsx +107 -107
- package/src/pillBadge/PillBadge.stories.tsx +257 -0
- package/src/pillBadge/PillBadge.tsx +60 -51
- package/src/pillBadge/styles.module.css +214 -214
- package/src/readOnlyTextInput/ReadOnlyTextInput.stories.tsx +49 -0
- package/src/readOnlyTextInput/ReadOnlyTextInput.tsx +24 -24
- package/src/readOnlyTextInput/styles.module.css +19 -19
- package/src/scoreBadge/ScoreBadge.stories.tsx +45 -0
- package/src/scoreBadge/ScoreBadge.tsx +135 -133
- package/src/search/Search.stories.tsx +65 -0
- package/src/search/Search.tsx +82 -82
- package/src/search/styles.module.css +40 -39
- package/src/siteLogo/ExampleLogo.stories.tsx +40 -0
- package/src/siteLogo/SiteLogo.stories.tsx +28 -0
- package/src/siteLogo/SiteLogo.tsx +24 -24
- package/src/sortForm/SortForm.stories.tsx +111 -0
- package/src/sortForm/SortForm.tsx +121 -0
- package/src/sortForm/styles.module.css +40 -0
- package/src/switch/Switch.stories.tsx +68 -0
- package/src/switch/Switch.tsx +152 -86
- package/src/switch/styles.module.css +54 -7
- package/src/toolTip/ToolTip.stories.tsx +131 -0
- package/src/toolTip/ToolTip.tsx +55 -55
- package/src/toolTip/styles.module.css +49 -49
- package/src/topNavigation/TopNavigation.stories.tsx +71 -0
- package/src/topNavigation/TopNavigation.tsx +67 -67
- package/src/topNavigation/styles.module.css +54 -54
- package/tsconfig.json +122 -121
|
@@ -1,419 +1,424 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
|
|
3
|
-
import clsx from "clsx";
|
|
4
|
-
import type { ChangeEvent } from "react";
|
|
5
|
-
import { type HTMLProps, type PropsWithChildren, useRef } from "react";
|
|
6
|
-
import { I18nextProvider, useTranslation } from "react-i18next";
|
|
7
|
-
import FormFieldCheckboxGroup from "../formFieldCheckboxGroup/FormFieldCheckboxGroup";
|
|
8
|
-
import FormFieldCheckboxOption from "../formFieldCheckboxOption/FormFieldCheckboxOption";
|
|
9
|
-
import FormFieldRadioGroup from "../formFieldRadioGroup/FormFieldRadioGroup";
|
|
10
|
-
import FormFieldRadioOption from "../formFieldRadioOption/FormFieldRadioOption";
|
|
11
|
-
import FormFieldSwitch from "../formFieldSwitch/FormFieldSwitch";
|
|
12
|
-
import Heading, {
|
|
13
|
-
clampHeadingLevel,
|
|
14
|
-
type HeadingProps,
|
|
15
|
-
} from "../heading/Heading";
|
|
16
|
-
import i18n from "../i18n";
|
|
17
|
-
import Paragraph from "../paragraph/Paragraph";
|
|
18
|
-
import ToolTip from "../toolTip/ToolTip";
|
|
19
|
-
import styles from "./styles.module.css";
|
|
20
|
-
|
|
21
|
-
enum FilterType {
|
|
22
|
-
Toggle = "toggle",
|
|
23
|
-
Date = "date",
|
|
24
|
-
Multi = "multi-select",
|
|
25
|
-
Single = "single-select",
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export interface SelectOption {
|
|
29
|
-
value: string;
|
|
30
|
-
label: string;
|
|
31
|
-
description?: string | null;
|
|
32
|
-
count: number;
|
|
33
|
-
selected: boolean;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
*
|
|
95
|
-
*/
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
)
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
);
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
filterKey
|
|
287
|
-
) => {
|
|
288
|
-
const
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
{
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
{option.
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
{option.
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import clsx from "clsx";
|
|
4
|
+
import type { ChangeEvent } from "react";
|
|
5
|
+
import { type HTMLProps, type PropsWithChildren, useRef } from "react";
|
|
6
|
+
import { I18nextProvider, useTranslation } from "react-i18next";
|
|
7
|
+
import FormFieldCheckboxGroup from "../formFieldCheckboxGroup/FormFieldCheckboxGroup";
|
|
8
|
+
import FormFieldCheckboxOption from "../formFieldCheckboxOption/FormFieldCheckboxOption";
|
|
9
|
+
import FormFieldRadioGroup from "../formFieldRadioGroup/FormFieldRadioGroup";
|
|
10
|
+
import FormFieldRadioOption from "../formFieldRadioOption/FormFieldRadioOption";
|
|
11
|
+
import FormFieldSwitch from "../formFieldSwitch/FormFieldSwitch";
|
|
12
|
+
import Heading, {
|
|
13
|
+
clampHeadingLevel,
|
|
14
|
+
type HeadingProps,
|
|
15
|
+
} from "../heading/Heading";
|
|
16
|
+
import i18n from "../i18n";
|
|
17
|
+
import Paragraph from "../paragraph/Paragraph";
|
|
18
|
+
import ToolTip from "../toolTip/ToolTip";
|
|
19
|
+
import styles from "./styles.module.css";
|
|
20
|
+
|
|
21
|
+
enum FilterType {
|
|
22
|
+
Toggle = "toggle",
|
|
23
|
+
Date = "date",
|
|
24
|
+
Multi = "multi-select",
|
|
25
|
+
Single = "single-select",
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface SelectOption {
|
|
29
|
+
value: string;
|
|
30
|
+
label: string;
|
|
31
|
+
description?: string | null;
|
|
32
|
+
count: number;
|
|
33
|
+
selected: boolean;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
type FilterLabel<T> = T extends string ? string : string | [string, string];
|
|
37
|
+
|
|
38
|
+
interface BaseFilterItems {
|
|
39
|
+
key: string;
|
|
40
|
+
label: FilterLabel<string>;
|
|
41
|
+
description: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
interface ToggleFilterData extends Omit<BaseFilterItems, "label"> {
|
|
45
|
+
type: FilterType.Toggle;
|
|
46
|
+
isExplicitFalse?: boolean;
|
|
47
|
+
label: FilterLabel<unknown>;
|
|
48
|
+
value?: boolean;
|
|
49
|
+
count?: number;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
interface DateFilterData extends BaseFilterItems {
|
|
53
|
+
type: FilterType.Date;
|
|
54
|
+
value?: string;
|
|
55
|
+
count?: number;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
interface MultiSelectFilterData extends BaseFilterItems {
|
|
59
|
+
type: FilterType.Multi;
|
|
60
|
+
options: SelectOption[];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
interface SingleSelectFilterData extends BaseFilterItems {
|
|
64
|
+
type: FilterType.Single;
|
|
65
|
+
options: SelectOption[];
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export type FilterData =
|
|
69
|
+
| ToggleFilterData
|
|
70
|
+
| DateFilterData
|
|
71
|
+
| MultiSelectFilterData
|
|
72
|
+
| SingleSelectFilterData;
|
|
73
|
+
|
|
74
|
+
type SelectedFilters = Record<string, Array<string | [string, string]>>;
|
|
75
|
+
|
|
76
|
+
type SelectedFiltersMap = Map<
|
|
77
|
+
string | [string, string],
|
|
78
|
+
Array<string | [string, string]>
|
|
79
|
+
>;
|
|
80
|
+
|
|
81
|
+
export interface FacetFiltersProps extends HTMLProps<HTMLDivElement> {
|
|
82
|
+
title?: string;
|
|
83
|
+
startHeadingLevel?: HeadingProps["level"];
|
|
84
|
+
filters: FilterData[] | null | undefined;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Keys of toggle-filters that return true when not set;
|
|
88
|
+
* FIXME: Should be returned by the API: `toggle` shoud have a `isExplicitFalse` key
|
|
89
|
+
*/
|
|
90
|
+
explicitFalseFilters?: string[];
|
|
91
|
+
/**
|
|
92
|
+
* Callback function called when filter option has changed.
|
|
93
|
+
* @param selectedFilters current selected filters at the moment of change
|
|
94
|
+
* @returns
|
|
95
|
+
*/
|
|
96
|
+
onFilterChange?: (selectedFilters: SelectedFilters) => void;
|
|
97
|
+
/**
|
|
98
|
+
* Types of filters for which the onFilterChange callback should be debounced. Default: ["date", "single-select"]
|
|
99
|
+
*/
|
|
100
|
+
debounceTypes?: Array<FilterType>;
|
|
101
|
+
/**
|
|
102
|
+
* Delay for debouncing the onFilterChange callback, in milliseconds. Default: 600
|
|
103
|
+
*/
|
|
104
|
+
debounceDelay?: number;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* @deprecated Use getSelectedFiltersMap, that will return a map with keys as a tuple with key and label
|
|
109
|
+
* @param filters
|
|
110
|
+
* @param withLabels Note: keys have no labels, use the map version
|
|
111
|
+
* @returns object
|
|
112
|
+
*/
|
|
113
|
+
export const getSelectedFilters = (
|
|
114
|
+
filters: FilterData[] | null | undefined,
|
|
115
|
+
withLabels = false,
|
|
116
|
+
): SelectedFilters => {
|
|
117
|
+
return (
|
|
118
|
+
filters?.reduce((acc, filter) => {
|
|
119
|
+
if (filter.type === FilterType.Multi) {
|
|
120
|
+
const keys: (string | [string, string])[] = filter.options
|
|
121
|
+
?.filter((option) => option.selected)
|
|
122
|
+
.map((option) =>
|
|
123
|
+
withLabels ? [option.value, option.label] : option.value,
|
|
124
|
+
);
|
|
125
|
+
if (keys?.length > 0) {
|
|
126
|
+
acc[filter.key] = keys;
|
|
127
|
+
}
|
|
128
|
+
} else if (filter.type === FilterType.Toggle && filter.value) {
|
|
129
|
+
acc[filter.key] = withLabels
|
|
130
|
+
? [
|
|
131
|
+
[
|
|
132
|
+
"true",
|
|
133
|
+
Array.isArray(filter.label) ? filter.label[0] : filter.label,
|
|
134
|
+
],
|
|
135
|
+
]
|
|
136
|
+
: ["true"];
|
|
137
|
+
} else if (filter.type === FilterType.Date && filter.value) {
|
|
138
|
+
acc[filter.key] = withLabels
|
|
139
|
+
? [[filter.value, filter.label]]
|
|
140
|
+
: [filter.value];
|
|
141
|
+
} else if (filter.type === FilterType.Single) {
|
|
142
|
+
const selectedOption = filter.options?.find(
|
|
143
|
+
(option) => option.selected,
|
|
144
|
+
);
|
|
145
|
+
if (selectedOption) {
|
|
146
|
+
acc[filter.key] = withLabels
|
|
147
|
+
? [[selectedOption.value, selectedOption.label]]
|
|
148
|
+
: [selectedOption.value];
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return acc;
|
|
152
|
+
}, {} as SelectedFilters) ?? {}
|
|
153
|
+
);
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
export const getSelectedFiltersMap = (
|
|
157
|
+
filters: FilterData[] | null | undefined,
|
|
158
|
+
withLabels = false,
|
|
159
|
+
): SelectedFiltersMap => {
|
|
160
|
+
return (
|
|
161
|
+
filters?.reduce((acc, filter) => {
|
|
162
|
+
if (filter.type === FilterType.Multi) {
|
|
163
|
+
const keys: (string | [string, string])[] = filter.options
|
|
164
|
+
?.filter((option) => option.selected)
|
|
165
|
+
.map((option) =>
|
|
166
|
+
withLabels ? [option.value, option.label] : option.value,
|
|
167
|
+
);
|
|
168
|
+
if (keys?.length > 0) {
|
|
169
|
+
withLabels
|
|
170
|
+
? acc.set([filter.key, filter.label], keys)
|
|
171
|
+
: acc.set(filter.key, keys);
|
|
172
|
+
}
|
|
173
|
+
} else if (filter.type === FilterType.Toggle) {
|
|
174
|
+
let value = filter.value && "true";
|
|
175
|
+
const keyLabel = Array.isArray(filter.label)
|
|
176
|
+
? filter.label[0]
|
|
177
|
+
: filter.label;
|
|
178
|
+
const valueLabel = Array.isArray(filter.label)
|
|
179
|
+
? filter.value
|
|
180
|
+
? filter.label[0]
|
|
181
|
+
: filter.label[1]
|
|
182
|
+
: filter.label;
|
|
183
|
+
|
|
184
|
+
if (filter.isExplicitFalse) {
|
|
185
|
+
value = filter.value ? "true" : "false";
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (value) {
|
|
189
|
+
withLabels
|
|
190
|
+
? acc.set([filter.key, keyLabel], [[value, valueLabel]])
|
|
191
|
+
: acc.set(filter.key, [value]);
|
|
192
|
+
}
|
|
193
|
+
} else if (filter.type === FilterType.Date && filter.value) {
|
|
194
|
+
withLabels
|
|
195
|
+
? acc.set([filter.key, filter.label], [[filter.value, filter.label]])
|
|
196
|
+
: acc.set(filter.key, [filter.value]);
|
|
197
|
+
} else if (filter.type === FilterType.Single) {
|
|
198
|
+
const selectedOption = filter.options?.find(
|
|
199
|
+
(option) => option.selected,
|
|
200
|
+
);
|
|
201
|
+
if (selectedOption) {
|
|
202
|
+
withLabels
|
|
203
|
+
? acc.set(
|
|
204
|
+
[filter.key, filter.label],
|
|
205
|
+
[[selectedOption.value, selectedOption.label]],
|
|
206
|
+
)
|
|
207
|
+
: acc.set(filter.key, [selectedOption.value]);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return acc;
|
|
211
|
+
}, new Map() as SelectedFiltersMap) ?? new Map()
|
|
212
|
+
);
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
const updateFilters = (
|
|
216
|
+
selectedFilters: SelectedFilters,
|
|
217
|
+
filterKey: string,
|
|
218
|
+
filterValue: string,
|
|
219
|
+
checked: boolean,
|
|
220
|
+
type: FilterType,
|
|
221
|
+
) => {
|
|
222
|
+
if (type === FilterType.Toggle) {
|
|
223
|
+
return {
|
|
224
|
+
...selectedFilters,
|
|
225
|
+
[filterKey]: [checked ? filterValue : "false"],
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
return {
|
|
230
|
+
...selectedFilters,
|
|
231
|
+
[filterKey]: checked
|
|
232
|
+
? [...(selectedFilters[filterKey] || []), filterValue]
|
|
233
|
+
: (selectedFilters[filterKey] || []).filter(
|
|
234
|
+
(value) => value !== filterValue,
|
|
235
|
+
),
|
|
236
|
+
};
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
const debounce = <T extends unknown[]>(
|
|
240
|
+
fn: (...args: T) => void,
|
|
241
|
+
delay: number,
|
|
242
|
+
) => {
|
|
243
|
+
let timeoutId: ReturnType<typeof setTimeout> | null = null;
|
|
244
|
+
return (...args: T) => {
|
|
245
|
+
if (timeoutId) {
|
|
246
|
+
clearTimeout(timeoutId);
|
|
247
|
+
}
|
|
248
|
+
timeoutId = setTimeout(() => {
|
|
249
|
+
fn(...args);
|
|
250
|
+
}, delay);
|
|
251
|
+
};
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
const FacetFilters = (props: PropsWithChildren<FacetFiltersProps>) => {
|
|
255
|
+
const { t } = useTranslation();
|
|
256
|
+
const thisRef = useRef<HTMLDivElement>(null);
|
|
257
|
+
const {
|
|
258
|
+
title,
|
|
259
|
+
startHeadingLevel = 2,
|
|
260
|
+
filters,
|
|
261
|
+
explicitFalseFilters,
|
|
262
|
+
onFilterChange = () => {},
|
|
263
|
+
debounceTypes = [FilterType.Date, FilterType.Single],
|
|
264
|
+
debounceDelay = 600,
|
|
265
|
+
...restProps
|
|
266
|
+
} = props;
|
|
267
|
+
|
|
268
|
+
const selectedFilters = getSelectedFilters(filters);
|
|
269
|
+
|
|
270
|
+
// Callback function (for React) and CustomEvent (for non-React) to notify about filter changes
|
|
271
|
+
const emitChange = (newSelectedFilters: SelectedFilters) => {
|
|
272
|
+
onFilterChange(newSelectedFilters);
|
|
273
|
+
const customEvent = new CustomEvent("onFilterChange", {
|
|
274
|
+
detail: newSelectedFilters,
|
|
275
|
+
});
|
|
276
|
+
if (thisRef.current) thisRef.current.dispatchEvent(customEvent);
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
const debouncedEmitChange = useRef(
|
|
280
|
+
debounce(emitChange, debounceDelay),
|
|
281
|
+
).current;
|
|
282
|
+
|
|
283
|
+
const handleChange = (
|
|
284
|
+
event: ChangeEvent<HTMLInputElement>,
|
|
285
|
+
type: FilterType,
|
|
286
|
+
filterKey = event.target.name,
|
|
287
|
+
) => {
|
|
288
|
+
const newSelectedFilters = updateFilters(
|
|
289
|
+
selectedFilters,
|
|
290
|
+
filterKey,
|
|
291
|
+
event.target.value,
|
|
292
|
+
event.target.checked,
|
|
293
|
+
type,
|
|
294
|
+
);
|
|
295
|
+
|
|
296
|
+
if (debounceTypes.includes(type)) {
|
|
297
|
+
debouncedEmitChange(newSelectedFilters);
|
|
298
|
+
} else {
|
|
299
|
+
emitChange(newSelectedFilters);
|
|
300
|
+
}
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
return (
|
|
304
|
+
<div
|
|
305
|
+
ref={thisRef}
|
|
306
|
+
className={clsx([styles.facetFilters, props.className])}
|
|
307
|
+
{...restProps}
|
|
308
|
+
>
|
|
309
|
+
{title ? (
|
|
310
|
+
<Heading level={startHeadingLevel} appearanceLevel={3}>
|
|
311
|
+
{title}
|
|
312
|
+
</Heading>
|
|
313
|
+
) : null}
|
|
314
|
+
{/* Temporary filter on `date` types */}
|
|
315
|
+
{filters
|
|
316
|
+
?.filter(({ type }) => type !== "date")
|
|
317
|
+
.map((facet) => (
|
|
318
|
+
<div className={styles.facet} key={facet.key}>
|
|
319
|
+
<Heading
|
|
320
|
+
level={
|
|
321
|
+
title
|
|
322
|
+
? clampHeadingLevel(startHeadingLevel + 1)
|
|
323
|
+
: startHeadingLevel
|
|
324
|
+
}
|
|
325
|
+
appearanceLevel={5}
|
|
326
|
+
>
|
|
327
|
+
{facet.label}
|
|
328
|
+
</Heading>
|
|
329
|
+
<Paragraph id={`${facet.key}-label`} purpose="short">
|
|
330
|
+
{facet.description}
|
|
331
|
+
</Paragraph>
|
|
332
|
+
{facet.type === "toggle" ? (
|
|
333
|
+
<FormFieldSwitch
|
|
334
|
+
label=""
|
|
335
|
+
labelledById={`${facet.key}-label`}
|
|
336
|
+
name={facet.key}
|
|
337
|
+
explicit={explicitFalseFilters?.includes(facet.key)}
|
|
338
|
+
defaultChecked={facet.value}
|
|
339
|
+
value={
|
|
340
|
+
explicitFalseFilters?.includes(facet.key)
|
|
341
|
+
? ["true", "false"]
|
|
342
|
+
: "true"
|
|
343
|
+
}
|
|
344
|
+
amount={facet.count || 0}
|
|
345
|
+
labels={{
|
|
346
|
+
on: t("components.filter-on"),
|
|
347
|
+
off: t("components.filter-off"),
|
|
348
|
+
}}
|
|
349
|
+
onChange={(event) => handleChange(event, facet.type)}
|
|
350
|
+
/>
|
|
351
|
+
) : null}
|
|
352
|
+
{/* TODO: Date selector
|
|
353
|
+
{facet.type === "date" ? <div>TODO</div> : null}
|
|
354
|
+
*/}
|
|
355
|
+
{facet.type === "multi-select" ? (
|
|
356
|
+
<FormFieldCheckboxGroup>
|
|
357
|
+
{facet.options?.map((option) => (
|
|
358
|
+
<FormFieldCheckboxOption
|
|
359
|
+
key={option.value}
|
|
360
|
+
label={option.label}
|
|
361
|
+
name={facet.key}
|
|
362
|
+
value={option.value}
|
|
363
|
+
defaultChecked={option.selected}
|
|
364
|
+
amount={option.count}
|
|
365
|
+
onChange={(event) => handleChange(event, facet.type)}
|
|
366
|
+
>
|
|
367
|
+
{option.description ? (
|
|
368
|
+
<ToolTip
|
|
369
|
+
text={option.description}
|
|
370
|
+
aria-label={t("components.info-about", {
|
|
371
|
+
subject: option.label,
|
|
372
|
+
})}
|
|
373
|
+
/>
|
|
374
|
+
) : null}
|
|
375
|
+
</FormFieldCheckboxOption>
|
|
376
|
+
))}
|
|
377
|
+
</FormFieldCheckboxGroup>
|
|
378
|
+
) : null}
|
|
379
|
+
{facet.type === "single-select" ? (
|
|
380
|
+
<FormFieldRadioGroup>
|
|
381
|
+
<FormFieldRadioOption
|
|
382
|
+
key="none"
|
|
383
|
+
label={t("components.filter-all")}
|
|
384
|
+
name={facet.key}
|
|
385
|
+
value=""
|
|
386
|
+
onChange={(event) => handleChange(event, facet.type)}
|
|
387
|
+
/>
|
|
388
|
+
{facet.options?.map((option) => (
|
|
389
|
+
<FormFieldRadioOption
|
|
390
|
+
key={option.value}
|
|
391
|
+
label={option.label}
|
|
392
|
+
name={facet.key}
|
|
393
|
+
value={option.value}
|
|
394
|
+
defaultChecked={option.selected}
|
|
395
|
+
amount={option.count}
|
|
396
|
+
onChange={(event) => handleChange(event, facet.type)}
|
|
397
|
+
>
|
|
398
|
+
{option.description ? (
|
|
399
|
+
<ToolTip
|
|
400
|
+
text={option.description}
|
|
401
|
+
aria-label={t("components.info-about", {
|
|
402
|
+
subject: option.label,
|
|
403
|
+
})}
|
|
404
|
+
/>
|
|
405
|
+
) : null}
|
|
406
|
+
</FormFieldRadioOption>
|
|
407
|
+
))}
|
|
408
|
+
</FormFieldRadioGroup>
|
|
409
|
+
) : null}
|
|
410
|
+
</div>
|
|
411
|
+
))}
|
|
412
|
+
</div>
|
|
413
|
+
);
|
|
414
|
+
};
|
|
415
|
+
|
|
416
|
+
const TranslatedFacetFilters = (props: FacetFiltersProps) => {
|
|
417
|
+
return (
|
|
418
|
+
<I18nextProvider i18n={i18n}>
|
|
419
|
+
<FacetFilters {...props} />
|
|
420
|
+
</I18nextProvider>
|
|
421
|
+
);
|
|
422
|
+
};
|
|
423
|
+
|
|
424
|
+
export default TranslatedFacetFilters;
|