@bytebrand/fe-ui-core-autobahn 1.0.190 → 1.0.191
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/cards/CarCard.tsx +12 -43
- package/cards/CarCardSkeleton.tsx +103 -0
- package/cards/CarRowSkeleton.tsx +152 -0
- package/cards/cardParts.tsx +1253 -1258
- package/cards/index.ts +6 -0
- package/chrome/AccountMenuIcon.tsx +109 -0
- package/chrome/Footer.tsx +16 -3
- package/chrome/TopBar.tsx +139 -266
- package/compat/CookieModal/CookieModal.tsx +20 -6
- package/compat/CookieModal/Modal.tsx +6 -3
- package/compat/CookieModal/modals/ManageCookieModal/ManageCookieModal.tsx +43 -15
- package/compat/CookieModal/modals/PreviewCookieModal/PreviewCookieModal.tsx +4 -3
- package/compat/CookieModal/useModal.ts +5 -1
- package/compat/Loader/Loader.tsx +1 -7
- package/compat/MdField/MdField.tsx +28 -4
- package/compat/TimePicker/TimePicker.tsx +12 -2
- package/constants/app.ts +1 -11
- package/constants/core.ts +1 -12
- package/data/toAutobahnCar.ts +16 -2
- package/iconsvg/IconSVG.tsx +1 -5
- package/locales/de/autobahn.json +880 -848
- package/locales/en/autobahn.json +880 -848
- package/package.json +2 -2
- package/theme/md3.css +5321 -1207
- package/ui/CreditCostNotice.tsx +43 -43
- package/ui/Dropdown.tsx +29 -10
- package/ui/FormCheckbox.tsx +22 -2
- package/ui/FormField.tsx +2 -1
- package/ui/Icon.tsx +6 -0
- package/ui/MfieldCheckIcon.tsx +13 -0
- package/ui/Modal.tsx +84 -6
- package/ui/Skeleton.tsx +79 -20
- package/ui/index.ts +93 -91
- package/ui/scrollFieldIntoView.ts +41 -0
- package/ui/usePortalMenuPosition.ts +27 -15
- package/utils/cookieConsent.ts +84 -0
- package/utils/index.ts +10 -0
- package/vdp/FinanceCalculator.tsx +1095 -1081
- package/vdp/VdpModules.tsx +4417 -4387
- package/vdp/types.ts +5 -5
- package/vehiclesProps/accidentDisclosure.ts +25 -0
- package/vehiclesProps/decoratedLightProps.tsx +4 -0
- package/vehiclesProps/decoratedProps.tsx +4 -0
package/ui/index.ts
CHANGED
|
@@ -1,91 +1,93 @@
|
|
|
1
|
-
// Autobahn (auto.de redesign) — presentational UI primitives.
|
|
2
|
-
//
|
|
3
|
-
// Typed, pure React 18 + TS port of the design kit's primitives from
|
|
4
|
-
// docs/redesign/design-source/ui_kits/website/ui.jsx. The original kit exported
|
|
5
|
-
// everything via `Object.assign(window, {...})`; here each primitive is a real
|
|
6
|
-
// ES module with an explicit props interface, re-exported below.
|
|
7
|
-
//
|
|
8
|
-
// SCOPING — IMPORTANT:
|
|
9
|
-
// These components rely on the scoped CSS layer at
|
|
10
|
-
// services/fe-main/source/theme/autobahn/ (md3.css)
|
|
11
|
-
// where EVERY utility class is scoped under `.md3` (e.g. `.md3 .mbtn`,
|
|
12
|
-
// `.md3 .chip`, `.md3 .statchip--good`, `.md3 .segmented .on`, `.md3 .mfield`,
|
|
13
|
-
// `.md3 .num`, `.md3 .car-arrow`, `.md3 .imglabel`, `.md3 .md-title`, …).
|
|
14
|
-
// They therefore ONLY render correctly inside a `<div className="md3">` subtree.
|
|
15
|
-
//
|
|
16
|
-
// All components are pure/presentational: no store, no API, no window access.
|
|
17
|
-
|
|
18
|
-
export { default as Icon } from './Icon';
|
|
19
|
-
export type { IconProps } from './Icon';
|
|
20
|
-
|
|
21
|
-
export { default as Button } from './Button';
|
|
22
|
-
export type { ButtonProps, ButtonVariant, ButtonSize } from './Button';
|
|
23
|
-
|
|
24
|
-
export { default as IconButton } from './IconButton';
|
|
25
|
-
export type { IconButtonProps } from './IconButton';
|
|
26
|
-
|
|
27
|
-
export { default as Chip } from './Chip';
|
|
28
|
-
export type { ChipProps } from './Chip';
|
|
29
|
-
|
|
30
|
-
export { default as StatChip } from './StatChip';
|
|
31
|
-
export type { StatChipProps, StatChipTone } from './StatChip';
|
|
32
|
-
|
|
33
|
-
export { default as CreditCostNotice, CREDIT_COST_WARNING_DE } from './CreditCostNotice';
|
|
34
|
-
export type { CreditCostNoticeProps, CreditCostNoticeTone, CreditCostNoticeSize } from './CreditCostNotice';
|
|
35
|
-
|
|
36
|
-
export { default as Segmented } from './Segmented';
|
|
37
|
-
export type { SegmentedProps, SegmentedOption } from './Segmented';
|
|
38
|
-
|
|
39
|
-
export { default as FormField } from './FormField';
|
|
40
|
-
export type { FormFieldProps } from './FormField';
|
|
41
|
-
|
|
42
|
-
export { default as Dropdown } from './Dropdown';
|
|
43
|
-
export type { DropdownProps, DropdownOption } from './Dropdown';
|
|
44
|
-
|
|
45
|
-
export {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
export {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
export {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
export {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
export {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
export {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
export { default as
|
|
67
|
-
export type {
|
|
68
|
-
export { default as
|
|
69
|
-
export type {
|
|
70
|
-
export { default as
|
|
71
|
-
export type {
|
|
72
|
-
export { default as
|
|
73
|
-
export type {
|
|
74
|
-
export { default as
|
|
75
|
-
export type {
|
|
76
|
-
export { default as
|
|
77
|
-
export type {
|
|
78
|
-
export { default as
|
|
79
|
-
export type {
|
|
80
|
-
export { default as
|
|
81
|
-
export type {
|
|
82
|
-
export { default as
|
|
83
|
-
export type {
|
|
84
|
-
export { default as
|
|
85
|
-
export type {
|
|
86
|
-
export { default as
|
|
87
|
-
export type {
|
|
88
|
-
export { default as
|
|
89
|
-
export type {
|
|
90
|
-
export { default as
|
|
91
|
-
export type {
|
|
1
|
+
// Autobahn (auto.de redesign) — presentational UI primitives.
|
|
2
|
+
//
|
|
3
|
+
// Typed, pure React 18 + TS port of the design kit's primitives from
|
|
4
|
+
// docs/redesign/design-source/ui_kits/website/ui.jsx. The original kit exported
|
|
5
|
+
// everything via `Object.assign(window, {...})`; here each primitive is a real
|
|
6
|
+
// ES module with an explicit props interface, re-exported below.
|
|
7
|
+
//
|
|
8
|
+
// SCOPING — IMPORTANT:
|
|
9
|
+
// These components rely on the scoped CSS layer at
|
|
10
|
+
// services/fe-main/source/theme/autobahn/ (md3.css)
|
|
11
|
+
// where EVERY utility class is scoped under `.md3` (e.g. `.md3 .mbtn`,
|
|
12
|
+
// `.md3 .chip`, `.md3 .statchip--good`, `.md3 .segmented .on`, `.md3 .mfield`,
|
|
13
|
+
// `.md3 .num`, `.md3 .car-arrow`, `.md3 .imglabel`, `.md3 .md-title`, …).
|
|
14
|
+
// They therefore ONLY render correctly inside a `<div className="md3">` subtree.
|
|
15
|
+
//
|
|
16
|
+
// All components are pure/presentational: no store, no API, no window access.
|
|
17
|
+
|
|
18
|
+
export { default as Icon } from './Icon';
|
|
19
|
+
export type { IconProps } from './Icon';
|
|
20
|
+
|
|
21
|
+
export { default as Button } from './Button';
|
|
22
|
+
export type { ButtonProps, ButtonVariant, ButtonSize } from './Button';
|
|
23
|
+
|
|
24
|
+
export { default as IconButton } from './IconButton';
|
|
25
|
+
export type { IconButtonProps } from './IconButton';
|
|
26
|
+
|
|
27
|
+
export { default as Chip } from './Chip';
|
|
28
|
+
export type { ChipProps } from './Chip';
|
|
29
|
+
|
|
30
|
+
export { default as StatChip } from './StatChip';
|
|
31
|
+
export type { StatChipProps, StatChipTone } from './StatChip';
|
|
32
|
+
|
|
33
|
+
export { default as CreditCostNotice, CREDIT_COST_WARNING_DE } from './CreditCostNotice';
|
|
34
|
+
export type { CreditCostNoticeProps, CreditCostNoticeTone, CreditCostNoticeSize } from './CreditCostNotice';
|
|
35
|
+
|
|
36
|
+
export { default as Segmented } from './Segmented';
|
|
37
|
+
export type { SegmentedProps, SegmentedOption } from './Segmented';
|
|
38
|
+
|
|
39
|
+
export { default as FormField } from './FormField';
|
|
40
|
+
export type { FormFieldProps } from './FormField';
|
|
41
|
+
|
|
42
|
+
export { default as Dropdown } from './Dropdown';
|
|
43
|
+
export type { DropdownProps, DropdownOption } from './Dropdown';
|
|
44
|
+
|
|
45
|
+
export { scrollFieldIntoView } from './scrollFieldIntoView';
|
|
46
|
+
|
|
47
|
+
export { default as Spec } from './Spec';
|
|
48
|
+
export type { SpecProps } from './Spec';
|
|
49
|
+
|
|
50
|
+
export { default as Price } from './Price';
|
|
51
|
+
export type { PriceProps } from './Price';
|
|
52
|
+
|
|
53
|
+
export { default as Stars } from './Stars';
|
|
54
|
+
export type { StarsProps } from './Stars';
|
|
55
|
+
|
|
56
|
+
export { default as PriceEvalBar } from './PriceEvalBar';
|
|
57
|
+
export type { PriceEvalBarProps } from './PriceEvalBar';
|
|
58
|
+
|
|
59
|
+
export { default as SaveChip } from './SaveChip';
|
|
60
|
+
export type { SaveChipProps } from './SaveChip';
|
|
61
|
+
|
|
62
|
+
export { default as CardCarousel } from './CardCarousel';
|
|
63
|
+
export type { CardCarouselProps } from './CardCarousel';
|
|
64
|
+
|
|
65
|
+
// ── md3 kit (Group-B in-place rebuild) — form-bound + layout + overlay primitives ──
|
|
66
|
+
export { default as FormDropdown } from './FormDropdown';
|
|
67
|
+
export type { FormDropdownProps } from './FormDropdown';
|
|
68
|
+
export { default as FormCheckbox } from './FormCheckbox';
|
|
69
|
+
export type { FormCheckboxProps } from './FormCheckbox';
|
|
70
|
+
export { default as FormRadioGroup } from './FormRadioGroup';
|
|
71
|
+
export type { FormRadioGroupProps } from './FormRadioGroup';
|
|
72
|
+
export { default as FormRadio } from './FormRadio';
|
|
73
|
+
export type { FormRadioProps } from './FormRadio';
|
|
74
|
+
export { default as Accordion } from './Accordion';
|
|
75
|
+
export type { AccordionProps } from './Accordion';
|
|
76
|
+
export { default as Modal } from './Modal';
|
|
77
|
+
export type { ModalProps, ModalSize } from './Modal';
|
|
78
|
+
export { default as DatePicker } from './DatePicker';
|
|
79
|
+
export type { DatePickerProps } from './DatePicker';
|
|
80
|
+
export { default as Table, Thead, Tbody, Tr, Th, Td } from './Table';
|
|
81
|
+
export type { TableProps, TheadProps, TbodyProps, TrProps, ThProps, TdProps, TableAlign } from './Table';
|
|
82
|
+
export { default as Switch } from './Switch';
|
|
83
|
+
export type { SwitchProps } from './Switch';
|
|
84
|
+
export { default as Textarea } from './Textarea';
|
|
85
|
+
export type { TextareaProps } from './Textarea';
|
|
86
|
+
export { default as Pagination } from './Pagination';
|
|
87
|
+
export type { PaginationProps } from './Pagination';
|
|
88
|
+
export { default as Stepper } from './Stepper';
|
|
89
|
+
export type { StepperProps, StepperStep, StepStatus } from './Stepper';
|
|
90
|
+
export { default as FileUpload } from './FileUpload';
|
|
91
|
+
export type { FileUploadProps } from './FileUpload';
|
|
92
|
+
export { default as Skeleton } from './Skeleton';
|
|
93
|
+
export type { SkeletonProps } from './Skeleton';
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// Autobahn (auto.de redesign) — shared "scroll a just-opened/just-focused field to the top of the
|
|
2
|
+
// page" behaviour, used by Dropdown.tsx and by fe-main's DualRange/RateSlider (FilterContent.tsx)
|
|
3
|
+
// text fields on /search/detailed. On mobile, opening a dropdown's menu or focusing a text field
|
|
4
|
+
// brings the on-screen keyboard up and/or needs room for a popover below the field — if the field
|
|
5
|
+
// is sitting mid-page, there may not be enough space left below it once the keyboard/menu takes
|
|
6
|
+
// its share. Scrolling the field to the very top of the page first maximizes what's available.
|
|
7
|
+
//
|
|
8
|
+
// Extracted out of Dropdown.tsx so it can be shared verbatim with fe-main's non-Dropdown form
|
|
9
|
+
// fields (DualRange/RateSlider's text inputs) — same problem, same fix, one place to keep them
|
|
10
|
+
// from drifting apart. See Dropdown.tsx's own call site for the original reasoning this was
|
|
11
|
+
// pulled from.
|
|
12
|
+
export function scrollFieldIntoView(field: HTMLElement): void {
|
|
13
|
+
if (typeof window === 'undefined') return;
|
|
14
|
+
// Mobile-only: the on-screen-keyboard/popover space problem this fixes doesn't exist on
|
|
15
|
+
// desktop, where there's no keyboard pushing the viewport around. Same breakpoint + matchMedia
|
|
16
|
+
// pattern as Modal.tsx/CardCarousel.tsx elsewhere in this lib.
|
|
17
|
+
if (window.matchMedia('(min-width: 601px)').matches) return;
|
|
18
|
+
// Anchor on whichever is higher up: the field itself, or a short field label/caption sitting
|
|
19
|
+
// directly above it (own previous sibling, or — the common "label above a row of controls"
|
|
20
|
+
// shape, e.g. "Marke & Modell" above the Make/Model row on /search/detailed — the wrapping
|
|
21
|
+
// row's previous sibling). Checked by height, not by class name, so this works for ANY
|
|
22
|
+
// caller's label without this needing to know that call site's specific markup.
|
|
23
|
+
const MAX_LABEL_HEIGHT = 30;
|
|
24
|
+
const asLabel = (el: Element | null): HTMLElement | null => {
|
|
25
|
+
if (!(el instanceof HTMLElement)) return null;
|
|
26
|
+
const h = el.getBoundingClientRect().height;
|
|
27
|
+
return h > 0 && h <= MAX_LABEL_HEIGHT ? el : null;
|
|
28
|
+
};
|
|
29
|
+
const anchor =
|
|
30
|
+
asLabel(field.previousElementSibling) ||
|
|
31
|
+
asLabel(field.parentElement && field.parentElement.previousElementSibling) ||
|
|
32
|
+
field;
|
|
33
|
+
// No sticky-header reservation here: every current caller (NewMainPage '/', FilterContent on
|
|
34
|
+
// '/search*') sits on a page where TopBar's own autoHideOnScroll is on (App.tsx: isHomePage ||
|
|
35
|
+
// isSearchPage) — the header slides itself out of the way the instant this scroll starts,
|
|
36
|
+
// independently of this call, so reserving space for it here would double-count.
|
|
37
|
+
const GAP = 8;
|
|
38
|
+
const rect = anchor.getBoundingClientRect();
|
|
39
|
+
const targetY = window.scrollY + rect.top - GAP;
|
|
40
|
+
window.scrollTo({ top: Math.max(0, targetY), behavior: 'smooth' });
|
|
41
|
+
}
|
|
@@ -45,6 +45,11 @@ export interface UsePortalMenuPositionArgs {
|
|
|
45
45
|
/** the trigger's wrapping element — always rendered (regardless of `open`), measured for position. */
|
|
46
46
|
rootRef: React.RefObject<HTMLElement>;
|
|
47
47
|
menuAlign?: 'left' | 'right';
|
|
48
|
+
/** 'auto' (default): flips ABOVE the trigger when there isn't room below (see ESTIMATED_MENU_HEIGHT
|
|
49
|
+
* below). 'down': always opens below, never flips — for a trigger where the caller knows the
|
|
50
|
+
* page has room below and an upward flip would overlap unrelated content above it (e.g. a
|
|
51
|
+
* trigger sitting right under a sticky/close heading). */
|
|
52
|
+
openDirection?: 'auto' | 'down';
|
|
48
53
|
/** called when the trigger scrolls out of view entirely, or a real user scroll happens after
|
|
49
54
|
* the post-open grace window — the menu has nothing sensible left to anchor to or chase. */
|
|
50
55
|
onCloseAway: () => void;
|
|
@@ -71,14 +76,32 @@ export interface UsePortalMenuPositionResult<TMenuEl extends HTMLElement = HTMLD
|
|
|
71
76
|
// reasonable estimate; it decides whether to flip ABOVE the trigger. The real size is then
|
|
72
77
|
// clamped to the space actually available (see `maxHeight` above), not just guessed at.
|
|
73
78
|
const ESTIMATED_MENU_HEIGHT = 300;
|
|
79
|
+
// .mselect-menu's own padding + border (6px*2 + 1px*2) — the consumers add it back on top of
|
|
80
|
+
// `maxHeight` for the box, so the space it fits into has to leave room for it.
|
|
81
|
+
const MENU_CHROME = 14;
|
|
74
82
|
// a scroll within this window of opening REPOSITIONS instead of closing — see the effect below.
|
|
75
83
|
const SELF_SCROLL_GRACE_MS = 500;
|
|
76
84
|
|
|
85
|
+
// Module-level (not hook-local) so Dropdown.tsx's own searchable-open scroll effect can reuse the
|
|
86
|
+
// exact same measurement — the sticky app header (.topbar, position:sticky/top:0) sits over the
|
|
87
|
+
// top of the viewport on every page that uses it (TopBar's autoHideOnScroll is opt-in, off by
|
|
88
|
+
// default — most pages keep it permanently docked), so anything that scrolls/positions content
|
|
89
|
+
// near the top of the viewport needs to stop at its live bottom edge, not y=0. Reading the
|
|
90
|
+
// header's live bottom edge (0 when absent, e.g. inside a modal, or when autoHideOnScroll has slid
|
|
91
|
+
// it away) gives a correct boundary without hardcoding a pixel height that could drift from the
|
|
92
|
+
// header's own CSS.
|
|
93
|
+
export const getSafeTop = (): number => {
|
|
94
|
+
if (typeof document === 'undefined') return 0;
|
|
95
|
+
const header = document.querySelector('.topbar');
|
|
96
|
+
return header ? Math.max(0, header.getBoundingClientRect().bottom) : 0;
|
|
97
|
+
};
|
|
98
|
+
|
|
77
99
|
export function usePortalMenuPosition<TMenuEl extends HTMLElement = HTMLDivElement>({
|
|
78
100
|
enabled,
|
|
79
101
|
open,
|
|
80
102
|
rootRef,
|
|
81
103
|
menuAlign = 'left',
|
|
104
|
+
openDirection = 'auto',
|
|
82
105
|
onCloseAway,
|
|
83
106
|
}: UsePortalMenuPositionArgs): UsePortalMenuPositionResult<TMenuEl> {
|
|
84
107
|
const menuElRef = React.useRef<TMenuEl | null>(null);
|
|
@@ -115,18 +138,6 @@ export function usePortalMenuPosition<TMenuEl extends HTMLElement = HTMLDivEleme
|
|
|
115
138
|
};
|
|
116
139
|
}, [enabled, open, portalRoot]);
|
|
117
140
|
|
|
118
|
-
// the portal menu's z-index (1400, .mselect-menu--portal) is intentionally higher than every
|
|
119
|
-
// other fixed overlay it must paint over (checkout sheets/modals) — which also means it would
|
|
120
|
-
// paint over the sticky app header (.topbar, position:sticky/top:0/z-index:50) if left
|
|
121
|
-
// unconstrained. Reading the header's live bottom edge (0 when absent, e.g. inside a modal, or
|
|
122
|
-
// when TopBar's autoHideOnScroll has slid it away) gives a correct top boundary without
|
|
123
|
-
// hardcoding a pixel height that could drift from the header's own CSS.
|
|
124
|
-
const getSafeTop = (): number => {
|
|
125
|
-
if (typeof document === 'undefined') return 0;
|
|
126
|
-
const header = document.querySelector('.topbar');
|
|
127
|
-
return header ? Math.max(0, header.getBoundingClientRect().bottom) : 0;
|
|
128
|
-
};
|
|
129
|
-
|
|
130
141
|
const [menuPos, setMenuPos] = React.useState<PortalMenuPos | null>(null);
|
|
131
142
|
|
|
132
143
|
const positionMenu = React.useCallback(() => {
|
|
@@ -144,13 +155,14 @@ export function usePortalMenuPosition<TMenuEl extends HTMLElement = HTMLDivEleme
|
|
|
144
155
|
}
|
|
145
156
|
const spaceBelow = window.innerHeight - rect.bottom - GAP;
|
|
146
157
|
const spaceAbove = rect.top - safeTop - GAP;
|
|
147
|
-
const openAbove = spaceBelow < ESTIMATED_MENU_HEIGHT && spaceAbove > spaceBelow;
|
|
158
|
+
const openAbove = openDirection === 'down' ? false : (spaceBelow < ESTIMATED_MENU_HEIGHT && spaceAbove > spaceBelow);
|
|
148
159
|
// cap the menu to the space it ACTUALLY has in whichever direction it opens, instead of
|
|
149
160
|
// trusting a static CSS max-height on its own — near the header or viewport edge that static
|
|
150
161
|
// cap can still be taller than what's really available, which is what let the menu paint over
|
|
151
162
|
// the header in the first place. The consumer's own overflow-y:auto takes it from there once
|
|
152
163
|
// content exceeds this.
|
|
153
|
-
|
|
164
|
+
// `available` is the LIST's height: the box (list + MENU_CHROME) must end inside the viewport.
|
|
165
|
+
const available = Math.max(120, Math.min(ESTIMATED_MENU_HEIGHT - 12, (openAbove ? spaceAbove : spaceBelow) - MENU_CHROME));
|
|
154
166
|
setMenuPos({
|
|
155
167
|
width: rect.width,
|
|
156
168
|
left: menuAlign === 'right' ? 'auto' : rect.left,
|
|
@@ -159,7 +171,7 @@ export function usePortalMenuPosition<TMenuEl extends HTMLElement = HTMLDivEleme
|
|
|
159
171
|
bottom: openAbove ? window.innerHeight - rect.top + GAP : 'auto',
|
|
160
172
|
maxHeight: available,
|
|
161
173
|
});
|
|
162
|
-
}, [enabled, menuAlign, onCloseAway, rootRef]);
|
|
174
|
+
}, [enabled, menuAlign, openDirection, onCloseAway, rootRef]);
|
|
163
175
|
|
|
164
176
|
// Synchronous (pre-paint) position computation. useLayoutEffect — not useEffect — matters here:
|
|
165
177
|
// it runs right after the DOM mutation that mounted the portal but BEFORE the browser paints, so
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// ADV-268 — the cookie consent store (`localStorage['cookieConfig']`: per category the DISABLED
|
|
2
|
+
// vendor-cookie names, see COOKIE_SCHEMA) plus what the account page needs on top of it:
|
|
3
|
+
// - when the choice last changed (`cookieConfigChangedAt`, ISO), written on every save that
|
|
4
|
+
// changes it — the consent dialogs save through saveCookieConfig;
|
|
5
|
+
// - a window event after each save, so a page showing the state can update live;
|
|
6
|
+
// - openCookieSettings(), which makes the mounted CookieModal show its settings dialog again.
|
|
7
|
+
// Storage access is guarded: with site storage blocked every read returns "no choice yet".
|
|
8
|
+
|
|
9
|
+
import { COOKIE_SCHEMA } from '../constants/common';
|
|
10
|
+
|
|
11
|
+
export const COOKIE_CONFIG_KEY = 'cookieConfig';
|
|
12
|
+
export const COOKIE_CONFIG_CHANGED_AT_KEY = 'cookieConfigChangedAt';
|
|
13
|
+
export const COOKIE_CONSENT_CHANGE_EVENT = 'autode:cookie-consent-change';
|
|
14
|
+
export const OPEN_COOKIE_SETTINGS_EVENT = 'autode:open-cookie-settings';
|
|
15
|
+
|
|
16
|
+
export interface ICookieConfig {
|
|
17
|
+
marketing: string[];
|
|
18
|
+
analytics: string[];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export type CookieCategoryState = 'on' | 'partial' | 'off';
|
|
22
|
+
|
|
23
|
+
export interface ICookieConsentState {
|
|
24
|
+
/** false until the visitor saved a choice in the cookie dialog */
|
|
25
|
+
decided: boolean;
|
|
26
|
+
/** ISO date of the last change, null when unknown (no choice yet, or saved before it was recorded) */
|
|
27
|
+
changedAt: string | null;
|
|
28
|
+
analytics: CookieCategoryState;
|
|
29
|
+
marketing: CookieCategoryState;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const vendorCookies = (category: 'analytics' | 'marketing'): string[] =>
|
|
33
|
+
Object.values(COOKIE_SCHEMA[category]).reduce((acc: string[], val: string[]) => acc.concat(val), []);
|
|
34
|
+
|
|
35
|
+
const readStorage = (key: string): string | null => {
|
|
36
|
+
try {
|
|
37
|
+
return localStorage.getItem(key);
|
|
38
|
+
} catch (e) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export const saveCookieConfig = (config: ICookieConfig | Record<string, string[]>) => {
|
|
44
|
+
const next = JSON.stringify(config);
|
|
45
|
+
try {
|
|
46
|
+
const previous = localStorage.getItem(COOKIE_CONFIG_KEY);
|
|
47
|
+
localStorage.setItem(COOKIE_CONFIG_KEY, next);
|
|
48
|
+
if (previous !== next || !localStorage.getItem(COOKIE_CONFIG_CHANGED_AT_KEY)) {
|
|
49
|
+
localStorage.setItem(COOKIE_CONFIG_CHANGED_AT_KEY, new Date().toISOString());
|
|
50
|
+
}
|
|
51
|
+
} catch (e) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
window.dispatchEvent(new Event(COOKIE_CONSENT_CHANGE_EVENT));
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export const getCookieConsentState = (): ICookieConsentState => {
|
|
58
|
+
let config: Partial<ICookieConfig> | null = null;
|
|
59
|
+
try {
|
|
60
|
+
config = JSON.parse(readStorage(COOKIE_CONFIG_KEY));
|
|
61
|
+
} catch (e) {
|
|
62
|
+
config = null;
|
|
63
|
+
}
|
|
64
|
+
if (!config) return { decided: false, changedAt: null, analytics: 'off', marketing: 'off' };
|
|
65
|
+
|
|
66
|
+
const categoryState = (category: 'analytics' | 'marketing'): CookieCategoryState => {
|
|
67
|
+
const disabled = Array.isArray(config[category]) ? config[category] : [];
|
|
68
|
+
const all = vendorCookies(category);
|
|
69
|
+
const allowed = all.filter((cookie) => !disabled.includes(cookie)).length;
|
|
70
|
+
if (allowed === all.length) return 'on';
|
|
71
|
+
return allowed ? 'partial' : 'off';
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
return {
|
|
75
|
+
decided: true,
|
|
76
|
+
changedAt: readStorage(COOKIE_CONFIG_CHANGED_AT_KEY),
|
|
77
|
+
analytics: categoryState('analytics'),
|
|
78
|
+
marketing: categoryState('marketing')
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export const openCookieSettings = () => {
|
|
83
|
+
window.dispatchEvent(new Event(OPEN_COOKIE_SETTINGS_EVENT));
|
|
84
|
+
};
|
package/utils/index.ts
CHANGED
|
@@ -62,6 +62,14 @@ export {
|
|
|
62
62
|
updateCookieList
|
|
63
63
|
} from './CommonUtils';
|
|
64
64
|
|
|
65
|
+
export {
|
|
66
|
+
COOKIE_CONSENT_CHANGE_EVENT,
|
|
67
|
+
getCookieConsentState,
|
|
68
|
+
openCookieSettings,
|
|
69
|
+
saveCookieConfig
|
|
70
|
+
} from './cookieConsent';
|
|
71
|
+
export type { CookieCategoryState, ICookieConsentState } from './cookieConsent';
|
|
72
|
+
|
|
65
73
|
export { getEquipment, getEquipmentCount } from '../vehiclesProps/equipment';
|
|
66
74
|
|
|
67
75
|
export type { IDecoratedProps, IEquipmentProps, ICarPropElement } from '../types/types';
|
|
@@ -83,3 +91,5 @@ export type { IValues, IFilters, IQuery } from './query';
|
|
|
83
91
|
// Decorated car props (renders React UI; lives in vehiclesProps/ with its
|
|
84
92
|
// IconContainer + Co2Widget dependencies under compat/).
|
|
85
93
|
export { default as getDecoratedProps } from '../vehiclesProps/decoratedProps';
|
|
94
|
+
export { setStrictConditionOwners, isStrictConditionOwner, strictAccidentStatus } from '../vehiclesProps/accidentDisclosure';
|
|
95
|
+
export type { AccidentStatus } from '../vehiclesProps/accidentDisclosure';
|