basalt-ui 2.15.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.
- package/CHANGELOG.md +157 -105
- package/MIGRATING.md +160 -12
- package/agent/agents/basalt-design-reviewer.md +3 -3
- package/agent/rules/basalt-mantine.md +1 -1
- package/agent/skills/basalt-design/SKILL.md +2 -2
- package/configs/card-inset.test.ts +57 -0
- package/configs/oxlint-basalt.json +1 -1
- package/configs/oxlint-plugin.js +42 -18
- package/configs/oxlint-plugin.test.ts +37 -6
- package/dist/agent/chat/thread-message.js +1 -1
- package/dist/agent/chat/thread-outcome-card.js +1 -1
- package/dist/charts/ChartCard.js +1 -1
- package/dist/charts/Donut.d.ts.map +1 -1
- package/dist/charts/Donut.js +2 -2
- package/dist/charts/DualPanel.js +2 -2
- package/dist/charts/Heatmap.d.ts.map +1 -1
- package/dist/charts/Heatmap.js +2 -2
- package/dist/charts/MirroredBars.js +2 -2
- package/dist/charts/Sparkline.d.ts +4 -2
- package/dist/charts/Sparkline.d.ts.map +1 -1
- package/dist/charts/Sparkline.js +3 -3
- package/dist/charts/chart-card.module.css +2 -2
- package/dist/charts/compile.d.ts +8 -3
- package/dist/charts/compile.d.ts.map +1 -1
- package/dist/charts/compile.js +19 -9
- package/dist/charts/cursor.d.ts +14 -1
- package/dist/charts/cursor.d.ts.map +1 -1
- package/dist/charts/cursor.js +29 -3
- package/dist/charts/date-tick-format.d.ts +17 -0
- package/dist/charts/date-tick-format.d.ts.map +1 -0
- package/dist/charts/date-tick-format.js +81 -0
- package/dist/charts/panel.d.ts +2 -1
- package/dist/charts/panel.d.ts.map +1 -1
- package/dist/charts/panel.js +3 -2
- package/dist/charts/types.d.ts +5 -1
- package/dist/charts/types.d.ts.map +1 -1
- package/dist/cli/shot/board.js +1 -1
- package/dist/cli/shot/capture.d.ts +16 -0
- package/dist/cli/shot/capture.d.ts.map +1 -1
- package/dist/cli/shot/capture.js +24 -3
- package/dist/cli/shot/measure.d.ts +21 -2
- package/dist/cli/shot/measure.d.ts.map +1 -1
- package/dist/cli/shot/measure.js +20 -5
- package/dist/cli/shot/playwright.d.ts +4 -0
- package/dist/cli/shot/playwright.d.ts.map +1 -1
- package/dist/cli/shot/types.d.ts +3 -2
- package/dist/cli/shot/types.d.ts.map +1 -1
- package/dist/dashboard/delta-badge.d.ts +2 -2
- package/dist/dashboard/delta-badge.d.ts.map +1 -1
- package/dist/dashboard/delta-badge.js +12 -14
- package/dist/dashboard/query-state.d.ts +35 -0
- package/dist/dashboard/query-state.d.ts.map +1 -1
- package/dist/dashboard/query-state.js +12 -1
- package/dist/dashboard/settings-section.d.ts.map +1 -1
- package/dist/dashboard/settings-section.js +5 -2
- package/dist/dashboard/stat-card-parts.d.ts +40 -0
- package/dist/dashboard/stat-card-parts.d.ts.map +1 -0
- package/dist/dashboard/stat-card-parts.js +55 -0
- package/dist/dashboard/stat-card.d.ts +46 -34
- package/dist/dashboard/stat-card.d.ts.map +1 -1
- package/dist/dashboard/stat-card.js +157 -88
- package/dist/dashboard/stat-card.module.css +222 -9
- package/dist/dashboard/stat-card.module.css.d.ts +20 -0
- package/dist/dashboard/widget-header.d.ts.map +1 -1
- package/dist/dashboard/widget-header.js +73 -9
- package/dist/dashboard/widget-header.module.css +28 -20
- package/dist/guard/guard-hook.d.ts.map +1 -1
- package/dist/guard/index.d.ts +4 -2
- package/dist/guard/index.d.ts.map +1 -1
- package/dist/guard/index.js +18 -4
- package/dist/guard/vx-names.d.ts.map +1 -1
- package/dist/guard/vx-names.js +1 -0
- package/dist/shell/app-mobile-nav.module.css +2 -2
- package/dist/shell/app-sidebar-account.js +1 -1
- package/dist/shell/app-sidebar.js +2 -2
- package/dist/shell/app-sidebar.module.css +8 -8
- package/dist/shell/index.js +5 -1
- package/dist/shell/page-bar.js +1 -1
- package/dist/table/data-table.d.ts.map +1 -1
- package/dist/table/data-table.js +3 -0
- package/dist/theme/chrome-vars.d.ts +82 -0
- package/dist/theme/chrome-vars.d.ts.map +1 -0
- package/dist/theme/chrome-vars.js +36 -0
- package/dist/theme/controls.module.css +20 -1
- package/dist/theme/controls.module.css.d.ts +1 -0
- package/dist/theme/index.d.ts.map +1 -1
- package/dist/theme/index.js +61 -54
- package/dist/tokens/core.d.ts +10 -4
- package/dist/tokens/core.d.ts.map +1 -1
- package/dist/tokens/core.js +16 -10
- package/dist/tokens/ctl-vars.d.ts +15 -0
- package/dist/tokens/ctl-vars.d.ts.map +1 -0
- package/dist/tokens/ctl-vars.js +22 -0
- package/dist/tokens/derive.d.ts.map +1 -1
- package/dist/tokens/derive.js +2 -2
- package/dist/tokens/palette.d.ts +37 -29
- package/dist/tokens/palette.d.ts.map +1 -1
- package/dist/tokens/palette.js +32 -21
- package/dist/tokens/space-scale.d.ts +14 -0
- package/dist/tokens/space-scale.d.ts.map +1 -0
- package/dist/tokens/space-scale.js +10 -0
- package/llms.txt +6 -3
- package/package.json +1 -1
- package/src/agent/chat/thread-message.tsx +1 -1
- package/src/agent/chat/thread-outcome-card.tsx +2 -2
- package/src/charts/ChartCard.tsx +1 -1
- package/src/charts/Donut.tsx +2 -2
- package/src/charts/DualPanel.tsx +2 -2
- package/src/charts/Heatmap.tsx +2 -2
- package/src/charts/MirroredBars.tsx +2 -2
- package/src/charts/Sparkline.tsx +7 -5
- package/src/charts/chart-card.module.css +2 -2
- package/src/charts/compile.ts +31 -11
- package/src/charts/cursor.ts +48 -3
- package/src/charts/date-tick-format.ts +132 -0
- package/src/charts/panel.tsx +5 -3
- package/src/charts/types.ts +5 -1
- package/src/cli/shot/board.ts +1 -1
- package/src/cli/shot/capture.ts +35 -3
- package/src/cli/shot/measure.ts +33 -6
- package/src/cli/shot/playwright.ts +1 -1
- package/src/cli/shot/types.ts +3 -2
- package/src/dashboard/delta-badge.tsx +24 -18
- package/src/dashboard/query-state.tsx +38 -0
- package/src/dashboard/settings-section.tsx +5 -2
- package/src/dashboard/stat-card-parts.tsx +108 -0
- package/src/dashboard/stat-card.module.css +222 -9
- package/src/dashboard/stat-card.module.css.d.ts +20 -0
- package/src/dashboard/stat-card.tsx +291 -183
- package/src/dashboard/widget-header.module.css +28 -20
- package/src/dashboard/widget-header.tsx +103 -7
- package/src/guard/guard-hook.ts +3 -1
- package/src/guard/index.ts +27 -13
- package/src/guard/vx-names.ts +1 -0
- package/src/shell/app-mobile-nav.module.css +2 -2
- package/src/shell/app-sidebar-account.tsx +1 -1
- package/src/shell/app-sidebar.module.css +8 -8
- package/src/shell/app-sidebar.tsx +2 -2
- package/src/shell/index.tsx +10 -4
- package/src/shell/page-bar.tsx +1 -1
- package/src/table/data-table.tsx +10 -4
- package/src/theme/__snapshots__/plain-theme.test.ts.snap +185 -85
- package/src/theme/chrome-vars.ts +111 -0
- package/src/theme/controls.module.css +20 -1
- package/src/theme/controls.module.css.d.ts +1 -0
- package/src/theme/ctl-theme.tsx +1 -1
- package/src/theme/index.ts +82 -124
- package/src/tokens/core.ts +16 -8
- package/src/tokens/ctl-vars.ts +32 -0
- package/src/tokens/derive.ts +7 -2
- package/src/tokens/palette.ts +40 -29
- package/src/tokens/space-scale.ts +13 -0
|
@@ -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
|
|
7
|
-
* `value` is not its own slot: the hero number is painted
|
|
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
|
|
65
|
-
*
|
|
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
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
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
|
-
*
|
|
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
|
|
103
|
-
*
|
|
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}`)
|
|
107
|
-
*
|
|
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
|
|
114
|
-
* `'right'` sits it beside the
|
|
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
|
-
/**
|
|
117
|
-
* raw `ActionIcon` with no `size` lands on the 24px step the
|
|
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,
|
|
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":"
|
|
1
|
+
{"version":3,"file":"stat-card.d.ts","sourceRoot":"","sources":["../../src/dashboard/stat-card.tsx"],"names":[],"mappings":"AA8FA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAUtC,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;AAGhE;;;GAGG;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;AAaD;;;;;;;;GAQG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAClC,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;CACf,CAAA;AA6CD;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,aAAa,GAAG,WAAW,GACrC,eAAe,CAAC,YAAY,CAAC,GAC7B,IAAI,CAAC,sBAAsB,EAAE,UAAU,CAAC,GACxC,IAAI,CAAC,uBAAuB,EAAE,OAAO,CAAC,GACtC,sBAAsB,GAAG;IACvB;iDAC6C;IAC7C,KAAK,EAAE,MAAM,CAAA;IACb;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB;4CACwC;IACxC,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB;;;;;;;;;;;;OAYG;IACH,SAAS,CAAC,EAAE,SAAS,oBAAoB,EAAE,CAAA;IAC3C;;;;;;;;;;;;;;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,
|
|
4
|
-
import {
|
|
5
|
-
|
|
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
|
|
19
|
+
const SPARKLINE_HEIGHT = 22;
|
|
13
20
|
function useSlotWidth(active) {
|
|
14
21
|
const [width, setWidth] = useState(0);
|
|
15
|
-
const
|
|
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
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
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
|
|
137
|
+
const sparklineSlot = !ready || sparkline === void 0 ? null : /* @__PURE__ */ jsx(
|
|
95
138
|
"div",
|
|
96
139
|
{
|
|
97
140
|
ref: slotRef,
|
|
@@ -99,49 +142,56 @@ 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
|
{
|
|
120
175
|
className: cx(classNames?.root, className),
|
|
121
176
|
style: {
|
|
122
|
-
// Card inset = the `cardInsetY`/`cardInsetX` role tokens (
|
|
123
|
-
//
|
|
124
|
-
//
|
|
125
|
-
//
|
|
126
|
-
//
|
|
127
|
-
// `overflow: hidden` clips
|
|
128
|
-
// the full-bleed sparkline to the card's rounded corners; an element's own `box-shadow`
|
|
129
|
-
// renders outside its border box and is NOT clipped by its own `overflow`, so the
|
|
130
|
-
// shadow-card ring is unaffected (verified — only an ANCESTOR's overflow clips a
|
|
131
|
-
// descendant's shadow). Mantine's Card root already sets `overflow: hidden`; this is
|
|
132
|
-
// explicit for intent.
|
|
177
|
+
// Card inset = the `cardInsetY`/`cardInsetX` role tokens (12/16 at level 0, the `sm`/`md`
|
|
178
|
+
// rungs of the spacing grid), matching every other basalt card because `ChartCard` reads
|
|
179
|
+
// the SAME two vars. Below `sm` the horizontal one steps a rung down (to 12) on its own:
|
|
180
|
+
// the responsive half of the ladder lives in `spaceMobileDecls` (`tokens/index.ts`), which
|
|
181
|
+
// is the only home that can reach an inline style like this one.
|
|
133
182
|
//
|
|
134
|
-
//
|
|
135
|
-
//
|
|
136
|
-
//
|
|
137
|
-
//
|
|
138
|
-
//
|
|
139
|
-
|
|
183
|
+
// `overflow: hidden` clips the full-bleed sparkline to the card's rounded corners. An
|
|
184
|
+
// element's own `box-shadow` renders outside its border box and is NOT clipped by its own
|
|
185
|
+
// `overflow`, so the shadow-card ring is unaffected.
|
|
186
|
+
//
|
|
187
|
+
// NO `minHeight`: the content states the height (the foot reserves its own), and cards in a
|
|
188
|
+
// grid row stretch to the tallest.
|
|
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 (`
|
|
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(
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
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
|
-
|
|
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
|
);
|