@bytebrand/fe-ui-core-autobahn 1.0.182 → 1.0.183

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.
@@ -0,0 +1,103 @@
1
+ // Autobahn (auto.de redesign) — CarCard loading placeholder.
2
+ //
3
+ // The shape of a CarCard while its data is on the way: the same card chrome (.mcard
4
+ // .cc-card — border, 18px radius, shadow) and, inside it, the card's own parts as
5
+ // skeleton bars on the line boxes CarCard's CSS gives them, so a grid of these is as
6
+ // tall as the grid of cards that replaces it and nothing below jumps:
7
+ // - photo: 4:3 plus the carousel's 14px (that's how tall .cc-media really renders), on
8
+ // the lighter --md-sc-low so the big area stays calm and the text bars read as content
9
+ // - title 24/27 (+6), trim 13/17 (+6), spec line 11/15 (+10)
10
+ // - price block on its hairline: tabs (39, +12), rate + price rating (58), terms (2 × 17)
11
+ // - phones (≤600, .show-mobile): the CTA row (9 + 40)
12
+ // - eco line (8 + 3 × 11) pinned to the bottom, like the card's
13
+ // Measured against real cards at 1467 / 768 / 390 px (571 / 541 / 593 tall).
14
+ //
15
+ // Decorative only (aria-hidden): the grid that shows these says what is loading.
16
+ // Renders correctly only inside a `<div className="md3">` subtree.
17
+
18
+ import React from 'react';
19
+
20
+ import Skeleton, { injectStyles } from '../ui/Skeleton';
21
+
22
+ export interface CarCardSkeletonProps {
23
+ className?: string;
24
+ style?: React.CSSProperties;
25
+ }
26
+
27
+ const CARD_SKELETON_CSS = `
28
+ .md3 .cc-skel { display: flex; flex-direction: column; pointer-events: none; }
29
+ .md3 .cc-skel .cc-skel-photo { height: 0; padding-bottom: calc(75% + 14px); border-radius: 0; --mskeleton-base: var(--md-sc-low); }
30
+ .md3 .cc-skel .cc-skel-body { flex: 1; display: flex; flex-direction: column; align-items: flex-start; padding: 0 18px 8px; margin-top: -3px; }
31
+ .md3 .cc-skel .cc-skel-title { width: 62%; height: 20px; margin: 4px 0 9px; border-radius: var(--md-r-xs); }
32
+ .md3 .cc-skel .cc-skel-trim { width: 82%; height: 11px; margin: 3px 0 9px; border-radius: var(--md-r-full); }
33
+ .md3 .cc-skel .cc-skel-spec { width: 92%; height: 9px; margin: 3px 0 13px; border-radius: var(--md-r-full); }
34
+ .md3 .cc-skel .cc-skel-price { align-self: stretch; border-top: 1px solid var(--md-outline-variant); }
35
+ .md3 .cc-skel .cc-skel-tabs { display: grid; grid-template-columns: repeat(3, 1fr); align-items: center; justify-items: center; height: 39px; margin-bottom: 12px; }
36
+ .md3 .cc-skel .cc-skel-tabs .mskeleton { width: 56%; height: 12px; border-radius: var(--md-r-full); }
37
+ .md3 .cc-skel .cc-skel-hero { display: flex; align-items: center; justify-content: space-between; gap: 12px; height: 58px; }
38
+ .md3 .cc-skel .cc-skel-rate { width: 46%; height: 42px; border-radius: var(--md-r-xs); }
39
+ .md3 .cc-skel .cc-skel-eval { display: flex; flex-direction: column; align-items: flex-end; gap: 10px; width: 112px; flex: none; }
40
+ .md3 .cc-skel .cc-skel-eval .mskeleton:first-child { width: 72px; height: 12px; border-radius: var(--md-r-full); }
41
+ .md3 .cc-skel .cc-skel-eval .mskeleton:last-child { width: 100%; height: 7px; border-radius: var(--md-r-full); }
42
+ .md3 .cc-skel .cc-skel-terms,
43
+ .md3 .cc-skel .cc-skel-eco { display: flex; flex-direction: column; }
44
+ .md3 .cc-skel .cc-skel-terms .mskeleton { width: 94%; height: 9px; margin: 4px 0; border-radius: var(--md-r-full); }
45
+ .md3 .cc-skel .cc-skel-terms .mskeleton:last-child { width: 60%; }
46
+ .md3 .cc-skel .cc-skel-cta { align-self: stretch; gap: 6px; margin-top: 9px; }
47
+ .md3 .cc-skel .cc-skel-cta .mskeleton { flex: 1.3 1 0; height: 40px; border-radius: var(--md-r-full); }
48
+ .md3 .cc-skel .cc-skel-cta .mskeleton:nth-child(2) { flex: none; width: 40px; }
49
+ .md3 .cc-skel .cc-skel-cta .mskeleton:last-child { flex: 1 1 0; }
50
+ .md3 .cc-skel .cc-skel-eco { align-self: stretch; margin-top: auto; padding-top: 8px; }
51
+ .md3 .cc-skel .cc-skel-eco .mskeleton { height: 7px; margin: 2px 0; border-radius: var(--md-r-full); }
52
+ .md3 .cc-skel .cc-skel-eco .mskeleton:last-child { width: 66%; }
53
+ @media (max-width: 1024px) {
54
+ .md3 .cc-skel .cc-skel-tabs { height: 38px; }
55
+ }`;
56
+
57
+ const CARD_SKELETON_STYLE_ID = 'md3-card-skeleton-styles';
58
+
59
+ injectStyles(CARD_SKELETON_STYLE_ID, CARD_SKELETON_CSS);
60
+
61
+ const CarCardSkeleton: React.FunctionComponent<CarCardSkeletonProps> = ({ className, style }) => {
62
+ React.useEffect(() => { injectStyles(CARD_SKELETON_STYLE_ID, CARD_SKELETON_CSS); }, []);
63
+ return (
64
+ <div className={'mcard cc-card cc-skel' + (className ? ` ${className}` : '')} style={style} aria-hidden="true">
65
+ <Skeleton className="cc-skel-photo" />
66
+ <div className="cc-skel-body">
67
+ <Skeleton className="cc-skel-title" />
68
+ <Skeleton className="cc-skel-trim" />
69
+ <Skeleton className="cc-skel-spec" />
70
+ <div className="cc-skel-price">
71
+ <div className="cc-skel-tabs">
72
+ <Skeleton />
73
+ <Skeleton />
74
+ <Skeleton />
75
+ </div>
76
+ <div className="cc-skel-hero">
77
+ <Skeleton className="cc-skel-rate" />
78
+ <div className="cc-skel-eval">
79
+ <Skeleton />
80
+ <Skeleton />
81
+ </div>
82
+ </div>
83
+ <div className="cc-skel-terms">
84
+ <Skeleton />
85
+ <Skeleton />
86
+ </div>
87
+ </div>
88
+ <div className="cc-skel-cta show-mobile">
89
+ <Skeleton />
90
+ <Skeleton />
91
+ <Skeleton />
92
+ </div>
93
+ <div className="cc-skel-eco">
94
+ <Skeleton />
95
+ <Skeleton />
96
+ <Skeleton />
97
+ </div>
98
+ </div>
99
+ </div>
100
+ );
101
+ };
102
+
103
+ export default CarCardSkeleton;
@@ -0,0 +1,152 @@
1
+ // Autobahn (auto.de redesign) — CarRow (SRP list row) loading placeholder.
2
+ //
3
+ // Built on CarRow's own classes (.mcard .listcard / .listcard-info / .specstrip /
4
+ // .listcard-price), so the 320 | 1fr | 240 grid, the column paddings and gaps, the grey
5
+ // price column and the tablet re-flow (≤980: photo + info, price full width below) all
6
+ // come from the same CSS as the real row. Inside, the row's parts as skeleton bars on their
7
+ // line boxes (measured against real rows at 1467 px, 299 / 348 tall):
8
+ // - info: title 22 + trim 18 · spec panel (2 × 3 facts, 85) · feature chips (2 rows, 54)
9
+ // · eco line (3 × 14) at the bottom
10
+ // - price: "Finanzierung ab" + rate + terms (87) · Leasing (66, optional) · Kaufen,
11
+ // rating + meter, CTA (129) at the bottom
12
+ // `withLeasing` toggles the Leasing block, the one thing that changes a real row's height
13
+ // (348 with it, 299 without), so a list can mix both like real results do.
14
+ //
15
+ // Bars on the grey panels (spec strip, price column) use a darker base so they read on
16
+ // --md-sc-low. Decorative only (aria-hidden): the list showing these says what is loading.
17
+ // Renders correctly only inside a `<div className="md3">` subtree.
18
+
19
+ import React from 'react';
20
+
21
+ import Skeleton, { injectStyles } from '../ui/Skeleton';
22
+
23
+ export interface CarRowSkeletonProps {
24
+ /** show the Leasing block in the price column (a real row has it when the car can be leased). */
25
+ withLeasing?: boolean;
26
+ className?: string;
27
+ style?: React.CSSProperties;
28
+ }
29
+
30
+ const ROW_SKELETON_CSS = `
31
+ .md3 .lc-skel { pointer-events: none; background: var(--md-sc-lowest); }
32
+ .md3 .lc-skel .lc-skel-photo { position: absolute; inset: 0; border-radius: 0; --mskeleton-base: var(--md-sc-low); }
33
+ .md3 .lc-skel .specstrip .mskeleton,
34
+ .md3 .lc-skel .listcard-price .mskeleton { --mskeleton-base: var(--md-sc-highest); }
35
+ .md3 .lc-skel .lc-skel-head { display: flex; flex-direction: column; }
36
+ .md3 .lc-skel .lc-skel-title { width: 44%; height: 16px; margin: 3px 0; border-radius: var(--md-r-xs); }
37
+ .md3 .lc-skel .lc-skel-trim { width: 68%; height: 10px; margin: 4px 0; border-radius: var(--md-r-full); }
38
+ .md3 .lc-skel .lc-skel-fact { display: flex; align-items: center; gap: 7px; height: 15px; }
39
+ .md3 .lc-skel .lc-skel-fact .mskeleton:first-child { flex: none; width: 15px; height: 15px; border-radius: 50%; }
40
+ .md3 .lc-skel .lc-skel-fact .mskeleton:last-child { width: 62%; height: 8px; border-radius: var(--md-r-full); }
41
+ .md3 .lc-skel .lc-skel-fact:nth-child(3n + 2) .mskeleton:last-child { width: 48%; }
42
+ .md3 .lc-skel .lc-skel-chips { display: flex; flex-wrap: wrap; gap: 6px; }
43
+ .md3 .lc-skel .lc-skel-chips .mskeleton { height: 24px; border-radius: 8px; }
44
+ .md3 .lc-skel .lc-skel-chips .mskeleton:nth-child(1) { width: 118px; }
45
+ .md3 .lc-skel .lc-skel-chips .mskeleton:nth-child(2) { width: 112px; }
46
+ .md3 .lc-skel .lc-skel-chips .mskeleton:nth-child(3) { width: 80px; }
47
+ .md3 .lc-skel .lc-skel-chips .mskeleton:nth-child(4) { width: 86px; }
48
+ .md3 .lc-skel .lc-skel-spacer { flex: 1; }
49
+ .md3 .lc-skel .lc-skel-eco { display: flex; flex-direction: column; }
50
+ .md3 .lc-skel .lc-skel-eco .mskeleton { height: 7px; margin: 4px 0 3px; border-radius: var(--md-r-full); }
51
+ .md3 .lc-skel .lc-skel-eco .mskeleton:last-child { width: 55%; }
52
+ .md3 .lc-skel .lc-skel-paths { display: flex; flex-direction: column; align-items: flex-start; }
53
+ .md3 .lc-skel .lc-skel-eyebrow { width: 96px; height: 9px; margin: 2px 0; border-radius: var(--md-r-full); }
54
+ .md3 .lc-skel .lc-skel-rate { display: flex; align-items: center; gap: 8px; height: 49px; margin-top: 4px; }
55
+ .md3 .lc-skel .lc-skel-rate .mskeleton:first-child { width: 120px; height: 38px; border-radius: var(--md-r-xs); }
56
+ .md3 .lc-skel .lc-skel-rate .mskeleton:last-child { width: 28px; height: 9px; border-radius: var(--md-r-full); }
57
+ .md3 .lc-skel .lc-skel-terms { width: 170px; max-width: 100%; height: 8px; margin: 11px 0 2px; border-radius: var(--md-r-full); }
58
+ .md3 .lc-skel .lc-skel-lease,
59
+ .md3 .lc-skel .lc-skel-buy { display: flex; flex-direction: column; border-top: 1px solid var(--md-outline-variant); }
60
+ .md3 .lc-skel .lc-skel-lease { padding-top: 14px; }
61
+ .md3 .lc-skel .lc-skel-line { display: flex; align-items: center; justify-content: space-between; gap: 10px; height: 21px; }
62
+ .md3 .lc-skel .lc-skel-line .mskeleton:first-child { width: 56px; height: 9px; border-radius: var(--md-r-full); }
63
+ .md3 .lc-skel .lc-skel-line .mskeleton:last-child { width: 72px; height: 15px; border-radius: var(--md-r-xs); }
64
+ .md3 .lc-skel .lc-skel-lease-terms { display: flex; flex-direction: column; margin-top: 6px; }
65
+ .md3 .lc-skel .lc-skel-lease-terms .mskeleton { height: 7px; margin: 2px 0 3px; border-radius: var(--md-r-full); }
66
+ .md3 .lc-skel .lc-skel-lease-terms .mskeleton:last-child { width: 62%; }
67
+ .md3 .lc-skel .lc-skel-buy { margin-top: auto; padding-top: 9px; }
68
+ .md3 .lc-skel .lc-skel-buy .lc-skel-line { height: 22px; }
69
+ .md3 .lc-skel .lc-skel-eval { display: flex; align-items: center; gap: 10px; height: 24px; margin-top: 15px; }
70
+ .md3 .lc-skel .lc-skel-eval .mskeleton:first-child { flex: none; width: 84px; height: 24px; border-radius: 12px; }
71
+ .md3 .lc-skel .lc-skel-eval .mskeleton:last-child { flex: 1; height: 8px; border-radius: var(--md-r-full); }
72
+ .md3 .lc-skel .lc-skel-cta { height: 40px; margin-top: 18px; border-radius: var(--md-r-full); }`;
73
+
74
+ const ROW_SKELETON_STYLE_ID = 'md3-row-skeleton-styles';
75
+
76
+ injectStyles(ROW_SKELETON_STYLE_ID, ROW_SKELETON_CSS);
77
+
78
+ const FACTS = [0, 1, 2, 3, 4, 5];
79
+
80
+ const CarRowSkeleton: React.FunctionComponent<CarRowSkeletonProps> = ({ withLeasing = true, className, style }) => {
81
+ React.useEffect(() => { injectStyles(ROW_SKELETON_STYLE_ID, ROW_SKELETON_CSS); }, []);
82
+ return (
83
+ <div className={'mcard listcard lc-skel' + (className ? ` ${className}` : '')} style={style} aria-hidden="true">
84
+ <div className="listcard-media">
85
+ <Skeleton className="lc-skel-photo" />
86
+ </div>
87
+
88
+ <div className="listcard-info">
89
+ <div className="lc-skel-head">
90
+ <Skeleton className="lc-skel-title" />
91
+ <Skeleton className="lc-skel-trim" />
92
+ </div>
93
+ <div className="specstrip">
94
+ {FACTS.map((fact) => (
95
+ <div key={fact} className="lc-skel-fact">
96
+ <Skeleton />
97
+ <Skeleton />
98
+ </div>
99
+ ))}
100
+ </div>
101
+ <div className="lc-skel-chips">
102
+ <Skeleton />
103
+ <Skeleton />
104
+ <Skeleton />
105
+ <Skeleton />
106
+ </div>
107
+ <div className="lc-skel-spacer" />
108
+ <div className="lc-skel-eco">
109
+ <Skeleton />
110
+ <Skeleton />
111
+ <Skeleton />
112
+ </div>
113
+ </div>
114
+
115
+ <div className="listcard-price">
116
+ <div className="lc-skel-paths">
117
+ <Skeleton className="lc-skel-eyebrow" />
118
+ <div className="lc-skel-rate">
119
+ <Skeleton />
120
+ <Skeleton />
121
+ </div>
122
+ <Skeleton className="lc-skel-terms" />
123
+ </div>
124
+ {withLeasing && (
125
+ <div className="lc-skel-lease">
126
+ <div className="lc-skel-line">
127
+ <Skeleton />
128
+ <Skeleton />
129
+ </div>
130
+ <div className="lc-skel-lease-terms">
131
+ <Skeleton />
132
+ <Skeleton />
133
+ </div>
134
+ </div>
135
+ )}
136
+ <div className="lc-skel-buy">
137
+ <div className="lc-skel-line">
138
+ <Skeleton />
139
+ <Skeleton />
140
+ </div>
141
+ <div className="lc-skel-eval">
142
+ <Skeleton />
143
+ <Skeleton />
144
+ </div>
145
+ <Skeleton className="lc-skel-cta" />
146
+ </div>
147
+ </div>
148
+ </div>
149
+ );
150
+ };
151
+
152
+ export default CarRowSkeleton;
package/cards/index.ts CHANGED
@@ -11,6 +11,12 @@ export type { CarCardProps } from './CarCard';
11
11
  export { default as CarRow } from './CarRow';
