basalt-ui 2.16.0 → 2.17.0

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.
Files changed (89) hide show
  1. package/CHANGELOG.md +149 -126
  2. package/MIGRATING.md +101 -15
  3. package/agent/agents/basalt-design-reviewer.md +2 -2
  4. package/agent/skills/basalt-design/SKILL.md +2 -2
  5. package/configs/oxlint-plugin.js +2 -2
  6. package/dist/charts/Donut.d.ts.map +1 -1
  7. package/dist/charts/Donut.js +2 -2
  8. package/dist/charts/DualPanel.js +2 -2
  9. package/dist/charts/Heatmap.d.ts.map +1 -1
  10. package/dist/charts/Heatmap.js +2 -2
  11. package/dist/charts/MirroredBars.js +2 -2
  12. package/dist/charts/Sparkline.d.ts +4 -2
  13. package/dist/charts/Sparkline.d.ts.map +1 -1
  14. package/dist/charts/Sparkline.js +3 -3
  15. package/dist/charts/compile.d.ts +8 -3
  16. package/dist/charts/compile.d.ts.map +1 -1
  17. package/dist/charts/compile.js +19 -9
  18. package/dist/charts/cursor.d.ts +14 -1
  19. package/dist/charts/cursor.d.ts.map +1 -1
  20. package/dist/charts/cursor.js +29 -3
  21. package/dist/charts/date-tick-format.d.ts +17 -0
  22. package/dist/charts/date-tick-format.d.ts.map +1 -0
  23. package/dist/charts/date-tick-format.js +81 -0
  24. package/dist/charts/panel.d.ts +2 -1
  25. package/dist/charts/panel.d.ts.map +1 -1
  26. package/dist/charts/panel.js +3 -2
  27. package/dist/charts/types.d.ts +5 -1
  28. package/dist/charts/types.d.ts.map +1 -1
  29. package/dist/cli/shot/capture.d.ts +16 -0
  30. package/dist/cli/shot/capture.d.ts.map +1 -1
  31. package/dist/cli/shot/capture.js +24 -3
  32. package/dist/cli/shot/playwright.d.ts +4 -0
  33. package/dist/cli/shot/playwright.d.ts.map +1 -1
  34. package/dist/dashboard/delta-badge.d.ts +2 -2
  35. package/dist/dashboard/delta-badge.d.ts.map +1 -1
  36. package/dist/dashboard/delta-badge.js +12 -14
  37. package/dist/dashboard/query-state.d.ts +35 -0
  38. package/dist/dashboard/query-state.d.ts.map +1 -1
  39. package/dist/dashboard/query-state.js +12 -1
  40. package/dist/dashboard/stat-card-parts.d.ts +40 -0
  41. package/dist/dashboard/stat-card-parts.d.ts.map +1 -0
  42. package/dist/dashboard/stat-card-parts.js +55 -0
  43. package/dist/dashboard/stat-card.d.ts +46 -34
  44. package/dist/dashboard/stat-card.d.ts.map +1 -1
  45. package/dist/dashboard/stat-card.js +148 -79
  46. package/dist/dashboard/stat-card.module.css +220 -7
  47. package/dist/dashboard/stat-card.module.css.d.ts +20 -0
  48. package/dist/dashboard/widget-header.d.ts.map +1 -1
  49. package/dist/dashboard/widget-header.js +73 -9
  50. package/dist/dashboard/widget-header.module.css +25 -17
  51. package/dist/guard/index.js +2 -2
  52. package/dist/theme/chrome-vars.d.ts +82 -0
  53. package/dist/theme/chrome-vars.d.ts.map +1 -0
  54. package/dist/theme/chrome-vars.js +36 -0
  55. package/dist/theme/controls.module.css +20 -1
  56. package/dist/theme/controls.module.css.d.ts +1 -0
  57. package/dist/theme/index.d.ts.map +1 -1
  58. package/dist/theme/index.js +30 -33
  59. package/dist/tokens/derive.d.ts.map +1 -1
  60. package/dist/tokens/derive.js +2 -2
  61. package/llms.txt +6 -3
  62. package/package.json +1 -1
  63. package/src/charts/Donut.tsx +2 -2
  64. package/src/charts/DualPanel.tsx +2 -2
  65. package/src/charts/Heatmap.tsx +2 -2
  66. package/src/charts/MirroredBars.tsx +2 -2
  67. package/src/charts/Sparkline.tsx +7 -5
  68. package/src/charts/compile.ts +31 -11
  69. package/src/charts/cursor.ts +48 -3
  70. package/src/charts/date-tick-format.ts +132 -0
  71. package/src/charts/panel.tsx +5 -3
  72. package/src/charts/types.ts +5 -1
  73. package/src/cli/shot/capture.ts +35 -3
  74. package/src/cli/shot/playwright.ts +1 -1
  75. package/src/dashboard/delta-badge.tsx +24 -18
  76. package/src/dashboard/query-state.tsx +38 -0
  77. package/src/dashboard/stat-card-parts.tsx +108 -0
  78. package/src/dashboard/stat-card.module.css +220 -7
  79. package/src/dashboard/stat-card.module.css.d.ts +20 -0
  80. package/src/dashboard/stat-card.tsx +282 -174
  81. package/src/dashboard/widget-header.module.css +25 -17
  82. package/src/dashboard/widget-header.tsx +103 -7
  83. package/src/guard/index.ts +2 -2
  84. package/src/theme/__snapshots__/plain-theme.test.ts.snap +128 -40
  85. package/src/theme/chrome-vars.ts +111 -0
  86. package/src/theme/controls.module.css +20 -1
  87. package/src/theme/controls.module.css.d.ts +1 -0
  88. package/src/theme/index.ts +39 -101
  89. package/src/tokens/derive.ts +7 -2
