@bytebrand/fe-ui-core-autobahn 1.0.228 → 1.0.231
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/campaign/CampaignBand.tsx +26 -26
- package/campaign/CampaignBanner.tsx +86 -0
- package/campaign/CampaignBar.tsx +37 -0
- package/campaign/CampaignHero.tsx +56 -0
- package/campaign/CampaignSwitch.tsx +43 -0
- package/campaign/campaignVars.ts +12 -12
- package/campaign/campaigns.ts +77 -74
- package/campaign/index.ts +18 -6
- package/campaign/openInApp.ts +8 -0
- package/campaign/useCountdown.ts +28 -0
- package/cards/CarCard.tsx +407 -393
- package/cards/CarCardSkeleton.tsx +103 -0
- package/cards/CarRow.tsx +46 -22
- package/cards/CarRowSkeleton.tsx +152 -0
- package/cards/cardParts.tsx +53 -18
- package/cards/dealSignals.ts +36 -36
- 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/PriceRating/PriceRating.styl +5 -7
- package/compat/PriceRatingDetailed/PriceRatingDetailed.styl +8 -6
- package/compat/TimePicker/TimePicker.tsx +12 -2
- package/compat/legacy-theme/priceReviewColors.styl +18 -5
- package/constants/autobahn.ts +39 -0
- package/data/fieldMapping.ts +3 -3
- package/data/toAutobahnCar.ts +30 -14
- package/iconsvg/IconSVG.tsx +1 -5
- package/index.ts +19 -19
- package/locales/de/autobahn.json +925 -862
- package/locales/en/autobahn.json +925 -862
- package/package.json +2 -2
- package/theme/md3.css +16518 -11808
- 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/Stars.tsx +36 -18
- package/ui/StatChip.tsx +8 -3
- package/ui/index.ts +3 -0
- package/ui/ratingLink.ts +36 -0
- 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 +162 -34
- package/vdp/VdpModules.tsx +348 -976
- package/vdp/index.ts +6 -3
- package/vdp/types.ts +25 -15
- package/vehiclesProps/accidentDisclosure.ts +25 -0
- package/vehiclesProps/decoratedLightProps.tsx +4 -0
- package/vehiclesProps/decoratedProps.tsx +4 -0
|
@@ -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';
|
|
@@ -13,12 +13,13 @@
|
|
|
13
13
|
//
|
|
14
14
|
// Renders correctly only inside a `<div className="md3">` subtree.
|
|
15
15
|
|
|
16
|
-
import React, { useState } from 'react';
|
|
16
|
+
import React, { useState, useEffect, useLayoutEffect, useRef } from 'react';
|
|
17
17
|
import { TranslationFunction } from '../types';
|
|
18
18
|
|
|
19
19
|
import { Button, Icon, Switch, CreditCostNotice, CreditKeyFigures, hasCreditKeyFigures } from '../ui';
|
|
20
20
|
import type { CreditKeyFiguresData } from '../ui';
|
|
21
|
-
import {
|
|
21
|
+
import { ratingLinkProps } from '../ui/ratingLink';
|
|
22
|
+
import { TIER_KEYS, TIER_COLORS, TIER_TEXT_COLORS, TIER_BACKGROUNDS, NO_RATING_KEY, NO_RATING_COLOR, NO_RATING_BACKGROUND, evalTierOf } from '../constants';
|
|
22
23
|
|
|
23
24
|
/** Payment mode segment keys. Mirrors the design's ['fin','leasing','cash']. */
|
|
24
25
|
export type FinanceMode = 'fin' | 'leasing' | 'cash';
|
|
@@ -53,8 +54,18 @@ export const Slider: React.FunctionComponent<SliderProps> = ({
|
|
|
53
54
|
bubble,
|
|
54
55
|
bubblePaddingBottom = 34,
|
|
55
56
|
}) => {
|
|
57
|
+
// Local mirror of `value`, updated INSTANTLY on every native input event. Callers commonly
|
|
58
|
+
// debounce their own onChange (e.g. CheckoutFinancePanelNext's 50ms setCommonUserConfig,
|
|
59
|
+
// which also triggers a MobX-driven re-render of a much bigger subtree) — without this, the
|
|
60
|
+
// thumb still drags natively/smoothly (the browser owns that), but the gradient fill and any
|
|
61
|
+
// bubble label are driven by the `value` PROP, which only catches up once the debounced commit
|
|
62
|
+
// finally lands, so the fill visibly lags/stutters behind the thumb during a fast drag. Synced
|
|
63
|
+
// back to the prop via useEffect for externally-driven changes (e.g. a reset button).
|
|
64
|
+
const [localValue, setLocalValue] = useState(value);
|
|
65
|
+
useEffect(() => { setLocalValue(value); }, [value]);
|
|
66
|
+
|
|
56
67
|
const span = max - min;
|
|
57
|
-
const pct = span > 0 ? ((
|
|
68
|
+
const pct = span > 0 ? ((localValue - min) / span) * 100 : 0;
|
|
58
69
|
return (
|
|
59
70
|
<div>
|
|
60
71
|
<div style={{ position: 'relative', paddingTop: bubble ? 44 : 0, paddingBottom: bubble ? bubblePaddingBottom : 0 }}>
|
|
@@ -62,7 +73,7 @@ export const Slider: React.FunctionComponent<SliderProps> = ({
|
|
|
62
73
|
// thumb is 22px wide: interpolate the bubble anchor between half-thumb insets so it
|
|
63
74
|
// tracks the thumb center (a plain pct% drifts at the rail ends)
|
|
64
75
|
<span className="slider-bubble num" style={{ left: `calc(11px + (100% - 22px) * ${pct / 100})` }}>
|
|
65
|
-
{fmt(
|
|
76
|
+
{fmt(localValue)}
|
|
66
77
|
</span>
|
|
67
78
|
)}
|
|
68
79
|
<input
|
|
@@ -71,8 +82,12 @@ export const Slider: React.FunctionComponent<SliderProps> = ({
|
|
|
71
82
|
min={min}
|
|
72
83
|
max={max}
|
|
73
84
|
step={step}
|
|
74
|
-
value={
|
|
75
|
-
onChange={(e) =>
|
|
85
|
+
value={localValue}
|
|
86
|
+
onChange={(e) => {
|
|
87
|
+
const v = Number(e.target.value);
|
|
88
|
+
setLocalValue(v);
|
|
89
|
+
onChange(v);
|
|
90
|
+
}}
|
|
76
91
|
style={{ background: `linear-gradient(90deg, var(--md-primary) ${pct}%, var(--md-sc-highest) ${pct}%)` }}
|
|
77
92
|
/>
|
|
78
93
|
</div>
|
|
@@ -89,20 +104,119 @@ export const Slider: React.FunctionComponent<SliderProps> = ({
|
|
|
89
104
|
/**
|
|
90
105
|
* Segmented price-evaluation bar (Figma: 5 discrete tier segments, NOT a gradient) with a
|
|
91
106
|
* white ring marker. `leftPct` overrides the marker position (the Marktwert gauge positions
|
|
92
|
-
* it continuously); default = centered on the tier segment.
|
|
107
|
+
* it continuously); default = centered on the tier segment. `tier` null = "Keine Bewertung":
|
|
108
|
+
* the usual colours but no marker, since the price has no place on the scale.
|
|
93
109
|
*/
|
|
94
|
-
export const EvalBar: React.FunctionComponent<{ tier: number; leftPct?: number }> = ({ tier, leftPct }) => (
|
|
95
|
-
<div className=
|
|
110
|
+
export const EvalBar: React.FunctionComponent<{ tier: number | null; leftPct?: number }> = ({ tier, leftPct }) => (
|
|
111
|
+
<div className={`fin-eval-bar${tier == null ? ' fin-eval-bar--none' : ''}`}>
|
|
96
112
|
{TIER_COLORS.map((c, i) => (
|
|
97
113
|
<span key={i} className="fin-eval-seg" style={{ background: c }} />
|
|
98
114
|
))}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
115
|
+
{tier != null && (
|
|
116
|
+
<div
|
|
117
|
+
className="fin-eval-thumb"
|
|
118
|
+
style={{ left: `${leftPct != null ? leftPct : (tier + 0.5) * 20}%`, borderColor: TIER_COLORS[Math.max(0, Math.min(4, tier))] }}
|
|
119
|
+
/>
|
|
120
|
+
)}
|
|
103
121
|
</div>
|
|
104
122
|
);
|
|
105
123
|
|
|
124
|
+
/** The price-rating pill's state for a mapRating() `ratingLabel`, shared by every pill + EvalBar
|
|
125
|
+
* pair: the tier (null = "Keine Bewertung"), its translated label and its badge colours (text
|
|
126
|
+
* `color` on `background`, TIER_TEXT_COLORS / TIER_BACKGROUNDS: each tier its own, the same on
|
|
127
|
+
* every page). Every pill carries the "4" footnote (the footer's Preisbewertung note), whatever
|
|
128
|
+
* the rating, as on fe-landing's cards. */
|
|
129
|
+
export function evalPillOf(ratingLabel: string | undefined, t: (key: string) => string): {
|
|
130
|
+
tier: number | null;
|
|
131
|
+
isGood: boolean;
|
|
132
|
+
label: string;
|
|
133
|
+
color: string;
|
|
134
|
+
background: string;
|
|
135
|
+
} {
|
|
136
|
+
const tier = evalTierOf(ratingLabel);
|
|
137
|
+
if (tier == null) {
|
|
138
|
+
return { tier, isGood: false, label: t('autobahn:tier.' + NO_RATING_KEY), color: NO_RATING_COLOR, background: NO_RATING_BACKGROUND };
|
|
139
|
+
}
|
|
140
|
+
return {
|
|
141
|
+
tier,
|
|
142
|
+
isGood: TIER_KEYS[tier] === 'good',
|
|
143
|
+
label: t('autobahn:tier.' + TIER_KEYS[tier]),
|
|
144
|
+
color: TIER_TEXT_COLORS[tier],
|
|
145
|
+
background: TIER_BACKGROUNDS[tier],
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** the smallest font size (px) the pill's label is fitted down to */
|
|
150
|
+
const EVAL_PILL_MIN_FONT = 7;
|
|
151
|
+
const useIsoLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* The price-rating pill: always 108×28 whatever the rating (Figma "Guter-Preis⁴", 108 Fill × 28 Hug;
|
|
155
|
+
* md3.css .fin-eval-pill--fit), with the label and its "4" on one line between ~20px side paddings.
|
|
156
|
+
* A long label ("Keine Bewertung", "Erhöhter Preis", the English ones) steps the font size down
|
|
157
|
+
* from the CSS 12px until it fits, the way CreditKeyFigures fits its lines. It is fitted again when
|
|
158
|
+
* the label changes (language), when the pill first gets a width (a hidden tab or sheet), and once
|
|
159
|
+
* the fonts are ready (Arimo loads late where Arial is missing).
|
|
160
|
+
*/
|
|
161
|
+
export const EvalPill: React.FunctionComponent<{
|
|
162
|
+
label: string;
|
|
163
|
+
/** text colour and background: evalPillOf's (the tier's badge colours) */
|
|
164
|
+
color: string;
|
|
165
|
+
background?: string;
|
|
166
|
+
good?: boolean;
|
|
167
|
+
ariaLabel?: string;
|
|
168
|
+
}> = ({ label, color, background, good, ariaLabel }) => {
|
|
169
|
+
const ref = useRef<HTMLSpanElement>(null);
|
|
170
|
+
useIsoLayoutEffect(() => {
|
|
171
|
+
const el = ref.current;
|
|
172
|
+
if (!el || typeof window === 'undefined') return undefined;
|
|
173
|
+
const fit = (): void => {
|
|
174
|
+
el.style.fontSize = '';
|
|
175
|
+
const text = el.firstElementChild as HTMLElement | null;
|
|
176
|
+
if (!text || !el.clientWidth) return;
|
|
177
|
+
const style = window.getComputedStyle(el);
|
|
178
|
+
const room = el.clientWidth - parseFloat(style.paddingLeft) - parseFloat(style.paddingRight);
|
|
179
|
+
let size = parseFloat(style.fontSize) || 12;
|
|
180
|
+
for (let i = 0; i < 40 && size > EVAL_PILL_MIN_FONT && text.getBoundingClientRect().width > room + 0.5; i += 1) {
|
|
181
|
+
size = Math.max(EVAL_PILL_MIN_FONT, size - 0.25);
|
|
182
|
+
el.style.fontSize = `${size}px`;
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
fit();
|
|
186
|
+
let alive = true;
|
|
187
|
+
const fonts = (document as any).fonts;
|
|
188
|
+
if (fonts && fonts.ready) fonts.ready.then(() => alive && fit());
|
|
189
|
+
const RO = (window as any).ResizeObserver;
|
|
190
|
+
let width = el.clientWidth;
|
|
191
|
+
const ro = RO
|
|
192
|
+
? new RO(() => {
|
|
193
|
+
if (el.clientWidth !== width) {
|
|
194
|
+
width = el.clientWidth;
|
|
195
|
+
fit();
|
|
196
|
+
}
|
|
197
|
+
})
|
|
198
|
+
: null;
|
|
199
|
+
if (ro) ro.observe(el);
|
|
200
|
+
return () => {
|
|
201
|
+
alive = false;
|
|
202
|
+
if (ro) ro.disconnect();
|
|
203
|
+
};
|
|
204
|
+
}, [label]);
|
|
205
|
+
return (
|
|
206
|
+
<span
|
|
207
|
+
ref={ref}
|
|
208
|
+
className={`fin-eval-pill fin-eval-pill--fit${good ? ' fin-eval-pill--good' : ''}`}
|
|
209
|
+
style={{ color, background: background || `color-mix(in srgb, ${color} 16%, transparent)` }}
|
|
210
|
+
aria-label={ariaLabel}
|
|
211
|
+
>
|
|
212
|
+
<span className="fin-eval-pill-text">
|
|
213
|
+
{label}
|
|
214
|
+
<sup>4</sup>
|
|
215
|
+
</span>
|
|
216
|
+
</span>
|
|
217
|
+
);
|
|
218
|
+
};
|
|
219
|
+
|
|
106
220
|
/** Figma CTA icon — document with a check-in-circle badge over its bottom-right corner
|
|
107
221
|
* (no single lucide glyph matches; composed from file-text + a knocked-out check-circle).
|
|
108
222
|
* The badge backdrop assumes a filled (primary) button. */
|
|
@@ -411,6 +525,9 @@ export interface FinanceCalculatorProps {
|
|
|
411
525
|
onCall?: () => void;
|
|
412
526
|
/** open the Finanzierungs-/Leasingdetails popup (full breakdown + legal, expanded). Omit to hide the link. */
|
|
413
527
|
onShowDetails?: () => void;
|
|
528
|
+
/** the price-rating badge + bar were clicked: the page scrolls to its "Preis & Marktwert"
|
|
529
|
+
* section (#vdp-preis). Omit and they are not a link. */
|
|
530
|
+
onShowPriceRating?: () => void;
|
|
414
531
|
/** mobile only: open the "Rate anpassen" / "Details anzeigen" sheet (collapsed/default view).
|
|
415
532
|
* Omit to hide the trigger row (falls back to the desktop inline expander). */
|
|
416
533
|
onOpenAdjust?: () => void;
|
|
@@ -440,18 +557,29 @@ const range = (min: number, max: number, step: number): number[] => {
|
|
|
440
557
|
return out.length ? out : [min];
|
|
441
558
|
};
|
|
442
559
|
|
|
560
|
+
export interface DetailsLinkProps {
|
|
561
|
+
label: string;
|
|
562
|
+
onClick: () => void;
|
|
563
|
+
/** only the "ⓘ": the label becomes its name and tooltip (VdpStickyBar, ADV-438). */
|
|
564
|
+
iconOnly?: boolean;
|
|
565
|
+
tabIndex?: number;
|
|
566
|
+
}
|
|
567
|
+
|
|
443
568
|
/** quiet primary-colored text link (Finanzierungsdetails / Details anzeigen). */
|
|
444
|
-
const DetailsLink: React.FunctionComponent<
|
|
569
|
+
export const DetailsLink: React.FunctionComponent<DetailsLinkProps> = ({ label, onClick, iconOnly, tabIndex }) => (
|
|
445
570
|
<button
|
|
446
571
|
type="button"
|
|
447
572
|
onClick={onClick}
|
|
573
|
+
tabIndex={tabIndex}
|
|
574
|
+
{...(iconOnly ? { 'aria-label': label, title: label } : {})}
|
|
448
575
|
style={{
|
|
449
576
|
display: 'inline-flex',
|
|
450
577
|
alignItems: 'center',
|
|
451
578
|
gap: 5,
|
|
452
579
|
background: 'none',
|
|
453
580
|
border: 0,
|
|
454
|
-
|
|
581
|
+
// icon only: a 25px click area around the 15px icon that takes no space of its own
|
|
582
|
+
...(iconOnly ? { padding: 5, margin: -5 } : { padding: 0 }),
|
|
455
583
|
cursor: 'pointer',
|
|
456
584
|
color: 'var(--md-primary)',
|
|
457
585
|
font: 'inherit',
|
|
@@ -460,7 +588,7 @@ const DetailsLink: React.FunctionComponent<{ label: string; onClick: () => void
|
|
|
460
588
|
}}
|
|
461
589
|
>
|
|
462
590
|
<Icon name="info" size={15} color="var(--md-primary)" />
|
|
463
|
-
{label}
|
|
591
|
+
{!iconOnly && label}
|
|
464
592
|
</button>
|
|
465
593
|
);
|
|
466
594
|
|
|
@@ -516,6 +644,7 @@ const FinanceCalculator: React.FunctionComponent<FinanceCalculatorProps> = ({
|
|
|
516
644
|
secureLabel,
|
|
517
645
|
onCall,
|
|
518
646
|
onShowDetails,
|
|
647
|
+
onShowPriceRating,
|
|
519
648
|
onOpenAdjust,
|
|
520
649
|
onModeChange,
|
|
521
650
|
onDownChange,
|
|
@@ -531,14 +660,9 @@ const FinanceCalculator: React.FunctionComponent<FinanceCalculatorProps> = ({
|
|
|
531
660
|
const isLease = mode === 'leasing';
|
|
532
661
|
const terms = termOptions && termOptions.length ? termOptions : range(termMin, termMax, termStep);
|
|
533
662
|
const showStrike = listPrice != null && listPrice > price;
|
|
534
|
-
// price-evaluation
|
|
535
|
-
|
|
536
|
-
const evalTier
|
|
537
|
-
const isGoodTier = TIER_KEYS[evalTier] === 'good';
|
|
538
|
-
// each tier shows its own real label now (Top/Guter/Fairer/Erhöht/Hoher Preis) — no more
|
|
539
|
-
// collapsing 'good' onto the "Top-Preis" claim. Pill styling (colour/class/footnote) unchanged.
|
|
540
|
-
const evalTierLabel = t('autobahn:tier.' + TIER_KEYS[evalTier]);
|
|
541
|
-
const evalPillColor = isGoodTier ? TIER_COLORS[0] : TIER_COLORS[evalTier];
|
|
663
|
+
// price-evaluation pill + bar from the rating label: each tier its own label and colour,
|
|
664
|
+
// "Keine Bewertung" grey without a marker (an unknown label defaults to 'Guter Preis').
|
|
665
|
+
const { tier: evalTier, isGood: isGoodTier, label: evalTierLabel, color: evalPillColor, background: evalPillBackground } = evalPillOf(ratingLabel, t);
|
|
542
666
|
// condition summary (current selection) + its own details link — financing: "0 € Anzahlung ·
|
|
543
667
|
// 60 Monate · Finanzierungsdetails"; leasing: "25.000 € Sonderzahlung · 60 Mon. · 10.000
|
|
544
668
|
// km/Jahr · Details" (same wording/order as CarCard's own PriceTerms leaseTerms).
|
|
@@ -866,19 +990,23 @@ const FinanceCalculator: React.FunctionComponent<FinanceCalculatorProps> = ({
|
|
|
866
990
|
</div>
|
|
867
991
|
{/* col 2: pill + eval bar grouped together (display:contents on desktop — no-op,
|
|
868
992
|
preserves the original rate|pill / cond|bar auto-placement; mobile turns this into
|
|
869
|
-
a real flex column so the two stack tight with a fixed
|
|
870
|
-
<div
|
|
993
|
+
a real flex column so the two stack tight with a fixed 13px gap). */}
|
|
994
|
+
<div
|
|
995
|
+
className={ratingLabel && onShowPriceRating ? 'fin-eval-col rating-link' : 'fin-eval-col'}
|
|
996
|
+
{...(ratingLabel && onShowPriceRating
|
|
997
|
+
? ratingLinkProps(onShowPriceRating, t('autobahn:finance.priceRatingLink', { rating: evalTierLabel }))
|
|
998
|
+
: {})}
|
|
999
|
+
>
|
|
871
1000
|
{/* col 2 row 1: price-rating pill (Figma: bold colored label, NO icon) */}
|
|
872
1001
|
<div className="fin-eval-pill-cell">
|
|
873
1002
|
{ratingLabel && (
|
|
874
|
-
<
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
{evalTierLabel}
|
|
880
|
-
|
|
881
|
-
</span>
|
|
1003
|
+
<EvalPill
|
|
1004
|
+
label={evalTierLabel}
|
|
1005
|
+
color={evalPillColor}
|
|
1006
|
+
background={evalPillBackground}
|
|
1007
|
+
good={isGoodTier}
|
|
1008
|
+
ariaLabel={t('autobahn:finance.priceRatingAria', { rating: evalTierLabel })}
|
|
1009
|
+
/>
|
|
882
1010
|
)}
|
|
883
1011
|
</div>
|
|
884
1012
|
{/* segmented evaluation bar (Figma: discrete tiers, not a gradient) */}
|