@bytebrand/fe-ui-core-autobahn 1.0.188 → 1.0.189

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 CHANGED
@@ -38,6 +38,7 @@ import {
38
38
  GalleryActivityPill,
39
39
  cardSpec,
40
40
  PaymentMode,
41
+ startPaymentMode,
41
42
  callDealerSalesPhone,
42
43
  DEALER_SALES_PHONE,
43
44
  } from './cardParts';
@@ -98,6 +99,11 @@ export interface CarCardProps {
98
99
  * (still onOpenRateAdjust).
99
100
  */
100
101
  onShowFinancingDetails?: (car: AutobahnCar, mode: PaymentMode) => void;
102
+ /**
103
+ * Tab the price block opens on (default Finanzierung) — e.g. the SRP's leasing-only results
104
+ * open every card on Leasing. Ignored for a car without a lease rate (it has no Leasing tab).
105
+ */
106
+ initialMode?: PaymentMode;
101
107
  }
102
108
 
103
109
  const CarCard: React.FunctionComponent<CarCardProps> = ({
@@ -113,8 +119,9 @@ const CarCard: React.FunctionComponent<CarCardProps> = ({
113
119
  onCall,
114
120
  onOpenRateAdjust,
115
121
  onShowFinancingDetails,
122
+ initialMode,
116
123
  }) => {
117
- const [mode, setMode] = useState<PaymentMode>('financing');
124
+ const [mode, setMode] = useState<PaymentMode>(() => startPaymentMode(car, initialMode));
118
125
  const [photoIndex, setPhotoIndex] = useState(0);
119
126
  const [viewerOpen, setViewerOpen] = useState(false);
120
127
  const mediaRef = useRef<HTMLDivElement | null>(null);
@@ -157,6 +164,8 @@ const CarCard: React.FunctionComponent<CarCardProps> = ({
157
164
  // active that's already 3, so NEU is dropped rather than causing a 4th to overflow.
158
165
  const activeDealChips = [showDrop || showSave, showPct, !!car.zeroDown].filter(Boolean).length;
159
166
  const showNeu = asGoodAsNew && car.isNew && activeDealChips < 3;
167
+ // tabs the price block can switch to (PriceTabs shows Leasing only when the car has a lease rate)
168
+ const paymentModes: PaymentMode[] = car.lease != null ? ['financing', 'leasing', 'buy'] : ['financing', 'buy'];
160
169
  return (
161
170
  <article
162
171
  className="mcard mcard--interactive cc-card"
@@ -277,18 +286,46 @@ const CarCard: React.FunctionComponent<CarCardProps> = ({
277
286
  <div className="cc-price" style={{ marginTop: 0, borderTop: '1px solid var(--md-outline-variant)' }}>
278
287
  <PriceTabs car={car} mode={mode} onModeChange={setMode} t={t} />
279
288
  <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 8, marginTop: 10 }}>
280
- <PriceHero car={car} mode={mode} t={t} alwaysShowUnit />
289
+ {/* every tab's hero stacked in one grid cell (.cc-hero-stack), only the active one
290
+ visible, bottom-aligned — Kaufen's struck list price sits on its own line above
291
+ the price, so without this the row (and the card) grew/shrank by that line on
292
+ every tab switch. Same trick as .cc-terms-stack below. */}
293
+ <div className="cc-hero-stack">
294
+ {paymentModes.map((m) => (
295
+ <div
296
+ key={m}
297
+ className={'cc-hero-slot' + (m === mode ? '' : ' cc-hero-slot--hidden')}
298
+ aria-hidden={m === mode ? undefined : true}
299
+ >
300
+ <PriceHero car={car} mode={m} t={t} alwaysShowUnit />
301
+ </div>
302
+ ))}
303
+ </div>
281
304
  <PriceEvalCol car={car} t={t} />
282
305
  </div>
283
306
  {/* same fallback CardCtaRow already uses below: pages that haven't wired a real
284
- "Rate anpassen" sheet yet still get a working "Details" link (opens the car). */}
285
- <PriceTerms
286
- car={car}
287
- mode={mode}
288
- onOpenRateAdjust={onOpenRateAdjust || (() => onOpen(car))}
289
- onShowDetails={onShowFinancingDetails ? () => onShowFinancingDetails(car, mode) : undefined}
290
- t={t}
291
- />
307
+ "Rate anpassen" sheet yet still get a working "Details" link (opens the car).
308
+ Every tab's terms line is rendered into the same grid cell (.cc-terms-stack) and
309
+ only the active one is visible — the cell is as tall as the tallest line, so the
310
+ card keeps one height across Finanzierung/Leasing/Kaufen (Leasing's longer line
311
+ wraps to 2 lines on narrow phones). No change to the visible line itself. */}
312
+ <div className="cc-terms-stack">
313
+ {paymentModes.map((m) => (
314
+ <div
315
+ key={m}
316
+ className={'cc-terms-slot' + (m === mode ? '' : ' cc-terms-slot--hidden')}
317
+ aria-hidden={m === mode ? undefined : true}
318
+ >
319
+ <PriceTerms
320
+ car={car}
321
+ mode={m}
322
+ onOpenRateAdjust={onOpenRateAdjust || (() => onOpen(car))}
323
+ onShowDetails={onShowFinancingDetails ? () => onShowFinancingDetails(car, m) : undefined}
324
+ t={t}
325
+ />
326
+ </div>
327
+ ))}
328
+ </div>
292
329
  </div>
293
330
  {/* Mobile-only row (CardCtaRow itself carries the show-mobile class) — always
294
331
  rendered, with real fallbacks the page can override once it wires its own
package/cards/CarRow.tsx CHANGED
@@ -41,6 +41,7 @@ import {
41
41
  ZeroDownChip,
42
42
  fmtKm,
43
43
  PaymentMode,
44
+ startPaymentMode,
44
45
  ratingTone,
45
46
  } from './cardParts';
46
47
  import { AutobahnCar } from './types';
@@ -80,6 +81,8 @@ export interface CarRowProps {
80
81
  * links render as plain text (see PricePaths' own fallback).
81
82
  */
82
83
  onShowFinancingDetails?: (car: AutobahnCar, mode: PaymentMode) => void;
84
+ /** Tab the mobile price tabs open on — see CarCard's identically-named prop. */
85
+ initialMode?: PaymentMode;
83
86
  }
84
87
 
85
88
  const CarRow: React.FunctionComponent<CarRowProps> = ({
@@ -92,8 +95,9 @@ const CarRow: React.FunctionComponent<CarRowProps> = ({
92
95
  t,
93
96
  adminAction,
94
97
  onShowFinancingDetails,
98
+ initialMode,
95
99
  }) => {
96
- const [mode, setMode] = useState<PaymentMode>('financing');
100
+ const [mode, setMode] = useState<PaymentMode>(() => startPaymentMode(car, initialMode));
97
101
  const [photoIndex, setPhotoIndex] = useState(0);
98
102
  const mediaRef = useRef<HTMLDivElement | null>(null);
99
103
  // always call the LATEST onMediaEnter without re-arming the observer on every render (the
@@ -489,6 +489,11 @@ export const PriceEvalCol: React.FunctionComponent<{ car: AutobahnCar; t: Transl
489
489
 
490
490
  export type PaymentMode = 'financing' | 'leasing' | 'buy';
491
491
 
492
+ /** The tab a card opens on: the requested one (default Finanzierung), but never Leasing for a car
493
+ * without a lease rate — PriceTabs has no Leasing tab for it. */
494
+ export const startPaymentMode = (car: AutobahnCar, requested?: PaymentMode): PaymentMode =>
495
+ requested === 'leasing' && car.lease == null ? 'financing' : requested || 'financing';
496
+
492
497
  export interface PriceTabsProps {
493
498
  car: AutobahnCar;
494
499
  mode: PaymentMode;
@@ -710,7 +715,12 @@ export const PriceTerms: React.FunctionComponent<{
710
715
  onShowDetails?: () => void;
711
716
  t: TranslationFunction;
712
717
  }> = ({ car, mode, onOpenRateAdjust, onShowDetails, t }) => {
713
- if (mode === 'buy') return null;
718
+ // Kaufen (buy): a cash purchase has no financing terms/details link — used to `return null`
719
+ // here, which collapsed .cc-terms to 0 height on that tab while Financing/Leasing rendered a
720
+ // real line, jumping the price row (and everything below it: rating pill, CTA row) up/down on
721
+ // every tab switch. Render an empty, still-present .cc-terms div instead — same fix as the VDP
722
+ // FinanceCalculator's .fin-cond (md3.css), which reserves its line's height the same way.
723
+ if (mode === 'buy') return <div className="cc-terms" />;
714
724
  const finFirstInstallment =
715
725
  car.finFirstInstallment != null ? car.finFirstInstallment.toLocaleString('de-DE') : _finFirstInstallment;
716
726
  const finMonths = car.finMonths ?? _finMonths;
package/constants/app.ts CHANGED
@@ -40,7 +40,17 @@ export const LOCAL_STORAGE_KEY = {
40
40
  i18n_KEY: 'i18nLanguage'
41
41
  };
42
42
 
43
- export const DEFAULT_LANG: string = typeof window !== 'undefined' ? localStorage.getItem(LOCAL_STORAGE_KEY.i18n_KEY) : 'de';
43
+ // ADV-284: evaluated at import time — with site storage blocked, reading localStorage throws a
44
+ // SecurityError that took down the whole bundle. Blocked storage behaves like "nothing saved".
45
+ const readStoredLang = (): string | null => {
46
+ try {
47
+ return localStorage.getItem(LOCAL_STORAGE_KEY.i18n_KEY);
48
+ } catch (e) {
49
+ return null;
50
+ }
51
+ };
52
+
53
+ export const DEFAULT_LANG: string = typeof window !== 'undefined' ? readStoredLang() : 'de';
44
54
 
45
55
  // Default support contact phone
46
56
  export const CONTACT_PHONE: string = '+498004030182';
package/constants/core.ts CHANGED
@@ -35,7 +35,18 @@ export const LOCAL_STORAGE_KEY = {
35
35
  i18n_KEY: 'i18nLanguage'
36
36
  };
37
37
 
38
- export const DEFAULT_LANG: string = (typeof window !== 'undefined' ? window.localStorage.getItem(LOCAL_STORAGE_KEY.i18n_KEY) : null) ?? 'de';
38
+ // ADV-284: evaluated at import time — with site storage blocked, merely reading
39
+ // window.localStorage throws a SecurityError, which took down the whole bundle (landing
40
+ // page never rendered). Treat blocked storage like "no language saved".
41
+ const readStoredLang = (): string | null => {
42
+ try {
43
+ return typeof window !== 'undefined' ? window.localStorage.getItem(LOCAL_STORAGE_KEY.i18n_KEY) : null;
44
+ } catch (e) {
45
+ return null;
46
+ }
47
+ };
48
+
49
+ export const DEFAULT_LANG: string = readStoredLang() ?? 'de';
39
50
 
40
51
  export const ROW_STYLES = {
41
52
  marginBottom: 10