@bytebrand/fe-ui-core-autobahn 1.0.214 → 1.0.216
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 +59 -14
- package/cards/CarRow.tsx +33 -9
- package/cards/cardParts.tsx +58 -18
- package/compat/PriceRating/PriceRating.styl +5 -7
- package/compat/PriceRatingDetailed/PriceRatingDetailed.styl +8 -6
- package/compat/legacy-theme/priceReviewColors.styl +18 -5
- package/constants/app.ts +11 -1
- package/constants/autobahn.ts +39 -0
- package/constants/core.ts +12 -1
- package/data/fieldMapping.ts +3 -3
- package/data/toAutobahnCar.ts +14 -12
- package/locales/de/autobahn.json +3 -2
- package/locales/en/autobahn.json +3 -2
- package/package.json +2 -2
- package/theme/md3.css +115 -218
- package/ui/StatChip.tsx +8 -3
- package/ui/index.ts +1 -0
- package/ui/ratingLink.ts +36 -0
- package/vdp/FinanceCalculator.tsx +130 -27
- package/vdp/VdpModules.tsx +79 -669
- package/vdp/index.ts +0 -3
- package/vdp/types.ts +2 -12
|
@@ -13,12 +13,13 @@
|
|
|
13
13
|
//
|
|
14
14
|
// Renders correctly only inside a `<div className="md3">` subtree.
|
|
15
15
|
|
|
16
|
-
import React, { useState, useEffect } 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';
|
|
@@ -103,20 +104,119 @@ export const Slider: React.FunctionComponent<SliderProps> = ({
|
|
|
103
104
|
/**
|
|
104
105
|
* Segmented price-evaluation bar (Figma: 5 discrete tier segments, NOT a gradient) with a
|
|
105
106
|
* white ring marker. `leftPct` overrides the marker position (the Marktwert gauge positions
|
|
106
|
-
* 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.
|
|
107
109
|
*/
|
|
108
|
-
export const EvalBar: React.FunctionComponent<{ tier: number; leftPct?: number }> = ({ tier, leftPct }) => (
|
|
109
|
-
<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' : ''}`}>
|
|
110
112
|
{TIER_COLORS.map((c, i) => (
|
|
111
113
|
<span key={i} className="fin-eval-seg" style={{ background: c }} />
|
|
112
114
|
))}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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
|
+
)}
|
|
117
121
|
</div>
|
|
118
122
|
);
|
|
119
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
|
+
|
|
120
220
|
/** Figma CTA icon — document with a check-in-circle badge over its bottom-right corner
|
|
121
221
|
* (no single lucide glyph matches; composed from file-text + a knocked-out check-circle).
|
|
122
222
|
* The badge backdrop assumes a filled (primary) button. */
|
|
@@ -425,6 +525,9 @@ export interface FinanceCalculatorProps {
|
|
|
425
525
|
onCall?: () => void;
|
|
426
526
|
/** open the Finanzierungs-/Leasingdetails popup (full breakdown + legal, expanded). Omit to hide the link. */
|
|
427
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;
|
|
428
531
|
/** mobile only: open the "Rate anpassen" / "Details anzeigen" sheet (collapsed/default view).
|
|
429
532
|
* Omit to hide the trigger row (falls back to the desktop inline expander). */
|
|
430
533
|
onOpenAdjust?: () => void;
|
|
@@ -530,6 +633,7 @@ const FinanceCalculator: React.FunctionComponent<FinanceCalculatorProps> = ({
|
|
|
530
633
|
secureLabel,
|
|
531
634
|
onCall,
|
|
532
635
|
onShowDetails,
|
|
636
|
+
onShowPriceRating,
|
|
533
637
|
onOpenAdjust,
|
|
534
638
|
onModeChange,
|
|
535
639
|
onDownChange,
|
|
@@ -545,14 +649,9 @@ const FinanceCalculator: React.FunctionComponent<FinanceCalculatorProps> = ({
|
|
|
545
649
|
const isLease = mode === 'leasing';
|
|
546
650
|
const terms = termOptions && termOptions.length ? termOptions : range(termMin, termMax, termStep);
|
|
547
651
|
const showStrike = listPrice != null && listPrice > price;
|
|
548
|
-
// price-evaluation
|
|
549
|
-
|
|
550
|
-
const evalTier
|
|
551
|
-
const isGoodTier = TIER_KEYS[evalTier] === 'good';
|
|
552
|
-
// each tier shows its own real label now (Top/Guter/Fairer/Erhöht/Hoher Preis) — no more
|
|
553
|
-
// collapsing 'good' onto the "Top-Preis" claim. Pill styling (colour/class/footnote) unchanged.
|
|
554
|
-
const evalTierLabel = t('autobahn:tier.' + TIER_KEYS[evalTier]);
|
|
555
|
-
const evalPillColor = isGoodTier ? TIER_COLORS[0] : TIER_COLORS[evalTier];
|
|
652
|
+
// price-evaluation pill + bar from the rating label: each tier its own label and colour,
|
|
653
|
+
// "Keine Bewertung" grey without a marker (an unknown label defaults to 'Guter Preis').
|
|
654
|
+
const { tier: evalTier, isGood: isGoodTier, label: evalTierLabel, color: evalPillColor, background: evalPillBackground } = evalPillOf(ratingLabel, t);
|
|
556
655
|
// condition summary (current selection) + its own details link — financing: "0 € Anzahlung ·
|
|
557
656
|
// 60 Monate · Finanzierungsdetails"; leasing: "25.000 € Sonderzahlung · 60 Mon. · 10.000
|
|
558
657
|
// km/Jahr · Details" (same wording/order as CarCard's own PriceTerms leaseTerms).
|
|
@@ -880,19 +979,23 @@ const FinanceCalculator: React.FunctionComponent<FinanceCalculatorProps> = ({
|
|
|
880
979
|
</div>
|
|
881
980
|
{/* col 2: pill + eval bar grouped together (display:contents on desktop — no-op,
|
|
882
981
|
preserves the original rate|pill / cond|bar auto-placement; mobile turns this into
|
|
883
|
-
a real flex column so the two stack tight with a fixed
|
|
884
|
-
<div
|
|
982
|
+
a real flex column so the two stack tight with a fixed 13px gap). */}
|
|
983
|
+
<div
|
|
984
|
+
className={ratingLabel && onShowPriceRating ? 'fin-eval-col rating-link' : 'fin-eval-col'}
|
|
985
|
+
{...(ratingLabel && onShowPriceRating
|
|
986
|
+
? ratingLinkProps(onShowPriceRating, t('autobahn:finance.priceRatingLink', { rating: evalTierLabel }))
|
|
987
|
+
: {})}
|
|
988
|
+
>
|
|
885
989
|
{/* col 2 row 1: price-rating pill (Figma: bold colored label, NO icon) */}
|
|
886
990
|
<div className="fin-eval-pill-cell">
|
|
887
991
|
{ratingLabel && (
|
|
888
|
-
<
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
{evalTierLabel}
|
|
894
|
-
|
|
895
|
-
</span>
|
|
992
|
+
<EvalPill
|
|
993
|
+
label={evalTierLabel}
|
|
994
|
+
color={evalPillColor}
|
|
995
|
+
background={evalPillBackground}
|
|
996
|
+
good={isGoodTier}
|
|
997
|
+
ariaLabel={t('autobahn:finance.priceRatingAria', { rating: evalTierLabel })}
|
|
998
|
+
/>
|
|
896
999
|
)}
|
|
897
1000
|
</div>
|
|
898
1001
|
{/* segmented evaluation bar (Figma: discrete tiers, not a gradient) */}
|