@bytebrand/fe-ui-core-autobahn 1.0.212 → 1.0.214
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 +13 -51
- package/cards/CarRow.tsx +1 -5
- package/cards/cardParts.tsx +1358 -1368
- package/cards/types.ts +182 -182
- package/constants/app.ts +1 -11
- package/constants/core.ts +1 -12
- package/data/toAutobahnCar.ts +600 -600
- package/locales/de/autobahn.json +901 -891
- package/locales/en/autobahn.json +901 -891
- package/package.json +2 -2
- package/theme/md3.css +15986 -15678
- package/ui/CreditKeyFigures.tsx +244 -244
- package/ui/Stars.tsx +36 -18
- package/ui/index.ts +96 -96
- package/vdp/FinanceCalculator.tsx +1148 -1148
- package/vdp/VdpModules.tsx +4605 -3869
- package/vdp/index.ts +9 -0
- package/vdp/types.ts +32 -2
package/ui/CreditKeyFigures.tsx
CHANGED
|
@@ -1,244 +1,244 @@
|
|
|
1
|
-
import React, { useEffect, useLayoutEffect, useRef } from 'react';
|
|
2
|
-
|
|
3
|
-
import { TranslationFunction } from '../types';
|
|
4
|
-
import { formatEur, formatEurCents, formatPct } from '../utils/financeFormat';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Financing key figures of the representative example, in the order the PM asked for (ADV-405
|
|
8
|
-
* follow-up, 19.11): "60 Mon. · 24.549 € Nettokredit · Gesamtbetrag: 31.776,28 €" /
|
|
9
|
-
* "6,78 % Sollzins fest · 6,99 % eff. Jahreszins · Details". Same sources as the
|
|
10
|
-
* Finanzierungsdetails layer (FinanceDetailsModal): term = paybackPeriod, net loan =
|
|
11
|
-
* netLoanAmount, total = totalFinancingAmount (falls back to grossLoanAmount), nominal rate =
|
|
12
|
-
* nominalInterestRate, effective rate = annualPercentageRate. Leasing (kind: 'leasing', 19.11): see
|
|
13
|
-
* leasingKeyFigureLines / leasingKeyFigures below.
|
|
14
|
-
*/
|
|
15
|
-
export interface CreditKeyFiguresData {
|
|
16
|
-
/** financing (default) or leasing — the two products word their lines differently. */
|
|
17
|
-
kind?: 'financing' | 'leasing';
|
|
18
|
-
/** contract term (paybackPeriod) — exactly the layer's "Vertragslaufzeit" (e.g. 48, also with a Schlussrate). */
|
|
19
|
-
months?: number | null;
|
|
20
|
-
/** final instalment (Schlussrate) of the same calculation — not shown; kept for the hosts' data. */
|
|
21
|
-
finalInstallment?: number | null;
|
|
22
|
-
netLoan?: number | null;
|
|
23
|
-
/** financing: Gesamtbetrag; leasing: the layer's "Gesamt inkl. Restwert" (see leasingKeyFigures). */
|
|
24
|
-
total?: number | null;
|
|
25
|
-
nominal?: number | null;
|
|
26
|
-
apr?: number | null;
|
|
27
|
-
/** leasing: the layer's "Einmalige Sonderzahlung" (0 is a real figure: "0 € Anzahlung"). */
|
|
28
|
-
down?: number | null;
|
|
29
|
-
/** leasing: the layer's "Anschaffungspreis" ("… € Barpreis"). */
|
|
30
|
-
cashPrice?: number | null;
|
|
31
|
-
/** leasing: the layer's "Restwert (verpflichtend)" — "Kaufpflicht" is shown when it is real. */
|
|
32
|
-
residual?: number | null;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export interface CreditKeyFiguresProps {
|
|
36
|
-
t: TranslationFunction;
|
|
37
|
-
figures: CreditKeyFiguresData;
|
|
38
|
-
/** optional trailing element of line 2 (the host's existing "Details"/"Finanzierungsdetails" link). */
|
|
39
|
-
details?: React.ReactNode;
|
|
40
|
-
/** host class(es) for size/colour/spacing (follow the host block's conditions line). */
|
|
41
|
-
cls?: string;
|
|
42
|
-
/** false: no two-line auto-fit — the host keeps its own font size and lets the figures flow as
|
|
43
|
-
* one wrapping paragraph (SRL desktop price column, PM 19.11: "own size, three lines are fine"). */
|
|
44
|
-
fit?: boolean;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const real = (n: number | null | undefined): n is number => typeof n === 'number' && isFinite(n) && n > 0;
|
|
48
|
-
|
|
49
|
-
/** the parts of both lines — only real figures, never a fabricated value; empty lines are dropped. */
|
|
50
|
-
export function creditKeyFigureLines(t: TranslationFunction, f: CreditKeyFiguresData): string[][] {
|
|
51
|
-
if (f.kind === 'leasing') return leasingKeyFigureLines(t, f);
|
|
52
|
-
const line1: string[] = [];
|
|
53
|
-
const line2: string[] = [];
|
|
54
|
-
if (real(f.months)) {
|
|
55
|
-
// the layer's "Vertragslaufzeit" (not the "N Raten à" count, which is one less with a Schlussrate)
|
|
56
|
-
const months = Math.round(f.months);
|
|
57
|
-
line1.push(t('autobahn:finance.kfMonths', { months, defaultValue: `${months} Mon.` }));
|
|
58
|
-
}
|
|
59
|
-
if (real(f.netLoan)) {
|
|
60
|
-
const v = formatEur(Math.round(f.netLoan));
|
|
61
|
-
line1.push(t('autobahn:finance.kfNetLoan', { value: v, defaultValue: `${v}€ Nettokredit` }));
|
|
62
|
-
}
|
|
63
|
-
if (real(f.total)) {
|
|
64
|
-
const v = formatEurCents(f.total);
|
|
65
|
-
line1.push(t('autobahn:finance.kfTotal', { value: v, defaultValue: `Gesamtbetrag: ${v}€` }));
|
|
66
|
-
}
|
|
67
|
-
if (real(f.nominal)) {
|
|
68
|
-
const v = formatPct(f.nominal);
|
|
69
|
-
line2.push(t('autobahn:finance.kfNominal', { value: v, defaultValue: `${v} Sollzins fest` }));
|
|
70
|
-
}
|
|
71
|
-
if (real(f.apr)) {
|
|
72
|
-
const v = formatPct(f.apr);
|
|
73
|
-
line2.push(t('autobahn:finance.kfApr', { value: v, defaultValue: `${v} eff. Jahreszins` }));
|
|
74
|
-
}
|
|
75
|
-
return [line1.map(keepUnits), line2.map(keepUnits)];
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// keep every € / % on its amount's line (no-break space), like the € in the hosts' money strings
|
|
79
|
-
const keepUnits = (part: string): string => part.replace(/ (€|%)/g, '\u00a0$1');
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Leasing key figures, worded as the PM's leasing mock ("Vorschlag: Restwert - Leasing", 19.11):
|
|
83
|
-
* "0 € Anzahlung · 60 Mon. · 24.549 € Barpreis · 31.776,28 € Gesamtbetrag" /
|
|
84
|
-
* "Kaufpflicht · 6,78 % Sollzins fest · 6,99 % eff. Jahreszins · Details". Anzahlung = the layer's
|
|
85
|
-
* Einmalige Sonderzahlung, Barpreis = Anschaffungspreis, Gesamtbetrag = Gesamt inkl. Restwert,
|
|
86
|
-
* "Kaufpflicht" = the mandatory Restwert (only when there is one). € without a space before it
|
|
87
|
-
* (client 19.11, financing and leasing alike); % keeps its space.
|
|
88
|
-
*/
|
|
89
|
-
function leasingKeyFigureLines(t: TranslationFunction, f: CreditKeyFiguresData): string[][] {
|
|
90
|
-
const line1: string[] = [];
|
|
91
|
-
const line2: string[] = [];
|
|
92
|
-
if (typeof f.down === 'number' && isFinite(f.down) && f.down >= 0) {
|
|
93
|
-
const v = formatEur(Math.round(f.down));
|
|
94
|
-
line1.push(t('autobahn:finance.kfLeaseDown', { value: v, defaultValue: `${v}€ Anzahlung` }));
|
|
95
|
-
}
|
|
96
|
-
if (real(f.months)) {
|
|
97
|
-
const months = Math.round(f.months);
|
|
98
|
-
line1.push(t('autobahn:finance.kfMonths', { months, defaultValue: `${months} Mon.` }));
|
|
99
|
-
}
|
|
100
|
-
if (real(f.cashPrice)) {
|
|
101
|
-
const v = formatEur(Math.round(f.cashPrice));
|
|
102
|
-
line1.push(t('autobahn:finance.kfCashPrice', { value: v, defaultValue: `${v}€ Barpreis` }));
|
|
103
|
-
}
|
|
104
|
-
if (real(f.total)) {
|
|
105
|
-
const v = formatEurCents(f.total);
|
|
106
|
-
line1.push(t('autobahn:finance.kfLeaseTotal', { value: v, defaultValue: `${v}€ Gesamtbetrag` }));
|
|
107
|
-
}
|
|
108
|
-
if (real(f.residual)) {
|
|
109
|
-
line2.push(t('autobahn:finance.kfPurchaseObligation', { defaultValue: 'Kaufpflicht' }));
|
|
110
|
-
}
|
|
111
|
-
if (real(f.nominal)) {
|
|
112
|
-
const v = formatPct(f.nominal);
|
|
113
|
-
line2.push(t('autobahn:finance.kfNominal', { value: v, defaultValue: `${v} Sollzins fest` }));
|
|
114
|
-
}
|
|
115
|
-
if (real(f.apr)) {
|
|
116
|
-
const v = formatPct(f.apr);
|
|
117
|
-
line2.push(t('autobahn:finance.kfApr', { value: v, defaultValue: `${v} eff. Jahreszins` }));
|
|
118
|
-
}
|
|
119
|
-
return [line1.map(keepUnits), line2.map(keepUnits)];
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
/** true when at least one figure is real (otherwise hosts keep their previous conditions line). */
|
|
123
|
-
export function hasCreditKeyFigures(f: CreditKeyFiguresData): boolean {
|
|
124
|
-
return [f.months, f.netLoan, f.total, f.nominal, f.apr, f.cashPrice].some(real);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/** inputs of the Leasingdetails layer (FinanceDetailsModal, leasing) — see leasingKeyFigures. */
|
|
128
|
-
export interface LeasingKeyFigureInputs {
|
|
129
|
-
/** currentSalesPrice — the Anschaffungspreis fallback when there is no basePrice. */
|
|
130
|
-
price?: number | null;
|
|
131
|
-
/** common.basePrice ("no package" price). */
|
|
132
|
-
basePrice?: number | null;
|
|
133
|
-
monthly?: number | null;
|
|
134
|
-
term?: number | null;
|
|
135
|
-
/** Einmalige Sonderzahlung (leasing firstInstallment). */
|
|
136
|
-
down?: number | null;
|
|
137
|
-
/** Restwert (leasing finalInstallment). */
|
|
138
|
-
residual?: number | null;
|
|
139
|
-
withAddServices?: boolean | null;
|
|
140
|
-
/** the leasing package's one-time price (leasing addServicesCostRaw). */
|
|
141
|
-
addServicesCostRaw?: number | null;
|
|
142
|
-
nominal?: number | null;
|
|
143
|
-
apr?: number | null;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* The leasing key figures with the Leasingdetails layer's own arithmetic (FinanceDetailsModal,
|
|
148
|
-
* leasing branch), so line and layer never disagree: Anschaffungspreis = (basePrice, else price)
|
|
149
|
-
* + the package when it is in the rate; Gesamt inkl. Restwert = term × rate + Sonderzahlung + the
|
|
150
|
-
* package when paid separately + Restwert. A missing input leaves its figure out (never invented).
|
|
151
|
-
*/
|
|
152
|
-
export function leasingKeyFigures(i: LeasingKeyFigureInputs): CreditKeyFiguresData {
|
|
153
|
-
const raw = real(i.addServicesCostRaw) ? i.addServicesCostRaw : 0;
|
|
154
|
-
const base = real(i.basePrice) ? i.basePrice : real(i.price) ? i.price : undefined;
|
|
155
|
-
const down = typeof i.down === 'number' && isFinite(i.down) && i.down >= 0 ? i.down : undefined;
|
|
156
|
-
const residual = real(i.residual) ? i.residual : 0;
|
|
157
|
-
const ratesSum = real(i.monthly) && real(i.term) ? i.monthly * i.term : undefined;
|
|
158
|
-
return {
|
|
159
|
-
kind: 'leasing',
|
|
160
|
-
down,
|
|
161
|
-
months: real(i.term) ? i.term : undefined,
|
|
162
|
-
cashPrice: base != null ? base + (i.withAddServices && raw > 0 ? raw : 0) : undefined,
|
|
163
|
-
total: ratesSum != null ? ratesSum + (down || 0) + (raw > 0 && !i.withAddServices ? raw : 0) + residual : undefined,
|
|
164
|
-
residual: residual > 0 ? residual : undefined,
|
|
165
|
-
nominal: real(i.nominal) ? i.nominal : undefined,
|
|
166
|
-
apr: real(i.apr) ? i.apr : undefined,
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
/** smallest font the auto-fit goes down to (px); the PM wants both lines to stay one line each. */
|
|
171
|
-
const MIN_FIT_PX = 6;
|
|
172
|
-
const useIsoLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* Exactly two lines with the financing key figures (Kerndaten) — PM 19.11: "from the months to
|
|
176
|
-
* Details it has to fit in 2 lines everywhere". Each line is one unbroken line (nowrap); when the
|
|
177
|
-
* host is too narrow the block's font size steps down (from the host's conditions-line size) until
|
|
178
|
-
* both lines fit, re-measured on resize. The " · " separators reuse the quiet .cc-terms-dot. The
|
|
179
|
-
* optional `details` element (the host's details link/button) ends line 2, always labelled
|
|
180
|
-
* "Details" (card.price.detailsLink), as in the PM's mock.
|
|
181
|
-
*/
|
|
182
|
-
const CreditKeyFigures: React.FunctionComponent<CreditKeyFiguresProps> = ({ t, figures, details, cls, fit: autoFit = true }) => {
|
|
183
|
-
const [line1, line2] = creditKeyFigureLines(t, figures);
|
|
184
|
-
const ref = useRef<HTMLDivElement>(null);
|
|
185
|
-
const detailsLabel = t('autobahn:card.price.detailsLink', { defaultValue: 'Details' });
|
|
186
|
-
const detailsEl = React.isValidElement(details) ? React.cloneElement(details as React.ReactElement<any>, {}, detailsLabel) : details;
|
|
187
|
-
const key = `${line1.join('|')}#${line2.join('|')}#${detailsEl ? detailsLabel : ''}`;
|
|
188
|
-
|
|
189
|
-
useIsoLayoutEffect(() => {
|
|
190
|
-
const el = ref.current;
|
|
191
|
-
if (!autoFit || !el || typeof window === 'undefined') return undefined;
|
|
192
|
-
const fit = (): void => {
|
|
193
|
-
el.style.fontSize = '';
|
|
194
|
-
const lines = Array.prototype.slice.call(el.querySelectorAll('.ckf-line')) as HTMLElement[];
|
|
195
|
-
const tooWide = (): boolean => lines.some((l) => l.scrollWidth > l.clientWidth + 0.5);
|
|
196
|
-
if (!el.clientWidth || !tooWide()) return;
|
|
197
|
-
let size = parseFloat(window.getComputedStyle(el).fontSize) || 12;
|
|
198
|
-
for (let i = 0; i < 40 && size > MIN_FIT_PX && tooWide(); i++) {
|
|
199
|
-
size = Math.max(MIN_FIT_PX, size - 0.25);
|
|
200
|
-
el.style.fontSize = `${size}px`;
|
|
201
|
-
}
|
|
202
|
-
};
|
|
203
|
-
fit();
|
|
204
|
-
const RO = (window as any).ResizeObserver;
|
|
205
|
-
if (!RO) return undefined;
|
|
206
|
-
let width = el.clientWidth;
|
|
207
|
-
const ro = new RO(() => {
|
|
208
|
-
if (el.clientWidth !== width) {
|
|
209
|
-
width = el.clientWidth;
|
|
210
|
-
fit();
|
|
211
|
-
}
|
|
212
|
-
});
|
|
213
|
-
ro.observe(el);
|
|
214
|
-
return () => ro.disconnect();
|
|
215
|
-
}, [key, autoFit]);
|
|
216
|
-
|
|
217
|
-
const renderParts = (parts: string[]): React.ReactNode =>
|
|
218
|
-
parts.map((part, i) => (
|
|
219
|
-
<React.Fragment key={i}>
|
|
220
|
-
{i > 0 && <span className="cc-terms-dot"> · </span>}
|
|
221
|
-
{part}
|
|
222
|
-
</React.Fragment>
|
|
223
|
-
));
|
|
224
|
-
return (
|
|
225
|
-
<div ref={ref} className={'ckf' + (autoFit ? '' : ' ckf--flow') + (cls ? ` ${cls}` : '')}>
|
|
226
|
-
{line1.length > 0 && <span className="ckf-line">{renderParts(line1)}</span>}
|
|
227
|
-
{/* separator between the two lines — only shown when they flow as one paragraph (ckf--flow) */}
|
|
228
|
-
{line1.length > 0 && (line2.length > 0 || detailsEl) && <span className="ckf-sep cc-terms-dot"> · </span>}
|
|
229
|
-
{(line2.length > 0 || detailsEl) && (
|
|
230
|
-
<span className="ckf-line">
|
|
231
|
-
{renderParts(line2)}
|
|
232
|
-
{detailsEl && (
|
|
233
|
-
<>
|
|
234
|
-
{line2.length > 0 && <span className="cc-terms-dot"> · </span>}
|
|
235
|
-
<span className="ckf-details">{detailsEl}</span>
|
|
236
|
-
</>
|
|
237
|
-
)}
|
|
238
|
-
</span>
|
|
239
|
-
)}
|
|
240
|
-
</div>
|
|
241
|
-
);
|
|
242
|
-
};
|
|
243
|
-
|
|
244
|
-
export default CreditKeyFigures;
|
|
1
|
+
import React, { useEffect, useLayoutEffect, useRef } from 'react';
|
|
2
|
+
|
|
3
|
+
import { TranslationFunction } from '../types';
|
|
4
|
+
import { formatEur, formatEurCents, formatPct } from '../utils/financeFormat';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Financing key figures of the representative example, in the order the PM asked for (ADV-405
|
|
8
|
+
* follow-up, 19.11): "60 Mon. · 24.549 € Nettokredit · Gesamtbetrag: 31.776,28 €" /
|
|
9
|
+
* "6,78 % Sollzins fest · 6,99 % eff. Jahreszins · Details". Same sources as the
|
|
10
|
+
* Finanzierungsdetails layer (FinanceDetailsModal): term = paybackPeriod, net loan =
|
|
11
|
+
* netLoanAmount, total = totalFinancingAmount (falls back to grossLoanAmount), nominal rate =
|
|
12
|
+
* nominalInterestRate, effective rate = annualPercentageRate. Leasing (kind: 'leasing', 19.11): see
|
|
13
|
+
* leasingKeyFigureLines / leasingKeyFigures below.
|
|
14
|
+
*/
|
|
15
|
+
export interface CreditKeyFiguresData {
|
|
16
|
+
/** financing (default) or leasing — the two products word their lines differently. */
|
|
17
|
+
kind?: 'financing' | 'leasing';
|
|
18
|
+
/** contract term (paybackPeriod) — exactly the layer's "Vertragslaufzeit" (e.g. 48, also with a Schlussrate). */
|
|
19
|
+
months?: number | null;
|
|
20
|
+
/** final instalment (Schlussrate) of the same calculation — not shown; kept for the hosts' data. */
|
|
21
|
+
finalInstallment?: number | null;
|
|
22
|
+
netLoan?: number | null;
|
|
23
|
+
/** financing: Gesamtbetrag; leasing: the layer's "Gesamt inkl. Restwert" (see leasingKeyFigures). */
|
|
24
|
+
total?: number | null;
|
|
25
|
+
nominal?: number | null;
|
|
26
|
+
apr?: number | null;
|
|
27
|
+
/** leasing: the layer's "Einmalige Sonderzahlung" (0 is a real figure: "0 € Anzahlung"). */
|
|
28
|
+
down?: number | null;
|
|
29
|
+
/** leasing: the layer's "Anschaffungspreis" ("… € Barpreis"). */
|
|
30
|
+
cashPrice?: number | null;
|
|
31
|
+
/** leasing: the layer's "Restwert (verpflichtend)" — "Kaufpflicht" is shown when it is real. */
|
|
32
|
+
residual?: number | null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface CreditKeyFiguresProps {
|
|
36
|
+
t: TranslationFunction;
|
|
37
|
+
figures: CreditKeyFiguresData;
|
|
38
|
+
/** optional trailing element of line 2 (the host's existing "Details"/"Finanzierungsdetails" link). */
|
|
39
|
+
details?: React.ReactNode;
|
|
40
|
+
/** host class(es) for size/colour/spacing (follow the host block's conditions line). */
|
|
41
|
+
cls?: string;
|
|
42
|
+
/** false: no two-line auto-fit — the host keeps its own font size and lets the figures flow as
|
|
43
|
+
* one wrapping paragraph (SRL desktop price column, PM 19.11: "own size, three lines are fine"). */
|
|
44
|
+
fit?: boolean;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const real = (n: number | null | undefined): n is number => typeof n === 'number' && isFinite(n) && n > 0;
|
|
48
|
+
|
|
49
|
+
/** the parts of both lines — only real figures, never a fabricated value; empty lines are dropped. */
|
|
50
|
+
export function creditKeyFigureLines(t: TranslationFunction, f: CreditKeyFiguresData): string[][] {
|
|
51
|
+
if (f.kind === 'leasing') return leasingKeyFigureLines(t, f);
|
|
52
|
+
const line1: string[] = [];
|
|
53
|
+
const line2: string[] = [];
|
|
54
|
+
if (real(f.months)) {
|
|
55
|
+
// the layer's "Vertragslaufzeit" (not the "N Raten à" count, which is one less with a Schlussrate)
|
|
56
|
+
const months = Math.round(f.months);
|
|
57
|
+
line1.push(t('autobahn:finance.kfMonths', { months, defaultValue: `${months} Mon.` }));
|
|
58
|
+
}
|
|
59
|
+
if (real(f.netLoan)) {
|
|
60
|
+
const v = formatEur(Math.round(f.netLoan));
|
|
61
|
+
line1.push(t('autobahn:finance.kfNetLoan', { value: v, defaultValue: `${v}€ Nettokredit` }));
|
|
62
|
+
}
|
|
63
|
+
if (real(f.total)) {
|
|
64
|
+
const v = formatEurCents(f.total);
|
|
65
|
+
line1.push(t('autobahn:finance.kfTotal', { value: v, defaultValue: `Gesamtbetrag: ${v}€` }));
|
|
66
|
+
}
|
|
67
|
+
if (real(f.nominal)) {
|
|
68
|
+
const v = formatPct(f.nominal);
|
|
69
|
+
line2.push(t('autobahn:finance.kfNominal', { value: v, defaultValue: `${v} Sollzins fest` }));
|
|
70
|
+
}
|
|
71
|
+
if (real(f.apr)) {
|
|
72
|
+
const v = formatPct(f.apr);
|
|
73
|
+
line2.push(t('autobahn:finance.kfApr', { value: v, defaultValue: `${v} eff. Jahreszins` }));
|
|
74
|
+
}
|
|
75
|
+
return [line1.map(keepUnits), line2.map(keepUnits)];
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// keep every € / % on its amount's line (no-break space), like the € in the hosts' money strings
|
|
79
|
+
const keepUnits = (part: string): string => part.replace(/ (€|%)/g, '\u00a0$1');
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Leasing key figures, worded as the PM's leasing mock ("Vorschlag: Restwert - Leasing", 19.11):
|
|
83
|
+
* "0 € Anzahlung · 60 Mon. · 24.549 € Barpreis · 31.776,28 € Gesamtbetrag" /
|
|
84
|
+
* "Kaufpflicht · 6,78 % Sollzins fest · 6,99 % eff. Jahreszins · Details". Anzahlung = the layer's
|
|
85
|
+
* Einmalige Sonderzahlung, Barpreis = Anschaffungspreis, Gesamtbetrag = Gesamt inkl. Restwert,
|
|
86
|
+
* "Kaufpflicht" = the mandatory Restwert (only when there is one). € without a space before it
|
|
87
|
+
* (client 19.11, financing and leasing alike); % keeps its space.
|
|
88
|
+
*/
|
|
89
|
+
function leasingKeyFigureLines(t: TranslationFunction, f: CreditKeyFiguresData): string[][] {
|
|
90
|
+
const line1: string[] = [];
|
|
91
|
+
const line2: string[] = [];
|
|
92
|
+
if (typeof f.down === 'number' && isFinite(f.down) && f.down >= 0) {
|
|
93
|
+
const v = formatEur(Math.round(f.down));
|
|
94
|
+
line1.push(t('autobahn:finance.kfLeaseDown', { value: v, defaultValue: `${v}€ Anzahlung` }));
|
|
95
|
+
}
|
|
96
|
+
if (real(f.months)) {
|
|
97
|
+
const months = Math.round(f.months);
|
|
98
|
+
line1.push(t('autobahn:finance.kfMonths', { months, defaultValue: `${months} Mon.` }));
|
|
99
|
+
}
|
|
100
|
+
if (real(f.cashPrice)) {
|
|
101
|
+
const v = formatEur(Math.round(f.cashPrice));
|
|
102
|
+
line1.push(t('autobahn:finance.kfCashPrice', { value: v, defaultValue: `${v}€ Barpreis` }));
|
|
103
|
+
}
|
|
104
|
+
if (real(f.total)) {
|
|
105
|
+
const v = formatEurCents(f.total);
|
|
106
|
+
line1.push(t('autobahn:finance.kfLeaseTotal', { value: v, defaultValue: `${v}€ Gesamtbetrag` }));
|
|
107
|
+
}
|
|
108
|
+
if (real(f.residual)) {
|
|
109
|
+
line2.push(t('autobahn:finance.kfPurchaseObligation', { defaultValue: 'Kaufpflicht' }));
|
|
110
|
+
}
|
|
111
|
+
if (real(f.nominal)) {
|
|
112
|
+
const v = formatPct(f.nominal);
|
|
113
|
+
line2.push(t('autobahn:finance.kfNominal', { value: v, defaultValue: `${v} Sollzins fest` }));
|
|
114
|
+
}
|
|
115
|
+
if (real(f.apr)) {
|
|
116
|
+
const v = formatPct(f.apr);
|
|
117
|
+
line2.push(t('autobahn:finance.kfApr', { value: v, defaultValue: `${v} eff. Jahreszins` }));
|
|
118
|
+
}
|
|
119
|
+
return [line1.map(keepUnits), line2.map(keepUnits)];
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** true when at least one figure is real (otherwise hosts keep their previous conditions line). */
|
|
123
|
+
export function hasCreditKeyFigures(f: CreditKeyFiguresData): boolean {
|
|
124
|
+
return [f.months, f.netLoan, f.total, f.nominal, f.apr, f.cashPrice].some(real);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** inputs of the Leasingdetails layer (FinanceDetailsModal, leasing) — see leasingKeyFigures. */
|
|
128
|
+
export interface LeasingKeyFigureInputs {
|
|
129
|
+
/** currentSalesPrice — the Anschaffungspreis fallback when there is no basePrice. */
|
|
130
|
+
price?: number | null;
|
|
131
|
+
/** common.basePrice ("no package" price). */
|
|
132
|
+
basePrice?: number | null;
|
|
133
|
+
monthly?: number | null;
|
|
134
|
+
term?: number | null;
|
|
135
|
+
/** Einmalige Sonderzahlung (leasing firstInstallment). */
|
|
136
|
+
down?: number | null;
|
|
137
|
+
/** Restwert (leasing finalInstallment). */
|
|
138
|
+
residual?: number | null;
|
|
139
|
+
withAddServices?: boolean | null;
|
|
140
|
+
/** the leasing package's one-time price (leasing addServicesCostRaw). */
|
|
141
|
+
addServicesCostRaw?: number | null;
|
|
142
|
+
nominal?: number | null;
|
|
143
|
+
apr?: number | null;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* The leasing key figures with the Leasingdetails layer's own arithmetic (FinanceDetailsModal,
|
|
148
|
+
* leasing branch), so line and layer never disagree: Anschaffungspreis = (basePrice, else price)
|
|
149
|
+
* + the package when it is in the rate; Gesamt inkl. Restwert = term × rate + Sonderzahlung + the
|
|
150
|
+
* package when paid separately + Restwert. A missing input leaves its figure out (never invented).
|
|
151
|
+
*/
|
|
152
|
+
export function leasingKeyFigures(i: LeasingKeyFigureInputs): CreditKeyFiguresData {
|
|
153
|
+
const raw = real(i.addServicesCostRaw) ? i.addServicesCostRaw : 0;
|
|
154
|
+
const base = real(i.basePrice) ? i.basePrice : real(i.price) ? i.price : undefined;
|
|
155
|
+
const down = typeof i.down === 'number' && isFinite(i.down) && i.down >= 0 ? i.down : undefined;
|
|
156
|
+
const residual = real(i.residual) ? i.residual : 0;
|
|
157
|
+
const ratesSum = real(i.monthly) && real(i.term) ? i.monthly * i.term : undefined;
|
|
158
|
+
return {
|
|
159
|
+
kind: 'leasing',
|
|
160
|
+
down,
|
|
161
|
+
months: real(i.term) ? i.term : undefined,
|
|
162
|
+
cashPrice: base != null ? base + (i.withAddServices && raw > 0 ? raw : 0) : undefined,
|
|
163
|
+
total: ratesSum != null ? ratesSum + (down || 0) + (raw > 0 && !i.withAddServices ? raw : 0) + residual : undefined,
|
|
164
|
+
residual: residual > 0 ? residual : undefined,
|
|
165
|
+
nominal: real(i.nominal) ? i.nominal : undefined,
|
|
166
|
+
apr: real(i.apr) ? i.apr : undefined,
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** smallest font the auto-fit goes down to (px); the PM wants both lines to stay one line each. */
|
|
171
|
+
const MIN_FIT_PX = 6;
|
|
172
|
+
const useIsoLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Exactly two lines with the financing key figures (Kerndaten) — PM 19.11: "from the months to
|
|
176
|
+
* Details it has to fit in 2 lines everywhere". Each line is one unbroken line (nowrap); when the
|
|
177
|
+
* host is too narrow the block's font size steps down (from the host's conditions-line size) until
|
|
178
|
+
* both lines fit, re-measured on resize. The " · " separators reuse the quiet .cc-terms-dot. The
|
|
179
|
+
* optional `details` element (the host's details link/button) ends line 2, always labelled
|
|
180
|
+
* "Details" (card.price.detailsLink), as in the PM's mock.
|
|
181
|
+
*/
|
|
182
|
+
const CreditKeyFigures: React.FunctionComponent<CreditKeyFiguresProps> = ({ t, figures, details, cls, fit: autoFit = true }) => {
|
|
183
|
+
const [line1, line2] = creditKeyFigureLines(t, figures);
|
|
184
|
+
const ref = useRef<HTMLDivElement>(null);
|
|
185
|
+
const detailsLabel = t('autobahn:card.price.detailsLink', { defaultValue: 'Details' });
|
|
186
|
+
const detailsEl = React.isValidElement(details) ? React.cloneElement(details as React.ReactElement<any>, {}, detailsLabel) : details;
|
|
187
|
+
const key = `${line1.join('|')}#${line2.join('|')}#${detailsEl ? detailsLabel : ''}`;
|
|
188
|
+
|
|
189
|
+
useIsoLayoutEffect(() => {
|
|
190
|
+
const el = ref.current;
|
|
191
|
+
if (!autoFit || !el || typeof window === 'undefined') return undefined;
|
|
192
|
+
const fit = (): void => {
|
|
193
|
+
el.style.fontSize = '';
|
|
194
|
+
const lines = Array.prototype.slice.call(el.querySelectorAll('.ckf-line')) as HTMLElement[];
|
|
195
|
+
const tooWide = (): boolean => lines.some((l) => l.scrollWidth > l.clientWidth + 0.5);
|
|
196
|
+
if (!el.clientWidth || !tooWide()) return;
|
|
197
|
+
let size = parseFloat(window.getComputedStyle(el).fontSize) || 12;
|
|
198
|
+
for (let i = 0; i < 40 && size > MIN_FIT_PX && tooWide(); i++) {
|
|
199
|
+
size = Math.max(MIN_FIT_PX, size - 0.25);
|
|
200
|
+
el.style.fontSize = `${size}px`;
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
fit();
|
|
204
|
+
const RO = (window as any).ResizeObserver;
|
|
205
|
+
if (!RO) return undefined;
|
|
206
|
+
let width = el.clientWidth;
|
|
207
|
+
const ro = new RO(() => {
|
|
208
|
+
if (el.clientWidth !== width) {
|
|
209
|
+
width = el.clientWidth;
|
|
210
|
+
fit();
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
ro.observe(el);
|
|
214
|
+
return () => ro.disconnect();
|
|
215
|
+
}, [key, autoFit]);
|
|
216
|
+
|
|
217
|
+
const renderParts = (parts: string[]): React.ReactNode =>
|
|
218
|
+
parts.map((part, i) => (
|
|
219
|
+
<React.Fragment key={i}>
|
|
220
|
+
{i > 0 && <span className="cc-terms-dot"> · </span>}
|
|
221
|
+
{part}
|
|
222
|
+
</React.Fragment>
|
|
223
|
+
));
|
|
224
|
+
return (
|
|
225
|
+
<div ref={ref} className={'ckf' + (autoFit ? '' : ' ckf--flow') + (cls ? ` ${cls}` : '')}>
|
|
226
|
+
{line1.length > 0 && <span className="ckf-line">{renderParts(line1)}</span>}
|
|
227
|
+
{/* separator between the two lines — only shown when they flow as one paragraph (ckf--flow) */}
|
|
228
|
+
{line1.length > 0 && (line2.length > 0 || detailsEl) && <span className="ckf-sep cc-terms-dot"> · </span>}
|
|
229
|
+
{(line2.length > 0 || detailsEl) && (
|
|
230
|
+
<span className="ckf-line">
|
|
231
|
+
{renderParts(line2)}
|
|
232
|
+
{detailsEl && (
|
|
233
|
+
<>
|
|
234
|
+
{line2.length > 0 && <span className="cc-terms-dot"> · </span>}
|
|
235
|
+
<span className="ckf-details">{detailsEl}</span>
|
|
236
|
+
</>
|
|
237
|
+
)}
|
|
238
|
+
</span>
|
|
239
|
+
)}
|
|
240
|
+
</div>
|
|
241
|
+
);
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
export default CreditKeyFigures;
|
package/ui/Stars.tsx
CHANGED
|
@@ -3,27 +3,45 @@ import React from 'react';
|
|
|
3
3
|
import Icon from './Icon';
|
|
4
4
|
|
|
5
5
|
export interface StarsProps {
|
|
6
|
-
/** rating value 0–5; each star fills
|
|
6
|
+
/** rating value 0–5; each star fills by its exact share (4,52 → four full stars + 52 % of the fifth). */
|
|
7
7
|
value: number;
|
|
8
8
|
size?: number;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
)
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
)
|
|
11
|
+
const FILLED = '#F2A900';
|
|
12
|
+
const EMPTY = '#D8D6DC';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* 5-star row filled to the exact value: a grey star with the gold one clipped to the star's
|
|
16
|
+
* share on top, so a site rating of 4,5 shows four and a half stars (whole-number review
|
|
17
|
+
* ratings render exactly as before).
|
|
18
|
+
*/
|
|
19
|
+
const Stars: React.FunctionComponent<StarsProps> = ({ value, size = 16 }) => {
|
|
20
|
+
const v = Math.max(0, Math.min(5, Number(value) || 0));
|
|
21
|
+
return (
|
|
22
|
+
<span
|
|
23
|
+
role="img"
|
|
24
|
+
aria-label={`${v.toLocaleString('de-DE', { maximumFractionDigits: 1 })} von 5 Sternen`}
|
|
25
|
+
style={{ display: 'inline-flex', gap: 1 }}
|
|
26
|
+
>
|
|
27
|
+
{[0, 1, 2, 3, 4].map((i) => {
|
|
28
|
+
const share = Math.max(0, Math.min(1, v - i));
|
|
29
|
+
return (
|
|
30
|
+
<span key={i} style={{ position: 'relative', display: 'inline-flex', flex: 'none' }}>
|
|
31
|
+
<Icon name="star" size={size} color={EMPTY} style={{ fill: EMPTY }} />
|
|
32
|
+
{share > 0 && (
|
|
33
|
+
<span
|
|
34
|
+
aria-hidden="true"
|
|
35
|
+
style={{ position: 'absolute', top: 0, left: 0, bottom: 0, width: `${share * 100}%`, overflow: 'hidden', display: 'flex' }}
|
|
36
|
+
>
|
|
37
|
+
<Icon name="star" size={size} color={FILLED} style={{ fill: FILLED, flex: 'none' }} />
|
|
38
|
+
</span>
|
|
39
|
+
)}
|
|
40
|
+
</span>
|
|
41
|
+
);
|
|
42
|
+
})}
|
|
43
|
+
</span>
|
|
44
|
+
);
|
|
45
|
+
};
|
|
28
46
|
|
|
29
47
|
export default Stars;
|