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
@@ -0,0 +1,55 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { Skeleton } from "@mantine/core";
3
+ import { IconSlot } from "../theme/icon-slot.js";
4
+ import { CtlSlot } from "../theme/index.js";
5
+ import { InfoGlyph } from "./widget-header.js";
6
+ import classes from "./stat-card.module.css";
7
+ function CaptionRow({ title, icon, info, qualifier, actions }) {
8
+ return /* @__PURE__ */ jsxs("div", { className: classes.captionRow, children: [
9
+ /* @__PURE__ */ jsxs("div", { className: classes.captionMain, children: [
10
+ /* @__PURE__ */ jsxs("div", { className: classes.lead, children: [
11
+ /* @__PURE__ */ jsxs("h3", { className: classes.caption, children: [
12
+ icon !== void 0 && /* @__PURE__ */ jsx(IconSlot, { className: classes.icon, children: icon }),
13
+ /* @__PURE__ */ jsx("span", { className: classes.captionText, children: title })
14
+ ] }),
15
+ info !== void 0 && /* @__PURE__ */ jsx(InfoGlyph, { text: info })
16
+ ] }),
17
+ qualifier !== void 0 && /* @__PURE__ */ jsx("span", { className: classes.qualifier, children: qualifier })
18
+ ] }),
19
+ actions !== void 0 && /* @__PURE__ */ jsx("span", { className: classes.actions, "data-basalt-hit-scope": true, children: /* @__PURE__ */ jsx(CtlSlot, { tier: "widget", children: actions }) })
20
+ ] });
21
+ }
22
+ function Foot({ reserve, visualBand, visualNode, footerNode }) {
23
+ if (!reserve) return null;
24
+ return /* @__PURE__ */ jsxs("div", { className: classes.foot, "data-band": visualBand, children: [
25
+ visualNode,
26
+ footerNode
27
+ ] });
28
+ }
29
+ function rightSlotStyle(width, height) {
30
+ return {
31
+ "--basalt-stat-sparkline-w": `${width}px`,
32
+ "--basalt-stat-sparkline-h": `${height}px`
33
+ };
34
+ }
35
+ function ValueSkeleton() {
36
+ return /* @__PURE__ */ jsx(Skeleton, { className: classes.skeletonValue, radius: "sm" });
37
+ }
38
+ function VisualSkeleton() {
39
+ return /* @__PURE__ */ jsx(Skeleton, { className: classes.skeletonVisual });
40
+ }
41
+ function FooterSkeleton() {
42
+ return /* @__PURE__ */ jsx(Skeleton, { className: classes.skeletonFooter, radius: "sm" });
43
+ }
44
+ function BreakdownSkeleton({ rows }) {
45
+ return /* @__PURE__ */ jsx("div", { className: classes.breakdown, "aria-hidden": "true", children: Array.from({ length: rows }, (_, i) => /* @__PURE__ */ jsx("div", { className: classes.skeletonRowBox, children: /* @__PURE__ */ jsx(Skeleton, { className: classes.skeletonRow, radius: "sm" }) }, i)) });
46
+ }
47
+ export {
48
+ BreakdownSkeleton,
49
+ CaptionRow,
50
+ Foot,
51
+ FooterSkeleton,
52
+ ValueSkeleton,
53
+ VisualSkeleton,
54
+ rightSlotStyle
55
+ };
@@ -3,9 +3,8 @@ import type { WidgetHeaderDeltaProps, WidgetHeaderMetricProps, WidgetHeaderTitle
3
3
  import type { BasaltProps, SlotStylesProps, Tone } from '../common/props.js';
4
4
  import type { QueryStateLike } from './query-state.js';
5
5
  /**
6
- * The four boxes `StatCard` paints, and the whole styling seam it offers (`common/props.ts`).
7
- * `value` is not its own slot: the hero number is painted by `WidgetHeader`'s internal metrics row,
8
- * which does not yet accept a slot class of its own.
6
+ * The boxes `StatCard` paints, and the whole styling seam it offers (`common/props.ts`).
7
+ * `value` is not its own slot: the hero number is painted inside the `header` box.
9
8
  */
10
9
  export type StatCardSlot = 'root' | 'header' | 'body' | 'sparkline';
11
10
  /**
@@ -33,17 +32,6 @@ export type StatCardBreakdownRow = {
33
32
  export type StatCardSparklineSize = {
34
33
  width: number;
35
34
  height: number;
36
- /**
37
- * The card's `query` as a chart state — present only while the sparkline has nothing to draw
38
- * (pending, or failed with no data), so `<Sparkline {...size} />` forwards it and the tile shows a
39
- * sized placeholder instead of a hand-rolled `'—'`. Structurally a `ChartState`: this module
40
- * stays chart-free. Absent without a `query`, and once data has arrived.
41
- */
42
- state?: {
43
- pending?: boolean;
44
- error?: unknown;
45
- empty?: boolean;
46
- };
47
35
  };
