@qite/tide-booking-component 1.4.93 → 1.4.95

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 (181) hide show
  1. package/.prettierrc +9 -9
  2. package/.vs/ProjectSettings.json +3 -3
  3. package/.vs/VSWorkspaceState.json +5 -5
  4. package/build/build-cjs/index.js +81 -27
  5. package/build/build-cjs/src/booking-wizard/features/booking/booking-slice.d.ts +2 -1
  6. package/build/build-cjs/src/booking-wizard/features/booking/selectors.d.ts +4 -3
  7. package/build/build-cjs/src/booking-wizard/features/price-details/price-details-slice.d.ts +1 -0
  8. package/build/build-cjs/src/booking-wizard/features/price-details/selectors.d.ts +1 -0
  9. package/build/build-cjs/src/booking-wizard/features/sidebar/sidebar.d.ts +1 -0
  10. package/build/build-cjs/src/booking-wizard/types.d.ts +1 -0
  11. package/build/build-cjs/src/shared/utils/localization-util.d.ts +1 -0
  12. package/build/build-esm/index.js +81 -27
  13. package/build/build-esm/src/booking-wizard/features/booking/booking-slice.d.ts +2 -1
  14. package/build/build-esm/src/booking-wizard/features/booking/selectors.d.ts +4 -3
  15. package/build/build-esm/src/booking-wizard/features/price-details/price-details-slice.d.ts +1 -0
  16. package/build/build-esm/src/booking-wizard/features/price-details/selectors.d.ts +1 -0
  17. package/build/build-esm/src/booking-wizard/features/sidebar/sidebar.d.ts +1 -0
  18. package/build/build-esm/src/booking-wizard/types.d.ts +1 -0
  19. package/build/build-esm/src/shared/utils/localization-util.d.ts +1 -0
  20. package/package.json +83 -83
  21. package/src/booking-product/components/age-select.tsx +35 -35
  22. package/src/booking-product/components/amount-input.tsx +51 -51
  23. package/src/booking-product/components/date-range-picker/calendar.tsx +155 -155
  24. package/src/booking-product/components/footer.tsx +54 -54
  25. package/src/booking-product/components/header.tsx +57 -57
  26. package/src/booking-product/components/icon.tsx +200 -200
  27. package/src/booking-product/components/list-view.tsx +54 -54
  28. package/src/booking-product/components/rating.tsx +21 -21
  29. package/src/booking-product/components/rooms.tsx +171 -171
  30. package/src/booking-product/constants.ts +1 -1
  31. package/src/booking-product/index.tsx +21 -21
  32. package/src/booking-product/settings-context.ts +16 -16
  33. package/src/booking-product/types.ts +30 -30
  34. package/src/booking-product/utils/api.ts +26 -26
  35. package/src/booking-product/utils/price.ts +28 -28
  36. package/src/booking-wizard/api-settings-slice.ts +24 -24
  37. package/src/booking-wizard/components/icon.tsx +398 -398
  38. package/src/booking-wizard/components/labeled-input.tsx +56 -56
  39. package/src/booking-wizard/components/labeled-select.tsx +54 -54
  40. package/src/booking-wizard/components/message.tsx +21 -21
  41. package/src/booking-wizard/components/multi-range-filter.tsx +99 -99
  42. package/src/booking-wizard/components/phone-input.tsx +146 -146
  43. package/src/booking-wizard/components/print-offer-button.tsx +53 -53
  44. package/src/booking-wizard/components/product-card.tsx +23 -23
  45. package/src/booking-wizard/declarations.d.ts +4 -4
  46. package/src/booking-wizard/features/booking/booking-self-contained.tsx +16 -1
  47. package/src/booking-wizard/features/booking/booking-slice.ts +9 -1
  48. package/src/booking-wizard/features/booking/booking.tsx +16 -1
  49. package/src/booking-wizard/features/booking/selectors.ts +5 -0
  50. package/src/booking-wizard/features/flight-options/flight-filter.tsx +371 -371
  51. package/src/booking-wizard/features/flight-options/flight-option-flight.tsx +354 -354
  52. package/src/booking-wizard/features/flight-options/flight-option-modal.tsx +211 -211
  53. package/src/booking-wizard/features/flight-options/flight-option.tsx +57 -57
  54. package/src/booking-wizard/features/flight-options/flight-utils.ts +423 -423
  55. package/src/booking-wizard/features/price-details/price-details-api.ts +20 -20
  56. package/src/booking-wizard/features/price-details/price-details-slice.ts +2 -0
  57. package/src/booking-wizard/features/price-details/selectors.ts +1 -0
  58. package/src/booking-wizard/features/price-details/util.ts +115 -115
  59. package/src/booking-wizard/features/product-options/no-options.tsx +18 -18
  60. package/src/booking-wizard/features/product-options/none-option.tsx +73 -73
  61. package/src/booking-wizard/features/product-options/option-booking-airline-group.tsx +53 -53
  62. package/src/booking-wizard/features/product-options/option-booking-group.tsx +152 -152
  63. package/src/booking-wizard/features/product-options/option-item.tsx +236 -236
  64. package/src/booking-wizard/features/product-options/option-pax-card.tsx +159 -159
  65. package/src/booking-wizard/features/product-options/option-pax-group.tsx +122 -122
  66. package/src/booking-wizard/features/product-options/option-room.tsx +226 -226
  67. package/src/booking-wizard/features/product-options/option-unit-group.tsx +138 -138
  68. package/src/booking-wizard/features/room-options/room-utils.ts +154 -154
  69. package/src/booking-wizard/features/room-options/room.tsx +123 -123
  70. package/src/booking-wizard/features/room-options/traveler-rooms.tsx +64 -64
  71. package/src/booking-wizard/features/sidebar/index.tsx +2 -0
  72. package/src/booking-wizard/features/sidebar/sidebar-flight.tsx +66 -66
  73. package/src/booking-wizard/features/sidebar/sidebar.tsx +17 -1
  74. package/src/booking-wizard/features/summary/summary-booking-option-pax.tsx +23 -23
  75. package/src/booking-wizard/features/summary/summary-booking-option-unit.tsx +23 -23
  76. package/src/booking-wizard/features/summary/summary-flight.tsx +36 -36
  77. package/src/booking-wizard/features/summary/summary-per-booking-option-group.tsx +60 -60
  78. package/src/booking-wizard/features/summary/summary-per-pax-option-group.tsx +56 -56
  79. package/src/booking-wizard/features/summary/summary-per-unit-option-group.tsx +58 -58
  80. package/src/booking-wizard/features/summary/summary-slice.ts +27 -27
  81. package/src/booking-wizard/features/travelers-form/travelers-form-slice.ts +157 -157
  82. package/src/booking-wizard/features/travelers-form/travelers-form-util.ts +10 -10
  83. package/src/booking-wizard/features/travelers-form/type-ahead-input.tsx +85 -85
  84. package/src/booking-wizard/features/travelers-form/validate-form.ts +178 -178
  85. package/src/booking-wizard/index.tsx +27 -27
  86. package/src/booking-wizard/store.ts +26 -26
  87. package/src/booking-wizard/types.ts +1 -0
  88. package/src/booking-wizard/use-offer-printer.ts +108 -108
  89. package/src/content/components/LanguageSwitcher.tsx +158 -158
  90. package/src/content/components/accordion.tsx +30 -30
  91. package/src/content/components/contact.tsx +211 -211
  92. package/src/content/components/personal-contact-form.tsx +809 -809
  93. package/src/content/header/index.tsx +43 -43
  94. package/src/content/header/types.ts +26 -26
  95. package/src/qsm/components/date-picker/index.tsx +152 -152
  96. package/src/qsm/components/date-range-picker/calendar-day.tsx +49 -49
  97. package/src/qsm/components/date-range-picker/calendar.tsx +211 -211
  98. package/src/qsm/components/date-range-picker/index.tsx +404 -404
  99. package/src/qsm/index.tsx +26 -26
  100. package/src/qsm/store/qsm-store.ts +13 -13
  101. package/src/search-results/components/flight/flight-card.tsx +38 -38
  102. package/src/search-results/components/flight/flight-leg.tsx +61 -61
  103. package/src/search-results/components/flight/flight-path.tsx +23 -23
  104. package/src/search-results/components/multi-range-filter.tsx +104 -104
  105. package/src/search-results/components/search-results-container/search-results-container.tsx +2 -2
  106. package/src/search-results/index.tsx +24 -24
  107. package/src/search-results/search-results-configuration-context.ts +6 -6
  108. package/src/search-results/store/search-results-store.ts +13 -13
  109. package/src/shared/components/loader.tsx +16 -16
  110. package/src/shared/translations/ar-SA.json +2 -1
  111. package/src/shared/translations/da-DK.json +2 -1
  112. package/src/shared/translations/de-DE.json +2 -1
  113. package/src/shared/translations/en-GB.json +2 -1
  114. package/src/shared/translations/es-ES.json +2 -1
  115. package/src/shared/translations/fr-BE.json +2 -1
  116. package/src/shared/translations/fr-FR.json +2 -1
  117. package/src/shared/translations/is-IS.json +2 -1
  118. package/src/shared/translations/it-IT.json +2 -1
  119. package/src/shared/translations/ja-JP.json +2 -1
  120. package/src/shared/translations/nl-BE.json +2 -1
  121. package/src/shared/translations/nl-NL.json +2 -1
  122. package/src/shared/translations/no-NO.json +2 -1
  123. package/src/shared/translations/pl-PL.json +2 -1
  124. package/src/shared/translations/pt-PT.json +2 -1
  125. package/src/shared/translations/sv-SE.json +2 -1
  126. package/src/shared/utils/class-util.ts +7 -7
  127. package/src/shared/utils/query-string-util.ts +91 -91
  128. package/src/shared/utils/tide-api-utils.ts +34 -34
  129. package/src/shared/utils/use-media-query-util.ts +19 -19
  130. package/styles/abstracts/_mixins.scss +74 -74
  131. package/styles/abstracts/_variables.scss +57 -57
  132. package/styles/base/_fonts.scss +2 -2
  133. package/styles/base/_normalize.scss +227 -227
  134. package/styles/base/_typography.scss +35 -35
  135. package/styles/booking-joker-variables.scss +596 -596
  136. package/styles/booking-product-variables.scss +330 -330
  137. package/styles/booking-product.scss +438 -438
  138. package/styles/booking-qsm-variables.scss +501 -501
  139. package/styles/booking-qsm.scss +52 -52
  140. package/styles/booking-wizard-variables.scss +603 -603
  141. package/styles/booking-wizard.scss +61 -61
  142. package/styles/components/_accordion.scss +67 -67
  143. package/styles/components/_animations.scss +39 -39
  144. package/styles/components/_base.scss +107 -107
  145. package/styles/components/_breadcrumb.scss +92 -92
  146. package/styles/components/_button.scss +238 -238
  147. package/styles/components/_checkbox.scss +230 -230
  148. package/styles/components/_contact.scss +239 -239
  149. package/styles/components/_cta.scss +238 -238
  150. package/styles/components/_date-list.scss +41 -41
  151. package/styles/components/_date-range-picker.scss +223 -223
  152. package/styles/components/_decrement-increment.scss +35 -35
  153. package/styles/components/_dropdown.scss +72 -72
  154. package/styles/components/_faq.scss +27 -27
  155. package/styles/components/_flight-option.scss +1419 -1419
  156. package/styles/components/_gallery.scss +314 -314
  157. package/styles/components/_header.scss +113 -113
  158. package/styles/components/_img-slider.scss +175 -175
  159. package/styles/components/_info-message.scss +75 -75
  160. package/styles/components/_input.scss +35 -35
  161. package/styles/components/_list.scss +185 -185
  162. package/styles/components/_loader.scss +70 -70
  163. package/styles/components/_mixins.scss +579 -579
  164. package/styles/components/_passenger-picker.scss +306 -306
  165. package/styles/components/_phone-input.scss +8 -8
  166. package/styles/components/_placeholders.scss +165 -165
  167. package/styles/components/_qsm.scss +17 -17
  168. package/styles/components/_radiobutton.scss +170 -170
  169. package/styles/components/_select-wrapper.scss +76 -76
  170. package/styles/components/_slider.scss +128 -128
  171. package/styles/components/_spinner.scss +29 -29
  172. package/styles/components/_step-indicators.scss +161 -161
  173. package/styles/components/_table.scss +81 -81
  174. package/styles/components/_typeahead.scss +275 -275
  175. package/styles/components/_variables.scss +89 -89
  176. package/styles/content-blocks-variables.scss +507 -507
  177. package/styles/font.scss +2 -2
  178. package/styles/qsm/_calendar.scss +274 -274
  179. package/styles/qsm/_qsm.scss +1094 -1094
  180. package/styles/search.scss +1200 -1200
  181. package/tsconfig.json +24 -24
