@bytebrand/fe-ui-core-autobahn 1.0.225 → 1.0.226

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.
@@ -1,86 +0,0 @@
1
- // Autobahn (auto.de redesign) — the campaign's banner: headline and link on the left, cut-out cars on a wedge in
2
- // the campaign's colour on the right; the car in front reaches over the upper edge. Used on fe-main's home page.
3
- //
4
- // Texts, colours and dates come from the campaign, the cars from the page, the look from md3.css
5
- // (.campaign-banner). Nothing is shown before the campaign starts and after it has ended. Renders correctly only
6
- // inside a `<div className="md3">` subtree.
7
-
8
- import React, { useEffect, useRef, useState } from 'react';
9
- import { TranslationFunction } from '../types';
10
-
11
- import { Icon } from '../ui';
12
- import { Campaign, campaignPeriod, isCampaignRunning } from './campaigns';
13
- import { campaignVars } from './campaignVars';
14
- import { openInApp } from './openInApp';
15
- import { useCountdown } from './useCountdown';
16
-
17
- export interface CampaignBannerProps {
18
- campaign: Campaign;
19
- /** pictures of cars with a transparent background; the first one stands in front. */
20
- cars: string[];
21
- /** where the offers are; a real link (new tab, crawlers). */
22
- href: string;
23
- /** plain click: the app opens href itself, without loading the page anew. */
24
- onOpen: () => void;
25
- t: TranslationFunction;
26
- }
27
-
28
- /** true once a part of the element has been on screen (at once without IntersectionObserver). */
29
- const useSeen = (ref: React.RefObject<HTMLElement | null>): boolean => {
30
- const [seen, setSeen] = useState(false);
31
- useEffect(() => {
32
- const el = ref.current;
33
- if (!el || typeof IntersectionObserver === 'undefined') {
34
- setSeen(true);
35
- return undefined;
36
- }
37
- const observer = new IntersectionObserver((entries) => {
38
- if (!entries.some((entry) => entry.isIntersecting)) return;
39
- setSeen(true);
40
- observer.disconnect();
41
- }, { threshold: 0.3 });
42
- observer.observe(el);
43
- return () => observer.disconnect();
44
- }, [ref]);
45
- return seen;
46
- };
47
-
48
- const CampaignBanner: React.FunctionComponent<CampaignBannerProps> = ({ campaign, cars, href, onOpen, t }) => {
49
- const ref = useRef<HTMLAnchorElement>(null);
50
- const seen = useSeen(ref);
51
- const left = useCountdown(campaign.endsAt);
52
- if (!left || !isCampaignRunning(campaign)) return null;
53
- return (
54
- <a
55
- ref={ref}
56
- className={'campaign-banner campaign-banner--' + campaign.id + (seen ? ' campaign-banner--in' : '')}
57
- style={campaignVars(campaign)}
58
- href={href}
59
- onClick={openInApp(onOpen)}
60
- >
61
- <span className="campaign-banner-cars" aria-hidden="true">
62
- {cars.map((src, i) => (
63
- <img key={src} className={'campaign-banner-car campaign-banner-car--' + (i + 1)} src={src} alt="" decoding="async" />
64
- ))}
65
- <span className="campaign-banner-note">{t('autobahn:campaign.exampleCars')}</span>
66
- </span>
67
- <span className="campaign-banner-body">
68
- <span className="campaign-banner-period">{t(campaign.texts + '.period', { ...campaignPeriod(campaign) })}</span>
69
- <strong className="campaign-banner-title">{t(campaign.texts + '.bannerTitle')}</strong>
70
- <span className="campaign-banner-text">{t(campaign.texts + '.text')}</span>
71
- <span className="campaign-banner-foot">
72
- <span className="campaign-banner-cta">
73
- {t(campaign.texts + '.cta')}
74
- <Icon name="arrow-right" size={18} stroke={2.2} />
75
- </span>
76
- <span className="campaign-banner-ends">
77
- <Icon name="clock" size={16} stroke={2} />
78
- {t(left.days ? 'autobahn:campaign.endsInDays' : 'autobahn:campaign.endsInHours', { ...left })}
79
- </span>
80
- </span>
81
- </span>
82
- </a>
83
- );
84
- };
85
-
86
- export default CampaignBanner;
@@ -1,37 +0,0 @@
1
- // Autobahn (auto.de redesign) — the campaign's bar right under the site header, one link to its offers
2
- // (see campaigns.ts). Used on fe-main's home page.
3
- //
4
- // Texts, colours and dates come from the campaign, the look from md3.css (.campaign-bar). Nothing is shown before
5
- // the campaign starts and after it has ended. Renders correctly only inside a `<div className="md3">` subtree.
6
-
7
- import React from 'react';
8
- import { TranslationFunction } from '../types';
9
-
10
- import { Icon } from '../ui';
11
- import { Campaign, isCampaignRunning } from './campaigns';
12
- import { campaignVars } from './campaignVars';
13
- import { openInApp } from './openInApp';
14
- import { useCountdown } from './useCountdown';
15
-
16
- export interface CampaignBarProps {
17
- campaign: Campaign;
18
- /** where the offers are; a real link (new tab, crawlers). */
19
- href: string;
20
- /** plain click: the app opens href itself, without loading the page anew. */
21
- onOpen: () => void;
22
- t: TranslationFunction;
23
- }
24
-
25
- const CampaignBar: React.FunctionComponent<CampaignBarProps> = ({ campaign, href, onOpen, t }) => {
26
- const left = useCountdown(campaign.endsAt); // the bar goes by itself when the campaign ends
27
- if (!left || !isCampaignRunning(campaign)) return null;
28
- return (
29
- <a className={'campaign-bar campaign-bar--' + campaign.id} style={campaignVars(campaign)} href={href} onClick={openInApp(onOpen)}>
30
- {campaign.icon && <Icon name={campaign.icon} size={16} stroke={2.2} />}
31
- <span className="campaign-bar-label">{t(campaign.texts + '.label')}:</span>
32
- <span className="campaign-bar-offer">{t(campaign.texts + '.offer')}</span>
33
- </a>
34
- );
35
- };
36
-
37
- export default CampaignBar;
@@ -1,50 +0,0 @@
1
- // Autobahn (auto.de redesign) — the campaign hero: period, headline and a running countdown to the end of the
2
- // campaign (design "auto.de SRL Black Friday", A · Dark Edition). Used on fe-main's /search.
3
- //
4
- // Texts and dates come from the campaign (campaigns.ts), the look from md3.css (.campaign-hero). Nothing is
5
- // shown before the campaign starts and after it has ended. Renders correctly only inside a
6
- // `<div className="md3">` subtree.
7
-
8
- import React from 'react';
9
- import { TranslationFunction } from '../types';
10
-
11
- import { Campaign, campaignPeriod, isCampaignRunning } from './campaigns';
12
- import { campaignVars } from './campaignVars';
13
- import { useCountdown } from './useCountdown';
14
-
15
- export interface CampaignHeroProps {
16
- campaign: Campaign;
17
- t: TranslationFunction;
18
- }
19
-
20
- const twoDigits = (n: number): string => (n < 10 ? '0' + n : String(n));
21
-
22
- const CampaignHero: React.FunctionComponent<CampaignHeroProps> = ({ campaign, t }) => {
23
- const left = useCountdown(campaign.endsAt);
24
- if (!left || !isCampaignRunning(campaign)) return null;
25
- const units: Array<[string, number]> = [['days', left.days], ['hours', left.hours], ['minutes', left.minutes]];
26
- return (
27
- <section
28
- className={'campaign-hero campaign-hero--' + campaign.id}
29
- style={campaignVars(campaign)}
30
- aria-label={t(campaign.texts + '.label')}
31
- >
32
- <div>
33
- <div className="campaign-hero-period">{t(campaign.texts + '.period', { ...campaignPeriod(campaign) })}</div>
34
- <h2 className="campaign-hero-title">{t(campaign.texts + '.title')}</h2>
35
- <p className="campaign-hero-text">{t(campaign.texts + '.text')}</p>
36
- </div>
37
- <div className="campaign-hero-timer" role="timer" aria-label={t('autobahn:campaign.timeLeft', { ...left })}>
38
- {units.map(([unit, value]) => (
39
- <div key={unit} className="campaign-hero-unit" aria-hidden="true">
40
- <b>{twoDigits(value)}</b>
41
- <small>{t('autobahn:campaign.' + unit, { count: value })}</small>
42
- </div>
43
- ))}
44
- </div>
45
- <div className="campaign-hero-legal">{t(campaign.texts + '.legal')}</div>
46
- </section>
47
- );
48
- };
49
-
50
- export default CampaignHero;
@@ -1,43 +0,0 @@
1
- // Autobahn (auto.de redesign) — "only the campaign's cars", the switch above the filters of /search
2
- // (see campaigns.ts). Which search filter it turns on is the page's business.
3
- //
4
- // The md3 Switch on the campaign's dark card: the whole card is its label, so all of it can be clicked.
5
- // Renders correctly only inside a `<div className="md3">` subtree.
6
-
7
- import React from 'react';
8
- import { TranslationFunction } from '../types';
9
-
10
- import { Switch } from '../ui';
11
- import { Campaign } from './campaigns';
12
- import { campaignVars } from './campaignVars';
13
-
14
- export interface CampaignSwitchProps {
15
- campaign: Campaign;
16
- checked: boolean;
17
- onChange: (checked: boolean) => void;
18
- /** how many cars the switch leaves; null = not known yet (the line stays free). */
19
- count: number | null;
20
- language: string;
21
- t: TranslationFunction;
22
- }
23
-
24
- const CampaignSwitch: React.FunctionComponent<CampaignSwitchProps> = ({ campaign, checked, onChange, count, language, t }) => (
25
- <div className={'campaign-switch campaign-switch--' + campaign.id} style={campaignVars(campaign)}>
26
- <Switch
27
- checked={checked}
28
- onChange={(event) => onChange(event.target.checked)}
29
- label={(
30
- <>
31
- {t(campaign.texts + '.only')}
32
- <span className="campaign-switch-count">
33
- {count != null
34
- ? t('autobahn:campaign.vehicles', { count, number: count.toLocaleString(language === 'en' ? 'en-IN' : 'de-DE') })
35
- : '\u00a0'}
36
- </span>
37
- </>
38
- )}
39
- />
40
- </div>
41
- );
42
-
43
- export default CampaignSwitch;
@@ -1,12 +0,0 @@
1
- import type React from 'react';
2
- import { Campaign } from './campaigns';
3
-
4
- /** .mcard--campaign uses the campaign's background as one of several layers, and only the last layer may be a
5
- * plain colour — so a colour becomes a one-colour gradient. */
6
- const asImage = (background: string): string =>
7
- /gradient\(|url\(/.test(background) ? background : `linear-gradient(${background} 0 0)`;
8
-
9
- /** A campaign's colours as CSS variables (md3.css: .campaign-band, .campaign-hero). A card sets them too (with
10
- * .mcard--campaign), so that its border takes the band's colour and the band reaches the edge of the card. */
11
- export const campaignVars = (campaign: Campaign): React.CSSProperties =>
12
- ({ '--campaign-bg': asImage(campaign.background), '--campaign-fg': campaign.color || '#fff' } as React.CSSProperties);
@@ -1,74 +0,0 @@
1
- // Autobahn (auto.de redesign) — campaigns ("Black Friday"): the band on top of the car cards and of the
2
- // vehicle page's gallery (CampaignBand), the hero with the countdown (CampaignHero), the switch "only its cars"
3
- // (CampaignSwitch), the bar under the site header (CampaignBar) and the banner with cars (CampaignBanner).
4
- //
5
- // A campaign is data; the cards and the hero do not know any campaign by name. Which campaign runs is the
6
- // app's decision (fe-main: source/framework/constants/campaign.ts); without one nothing is shown.
7
- //
8
- // A new campaign (e.g. New Year) = one entry in CAMPAIGNS + its texts under "campaign" in
9
- // locales/{de,en}/autobahn.json. The components and md3.css stay as they are.
10
-
11
- import type { AutobahnCar } from '../cards/types';
12
- import { dealSignals, DealSource } from '../cards/dealSignals';
13
-
14
- /** What a campaign may look at: the part a card's AutobahnCar and the vehicle page's VehicleDetail share. */
15
- export type CampaignCar = DealSource & Pick<AutobahnCar, 'make' | 'model' | 'trim' | 'km' | 'price' | 'fuel'>;
16
-
17
- export interface Campaign {
18
- /** kebab-case id; also the modifier class `campaign-band--<id>` / `campaign-hero--<id>`. */
19
- id: string;
20
- /** i18n path of the campaign's texts: label (band, bar), period, title, text, legal (hero), only (switch),
21
- * offer (bar), bannerTitle, cta (banner, with the hero's period and text). */
22
- texts: string;
23
- /** icon in front of the label of the band and the bar — a name from the ui/Icon registry. */
24
- icon?: string;
25
- /** a dark colour or gradient: it carries `color` and the white text of the hero and the switch. */
26
- background: string;
27
- /** band label and icon, the hero's period line, the switch when it is on; white by default. */
28
- color?: string;
29
- /** first and last moment, with the German UTC offset. Outside of it neither the band nor the hero is shown;
30
- * the hero's period line and its countdown come from here too. */
31
- startsAt: string;
32
- endsAt: string;
33
- /** which cars carry the band. */
34
- appliesTo: (car: CampaignCar) => boolean;
35
- }
36
-
37
- /** the card shows both the green "−X € zum UVP" and the red "−X %" chip. */
38
- export const hasPriceDropChips = (car: CampaignCar): boolean => {
39
- const { drop, percent } = dealSignals(car);
40
- return drop && percent;
41
- };
42
-
43
- const blackFriday: Campaign = {
44
- id: 'black-friday',
45
- texts: 'autobahn:campaign.blackFriday',
46
- icon: 'tag',
47
- // black and gold of the Black Friday design ("auto.de SRL Black Friday", A · Dark Edition)
48
- background: '#111317',
49
- color: '#f7c544',
50
- // 24.11.–01.12.2026, the last day included
51
- startsAt: '2026-11-24T00:00:00+01:00',
52
- endsAt: '2026-12-02T00:00:00+01:00',
53
- appliesTo: hasPriceDropChips,
54
- };
55
-
56
- export const CAMPAIGNS = { blackFriday };
57
-
58
- export const isCampaignRunning = (campaign: Campaign, now: number = Date.now()): boolean =>
59
- now >= Date.parse(campaign.startsAt) && now < Date.parse(campaign.endsAt);
60
-
61
- /** the campaign whose band this car carries, if any. */
62
- export const campaignFor = (car: CampaignCar, campaign?: Campaign | null): Campaign | null =>
63
- campaign && isCampaignRunning(campaign) && campaign.appliesTo(car) ? campaign : null;
64
-
65
- /** first and last day as the hero shows them, e.g. { from: '24.11.', to: '01.12.2026' } — German days,
66
- * wherever the visitor is. */
67
- export const campaignPeriod = (campaign: Campaign): { from: string; to: string } => {
68
- const day = (at: number, year: boolean): string =>
69
- new Intl.DateTimeFormat('de-DE', {
70
- day: '2-digit', month: '2-digit', year: year ? 'numeric' : undefined, timeZone: 'Europe/Berlin',
71
- }).format(at);
72
- // endsAt is the first moment after the campaign
73
- return { from: day(Date.parse(campaign.startsAt), false), to: day(Date.parse(campaign.endsAt) - 1, true) };
74
- };
package/campaign/index.ts DELETED
@@ -1,18 +0,0 @@
1
- export { default as CampaignBand } from './CampaignBand';
2
- export type { CampaignBandProps } from './CampaignBand';
3
-
4
- export { default as CampaignBanner } from './CampaignBanner';
5
- export type { CampaignBannerProps } from './CampaignBanner';
6
-
7
- export { default as CampaignBar } from './CampaignBar';
8
- export type { CampaignBarProps } from './CampaignBar';
9
-
10
- export { default as CampaignHero } from './CampaignHero';
11
- export type { CampaignHeroProps } from './CampaignHero';
12
-
13
- export { default as CampaignSwitch } from './CampaignSwitch';
14
- export type { CampaignSwitchProps } from './CampaignSwitch';
15
-
16
- export { CAMPAIGNS, campaignFor, campaignPeriod, hasPriceDropChips, isCampaignRunning } from './campaigns';
17
- export type { Campaign, CampaignCar } from './campaigns';
18
- export { campaignVars } from './campaignVars';
@@ -1,8 +0,0 @@
1
- import type React from 'react';
2
-
3
- /** Click on a campaign's link: a plain click opens it in the app, a new tab or window stays the browser's. */
4
- export const openInApp = (onOpen: () => void) => (event: React.MouseEvent): void => {
5
- if (event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return;
6
- event.preventDefault();
7
- onOpen();
8
- };
@@ -1,28 +0,0 @@
1
- import { useEffect, useState } from 'react';
2
-
3
- export interface Countdown {
4
- days: number;
5
- hours: number;
6
- minutes: number;
7
- }
8
-
9
- const MINUTE = 60 * 1000;
10
-
11
- const minutesLeft = (endsAt: string): number => Math.floor((Date.parse(endsAt) - Date.now()) / MINUTE);
12
-
13
- /**
14
- * The time left until `endsAt` in whole minutes, counting down by itself; null once it is over.
15
- * It looks at the clock every second instead of adding up minutes, so it is right again at once after the
16
- * tab slept or the computer woke up; React renders only when the minute changes.
17
- */
18
- export const useCountdown = (endsAt: string): Countdown | null => {
19
- const [left, setLeft] = useState(() => minutesLeft(endsAt));
20
- useEffect(() => {
21
- const tick = (): void => setLeft(minutesLeft(endsAt));
22
- tick();
23
- const timer = setInterval(tick, 1000);
24
- return () => clearInterval(timer);
25
- }, [endsAt]);
26
- if (!(left >= 0)) return null;
27
- return { days: Math.floor(left / 1440), hours: Math.floor(left / 60) % 24, minutes: left % 60 };
28
- };
@@ -1,36 +0,0 @@
1
- // Autobahn (auto.de redesign) — which deal signals a card shows for a car.
2
- //
3
- // One rule for CarCard, CarRow, the vehicle page's gallery and the campaigns (campaign/campaigns.ts), so "this card shows the green −X € and the
4
- // red −X % chip" means the same everywhere.
5
-
6
- import { AutobahnCar } from './types';
7
-
8
- export type DealSource = Pick<AutobahnCar, 'asGoodAsNew' | 'drop' | 'dropPct' | 'savings' | 'isNew' | 'zeroDown'>;
9
-
10
- export interface DealSignals {
11
- /** DropChip, "−X € zum UVP". */
12
- drop: boolean;
13
- /** SaveChip (only without a drop). */
14
- save: boolean;
15
- /** PercentChip, "−X %". */
16
- percent: boolean;
17
- /** OfferBadge, "Angebot". */
18
- offer: boolean;
19
- /** NEU badge. */
20
- neu: boolean;
21
- }
22
-
23
- export const dealSignals = (car: DealSource): DealSignals => {
24
- // as-good-as-new gate (mileage < 1,000 km AND first registration unknown or < 12 months) —
25
- // undefined (older AutobahnCar producer not yet updated) fails OPEN, keeping prior behaviour.
26
- const asGoodAsNew = car.asGoodAsNew !== false;
27
- const drop = asGoodAsNew && car.drop != null;
28
- const save = asGoodAsNew && !drop && car.savings != null && car.savings > 600;
29
- const percent = asGoodAsNew && car.dropPct != null && car.dropPct > 0;
30
- const offer = !!(car.isNew || drop || save || percent || car.zeroDown);
31
- // PM call: the badge row only fits 3 pills — when Drop/Save + Percent + ZeroDown are all
32
- // active that's already 3, so NEU is dropped rather than causing a 4th to overflow.
33
- const activeChips = [drop || save, percent, !!car.zeroDown].filter(Boolean).length;
34
- const neu = asGoodAsNew && !!car.isNew && activeChips < 3;
35
- return { drop, save, percent, offer, neu };
36
- };