12
12
  export type { CarRowProps } from './CarRow';
13
13
 
14
+ export { default as CarCardSkeleton } from './CarCardSkeleton';
15
+ export type { CarCardSkeletonProps } from './CarCardSkeleton';
16
+
17
+ export { default as CarRowSkeleton } from './CarRowSkeleton';
18
+ export type { CarRowSkeletonProps } from './CarRowSkeleton';
19
+
14
20
  export {
15
21
  fmtKm,
16
22
  cardSpec,
@@ -42,6 +42,20 @@ import { TIER_LABELS, RatingTier, CO2_CLASSES, Co2Class } from '../constants/aut
42
42
  export const PLACEHOLDER_IMAGE =
43
43
  'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==';
44
44
 
45
+ /**
46
+ * The app-wide no-image asset, set ONCE at app start (fe-main's index.tsx passes its
47
+ * PLACEHOLDER_IMAGE_LARGE_URL, built from config.imagesAPI.imgUrlBase) — so every card that
48
+ * maps a car without a photo shows the "noimage" picture, not the transparent data URI above,
49
+ * without each page having to remember `deps.placeholder` (most didn't: the home page, /search,
50
+ * favourites and the dashboard all rendered an empty white photo). `deps.placeholder` still
51
+ * wins per call; the data URI stays the last resort (tests, an app that never sets this).
52
+ */
53
+ let defaultPlaceholder: string = PLACEHOLDER_IMAGE;
54
+
55
+ export function setPlaceholderImage(url: string): void {
56
+ defaultPlaceholder = url || PLACEHOLDER_IMAGE;
57
+ }
58
+
45
59
  /**
46
60
  * Dependencies the SRP container injects. Everything here is what the mapper
47
61
  * needs from the outside world — keeping the function itself pure.
@@ -67,7 +81,7 @@ export interface ToAutobahnCarDeps {
67
81
  t?: (key: string, options?: object) => string;
68
82
  /** active UI language ('de' | 'en' …). Drives de-DE vs en-IN number grouping for the EnVKV line. */
69
83
  language?: string;
70
- /** placeholder image URL override (defaults to PLACEHOLDER_IMAGE). */
84
+ /** placeholder image URL override (defaults to the one set with setPlaceholderImage). */
71
85
  placeholder?: string;
72
86
  /**
73
87
  * Buyer-activity stats for this car — UserActionsAPI 'stats/viewers' response, loaded async and
@@ -272,7 +286,7 @@ function isPluginHybrid(fuel: any): boolean {
272
286
  * `sizeOverride` lets a caller ask for a different size than `deps.imageSize` (e.g. a full-res
273
287
  * set for a lightbox, while the card thumbnail itself stays on the smaller default). */
274
288
  function buildGallery(storeCar: any, deps: ToAutobahnCarDeps, sizeOverride?: 'small' | 'medium' | 'large'): string[] {
275
- const placeholder = deps.placeholder || PLACEHOLDER_IMAGE;
289
+ const placeholder = deps.placeholder || defaultPlaceholder;
276
290
  // Only 'small' and 'large' variants are pre-generated by image-generator; 'medium' has no cached file.
277
291
  const size = sizeOverride || deps.imageSize || 'small';
278
292
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bytebrand/fe-ui-core-autobahn",
3
- "version": "1.0.182",
3
+ "version": "1.0.183",
4
4
  "description": "auto.de md3 (Autobahn) design system — UI primitives, cards, chrome, VDP modules, theme CSS and locales. Ships raw TypeScript source (like fe-ui-core before it); each consumer's bundler compiles it.",
5
5
  "main": "index.ts",
6
6
  "license": "UNLICENSED",
package/ui/Skeleton.tsx CHANGED
@@ -1,16 +1,31 @@
1
1
  // Autobahn (auto.de redesign) — md3 loading skeleton.
2
2
  //
3
- // md3.css ships no skeleton class, so this is the ONE addition covering every
4
- // legacy `Skeleton`/`SkeletonItem` (MUI) call site: a div with an animated
5
- // gradient shimmer built from --md surface tokens. Prop surface mirrors the
6
- // subset fe-main actually used (variant / width / height / className / style;
7
- // `animation` is accepted and ignored — the shimmer always runs).
3
+ // md3.css ships no skeleton class, so this component brings its own CSS. It is the ONE
4
+ // skeleton for every block (and every legacy `Skeleton`/`SkeletonItem` MUI call site):
5
+ // a block with a light passing over it, built from --md surface tokens. Prop surface
6
+ // mirrors the subset fe-main used (variant / width / height / className / style;
7
+ // `animation` is accepted and ignored — the sweep always runs) plus `tone`.
8
8
  // Renders correctly only inside a `<div className="md3">` subtree.
9
+ //
10
+ // - tone 'surface' (default): grey blocks on the light page surfaces.
11
+ // - tone 'inverse': white-alpha blocks for the brand/dark surfaces (the home hero's blue
12
+ // gradient, the label inside a filled button).
13
+ // - The base and the passing light are CSS custom properties (--mskeleton-base /
14
+ // --mskeleton-shine), so a block can retune both for its own background.
15
+ // - The light is a ::after band moved with transform only, so it runs on the compositor
16
+ // and stays smooth while the main thread is busy loading — exactly when skeletons show.
17
+ // The band is 60vw wide whatever the bar's width, so it travels at one speed: bars
18
+ // stacked on one left edge (a heading over copy lines) light up together.
19
+ // - prefers-reduced-motion: no sweep, a slow fade of the block instead.
20
+ // - Skeletons are aria-hidden; the region showing them carries aria-busy and a visually
21
+ // hidden `<span className="mskeleton-sr" role="status">…lädt…</span>` saying what loads.
9
22
 
10
23
  import React from 'react';
11
24
 
12
25
  export interface SkeletonProps {
13
26
  variant?: 'text' | 'rectangular' | 'circular';
27
+ /** 'surface' (default) on light surfaces, 'inverse' on the brand blue / dark surfaces. */
28
+ tone?: 'surface' | 'inverse';
14
29
  width?: number | string;
15
30
  height?: number | string;
16
31
  className?: string;
@@ -22,35 +37,78 @@ export interface SkeletonProps {
22
37
 
23
38
  const SKELETON_CSS = `
24
39
  .md3 .mskeleton {
40
+ --mskeleton-base: var(--md-sc);
41
+ --mskeleton-shine: rgba(255, 255, 255, .9);
42
+ position: relative;
25
43
  display: block;
26
- background: linear-gradient(90deg, var(--md-sc) 25%, var(--md-sc-high, var(--md-sc-lowest)) 37%, var(--md-sc) 63%);
27
- background-size: 400% 100%;
28
- animation: md3-skeleton-shimmer 1.4s ease infinite;
44
+ overflow: hidden;
29
45
  border-radius: var(--md-r-sm);
46
+ background-color: var(--mskeleton-base);
47
+ }
48
+ .md3 .mskeleton::after {
49
+ content: '';
50
+ position: absolute;
51
+ top: 0;
52
+ bottom: 0;
53
+ left: 0;
54
+ width: 60vw;
55
+ background: linear-gradient(100deg, rgba(255, 255, 255, 0) 30%, var(--mskeleton-shine) 50%, rgba(255, 255, 255, 0) 70%);
56
+ transform: translateX(-100%);
57
+ animation: md3-skeleton-sweep 1.8s cubic-bezier(.4, 0, .2, 1) infinite;
58
+ pointer-events: none;
59
+ }
60
+ .md3 .mskeleton--inverse {
61
+ --mskeleton-base: rgba(255, 255, 255, .14);
62
+ --mskeleton-shine: rgba(255, 255, 255, .26);
30
63
  }
31
64
  .md3 .mskeleton--text { border-radius: var(--md-r-xs, 4px); transform: scale(1, 0.7); }
65
+ .md3 .mskeleton-sr {
66
+ position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; border: 0;
67
+ overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
68
+ }
32
69
  .md3 .mskeleton--circular { border-radius: 50%; }
33
- @keyframes md3-skeleton-shimmer {
34
- 0% { background-position: 100% 50%; }
35
- 100% { background-position: 0 50%; }
70
+ @keyframes md3-skeleton-sweep {
71
+ 0% { transform: translateX(-100%); }
72
+ 70%, 100% { transform: translateX(100vw); }
73
+ }
74
+ @keyframes md3-skeleton-fade {
75
+ 50% { opacity: .55; }
76
+ }
77
+ @media (prefers-reduced-motion: reduce) {
78
+ .md3 .mskeleton::after { display: none; }
79
+ .md3 .mskeleton { animation: md3-skeleton-fade 2.4s ease-in-out infinite; }
36
80
  }`;
37
81
 
38
82
  const SKELETON_STYLE_ID = 'md3-skeleton-styles';
39
83
 
40
- // one <style id> in document.head no matter how many skeletons mount — the same
41
- // pattern fe-main's VehicleSmallCardMd3 uses. SSR-safe (guarded document access).
42
- function ensureStylesInjected(): void {
43
- if (typeof document === 'undefined' || document.getElementById(SKELETON_STYLE_ID)) {
84
+ /**
85
+ * One <style id> in document.head per stylesheet, no matter how many components mount.
86
+ * Called when a module loads (and again from the component), so the very first frame of a
87
+ * skeleton is already styled — an unstyled <span> would render as nothing for a frame and
88
+ * then pop in. A stale copy (an older bundle, hot reload) is overwritten. SSR-safe.
89
+ * Shared with the other skeleton shapes (e.g. cards/CarCardSkeleton).
90
+ */
91
+ export function injectStyles(id: string, css: string): void {
92
+ if (typeof document === 'undefined') {
44
93
  return;
45
94
  }
46
- const style = document.createElement('style');
47
- style.id = SKELETON_STYLE_ID;
48
- style.innerHTML = SKELETON_CSS;
49
- document.head.appendChild(style);
95
+ let style = document.getElementById(id);
96
+ if (!style) {
97
+ style = document.createElement('style');
98
+ style.id = id;
99
+ document.head.appendChild(style);
100
+ }
101
+ if (style.textContent !== css) {
102
+ style.textContent = css;
103
+ }
50
104
  }
51
105
 
106
+ const ensureStylesInjected = (): void => injectStyles(SKELETON_STYLE_ID, SKELETON_CSS);
107
+
108
+ ensureStylesInjected();
109
+
52
110
  const Skeleton: React.FunctionComponent<SkeletonProps> = ({
53
- variant = 'rectangular', width, height, className, style, children,
111
+ variant = 'rectangular', tone = 'surface', width, height, className, style, children,
54
112
  }) => {
55
113
  React.useEffect(() => { ensureStylesInjected(); }, []);
56
114
  const dims: React.CSSProperties = {};
@@ -62,6 +120,7 @@ const Skeleton: React.FunctionComponent<SkeletonProps> = ({
62
120
  className={
63
121
  'mskeleton' +
64
122
  (variant !== 'rectangular' ? ` mskeleton--${variant}` : '') +
123
+ (tone !== 'surface' ? ` mskeleton--${tone}` : '') +
65
124
  (className ? ` ${className}` : '')
66
125
  }
67
126
  style={{ ...dims, ...style }}