@@ -20,7 +20,7 @@ import { useCallback } from 'react'
20
20
  import type { ReactElement } from 'react'
21
21
  import { ChartShell } from './CartesianChart'
22
22
  import type { ChartShellProps, ShellContext } from './CartesianChart'
23
- import { defaultFormatX, engineRow, utcHeaderDate, visibleSeries, xGuide, yGuide } from './compile'
23
+ import { engineRow, utcHeaderDate, visibleSeries, xGuide, xTickFormat, yGuide } from './compile'
24
24
  import type { CartesianDefinition } from './compile'
25
25
  import { cursorBinding, followerOptions, quietWhileFollowing } from './cursor'
26
26
  import { plotAccess } from './plot-context'
@@ -110,7 +110,8 @@ type ChartScale = NonNullable<StoredChartSpec['scales'][string]>['scale']
110
110
  export const paneX = <X extends ChartX>(opts: {
111
111
  scale: ChartScale
112
112
  model: XScaleModel<X>
113
- format: (v: ChartValue) => string
113
+ /** A consumer's x format; absent, the span-aware default ({@link xTickFormat}). */
114
+ format?: ((v: ChartValue) => string) | undefined
114
115
  cls: ContainerClass
115
116
  /** The whole chart's height ({@link chartHeightOf}). */
116
117
  height: number
@@ -204,10 +205,11 @@ function panelDefinition<T, X extends ChartX>(
204
205
  const owned = new Set(series.map((s) => s.key))
205
206
  const visible = visibleSeries(series, hidden)
206
207
  const hiddenSeries = series.filter((s) => !visible.includes(s))
208
+ const headerFormat = xTickFormat(formatX ? (v: ChartValue) => formatX(v as X) : undefined, [])
207
209
  const header = (v: ChartValue, d: T): string => {
208
210
  if (tooltip?.formatHeader) return tooltip.formatHeader(v as X, d)
209
211
  if (v instanceof Date && !formatX) return utcHeaderDate(v)
210
- return formatX ? formatX(v as X) : defaultFormatX(v)
212
+ return headerFormat(v)
211
213
  }
212
214
  const definition: CartesianDefinition = {
213
215
  chart: () => composed,
@@ -303,7 +303,11 @@ export type CartesianChartProps<T, X extends ChartX = ChartX> = BasaltProps & {
303
303
  * extent (and warns in dev). A no-op on a string or band x (`Bars`, `MirroredBars`, `BandStrip`).
304
304
  */
305
305
  xDomain?: readonly [X, X] | undefined
306
- /** Tick label for an x value. Default: `DD.MM` for dates, compact numbers, strings verbatim. */
306
+ /**
307
+ * Tick label for an x value. Default: compact numbers, strings verbatim, and dates by tick step
308
+ * (`HH:MM` with the day on midnight, `DD.MM`, a month with the year on January; a label recurs
309
+ * only behind a day or year label).
310
+ */
307
311
  formatX?: ((x: X) => string) | undefined
308
312
  zones?: readonly ZoneSpec[] | undefined
309
313
  xZones?: readonly XZoneSpec<X>[] | undefined
@@ -225,6 +225,38 @@ export const tooltipSelector = (describedBy: string): string =>
225
225
  ? `[role="tooltip"][id=${JSON.stringify(describedBy)}]`
226
226
  : '[role="tooltip"]:not([data-shot-seen])'
227
227
 
228
+ /** `tooltipSelector`, narrowed to a rendered readout: a hidden 0×0 one of another chart never wins `.first()`. */
229
+ export const visibleTooltip = (describedBy: string): string =>
230
+ `${tooltipSelector(describedBy)}:visible`
231
+
232
+ /**
233
+ * Where a trigger is hovered: its centre, or the `data-shot-at="x,y"` fractions of its box when the
234
+ * centre paints no readout (a donut's hole).
235
+ */
236
+ export function hoverAtOf(el: Element | null): string {
237
+ return el?.getAttribute('data-shot-at') ?? ''
238
+ }
239
+
240
+ const HOVER_AT = /^\s*(\d*\.?\d+)\s*,\s*(\d*\.?\d+)\s*$/
241
+
242
+ /**
243
+ * Exactly two non-negative numbers, each in [0, 1): 1 is the box's far edge, outside it. Anything else (a missing half, a third
244
+ * field, a value outside the box, a sign) is null, so the trigger is hovered at its centre.
245
+ */
246
+ export function parseHoverAt(raw: string): { x: number; y: number } | null {
247
+ const m = HOVER_AT.exec(raw)
248
+ if (!m) return null
249
+ const [x, y] = [Number(m[1]), Number(m[2])]
250
+ return x < 1 && y < 1 ? { x, y } : null
251
+ }
252
+
253
+ export async function hoverTrigger(target: PwLocator): Promise<void> {
254
+ const at = parseHoverAt(String(await target.evaluate(hoverAtOf)))
255
+ const box = at ? await target.boundingBox() : null
256
+ const position = at && box ? { x: at.x * box.width, y: at.y * box.height } : undefined
257
+ await target.hover({ timeout: HOVER_TIMEOUT_MS, ...(position && { position }) })
258
+ }
259
+
228
260
  /**
229
261
  * The box of the tooltip an action opened, or null when none shows up. Call `markVisibleTooltips`
230
262
  * before the action; `describedBy` is the trigger's own tooltip id, when it has one.
@@ -234,7 +266,7 @@ async function openTooltipBox(
234
266
  describedBy: string,
235
267
  timeout = TIP_PROBE_MS,
236
268
  ): Promise<Box | null> {
237
- const tip = c.page.locator(tooltipSelector(describedBy)).first()
269
+ const tip = c.page.locator(visibleTooltip(describedBy)).first()
238
270
  try {
239
271
  await tip.waitFor({ state: 'visible', timeout })
240
272
  } catch {
@@ -262,7 +294,7 @@ async function captureHover(c: Ctx, name: string): Promise<void> {
262
294
  const inner = c.page.locator(`${sel(name)} [data-shot-hover]`).first()
263
295
  const target = (await inner.count()) > 0 ? inner : anchor
264
296
  await c.page.evaluate(markVisibleTooltips, undefined)
265
- await target.hover({ timeout: HOVER_TIMEOUT_MS })
297
+ await hoverTrigger(target)
266
298
  const describedBy = idOf(await target.evaluate(describedByOf))
267
299
  const [box, tip] = [await anchor.boundingBox(), await openTooltipBox(c, describedBy)]
268
300
  if (!box || !tip) return void (await snap(anchor, path))
@@ -337,7 +369,7 @@ async function captureTooltip(c: Ctx, name: string): Promise<void> {
337
369
  const anchor = anchorOf(c, name)
338
370
  await reveal(anchor)
339
371
  await c.page.evaluate(markVisibleTooltips, undefined)
340
- await trigger.hover({ timeout: HOVER_TIMEOUT_MS })
372
+ await hoverTrigger(trigger)
341
373
  const describedBy = idOf(await trigger.evaluate(describedByOf))
342
374
  const t = await openTooltipBox(c, describedBy, TOOLTIP_TIMEOUT_MS)
343
375
  if (!t) throw new Error('no visible [role="tooltip"] after hover')
@@ -26,7 +26,7 @@ export type ShotOptions = {
26
26
  export type PwLocator = {
27
27
  first(): PwLocator
28
28
  count(): Promise<number>
29
- hover(options?: { timeout?: number }): Promise<void>
29
+ hover(options?: { timeout?: number; position?: { x: number; y: number } }): Promise<void>
30
30
  isVisible(): Promise<boolean>
31
31
  boundingBox(): Promise<Box | null>
32
32
  scrollIntoViewIfNeeded(): Promise<void>
@@ -1,10 +1,12 @@
1
1
  /**
2
- * DeltaBadge — the KPI trend chip (docs/DESIGN-SPEC.md §5): mono 11.5px weight 600, status-color
3
- * text on a status-13% tint, control radius, 2px/7px padding, optional ▲/▼ glyph at 9px.
4
- * `polarity` decides the TONE the sign maps to — `'up-good'` (default) reads a rise as success and
5
- * a fall as danger; `'up-bad'` inverts that for a metric where a rise is the worse reading (a
6
- * cycle-top index, latency, error rate); `'neutral'` renders every sign in a faint, non-verdict
7
- * tint. Zero is always faint with no glyph, under every polarity. The label never carries a
2
+ * DeltaBadge — the KPI trend readout (docs/DESIGN-CORE.md: "up/down deltas are text colour only,
3
+ * never a fill"): a glyph and a signed figure in the trend colour, mono `sm`, with NO fill, border
4
+ * or padding in either scheme. The optional ▲/▼ glyph sits on the `micro` rung and `period` is
5
+ * `micro` muted. `polarity` decides the TONE the sign maps to — `'up-good'` (default) reads a rise
6
+ * as success and a fall as danger; `'up-bad'` inverts that for a metric where a rise is the worse
7
+ * reading (a cycle-top index, latency, error rate); `'neutral'` renders every sign in a faint,
8
+ * non-verdict
9
+ * colour. Zero is always faint with no glyph, under every polarity. The label never carries a
8
10
  * leading "+"; pass `format` to control the magnitude string (defaults to a one-decimal percentage
9
11
  * of the absolute value). The ▲/▼ glyph is DIRECTION, not verdict, and stays polarity-independent —
10
12
  * governed only by `withGlyph` and the sign.
@@ -16,13 +18,13 @@
16
18
  * @example
17
19
  * import { DeltaBadge } from 'basalt-ui'
18
20
  *
19
- * <DeltaBadge value={12.4} /> // ▲ 12.4%, success tint
20
- * <DeltaBadge value={-3.1} /> // ▼ 3.1%, danger tint
21
- * <DeltaBadge value={0} /> // 0.0%, neutral faint tint, no glyph
21
+ * <DeltaBadge value={12.4} /> // ▲ 12.4%, success colour
22
+ * <DeltaBadge value={-3.1} /> // ▼ 3.1%, danger colour
23
+ * <DeltaBadge value={0} /> // 0.0%, faint, no glyph
22
24
  * <DeltaBadge value={182} format={(v) => `${Math.abs(v)}ms`} withGlyph={false} />
23
- * <DeltaBadge value={35.9} polarity="up-bad" /> // ▲ 35.9%, danger tint — a rise is bad here
25
+ * <DeltaBadge value={35.9} polarity="up-bad" /> // ▲ 35.9%, danger — a rise is bad here
24
26
  */
25
- import { alpha, VX } from '../tokens'
27
+ import { VX } from '../tokens'
26
28
  import classes from './widget-header.module.css'
27
29
 
28
30
  export type DeltaPolarity = 'up-good' | 'up-bad' | 'neutral'
@@ -39,8 +41,8 @@ export type DeltaBadgeProps = {
39
41
  format?: (value: number) => string
40
42
  /** Render the ▲/▼ direction glyph. Defaults to `true`; a zero value never shows a glyph. */
41
43
  withGlyph?: boolean
42
- /** Optional comparison timeframe rendered directly after the value in a dimmer shade of the same
43
- * tone (e.g. `MoM`, `WoW`, `YTD`) — states what the delta is measured against without a hover. */
44
+ /** Optional comparison timeframe rendered directly after the value, muted (e.g. `MoM`, `WoW`,
45
+ * `YTD`) — states what the delta is measured against without a hover. */
44
46
  period?: string | undefined
45
47
  }
46
48
 
@@ -53,6 +55,13 @@ function resolveTone(value: number, polarity: DeltaPolarity): string {
53
55
  return good ? VX.status.good : VX.status.bad
54
56
  }
55
57
 
58
+ /** The direction mark for a signed value; zero has none. Direction only, never the verdict. */
59
+ function directionGlyph(value: number): '▲' | '▼' | undefined {
60
+ if (value > 0) return '▲'
61
+ if (value < 0) return '▼'
62
+ return undefined
63
+ }
64
+
56
65
  export function DeltaBadge({
57
66
  value,
58
67
  polarity = 'up-good',
@@ -61,14 +70,11 @@ export function DeltaBadge({
61
70
  period,
62
71
  }: DeltaBadgeProps) {
63
72
  const tone = resolveTone(value, polarity)
64
- const glyph = value > 0 ? '▲' : value < 0 ? '▼' : undefined
73
+ const glyph = directionGlyph(value)
65
74
  const showGlyph = withGlyph && glyph !== undefined
66
75
 
67
76
  return (
68
- <span
69
- className={classes.deltaBadge}
70
- style={{ backgroundColor: alpha(tone, 0.13), color: tone }}
71
- >
77
+ <span className={classes.deltaBadge} style={{ color: tone }}>
72
78
  {showGlyph && <span className={classes.deltaGlyph}>{glyph}</span>}
73
79
  {format(value)}
74
80
  {period !== undefined && <span className={classes.deltaPeriod}>{period}</span>}
@@ -173,6 +173,44 @@ function defaultIsEmpty(data: unknown): boolean {
173
173
  return false
174
174
  }
175
175
 
176
+ /**
177
+ * The body a card-sized consumer should show for `query`, resolved by ONE precedence:
178
+ * error > pending > empty > ready.
179
+ *
180
+ * - `error`: the fetch failed and there is nothing to show — no data, or data that is empty (an
181
+ * errored refetch over a cached `[]` is a failure, never "no data");
182
+ * - `pending`: no data, not failed, and a fetch is in flight or paused;
183
+ * - `empty`: no data and nothing in flight (an `enabled: false` query), or data that is empty by
184
+ * the same rule as {@link QueryState} (`null`, `[]`, `{ data: [] }`);
185
+ * - `ready`: data worth showing; `refreshFailed` is true when a background refetch failed over it
186
+ * (the "showing cached data" banner case).
187
+ *
188
+ * `QueryState` renders a whole region and keeps its own branch order; this is for a consumer that
189
+ * swaps one region of a larger surface (`StatCard`'s figure) and needs the same words for the same
190
+ * states. Switch over `kind` and end with `default: return branch satisfies never`.
191
+ */
192
+ export type QueryBranch<TData> =
193
+ | { kind: 'error'; query: QueryStateLike<TData>; error: unknown }
194
+ | { kind: 'pending'; query: QueryStateLike<TData> }
195
+ | { kind: 'empty'; query: QueryStateLike<TData> }
196
+ | { kind: 'ready'; query: QueryStateLike<TData>; data: TData; refreshFailed: boolean }
197
+
198
+ export function resolveQueryBranch<TData>(
199
+ query: QueryStateLike<TData>,
200
+ /** Names the container in the throw on a malformed `query` (`'StatCard'`). */
201
+ caller: string,
202
+ isEmpty: (data: TData) => boolean = defaultIsEmpty,
203
+ ): QueryBranch<TData> {
204
+ assertQueryStateLike(caller, query)
205
+ const { data, isError, error, fetchStatus } = query
206
+ if (data === undefined) {
207
+ if (isError) return { kind: 'error', query, error }
208
+ return fetchStatus === 'idle' ? { kind: 'empty', query } : { kind: 'pending', query }
209
+ }
210
+ if (isEmpty(data)) return isError ? { kind: 'error', query, error } : { kind: 'empty', query }
211
+ return { kind: 'ready', query, data, refreshFailed: isError }
212
+ }
213
+
176
214
  /**
177
215
  * ONE slot, and the single-member union is the statement (`common/props.ts` lists this among the
178
216
  * composites): `root` is whichever branch is live — the error alert's stack, the spinner's centre,
@@ -0,0 +1,108 @@
1
+ /**
2
+ * The pieces `StatCard` lays out around its value row: the caption row, the foot, and the
3
+ * skeletons that hold their footprint while a reading is pending. Split out so `stat-card.tsx`
4
+ * orchestrates (which branch, which placement) and these draw. Internal: not exported from any barrel.
5
+ */
6
+ import { Skeleton } from '@mantine/core'
7
+ import type { CSSProperties, ReactNode } from 'react'
8
+ import { IconSlot } from '../theme/icon-slot'
9
+ import { CtlSlot } from '../theme'
10
+ import { InfoGlyph } from './widget-header'
11
+ import classes from './stat-card.module.css'
12
+
13
+ export type CaptionRowProps = {
14
+ title: string
15
+ icon?: ReactNode
16
+ info?: string
17
+ qualifier?: string
18
+ actions?: ReactNode
19
+ }
20
+
21
+ /**
22
+ * Title, `info` glyph and `qualifier` in one wrapping group, `actions` pinned at the end. When
23
+ * caption + info + qualifier do not fit, the qualifier wraps UNDER the caption instead of truncating
24
+ * either: the container's width decides, never the viewport's.
25
+ */
26
+ export function CaptionRow({ title, icon, info, qualifier, actions }: CaptionRowProps) {
27
+ return (
28
+ <div className={classes.captionRow}>
29
+ <div className={classes.captionMain}>
30
+ <div className={classes.lead}>
31
+ <h3 className={classes.caption}>
32
+ {icon !== undefined && <IconSlot className={classes.icon}>{icon}</IconSlot>}
33
+ <span className={classes.captionText}>{title}</span>
34
+ </h3>
35
+ {/* OUTSIDE the heading on purpose: `info` would otherwise become part of its name. */}
36
+ {info !== undefined && <InfoGlyph text={info} />}
37
+ </div>
38
+ {qualifier !== undefined && <span className={classes.qualifier}>{qualifier}</span>}
39
+ </div>
40
+ {/* `tier="widget"`: the caption row is 24px (`--vx-space-control-height-widget`), so a card
41
+ with a kebab is the same height as one without (`theme/ctl-theme.tsx`). */}
42
+ {actions !== undefined && (
43
+ <span className={classes.actions} data-basalt-hit-scope>
44
+ <CtlSlot tier="widget">{actions}</CtlSlot>
45
+ </span>
46
+ )}
47
+ </div>
48
+ )
49
+ }
50
+
51
+ export type FootProps = {
52
+ /** Reserve the foot's height (a visual AND a footer line) even when a branch shows neither. */
53
+ reserve: boolean
54
+ /** The visual band is part of the reservation only for the `bleed` placement; `right` keeps its
55
+ * slot beside the breakdown, so a footer there reserves one line, not a band. */
56
+ visualBand: boolean
57
+ visualNode: ReactNode
58
+ footerNode: ReactNode
59
+ }
60
+
61
+ /**
62
+ * The visual and its footer line, pinned to the card's bottom. It reserves visual + gap + footer
63
+ * whenever `reserve` is set, so a card with a sparkline and no footer, one with both, and one in a
64
+ * pending or failed branch are the same height (SPEC § 6.1 footprint).
65
+ */
66
+ export function Foot({ reserve, visualBand, visualNode, footerNode }: FootProps) {
67
+ if (!reserve) return null
68
+ return (
69
+ <div className={classes.foot} data-band={visualBand}>
70
+ {visualNode}
71
+ {footerNode}
72
+ </div>
73
+ )
74
+ }
75
+
76
+ /** The `'right'` slot's size, handed to CSS as custom properties (an inline `flex-basis` would also
77
+ * apply in a narrow card, where the row is a column and the basis becomes the HEIGHT). */
78
+ export function rightSlotStyle(width: number, height: number): CSSProperties {
79
+ return {
80
+ '--basalt-stat-sparkline-w': `${width}px`,
81
+ '--basalt-stat-sparkline-h': `${height}px`,
82
+ } as CSSProperties
83
+ }
84
+
85
+ export function ValueSkeleton() {
86
+ return <Skeleton className={classes.skeletonValue} radius="sm" />
87
+ }
88
+
89
+ export function VisualSkeleton() {
90
+ return <Skeleton className={classes.skeletonVisual} />
91
+ }
92
+
93
+ export function FooterSkeleton() {
94
+ return <Skeleton className={classes.skeletonFooter} radius="sm" />
95
+ }
96
+
97
+ /** One placeholder row per `breakdown` row, each at the real row's height. */
98
+ export function BreakdownSkeleton({ rows }: { rows: number }) {
99
+ return (
100
+ <div className={classes.breakdown} aria-hidden="true">
101
+ {Array.from({ length: rows }, (_, i) => (
102
+ <div key={i} className={classes.skeletonRowBox}>
103
+ <Skeleton className={classes.skeletonRow} radius="sm" />
104
+ </div>
105
+ ))}
106
+ </div>
107
+ )
108
+ }
@@ -5,7 +5,18 @@
5
5
  * than 480px (`container: basalt-card`, set on the Card root in `stat-card.tsx`).
6
6
  */
7
7
 
8
+ /* Foot geometry, single-sourced: the visual slot (SPEC § 6.2: 22), one `sm` footer line (20) and the
9
+ * 4px between them. The foot reserves all three whenever it exists (`.foot`), which is what keeps a
10
+ * card with a sparkline and one without a footer the same height. */
8
11
  .body {
12
+ --basalt-stat-visual-h: 1.375rem;
13
+ --basalt-stat-footer-h: 1.25rem;
14
+ --basalt-stat-foot-gap: 0.25rem;
15
+ /* The figure's size and line box, in one place: `.value`, the empty line and the pending skeleton
16
+ * all read them, so nothing moves when a reading lands. */
17
+ --basalt-stat-figure-size: var(--vx-text-kpi);
18
+ --basalt-stat-figure-line: 1.25;
19
+ --basalt-stat-figure-h: calc(var(--basalt-stat-figure-size) * var(--basalt-stat-figure-line));
9
20
  display: flex;
10
21
  flex-direction: column;
11
22
  gap: var(--vx-space-stat-card-gap);
@@ -16,6 +27,210 @@
16
27
  min-width: 0;
17
28
  }
18
29
 
30
+ /* ── caption row ─────────────────────────────────────────────────────────────────────────────── */
31
+
32
+ /* `captionMain` takes the row; the actions slot sits at its end. The row is 24px (the widget control
33
+ * step) so a card with a kebab is the same height as one without. */
34
+ .captionRow {
35
+ display: flex;
36
+ align-items: flex-start;
37
+ gap: var(--vx-space-control-gap, 0.375rem);
38
+ min-height: calc(var(--vx-space-control-height-widget, 1.5rem) * var(--mantine-scale, 1));
39
+ }
40
+
41
+ /* Wraps on purpose: when caption + info + qualifier do not fit, the qualifier drops UNDER the caption
42
+ * instead of truncating either — the container's width decides, never the viewport's. */
43
+ .captionMain {
44
+ display: flex;
45
+ flex: 1 1 0;
46
+ flex-wrap: wrap;
47
+ align-items: center;
48
+ /* Caption left, qualifier right; a qualifier that wraps is alone on its line, so it sits at the start. */
49
+ justify-content: space-between;
50
+ column-gap: var(--vx-space-control-gap, 0.375rem);
51
+ min-width: 0;
52
+ min-height: calc(var(--vx-space-control-height-widget, 1.5rem) * var(--mantine-scale, 1));
53
+ }
54
+
55
+ /* Caption and info glyph travel together: the pair is the first item of the row. */
56
+ .lead {
57
+ display: inline-flex;
58
+ align-items: center;
59
+ column-gap: var(--vx-space-control-gap, 0.375rem);
60
+ min-width: 0;
61
+ }
62
+
63
+ .caption {
64
+ display: inline-flex;
65
+ align-items: center;
66
+ gap: 5px;
67
+ margin: 0;
68
+ min-width: 0;
69
+ font-family: var(--basalt-font-mono);
70
+ font-size: var(--vx-text-micro);
71
+ font-weight: 500;
72
+ text-transform: uppercase;
73
+ letter-spacing: 0.06em;
74
+ color: var(--vx-faint);
75
+ }
76
+
77
+ .captionText {
78
+ overflow: hidden;
79
+ text-overflow: ellipsis;
80
+ white-space: nowrap;
81
+ }
82
+
83
+ .icon {
84
+ color: var(--vx-faint);
85
+ --vx-space-icon-size: 0.875rem;
86
+ }
87
+
88
+ .qualifier {
89
+ font-family: var(--basalt-font-mono);
90
+ font-size: var(--vx-text-micro);
91
+ color: var(--vx-muted);
92
+ /* Wraps before it is ever cut: a qualifier too long for the row on its own line breaks its words. */
93
+ overflow-wrap: anywhere;
94
+ min-width: 0;
95
+ }
96
+
97
+ /* Law C15: the shared hit overlay; `--vx-hit-gap` caps the expansion at the control gap. */
98
+ .actions {
99
+ --vx-hit-gap: var(--vx-space-control-gap);
100
+ display: inline-flex;
101
+ flex: none;
102
+ align-items: center;
103
+ gap: var(--vx-space-control-gap, 0.375rem);
104
+ }
105
+
106
+ /* ── value row ───────────────────────────────────────────────────────────────────────────────── */
107
+
108
+ /* The figure and its unit share a baseline; the delta follows them, on the same baseline, and wraps
109
+ * under when the card is too narrow for all three. Three sizes only: micro, sm, hero. */
110
+ .valueRow {
111
+ display: flex;
112
+ flex-wrap: wrap;
113
+ align-items: baseline;
114
+ column-gap: var(--vx-space-stack-sm);
115
+ row-gap: 2px;
116
+ min-width: 0;
117
+ }
118
+
119
+ .figure {
120
+ display: inline-flex;
121
+ align-items: baseline;
122
+ gap: 4px;
123
+ min-width: 0;
124
+ }
125
+
126
+ /* NEVER truncated: the numeral IS the content. It shrinks with the card's own width instead (the
127
+ * `cqi` clamp below), and `overflow-wrap` breaks a pathological string rather than clipping it. */
128
+ .value {
129
+ min-width: 0;
130
+ overflow-wrap: anywhere;
131
+ font-family: var(--basalt-font-mono);
132
+ font-size: var(--basalt-stat-figure-size);
133
+ line-height: var(--basalt-stat-figure-line);
134
+ font-weight: 500;
135
+ letter-spacing: -0.02em;
136
+ color: var(--vx-ink);
137
+ }
138
+
139
+ /* Mono like the number it qualifies, `sm` and muted: the SMALL half of the pair. Never shrinks — a
140
+ * unit clipped to `TS…` would state nothing. */
141
+ .unit {
142
+ flex-shrink: 0;
143
+ font-family: var(--basalt-font-mono);
144
+ font-size: var(--vx-text-sm);
145
+ font-weight: 500;
146
+ color: var(--vx-muted);
147
+ }
148
+
149
+ /* The numeral shrinks with its card (`cqi` resolves against the card's container wherever the var is
150
+ * read). `(width >= 0px)` is always true but only inside a `basalt-card` container. */
151
+ @container basalt-card (width >= 0px) {
152
+ .body {
153
+ --basalt-stat-figure-size: clamp(var(--vx-text-lg), 8cqi, var(--vx-text-kpi));
154
+ }
155
+ }
156
+
157
+ /* ── states ──────────────────────────────────────────────────────────────────────────────────── */
158
+
159
+ /* The empty branch: one muted line in the figure's place, at the figure row's height. */
160
+ .empty {
161
+ display: flex;
162
+ align-items: center;
163
+ margin: 0;
164
+ min-height: var(--basalt-stat-figure-h);
165
+ font-size: var(--vx-text-sm);
166
+ color: var(--vx-muted);
167
+ }
168
+
169
+ /* The pending skeleton holds the card's own footprint: a value bar at the figure's height, the
170
+ * visual slot at 22, the footer at one `sm` line. */
171
+ .skeletonValue {
172
+ width: 45%;
173
+ height: var(--basalt-stat-figure-h);
174
+ }
175
+
176
+ .skeletonVisual {
177
+ --skeleton-radius: 0;
178
+ height: var(--basalt-stat-visual-h);
179
+ margin-inline: calc(-1 * var(--vx-space-card-inset-x, 1rem));
180
+ }
181
+
182
+ .sparklineRight .skeletonVisual {
183
+ flex: 1 1 auto;
184
+ margin-inline: 0;
185
+ }
186
+
187
+ .skeletonRowBox {
188
+ display: flex;
189
+ align-items: center;
190
+ min-height: var(--vx-space-control-height-tag);
191
+ }
192
+
193
+ .skeletonRow {
194
+ width: 60%;
195
+ height: 0.625rem;
196
+ }
197
+
198
+ .skeletonFooter {
199
+ width: 55%;
200
+ height: 0.75rem;
201
+ margin-block: 0.25rem;
202
+ }
203
+
204
+ /* ── foot: the visual and its footer line ────────────────────────────────────────────────────── */
205
+
206
+ /* Pinned to the card's bottom (`margin-top: auto`) and reserving visual + gap + footer whenever it
207
+ * exists, bottom-aligned, so the visual and the footer never move when one of them is absent. */
208
+ .foot {
209
+ display: flex;
210
+ flex-direction: column;
211
+ justify-content: flex-end;
212
+ gap: var(--basalt-stat-foot-gap);
213
+ margin-top: auto;
214
+ min-width: 0;
215
+ min-height: calc(
216
+ var(--basalt-stat-visual-h) + var(--basalt-stat-foot-gap) + var(--basalt-stat-footer-h)
217
+ );
218
+ }
219
+
220
+ .foot[data-band='false'] {
221
+ min-height: var(--basalt-stat-footer-h);
222
+ }
223
+
224
+ .footer {
225
+ margin: 0;
226
+ overflow: hidden;
227
+ text-overflow: ellipsis;
228
+ white-space: nowrap;
229
+ font-size: var(--vx-text-sm);
230
+ line-height: var(--basalt-stat-footer-h);
231
+ color: var(--vx-muted);
232
+ }
233
+
19
234
  /*
20
235
  * `right` placement's second row (measured defect: the "···" actions trigger, and the "Data"
21
236
  * select, sat ~74-88px in from the card's right edge — a phone-only 13px is correct). The cause was
@@ -122,9 +337,8 @@
122
337
  }
123
338
 
124
339
  .sparklineBleed {
125
- margin-top: auto;
340
+ height: var(--basalt-stat-visual-h);
126
341
  margin-inline: calc(-1 * var(--vx-space-card-inset-x, 1rem));
127
- margin-bottom: calc(-1 * var(--vx-space-card-inset-y, 0.75rem));
128
342
  }
129
343
 
130
344
  /* Asks for `StatCard`'s `SPARKLINE_RIGHT_WIDTH`/`_HEIGHT` (handed down as custom properties, so this
@@ -132,12 +346,12 @@
132
346
  * this restructure keeps at the SPARKLINE's own level rather than the row's: `.metricsRow` does not
133
347
  * set `align-items: flex-end` itself, because a card with no breakdown would then need nothing to
134
348
  * anchor against — only the sparkline opts into sitting at the row's bottom edge, which matters once
135
- * a breakdown taller than the trend's own 26px is the row's other child. */
349
+ * a breakdown taller than the trend's own 22px is the row's other child. */
136
350
  .sparklineRight {
137
351
  display: flex;
138
352
  flex: 0 1 var(--basalt-stat-sparkline-w, 4.5rem);
139
353
  min-width: 0;
140
- height: var(--basalt-stat-sparkline-h, 1.625rem);
354
+ height: var(--basalt-stat-sparkline-h, 1.375rem);
141
355
  align-items: flex-end;
142
356
  align-self: flex-end;
143
357
  overflow: hidden;
@@ -151,8 +365,8 @@
151
365
  }
152
366
 
153
367
  /* The row became a COLUMN, so `flex-basis` is now the main-axis HEIGHT — the 72px width would
154
- * become a 72px-tall box around 26px of bars. `flex: none` + the height keeps the bled trend the
155
- * same 26px it is beside a hero row. `align-self: stretch` resets the row-only `flex-end` above:
368
+ * become a 72px-tall box around 22px of bars. `flex: none` + the height keeps the bled trend the
369
+ * same 22px it is beside a hero row. `align-self: stretch` resets the row-only `flex-end` above:
156
370
  * the cross axis is horizontal now, and this slot must fill the card's width like `.sparklineBleed`
157
371
  * does, not shrink to its content and sit flush right. */
158
372
  .metricsRow .sparklineRight {
@@ -160,6 +374,5 @@
160
374
  align-self: stretch;
161
375
  margin-top: auto;
162
376
  margin-inline: calc(-1 * var(--vx-space-card-inset-x, 1rem));
163
- margin-bottom: calc(-1 * var(--vx-space-card-inset-y, 0.75rem));
164
377
  }
165
378
  }
@@ -4,6 +4,26 @@
4
4
  */
5
5
  declare const classes: {
6
6
  readonly body: string
7
+ readonly captionRow: string
8
+ readonly captionMain: string
9
+ readonly lead: string
10
+ readonly caption: string
11
+ readonly captionText: string
12
+ readonly icon: string
13
+ readonly qualifier: string
14
+ readonly actions: string
15
+ readonly valueRow: string
16
+ readonly figure: string
17
+ readonly value: string
18
+ readonly unit: string
19
+ readonly empty: string
20
+ readonly skeletonValue: string
21
+ readonly skeletonVisual: string
22
+ readonly skeletonFooter: string
23
+ readonly skeletonRowBox: string
24
+ readonly skeletonRow: string
25
+ readonly foot: string
26
+ readonly footer: string
7
27
  readonly header: string
8
28
  readonly metricsRow: string
9
29
  readonly breakdown: string