48
36
  /**
49
37
  * `StatCard` re-publishes three NAMED `WidgetHeader` slices (`WidgetHeaderTitleProps` /
@@ -60,10 +48,32 @@ export type StatCardSparklineSize = {
60
48
  * `Section` and `ChartCard` still cut their own ad-hoc subsets; both should move onto these same
61
49
  * three slices.
62
50
  */
63
- export type StatCardProps = BasaltProps & SlotStylesProps<StatCardSlot> & WidgetHeaderTitleProps & Omit<WidgetHeaderMetricProps, 'value'> & WidgetHeaderDeltaProps & {
64
- /** Pre-formatted KPI value string (mono ~24px, weight 600, ink) — the hero-row value. Required
65
- * here, unlike on `WidgetHeader`: see the type's own doc. */
51
+ export type StatCardProps = BasaltProps & SlotStylesProps<StatCardSlot> & Omit<WidgetHeaderTitleProps, 'subtitle'> & Omit<WidgetHeaderMetricProps, 'value'> & WidgetHeaderDeltaProps & {
52
+ /** Pre-formatted hero figure (mono `kpi`, weight 500, ink). Required here, unlike on
53
+ * `WidgetHeader`: see the type's own doc. */
66
54
  value: string;
55
+ /**
56
+ * Right-aligned on the caption row, `micro` muted: the period, target or source the figure is
57
+ * measured over (`30 days`, `target 99.9%`). Wraps under the caption when the card is too narrow
58
+ * for both. Not a restatement of the caption.
59
+ */
60
+ qualifier?: string;
61
+ /**
62
+ * One muted `sm` line in the foot, under the visual: a source or "as of"
63
+ * (`Source: events table`, `as of 14:02`), never a restatement of the caption. It was a line
64
+ * under the title before; the old placement has no replacement — put the text in `qualifier`
65
+ * (period/target) or `info` (method).
66
+ */
67
+ subtitle?: string;
68
+ /**
69
+ * Shows the skeleton at the card's own footprint (caption stays, value bar, visual slot) without
70
+ * a query — for a streamed or suspended value. With a `query` the pending branch shows it by
71
+ * itself. No spinner ever renders inside a card.
72
+ */
73
+ loading?: boolean;
74
+ /** The one muted line the empty branch shows in place of the figure. Say why it is empty.
75
+ * Default `No data for this period`. */
76
+ emptyText?: string;
67
77
  /**
68
78
  * The parts the hero number is made of — compact rows under it, one line each, no hairlines.
69
79
  *
@@ -79,15 +89,16 @@ export type StatCardProps = BasaltProps & SlotStylesProps<StatCardSlot> & Widget
79
89
  */
80
90
  breakdown?: readonly StatCardBreakdownRow[];
81
91
  /**
82
- * The async result behind the number. Supplied, the card renders its pending / error / empty
83
- * branch through {@link QueryState} at the `'section'` tier, INSIDE the card body and directly
84
- * under the header — so the title, the icon and the info glyph stay put while the reading below
85
- * them resolves. Omitted, the card renders exactly as it always has (audit B #3).
92
+ * The async result behind the number. Supplied, the card picks its body from it, at the card's
93
+ * own footprint and with the caption row untouched:
94
+ *
95
+ * - pending → the skeleton (caption, value bar, visual slot), never a spinner;
96
+ * - error with no data → `QueryState`'s error at the `'section'` tier: one sentence and Retry;
97
+ * - empty (`[]`, `{ data: [] }`, or idle with no data) → one muted line, {@link emptyText};
98
+ * - data → the figure, with `breakdown` behind `QueryState`. A failed background refetch shows
99
+ * its "cached data" banner over the breakdown only; the figure path adds no banner.
86
100
  *
87
- * It exists because the alternative every consumer wrote is the four-way switch `QueryState`
88
- * exists to delete, and got it wrong in the direction that renders "no data" over a 500. The
89
- * BRANCH is basalt's; the number is not — `value` is still whatever you formatted, so pass a
90
- * placeholder (`'—'`) while the query is pending rather than a stale one.
101
+ * The BRANCH is basalt's; the number is not — `value` is still whatever you formatted.
91
102
  *
92
103
  * @example
93
104
  * <StatCard title="Active users" value={q.data ? fmt(q.data.count) : '—'} query={q} />
@@ -99,22 +110,23 @@ export type StatCardProps = BasaltProps & SlotStylesProps<StatCardSlot> & Widget
99
110
  * Prefer the render prop for any SVG sparkline: those take numeric `width`/`height`
100
111
  * (SVG attributes), so a plain node has to hardcode a width, and a hardcoded width is not
101
112
  * full-bleed on any viewport but the one it was typed on. With `sparklinePlacement="bleed"` the
102
- * measured width is the card's own inner width including the bled inset; with `'right'` it is the
103
- * fixed 72×26 slot (see {@link SPARKLINE_RIGHT_WIDTH} for why that one is not measured).
113
+ * measured width is the card's own inner width including the bled inset, 22 px tall; with
114
+ * `'right'` it is the 72×22 slot (see {@link SPARKLINE_RIGHT_WIDTH} for why the width is a basis).
104
115
  *
105
116
  * A render prop is a sanctioned pattern here, so `react/no-unstable-nested-components` is
106
- * configured with `allowAsProps` in the shipped preset. Spread the size (`{...size}`) to forward
107
- * `state` along with the box.
117
+ * configured with `allowAsProps` in the shipped preset. Spread the size (`{...size}`) into the
118
+ * chart.
108
119
  *
109
120
  * @example
110
121
  * sparkline={(size) => <Sparkline ariaLabel="Active users" data={history} {...size} />}
111
122
  */
112
123
  sparkline?: ReactNode | ((size: StatCardSparklineSize) => ReactNode);
113
- /** Where `sparkline` sits. `'bleed'` (default) is today's full-width row bled to the card edges;
114
- * `'right'` sits it beside the hero value row. Collapses to `'bleed'` in a card narrower than 480px. */
124
+ /** Where `sparkline` sits. `'bleed'` (default) is the foot, full card width, bled to the side
125
+ * edges; `'right'` sits it beside the `breakdown` rows. Collapses to `'bleed'` in a card narrower
126
+ * than 480px. */
115
127
  sparklinePlacement?: 'bleed' | 'right';
116
- /** Header-right slot (e.g. a ghost "..." menu trigger) — wrapped in `CtlSlot tier="widget"`, so a
117
- * raw `ActionIcon` with no `size` lands on the 24px step the 28px header row holds (C1/C5). */
128
+ /** Caption-row right slot (e.g. a ghost "..." menu trigger) — wrapped in `CtlSlot tier="widget"`,
129
+ * so a raw `ActionIcon` with no `size` lands on the 24px step the caption row holds (C1/C5). */
118
130
  actions?: ReactNode;
119
131
  /** Threshold verdict — draws an accent rail down the card's leading edge and announces itself to
120
132
  * assistive tech. Omitting it is NOT `'good'`: omitted covers a reading that is fine AND one that
@@ -122,5 +134,5 @@ export type StatCardProps = BasaltProps & SlotStylesProps<StatCardSlot> & Widget
122
134
  * `'good'` only to assert a measured value that has earned the verdict. */
123
135
  tone?: Tone;
124
136
  };
125
- export declare function StatCard({ title, icon, subtitle, info, value, unit, breakdown, query, delta, deltaPeriod, deltaPolarity, deltaFormat, deltaGlyph, sparkline, sparklinePlacement, actions, tone, className, style, classNames, }: StatCardProps): import("react").JSX.Element;
137
+ export declare function StatCard({ title, icon, info, qualifier, subtitle, value, unit, breakdown, query, loading, emptyText, delta, deltaPeriod, deltaPolarity, deltaFormat, deltaGlyph, sparkline, sparklinePlacement, actions, tone, className, style, classNames, }: StatCardProps): import("react").JSX.Element;
126
138
  //# sourceMappingURL=stat-card.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"stat-card.d.ts","sourceRoot":"","sources":["../../src/dashboard/stat-card.tsx"],"names":[],"mappings":"AAiGA,OAAO,KAAK,EAAiB,SAAS,EAAE,MAAM,OAAO,CAAA;AAErD,OAAO,KAAK,EACV,sBAAsB,EACtB,uBAAuB,EACvB,sBAAsB,EACvB,MAAM,iBAAiB,CAAA;AAIxB,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AAEzE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAInD;;;;GAIG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,QAAQ,GAAG,MAAM,GAAG,WAAW,CAAA;AAEnE;;;;;;;GAOG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,IAAI,CAAC,EAAE,IAAI,CAAA;CACrB,CAAA;AAcD;;;;;;;;GAQG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAClC,KAAK,EAAE,MAAM,CAAA;IAC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AC3C;;;;;;;;;;;;;;OAcG;IACH,KAAK,CAAC,EAAE,cAAc,CAAC,OAAO,CAAC,CAAA;IAC/B;;;;;;;;;;;;;;;OAeG;IACH,SAAS,CAAC,EAAE,SAAS,GAAG,CAAC,CAAC,IAAI,EAAE,qBAAqB,KAAK,SAAS,CAAC,CAAA;IACpE;;qBAEiB;IACjB,kBAAkB,CAAC,EAAE,OAAO,GAAG,OAAO,CAAA;IACtC;oGACgG;IAChG,OAAO,CAAC,EAAE,SAAS,CAAA;IACnB;;;+EAG2E;IAC3E,IAAI,CAAC,EAAE,IAAI,CAAA;CACZ,CAAA;AA0EH,wBAAgB,QAAQ,CAAC,EACvB,KAAK,EACL,IAAI,EACJ,IAAI,EACJ,SAAS,EACT,QAAQ,EACR,KAAK,EACL,IAAI,EACJ,SAAS,EACT,KAAK,EACL,OAAe,EACf,SAAqC,EACrC,KAAK,EACL,WAAW,EACX,aAAa,EACb,WAAW,EACX,UAAU,EACV,SAAS,EACT,kBAA4B,EAC5B,OAAO,EACP,IAAI,EACJ,SAAS,EACT,KAAK,EACL,UAAU,GACX,EAAE,aAAa,+BAwMf"}
@@ -1,20 +1,26 @@
1
1
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
2
  import { Box, Card, VisuallyHidden } from "@mantine/core";
3
- import { useEffect, useRef, useState } from "react";
4
- import { WidgetHeader } from "./widget-header.js";
5
- import { CtlSlot } from "../theme/index.js";
3
+ import { useEffect, useState } from "react";
4
+ import {
5
+ BreakdownSkeleton,
6
+ CaptionRow,
7
+ FooterSkeleton,
8
+ Foot,
9
+ ValueSkeleton,
10
+ VisualSkeleton,
11
+ rightSlotStyle
12
+ } from "./stat-card-parts.js";
13
+ import { DeltaBadge } from "./delta-badge.js";
6
14
  import { VX } from "../tokens/index.js";
7
15
  import { cx } from "../common/props.js";
8
- import { QueryState } from "./query-state.js";
9
- import { assertQueryStateLike } from "../common/query-state-like.js";
16
+ import { ErrorState, QueryState, resolveQueryBranch } from "./query-state.js";
10
17
  import classes from "./stat-card.module.css";
11
18
  const SPARKLINE_RIGHT_WIDTH = 72;
12
- const SPARKLINE_RIGHT_HEIGHT = 26;
19
+ const SPARKLINE_HEIGHT = 22;
13
20
  function useSlotWidth(active) {
14
21
  const [width, setWidth] = useState(0);
15
- const nodeRef = useRef(null);
22
+ const [node, setNode] = useState(null);
16
23
  useEffect(() => {
17
- const node = nodeRef.current;
18
24
  if (!active || node === null) return;
19
25
  const measure = () => {
20
26
  setWidth(node.getBoundingClientRect().width);
@@ -26,20 +32,8 @@ function useSlotWidth(active) {
26
32
  return () => {
27
33
  observer.disconnect();
28
34
  };
29
- }, [active]);
30
- return {
31
- ref: (node) => {
32
- nodeRef.current = node;
33
- },
34
- width
35
- };
36
- }
37
- function sparklineState(query) {
38
- if (query === void 0) return void 0;
39
- assertQueryStateLike("StatCard", query);
40
- if (query.data !== void 0) return void 0;
41
- if (query.isError) return { error: query.error ?? true };
42
- return query.fetchStatus === "idle" ? void 0 : { pending: true };
35
+ }, [active, node]);
36
+ return { ref: setNode, width };
43
37
  }
44
38
  const TONE_RAIL_WIDTH = 3;
45
39
  const TONE_LABEL = {
@@ -47,15 +41,65 @@ const TONE_LABEL = {
47
41
  warn: "Past the warning threshold",
48
42
  bad: "Past the severe threshold"
49
43
  };
44
+ function renderValueBody({
45
+ pending,
46
+ resolved,
47
+ figure,
48
+ emptyText
49
+ }) {
50
+ if (resolved === void 0) return pending ? /* @__PURE__ */ jsx(ValueSkeleton, {}) : figure;
51
+ if (pending && resolved.kind !== "error") return /* @__PURE__ */ jsx(ValueSkeleton, {});
52
+ switch (resolved.kind) {
53
+ case "pending":
54
+ return /* @__PURE__ */ jsx(ValueSkeleton, {});
55
+ case "error":
56
+ return /* @__PURE__ */ jsx(
57
+ ErrorState,
58
+ {
59
+ error: resolved.error,
60
+ title: "Could not load this figure",
61
+ tier: "section",
62
+ onRetry: () => void resolved.query.refetch(),
63
+ retrying: resolved.query.fetchStatus === "fetching"
64
+ }
65
+ );
66
+ case "empty":
67
+ return /* @__PURE__ */ jsx("p", { className: classes.empty, children: emptyText });
68
+ case "ready":
69
+ return figure;
70
+ default:
71
+ return resolved;
72
+ }
73
+ }
74
+ function renderVisualNode({
75
+ show,
76
+ pending,
77
+ slot
78
+ }) {
79
+ if (!show) return null;
80
+ if (pending) return /* @__PURE__ */ jsx(VisualSkeleton, {});
81
+ return slot;
82
+ }
83
+ function renderFooterNode({
84
+ subtitle,
85
+ pending
86
+ }) {
87
+ if (subtitle === void 0) return null;
88
+ if (pending) return /* @__PURE__ */ jsx(FooterSkeleton, {});
89
+ return /* @__PURE__ */ jsx("p", { className: classes.footer, title: subtitle, children: subtitle });
90
+ }
50
91
  function StatCard({
51
92
  title,
52
93
  icon,
53
- subtitle,
54
94
  info,
95
+ qualifier,
96
+ subtitle,
55
97
  value,
56
98
  unit,
57
99
  breakdown,
58
100
  query,
101
+ loading = false,
102
+ emptyText = "No data for this period",
59
103
  delta,
60
104
  deltaPeriod,
61
105
  deltaPolarity,
@@ -72,12 +116,11 @@ function StatCard({
72
116
  const isRender = typeof sparkline === "function";
73
117
  const bleeds = sparklinePlacement === "bleed";
74
118
  const { ref: slotRef, width: slotWidth } = useSlotWidth(isRender);
75
- const state = sparklineState(query);
76
- const measured = {
77
- width: slotWidth,
78
- height: SPARKLINE_RIGHT_HEIGHT,
79
- ...state !== void 0 && { state }
80
- };
119
+ const resolved = query === void 0 ? void 0 : resolveQueryBranch(query, "StatCard");
120
+ const kind = resolved?.kind ?? "ready";
121
+ const pending = loading || kind === "pending";
122
+ const ready = !pending && kind === "ready";
123
+ const measured = { width: slotWidth, height: SPARKLINE_HEIGHT };
81
124
  const breakdownRows = breakdown === void 0 || breakdown.length === 0 ? null : /* @__PURE__ */ jsx("dl", { className: classes.breakdown, children: breakdown.map((row) => /* @__PURE__ */ jsxs(
82
125
  "div",
83
126
  {
@@ -91,7 +134,7 @@ function StatCard({
91
134
  row.label
92
135
  )) });
93
136
  const breakdownContent = query === void 0 ? breakdownRows : /* @__PURE__ */ jsx(QueryState, { query, tier: "section", children: breakdownRows });
94
- const sparklineNode = sparkline === void 0 ? null : /* @__PURE__ */ jsx(
137
+ const sparklineSlot = !ready || sparkline === void 0 ? null : /* @__PURE__ */ jsx(
95
138
  "div",
96
139
  {
97
140
  ref: slotRef,
@@ -99,21 +142,33 @@ function StatCard({
99
142
  bleeds ? classes.sparklineBleed : classes.sparklineRight,
100
143
  classNames?.sparkline
101
144
  ),
102
- ...!bleeds && {
103
- // CUSTOM PROPERTIES, not `flexBasis`/`height` directly. A React inline style beats every
104
- // stylesheet rule, so an inline `flexBasis: 72` also applied in a narrow card — where `'right'`
105
- // collapses `.metricsRow` to a COLUMN and flex-basis is therefore the main-axis HEIGHT.
106
- // The mobile sparkline rendered in a 72px-tall box holding 26px of bars, which is the dead
107
- // band under every KPI value on a phone. Handed to CSS as values instead, the media query
108
- // can reset the box and the numbers still live in one place.
109
- style: {
110
- "--basalt-stat-sparkline-w": `${SPARKLINE_RIGHT_WIDTH}px`,
111
- "--basalt-stat-sparkline-h": `${SPARKLINE_RIGHT_HEIGHT}px`
112
- }
113
- },
145
+ ...!bleeds && { style: rightSlotStyle(SPARKLINE_RIGHT_WIDTH, SPARKLINE_HEIGHT) },
114
146
  children: isRender ? measured.width > 0 && sparkline(measured) : sparkline
115
147
  }
116
148
  );
149
+ const figure = /* @__PURE__ */ jsxs("div", { className: classes.valueRow, children: [
150
+ /* @__PURE__ */ jsxs("span", { className: classes.figure, children: [
151
+ /* @__PURE__ */ jsx("span", { className: classes.value, children: value }),
152
+ unit !== void 0 && /* @__PURE__ */ jsx("span", { className: classes.unit, children: unit })
153
+ ] }),
154
+ delta !== void 0 && /* @__PURE__ */ jsx(
155
+ DeltaBadge,
156
+ {
157
+ value: delta,
158
+ period: deltaPeriod,
159
+ ...deltaPolarity !== void 0 && { polarity: deltaPolarity },
160
+ ...deltaFormat !== void 0 && { format: deltaFormat },
161
+ ...deltaGlyph !== void 0 && { withGlyph: deltaGlyph }
162
+ }
163
+ )
164
+ ] });
165
+ const valueBody = renderValueBody({ pending, resolved, figure, emptyText });
166
+ const breakdownCount = breakdown?.length ?? 0;
167
+ const hasBreakdown = breakdownCount > 0;
168
+ const rightRow = !bleeds && (ready ? breakdownContent !== null || sparklineSlot !== null : pending && (hasBreakdown || sparkline !== void 0));
169
+ const hasBleedVisual = sparkline !== void 0 && bleeds;
170
+ const visualNode = renderVisualNode({ show: hasBleedVisual, pending, slot: sparklineSlot });
171
+ const footerNode = renderFooterNode({ subtitle, pending });
117
172
  return /* @__PURE__ */ jsxs(
118
173
  Card,
119
174
  {
@@ -127,21 +182,16 @@ function StatCard({
127
182
  //
128
183
  // `overflow: hidden` clips the full-bleed sparkline to the card's rounded corners. An
129
184
  // element's own `box-shadow` renders outside its border box and is NOT clipped by its own
130
- // `overflow`, so the shadow-card ring is unaffected (verified — only an ANCESTOR's overflow
131
- // clips a descendant's shadow). Mantine's Card root already sets `overflow: hidden`; this
132
- // is explicit for intent.
185
+ // `overflow`, so the shadow-card ring is unaffected.
133
186
  //
134
- // NO `minHeight`. It was 118px, which is ~25px of dead space under a card holding a title
135
- // row, a hero row and a 26px trend — and it was dead space the card could not use, since the
136
- // body is `height: 100%` and the sparkline is `margin-top: auto`. The content is what states
137
- // the height now (~88-96px), and four cards in a `SimpleGrid` still match because a grid row
138
- // stretches its items.
187
+ // NO `minHeight`: the content states the height (the foot reserves its own), and cards in a
188
+ // grid row stretch to the tallest.
139
189
  padding: "var(--vx-space-card-inset-y, 0.75rem) var(--vx-space-card-inset-x, 1rem)",
140
190
  overflow: "hidden",
141
191
  // Anchors the tone rail. Set unconditionally so a card's stacking context does not change
142
192
  // depending on whether it happens to have crossed a threshold this render.
143
193
  position: "relative",
144
- // The card's own width drives its chrome (`widget-header.module.css`, `.metricsRow`).
194
+ // The card's own width drives its chrome (`stat-card.module.css`).
145
195
  containerType: "inline-size",
146
196
  containerName: "basalt-card",
147
197
  ...style
@@ -168,35 +218,54 @@ function StatCard({
168
218
  }
169
219
  )
170
220
  ] }),
171
- /* @__PURE__ */ jsxs("div", { className: cx(classes.body, classNames?.body), "data-placement": sparklinePlacement, children: [
172
- /* @__PURE__ */ jsxs("div", { className: cx(classes.header, classNames?.header), children: [
173
- /* @__PURE__ */ jsx(
174
- WidgetHeader,
175
- {
176
- tier: "widget",
177
- title,
178
- ...icon !== void 0 && { icon },
179
- ...subtitle !== void 0 && { subtitle },
180
- ...info !== void 0 && { info },
181
- value,
182
- ...unit !== void 0 && { unit },
183
- ...delta !== void 0 && { delta },
184
- ...deltaPeriod !== void 0 && { deltaPeriod },
185
- ...deltaPolarity !== void 0 && { deltaPolarity },
186
- ...deltaFormat !== void 0 && { deltaFormat },
187
- ...deltaGlyph !== void 0 && { deltaGlyph },
188
- ...actions !== void 0 && {
189
- actions: /* @__PURE__ */ jsx(CtlSlot, { tier: "widget", children: actions })
221
+ /* @__PURE__ */ jsxs(
222
+ "div",
223
+ {
224
+ className: cx(classes.body, classNames?.body),
225
+ "data-placement": sparklinePlacement,
226
+ ...pending && { "aria-busy": true },
227
+ children: [
228
+ pending && /* @__PURE__ */ jsx(VisuallyHidden, { children: `Loading ${title}` }),
229
+ /* @__PURE__ */ jsxs("div", { className: cx(classes.header, classNames?.header), children: [
230
+ /* @__PURE__ */ jsx(
231
+ CaptionRow,
232
+ {
233
+ title,
234
+ ...icon !== void 0 && { icon },
235
+ ...info !== void 0 && { info },
236
+ ...qualifier !== void 0 && { qualifier },
237
+ ...actions !== void 0 && { actions }
238
+ }
239
+ ),
240
+ valueBody,
241
+ bleeds && (pending ? hasBreakdown && /* @__PURE__ */ jsx(BreakdownSkeleton, { rows: breakdownCount }) : ready && breakdownContent)
242
+ ] }),
243
+ rightRow && /* @__PURE__ */ jsx("div", { className: classes.metricsRow, children: ready ? /* @__PURE__ */ jsxs(Fragment, { children: [
244
+ breakdownContent,
245
+ sparklineSlot
246
+ ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
247
+ hasBreakdown && /* @__PURE__ */ jsx(BreakdownSkeleton, { rows: breakdownCount }),
248
+ sparkline !== void 0 && /* @__PURE__ */ jsx(
249
+ "div",
250
+ {
251
+ className: classes.sparklineRight,
252
+ style: rightSlotStyle(SPARKLINE_RIGHT_WIDTH, SPARKLINE_HEIGHT),
253
+ children: /* @__PURE__ */ jsx(VisualSkeleton, {})
254
+ }
255
+ )
256
+ ] }) }),
257
+ /* @__PURE__ */ jsx(
258
+ Foot,
259
+ {
260
+ reserve: hasBleedVisual || subtitle !== void 0,
261
+ visualBand: bleeds,
262
+ visualNode,
263
+ footerNode
190
264
  }
191
- }
192
- ),
193
- bleeds && breakdownContent
194
- ] }),
195
- bleeds ? sparklineNode : (breakdownContent !== null || sparklineNode !== null) && /* @__PURE__ */ jsxs("div", { className: classes.metricsRow, children: [
196
- breakdownContent,
197
- sparklineNode
198
- ] })
199
- ] })
265
+ )
266
+ ]
267
+ }
268
+ )
200
269
  ]
201
270
  }
202
271
  );