@@ -1,108 +1,108 @@
1
- import { useCallback, useContext, useState } from 'react';
2
- import SettingsContext from './settings-context';
3
- import { buildTideClientConfig } from '../shared/utils/tide-api-utils';
4
- import { book, print } from '@qite/tide-client';
5
-
6
- import type {
7
- BookingPackage,
8
- BookingPackageBookRequest,
9
- BookingPackageDossier,
10
- BookingPackageRequest,
11
- AgentPrintActionRequest,
12
- Pax,
13
- BookingPackagePax
14
- } from '@qite/tide-client/build/types';
15
-
16
- export interface UseOfferPrinterArgs {
17
- bookingPackage?: BookingPackage;
18
- getPax: () => Pax[] | undefined;
19
- tagIds?: number[];
20
- printActionId?: number | null;
21
- onPrinted?: (pdfUrl: string) => void;
22
- }
23
-
24
- export function useOfferPrinter({ bookingPackage, getPax, tagIds = [], printActionId = null, onPrinted }: UseOfferPrinterArgs) {
25
- const settings = useContext(SettingsContext);
26
- if (!settings) throw new Error('useOfferPrinter must be used inside <BookingWizard>');
27
-
28
- const { language, officeId } = settings;
29
- const agentId = (settings as any).agentAdressId;
30
-
31
- if (typeof agentId !== 'number' || agentId <= 0) {
32
- throw new Error('Missing agentAdressId in wizard settings');
33
- }
34
-
35
- const [stage, setStage] = useState<'idle' | 'creating' | 'printing'>('idle');
36
- const loading = stage !== 'idle';
37
-
38
- const createOffer = useCallback(async (): Promise<BookingPackageDossier> => {
39
- const paxRaw = getPax();
40
- if (!bookingPackage || !paxRaw?.length) {
41
- throw new Error('Missing booking package or pax');
42
- }
43
-
44
- const pax = paxRaw as unknown as BookingPackagePax[];
45
-
46
- const request: BookingPackageRequest<BookingPackageBookRequest> = {
47
- officeId,
48
- agentId,
49
- payload: {
50
- package: bookingPackage,
51
- status: 0,
52
- pax,
53
- nonTravelPax: [],
54
- notifications: [],
55
- tagIds,
56
- customerRequests: []
57
- }
58
- };
59
-
60
- const cfg = buildTideClientConfig();
61
- return book(cfg, request, undefined, language);
62
- }, [agentId, bookingPackage, getPax, language, officeId, tagIds]);
63
-
64
- const languageData = [
65
- { code: 'nl-BE', tideId: 1 },
66
- { code: 'fr-BE', tideId: 2 },
67
- { code: 'en-GB', tideId: 3 }
68
- ];
69
-
70
- function getTideLanguageId(code: string) {
71
- return languageData.find((l) => l.code === code)?.tideId || 1;
72
- }
73
-
74
- const printOffer = useCallback(
75
- async (offer: BookingPackageDossier) => {
76
- const cfg = buildTideClientConfig();
77
-
78
- const req: AgentPrintActionRequest = {
79
- id: printActionId ?? 0,
80
- dossierNumber: (offer as any).dossierNumber ?? (offer as any).number,
81
- languageId: getTideLanguageId(language)
82
- };
83
-
84
- const res = await print(cfg, req);
85
- const buf = await res.arrayBuffer();
86
- const url = URL.createObjectURL(new Blob([buf], { type: 'application/pdf' }));
87
- onPrinted?.(url);
88
- window.open(url);
89
- },
90
- [language, onPrinted]
91
- );
92
-
93
- const handlePrint = useCallback(async () => {
94
- try {
95
- setStage('creating');
96
- const offer = await createOffer();
97
- setStage('printing');
98
- await printOffer(offer);
99
- } catch (err) {
100
- console.error('Offer print failed:', err);
101
- throw err;
102
- } finally {
103
- setStage('idle');
104
- }
105
- }, [createOffer, printOffer]);
106
-
107
- return { handlePrint, loading, stage };
108
- }
1
+ import { useCallback, useContext, useState } from 'react';
2
+ import SettingsContext from './settings-context';
3
+ import { buildTideClientConfig } from '../shared/utils/tide-api-utils';
4
+ import { book, print } from '@qite/tide-client';
5
+
6
+ import type {
7
+ BookingPackage,
8
+ BookingPackageBookRequest,
9
+ BookingPackageDossier,
10
+ BookingPackageRequest,
11
+ AgentPrintActionRequest,
12
+ Pax,
13
+ BookingPackagePax
14
+ } from '@qite/tide-client/build/types';
15
+
16
+ export interface UseOfferPrinterArgs {
17
+ bookingPackage?: BookingPackage;
18
+ getPax: () => Pax[] | undefined;
19
+ tagIds?: number[];
20
+ printActionId?: number | null;
21
+ onPrinted?: (pdfUrl: string) => void;
22
+ }
23
+
24
+ export function useOfferPrinter({ bookingPackage, getPax, tagIds = [], printActionId = null, onPrinted }: UseOfferPrinterArgs) {
25
+ const settings = useContext(SettingsContext);
26
+ if (!settings) throw new Error('useOfferPrinter must be used inside <BookingWizard>');
27
+
28
+ const { language, officeId } = settings;
29
+ const agentId = (settings as any).agentAdressId;
30
+
31
+ if (typeof agentId !== 'number' || agentId <= 0) {
32
+ throw new Error('Missing agentAdressId in wizard settings');
33
+ }
34
+
35
+ const [stage, setStage] = useState<'idle' | 'creating' | 'printing'>('idle');
36
+ const loading = stage !== 'idle';
37
+
38
+ const createOffer = useCallback(async (): Promise<BookingPackageDossier> => {
39
+ const paxRaw = getPax();
40
+ if (!bookingPackage || !paxRaw?.length) {
41
+ throw new Error('Missing booking package or pax');
42
+ }
43
+
44
+ const pax = paxRaw as unknown as BookingPackagePax[];
45
+
46
+ const request: BookingPackageRequest<BookingPackageBookRequest> = {
47
+ officeId,
48
+ agentId,
49
+ payload: {
50
+ package: bookingPackage,
51
+ status: 0,
52
+ pax,
53
+ nonTravelPax: [],
54
+ notifications: [],
55
+ tagIds,
56
+ customerRequests: []
57
+ }
58
+ };
59
+
60
+ const cfg = buildTideClientConfig();
61
+ return book(cfg, request, undefined, language);
62
+ }, [agentId, bookingPackage, getPax, language, officeId, tagIds]);
63
+
64
+ const languageData = [
65
+ { code: 'nl-BE', tideId: 1 },
66
+ { code: 'fr-BE', tideId: 2 },
67
+ { code: 'en-GB', tideId: 3 }
68
+ ];
69
+
70
+ function getTideLanguageId(code: string) {
71
+ return languageData.find((l) => l.code === code)?.tideId || 1;
72
+ }
73
+
74
+ const printOffer = useCallback(
75
+ async (offer: BookingPackageDossier) => {
76
+ const cfg = buildTideClientConfig();
77
+
78
+ const req: AgentPrintActionRequest = {
79
+ id: printActionId ?? 0,
80
+ dossierNumber: (offer as any).dossierNumber ?? (offer as any).number,
81
+ languageId: getTideLanguageId(language)
82
+ };
83
+
84
+ const res = await print(cfg, req);
85
+ const buf = await res.arrayBuffer();
86
+ const url = URL.createObjectURL(new Blob([buf], { type: 'application/pdf' }));
87
+ onPrinted?.(url);
88
+ window.open(url);
89
+ },
90
+ [language, onPrinted]
91
+ );
92
+
93
+ const handlePrint = useCallback(async () => {
94
+ try {
95
+ setStage('creating');
96
+ const offer = await createOffer();
97
+ setStage('printing');
98
+ await printOffer(offer);
99
+ } catch (err) {
100
+ console.error('Offer print failed:', err);
101
+ throw err;
102
+ } finally {
103
+ setStage('idle');
104
+ }
105
+ }, [createOffer, printOffer]);
106
+
107
+ return { handlePrint, loading, stage };
108
+ }
@@ -1,158 +1,158 @@
1
- import React, { useEffect, useRef, useState } from 'react';
2
-
3
- type Lang = { code: string; label: string };
4
-
5
- interface LanguageSwitcherProps {
6
- value?: string;
7
- languages?: Lang[];
8
- onChange?: (code: string) => void;
9
- }
10
-
11
- const DEFAULT_LANGUAGES: Lang[] = [
12
- { code: 'EN', label: 'English' },
13
- { code: 'NL', label: 'Nederlands' },
14
- { code: 'FR', label: 'Français' },
15
- { code: 'DE', label: 'Deutsch' }
16
- ];
17
-
18
- const LanguageSwitcher: React.FC<LanguageSwitcherProps> = ({ value = 'EN', languages = DEFAULT_LANGUAGES, onChange }) => {
19
- const [open, setOpen] = useState(false);
20
- const [current, setCurrent] = useState(value);
21
- const rootRef = useRef<HTMLDivElement | null>(null);
22
- const buttonRef = useRef<HTMLButtonElement | null>(null);
23
- const menuId = 'language-switcher-menu';
24
-
25
- // Keep in sync if parent controls value
26
- useEffect(() => setCurrent(value), [value]);
27
-
28
- // Close on outside click
29
- useEffect(() => {
30
- const onPointerDown = (e: PointerEvent) => {
31
- if (!open) return;
32
- const target = e.target as Node;
33
- if (rootRef.current && !rootRef.current.contains(target)) setOpen(false);
34
- };
35
- window.addEventListener('pointerdown', onPointerDown);
36
- return () => window.removeEventListener('pointerdown', onPointerDown);
37
- }, [open]);
38
-
39
- // Close on ESC
40
- useEffect(() => {
41
- const onKeyDown = (e: KeyboardEvent) => {
42
- if (!open) return;
43
- if (e.key === 'Escape') {
44
- setOpen(false);
45
- buttonRef.current?.focus();
46
- }
47
- };
48
- window.addEventListener('keydown', onKeyDown);
49
- return () => window.removeEventListener('keydown', onKeyDown);
50
- }, [open]);
51
-
52
- const selectLang = (code: string) => {
53
- setCurrent(code);
54
- onChange?.(code);
55
- setOpen(false);
56
- buttonRef.current?.focus();
57
- };
58
-
59
- const onButtonKeyDown: React.KeyboardEventHandler<HTMLButtonElement> = (e) => {
60
- if (e.key === 'Enter' || e.key === ' ') {
61
- e.preventDefault();
62
- setOpen((v) => !v);
63
- }
64
- if (e.key === 'ArrowDown') {
65
- e.preventDefault();
66
- setOpen(true);
67
- // focus first option next tick
68
- requestAnimationFrame(() => {
69
- rootRef.current?.querySelector<HTMLButtonElement>('[role="menuitemradio"]')?.focus();
70
- });
71
- }
72
- };
73
-
74
- const onMenuKeyDown: React.KeyboardEventHandler<HTMLDivElement> = (e) => {
75
- const items = Array.from(rootRef.current?.querySelectorAll<HTMLButtonElement>('[role="menuitemradio"]') ?? []);
76
- if (!items.length) return;
77
-
78
- const idx = items.indexOf(document.activeElement as HTMLButtonElement);
79
-
80
- if (e.key === 'ArrowDown') {
81
- e.preventDefault();
82
- items[(idx + 1 + items.length) % items.length].focus();
83
- } else if (e.key === 'ArrowUp') {
84
- e.preventDefault();
85
- items[(idx - 1 + items.length) % items.length].focus();
86
- } else if (e.key === 'Home') {
87
- e.preventDefault();
88
- items[0].focus();
89
- } else if (e.key === 'End') {
90
- e.preventDefault();
91
- items[items.length - 1].focus();
92
- }
93
- };
94
-
95
- return (
96
- <div className="nav__subnav__languages" ref={rootRef}>
97
- {/* <svg
98
- className="nav__subnav__languages__icon"
99
- xmlns="http://www.w3.org/2000/svg"
100
- width="16"
101
- height="16"
102
- fill="currentColor"
103
- viewBox="0 0 16 16"
104
- aria-hidden="true"
105
- >
106
- <path d="M0 8a8 8 0 1 1 16 0A8 8 0 0 1 0 8zm8-7a7 7 0 0 0-6.468 4.146h12.936A7 7 0 0 0 8 1zm-6.218 5.5a13.334 13.334 0 0 1 .664-1.75H13.55c.24.56.42 1.17.528 1.75H1.782zm-.57 1.5h13.576a13.334 13.334 0 0 1-.664 1.75H2.208a13.334 13.334 0 0 1-.664-1.75zm.57 3.5c.796 2.07 2.39 3.5 4.22 3.5s3.424-1.43 4.22-3.5H1.782zM8 15a7 7 0 0 0 6.468-4.146H1.532A7 7 0 0 0 8 15z" />
107
- </svg> */}
108
-
109
- <button
110
- ref={buttonRef}
111
- type="button"
112
- className="nav__subnav__languages__button"
113
- aria-haspopup="menu"
114
- aria-expanded={open}
115
- aria-controls={menuId}
116
- onClick={() => setOpen((v) => !v)}
117
- onKeyDown={onButtonKeyDown}>
118
- <span className="nav__subnav__languages__value">{current}</span>
119
- <svg
120
- className="nav__subnav__languages__chevron"
121
- xmlns="http://www.w3.org/2000/svg"
122
- width="14"
123
- height="14"
124
- viewBox="0 0 24 24"
125
- fill="none"
126
- stroke="currentColor"
127
- strokeWidth="2"
128
- strokeLinecap="round"
129
- strokeLinejoin="round"
130
- aria-hidden="true">
131
- <path d="m6 9 6 6 6-6" />
132
- </svg>
133
- </button>
134
-
135
- <div
136
- id={menuId}
137
- className={`nav__subnav__languages__dropdown ${open ? 'is-open' : ''}`}
138
- role="menu"
139
- aria-label="Select language"
140
- onKeyDown={onMenuKeyDown}>
141
- {languages.map((l) => (
142
- <button
143
- key={l.code}
144
- type="button"
145
- className={`nav__subnav__languages__option ${l.code === current ? 'is-active' : ''}`}
146
- role="menuitemradio"
147
- aria-checked={l.code === current}
148
- onClick={() => selectLang(l.code)}>
149
- <span className="nav__subnav__languages__option__code">{l.code}</span>
150
- <span className="nav__subnav__languages__option__label">{l.label}</span>
151
- </button>
152
- ))}
153
- </div>
154
- </div>
155
- );
156
- };
157
-
158
- export default LanguageSwitcher;
1
+ import React, { useEffect, useRef, useState } from 'react';
2
+
3
+ type Lang = { code: string; label: string };
4
+
5
+ interface LanguageSwitcherProps {
6
+ value?: string;
7
+ languages?: Lang[];
8
+ onChange?: (code: string) => void;
9
+ }
10
+
11
+ const DEFAULT_LANGUAGES: Lang[] = [
12
+ { code: 'EN', label: 'English' },
13
+ { code: 'NL', label: 'Nederlands' },
14
+ { code: 'FR', label: 'Français' },
15
+ { code: 'DE', label: 'Deutsch' }
16
+ ];
17
+
18
+ const LanguageSwitcher: React.FC<LanguageSwitcherProps> = ({ value = 'EN', languages = DEFAULT_LANGUAGES, onChange }) => {
19
+ const [open, setOpen] = useState(false);
20
+ const [current, setCurrent] = useState(value);
21
+ const rootRef = useRef<HTMLDivElement | null>(null);
22
+ const buttonRef = useRef<HTMLButtonElement | null>(null);
23
+ const menuId = 'language-switcher-menu';
24
+
25
+ // Keep in sync if parent controls value
26
+ useEffect(() => setCurrent(value), [value]);
27
+
28
+ // Close on outside click
29
+ useEffect(() => {
30
+ const onPointerDown = (e: PointerEvent) => {
31
+ if (!open) return;
32
+ const target = e.target as Node;
33
+ if (rootRef.current && !rootRef.current.contains(target)) setOpen(false);
34
+ };
35
+ window.addEventListener('pointerdown', onPointerDown);
36
+ return () => window.removeEventListener('pointerdown', onPointerDown);
37
+ }, [open]);
38
+
39
+ // Close on ESC
40
+ useEffect(() => {
41
+ const onKeyDown = (e: KeyboardEvent) => {
42
+ if (!open) return;
43
+ if (e.key === 'Escape') {
44
+ setOpen(false);
45
+ buttonRef.current?.focus();
46
+ }
47
+ };
48
+ window.addEventListener('keydown', onKeyDown);
49
+ return () => window.removeEventListener('keydown', onKeyDown);
50
+ }, [open]);
51
+
52
+ const selectLang = (code: string) => {
53
+ setCurrent(code);
54
+ onChange?.(code);
55
+ setOpen(false);
56
+ buttonRef.current?.focus();
57
+ };
58
+
59
+ const onButtonKeyDown: React.KeyboardEventHandler<HTMLButtonElement> = (e) => {
60
+ if (e.key === 'Enter' || e.key === ' ') {
61
+ e.preventDefault();
62
+ setOpen((v) => !v);
63
+ }
64
+ if (e.key === 'ArrowDown') {
65
+ e.preventDefault();
66
+ setOpen(true);
67
+ // focus first option next tick
68
+ requestAnimationFrame(() => {
69
+ rootRef.current?.querySelector<HTMLButtonElement>('[role="menuitemradio"]')?.focus();
70
+ });
71
+ }
72
+ };
73
+
74
+ const onMenuKeyDown: React.KeyboardEventHandler<HTMLDivElement> = (e) => {
75
+ const items = Array.from(rootRef.current?.querySelectorAll<HTMLButtonElement>('[role="menuitemradio"]') ?? []);
76
+ if (!items.length) return;
77
+
78
+ const idx = items.indexOf(document.activeElement as HTMLButtonElement);
79
+
80
+ if (e.key === 'ArrowDown') {
81
+ e.preventDefault();
82
+ items[(idx + 1 + items.length) % items.length].focus();
83
+ } else if (e.key === 'ArrowUp') {
84
+ e.preventDefault();
85
+ items[(idx - 1 + items.length) % items.length].focus();
86
+ } else if (e.key === 'Home') {
87
+ e.preventDefault();
88
+ items[0].focus();
89
+ } else if (e.key === 'End') {
90
+ e.preventDefault();
91
+ items[items.length - 1].focus();
92
+ }
93
+ };
94
+
95
+ return (
96
+ <div className="nav__subnav__languages" ref={rootRef}>
97
+ {/* <svg
98
+ className="nav__subnav__languages__icon"
99
+ xmlns="http://www.w3.org/2000/svg"
100
+ width="16"
101
+ height="16"
102
+ fill="currentColor"
103
+ viewBox="0 0 16 16"
104
+ aria-hidden="true"
105
+ >
106
+ <path d="M0 8a8 8 0 1 1 16 0A8 8 0 0 1 0 8zm8-7a7 7 0 0 0-6.468 4.146h12.936A7 7 0 0 0 8 1zm-6.218 5.5a13.334 13.334 0 0 1 .664-1.75H13.55c.24.56.42 1.17.528 1.75H1.782zm-.57 1.5h13.576a13.334 13.334 0 0 1-.664 1.75H2.208a13.334 13.334 0 0 1-.664-1.75zm.57 3.5c.796 2.07 2.39 3.5 4.22 3.5s3.424-1.43 4.22-3.5H1.782zM8 15a7 7 0 0 0 6.468-4.146H1.532A7 7 0 0 0 8 15z" />
107
+ </svg> */}
108
+
109
+ <button
110
+ ref={buttonRef}
111
+ type="button"
112
+ className="nav__subnav__languages__button"
113
+ aria-haspopup="menu"
114
+ aria-expanded={open}
115
+ aria-controls={menuId}
116
+ onClick={() => setOpen((v) => !v)}
117
+ onKeyDown={onButtonKeyDown}>
118
+ <span className="nav__subnav__languages__value">{current}</span>
119
+ <svg
120
+ className="nav__subnav__languages__chevron"
121
+ xmlns="http://www.w3.org/2000/svg"
122
+ width="14"
123
+ height="14"
124
+ viewBox="0 0 24 24"
125
+ fill="none"
126
+ stroke="currentColor"
127
+ strokeWidth="2"
128
+ strokeLinecap="round"
129
+ strokeLinejoin="round"
130
+ aria-hidden="true">
131
+ <path d="m6 9 6 6 6-6" />
132
+ </svg>
133
+ </button>
134
+
135
+ <div
136
+ id={menuId}
137
+ className={`nav__subnav__languages__dropdown ${open ? 'is-open' : ''}`}
138
+ role="menu"
139
+ aria-label="Select language"
140
+ onKeyDown={onMenuKeyDown}>
141
+ {languages.map((l) => (
142
+ <button
143
+ key={l.code}
144
+ type="button"
145
+ className={`nav__subnav__languages__option ${l.code === current ? 'is-active' : ''}`}
146
+ role="menuitemradio"
147
+ aria-checked={l.code === current}
148
+ onClick={() => selectLang(l.code)}>
149
+ <span className="nav__subnav__languages__option__code">{l.code}</span>
150
+ <span className="nav__subnav__languages__option__label">{l.label}</span>
151
+ </button>
152
+ ))}
153
+ </div>
154
+ </div>
155
+ );
156
+ };
157
+
158
+ export default LanguageSwitcher;
@@ -1,30 +1,30 @@
1
- import React from 'react';
2
- import Icon from './icon';
3
-
4
- interface AccordionProps {
5
- summary: React.ReactNode;
6
- children: React.ReactNode;
7
- defaultOpen?: boolean;
8
- className?: string;
9
- }
10
-
11
- export default function Accordion({ summary, children, defaultOpen = false, className = '' }: AccordionProps) {
12
- const [open, setOpen] = React.useState(defaultOpen);
13
-
14
- return (
15
- <div className={['accordion', open && 'accordion--open', className].filter(Boolean).join(' ')}>
16
- <button className="accordion__trigger" type="button" aria-expanded={open} onClick={() => setOpen((v) => !v)}>
17
- <span>{summary}</span>
18
- <span className="accordion__icon" aria-hidden>
19
- <Icon name="ui-chevron" width={20} height={20} />
20
- </span>
21
- </button>
22
-
23
- <div className="accordion__panel">
24
- <div className="accordion__panelInner">
25
- <div className="accordion__content">{children}</div>
26
- </div>
27
- </div>
28
- </div>
29
- );
30
- }
1
+ import React from 'react';
2
+ import Icon from './icon';
3
+
4
+ interface AccordionProps {
5
+ summary: React.ReactNode;
6
+ children: React.ReactNode;
7
+ defaultOpen?: boolean;
8
+ className?: string;
9
+ }
10
+
11
+ export default function Accordion({ summary, children, defaultOpen = false, className = '' }: AccordionProps) {
12
+ const [open, setOpen] = React.useState(defaultOpen);
13
+
14
+ return (
15
+ <div className={['accordion', open && 'accordion--open', className].filter(Boolean).join(' ')}>
16
+ <button className="accordion__trigger" type="button" aria-expanded={open} onClick={() => setOpen((v) => !v)}>
17
+ <span>{summary}</span>
18
+ <span className="accordion__icon" aria-hidden>
19
+ <Icon name="ui-chevron" width={20} height={20} />
20
+ </span>
21
+ </button>
22
+
23
+ <div className="accordion__panel">
24
+ <div className="accordion__panelInner">
25
+ <div className="accordion__content">{children}</div>
26
+ </div>
27
+ </div>
28
+ </div>
29
+ );
30
+ }