basalt-ui 2.16.0 → 2.18.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 +165 -124
- package/MIGRATING.md +133 -15
- package/agent/agents/basalt-design-reviewer.md +2 -2
- package/agent/skills/basalt-design/SKILL.md +3 -3
- package/configs/oxlint-plugin.js +2 -2
- 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/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/help.d.ts +1 -0
- package/dist/cli/help.d.ts.map +1 -1
- package/dist/cli/help.js +8 -2
- package/dist/cli/shot/capture.d.ts +28 -1
- package/dist/cli/shot/capture.d.ts.map +1 -1
- package/dist/cli/shot/capture.js +96 -13
- package/dist/cli/shot/index.d.ts +10 -1
- package/dist/cli/shot/index.d.ts.map +1 -1
- package/dist/cli/shot/index.js +40 -5
- package/dist/cli/shot/playwright.d.ts +4 -0
- package/dist/cli/shot/playwright.d.ts.map +1 -1
- package/dist/cli/shot/real-data.d.ts +35 -0
- package/dist/cli/shot/real-data.d.ts.map +1 -0
- package/dist/cli/shot/real-data.js +120 -0
- package/dist/cli/shot/serve.d.ts +2 -2
- package/dist/cli/shot/serve.d.ts.map +1 -1
- package/dist/cli/shot/serve.js +16 -2
- package/dist/dashboard/bar-list.d.ts +29 -0
- package/dist/dashboard/bar-list.d.ts.map +1 -0
- package/dist/dashboard/bar-list.js +52 -0
- package/dist/dashboard/bar-list.module.css +73 -0
- package/dist/dashboard/bar-list.module.css.d.ts +16 -0
- 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/index.d.ts +2 -0
- package/dist/dashboard/index.d.ts.map +1 -1
- package/dist/dashboard/index.js +4 -0
- package/dist/dashboard/meter-model.d.ts +78 -0
- package/dist/dashboard/meter-model.d.ts.map +1 -0
- package/dist/dashboard/meter-model.js +91 -0
- package/dist/dashboard/meter-parts.d.ts +42 -0
- package/dist/dashboard/meter-parts.d.ts.map +1 -0
- package/dist/dashboard/meter-parts.js +163 -0
- package/dist/dashboard/meter.d.ts +112 -0
- package/dist/dashboard/meter.d.ts.map +1 -0
- package/dist/dashboard/meter.js +43 -0
- package/dist/dashboard/meter.module.css +150 -0
- package/dist/dashboard/meter.module.css.d.ts +28 -0
- 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/scale.d.ts +9 -0
- package/dist/dashboard/scale.d.ts.map +1 -0
- package/dist/dashboard/scale.js +10 -0
- 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 +148 -79
- package/dist/dashboard/stat-card.module.css +220 -7
- 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 +25 -17
- package/dist/guard/index.js +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- 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 +30 -33
- package/dist/tokens/derive.d.ts +11 -1
- package/dist/tokens/derive.d.ts.map +1 -1
- package/dist/tokens/derive.js +9 -24
- package/dist/tokens/status-text.d.ts +26 -0
- package/dist/tokens/status-text.d.ts.map +1 -0
- package/dist/tokens/status-text.js +68 -0
- package/llms.txt +36 -4
- package/package.json +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/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/help.ts +22 -2
- package/src/cli/shot/capture.ts +133 -12
- package/src/cli/shot/index.ts +50 -4
- package/src/cli/shot/playwright.ts +1 -1
- package/src/cli/shot/real-data.ts +165 -0
- package/src/cli/shot/serve.ts +28 -3
- package/src/dashboard/bar-list.module.css +73 -0
- package/src/dashboard/bar-list.module.css.d.ts +16 -0
- package/src/dashboard/bar-list.tsx +112 -0
- package/src/dashboard/delta-badge.tsx +24 -18
- package/src/dashboard/index.ts +2 -0
- package/src/dashboard/meter-model.ts +161 -0
- package/src/dashboard/meter-parts.tsx +223 -0
- package/src/dashboard/meter.module.css +150 -0
- package/src/dashboard/meter.module.css.d.ts +28 -0
- package/src/dashboard/meter.tsx +162 -0
- package/src/dashboard/query-state.tsx +38 -0
- package/src/dashboard/scale.ts +13 -0
- package/src/dashboard/stat-card-parts.tsx +108 -0
- package/src/dashboard/stat-card.module.css +220 -7
- package/src/dashboard/stat-card.module.css.d.ts +20 -0
- package/src/dashboard/stat-card.tsx +282 -174
- package/src/dashboard/widget-header.module.css +25 -17
- package/src/dashboard/widget-header.tsx +103 -7
- package/src/guard/index.ts +2 -2
- package/src/index.ts +4 -0
- package/src/theme/__snapshots__/plain-theme.test.ts.snap +128 -40
- 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/index.ts +39 -101
- package/src/tokens/derive.ts +19 -26
- package/src/tokens/status-text.ts +85 -0
|
@@ -1,31 +1,35 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* StatCard — the
|
|
3
|
-
*
|
|
4
|
-
* height, ~88-96px for the title/hero/trend shape). The header composes
|
|
5
|
-
* `WidgetHeader tier="widget"` — title/icon/value/delta/deltaPeriod all render through it, on the
|
|
6
|
-
* shared hero-metric row under the title. `actions` (e.g. a ghost "..." menu trigger) is wrapped in
|
|
7
|
-
* `CtlSlot tier="widget"` — the 24px ActionIcon step the 28px widget header row can hold, not the
|
|
8
|
-
* 30px `ctl` tier, which used to grow the row and knock a card with a kebab 2px out of line with the
|
|
9
|
-
* card beside it. `StatCard` is Mantine-coupled (`src/dashboard/`), unlike `ChartCard`, so it can
|
|
10
|
-
* mount the slot at all; `ChartCard` writes the same `data-basalt-tier="widget"` marker by hand.
|
|
2
|
+
* StatCard — the metric card (docs/waves/design-parity/SPEC.md § 6.1): a panel + shadow-card +
|
|
3
|
+
* card-radius card (inset `cardInsetY`/`cardInsetX`, no min-height) holding, top to bottom,
|
|
11
4
|
*
|
|
12
|
-
* `
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
5
|
+
* 1. the CAPTION row — `title` as a mono uppercase `micro` faint label, the optional `info` glyph,
|
|
6
|
+
* `qualifier` right-aligned (period, target or source; it takes its own line UNDER the caption,
|
|
7
|
+
* left-aligned, when the card is too narrow for both), and the `actions` slot;
|
|
8
|
+
* 2. the VALUE row — the hero figure (`kpi`, mono 500), `unit` inline at `sm` muted on the same
|
|
9
|
+
* baseline, then the delta (text only — see `DeltaBadge`) and its muted `deltaPeriod`;
|
|
10
|
+
* 3. the FOOT — the `sparkline` visual (22 px, bled to the card's side edges) and one muted `sm`
|
|
11
|
+
* `subtitle` line under it (a source or "as of", never a restatement of the caption).
|
|
16
12
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* beside the title instead of inside the heading's accessible name.
|
|
13
|
+
* Exactly three type sizes: `micro` (caption, qualifier, delta period), `sm` (unit, delta, footer)
|
|
14
|
+
* and the hero. The foot reserves the height of a visual plus a footer line whenever either is
|
|
15
|
+
* present, so cards in one grid row share a footprint with or without a visual.
|
|
21
16
|
*
|
|
22
|
-
* `
|
|
23
|
-
*
|
|
17
|
+
* `StatCard` renders this anatomy itself (it no longer goes through `WidgetHeader`, whose head-font
|
|
18
|
+
* title is `ChartCard`'s and the section headers'). `InfoGlyph` and `DeltaBadge` are the shared parts.
|
|
24
19
|
*
|
|
25
|
-
* `
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
20
|
+
* `sparklinePlacement` decides where the trend visual sits: `'bleed'` (default) puts it in the foot,
|
|
21
|
+
* full card width; `'right'` sits it beside the `breakdown` rows below the value row, a fixed 72×22
|
|
22
|
+
* slot. In a card narrower than 480px, `'right'` collapses back to the `'bleed'` layout — CSS only.
|
|
23
|
+
*
|
|
24
|
+
* `src/dashboard` stays chart-free — `sparkline` is a plain `ReactNode` slot (or a render prop over
|
|
25
|
+
* the slot's measured box), never a chart import here. Pass `<Sparkline>` from `basalt-ui/charts` at
|
|
26
|
+
* the call site: its defaults (end dot in the line neutral, 1.5 stroke, no axes) are made for this slot.
|
|
27
|
+
*
|
|
28
|
+
* `query` drives the card's branches at the card's own footprint: pending shows a skeleton (caption,
|
|
29
|
+
* value bar, visual slot — never a spinner), failed-with-no-data replaces the value row with the
|
|
30
|
+
* `QueryState` error (one sentence + Retry), and an empty result replaces it with one muted line
|
|
31
|
+
* (`emptyText`). `loading` shows the same skeleton with no query at all. The caption row stays put
|
|
32
|
+
* in every branch.
|
|
29
33
|
*
|
|
30
34
|
* `tone` marks the card as past a threshold with an accent rail down its leading edge. It exists
|
|
31
35
|
* because `value` is typed `string`: without it, a card whose number has crossed a threshold reads
|
|
@@ -41,45 +45,37 @@
|
|
|
41
45
|
*
|
|
42
46
|
* @example
|
|
43
47
|
* import { StatCard } from 'basalt-ui'
|
|
48
|
+
* import { Sparkline } from 'basalt-ui/charts'
|
|
44
49
|
*
|
|
45
50
|
* // `sparkline` is a RENDER PROP over the slot's measured box, so full-bleed is genuinely the
|
|
46
51
|
* // card's width — no measuring wrapper component, no hardcoded pixel value.
|
|
47
52
|
* <StatCard
|
|
48
|
-
* title="Active
|
|
53
|
+
* title="Active users"
|
|
54
|
+
* qualifier="30 days"
|
|
49
55
|
* value="12,483"
|
|
50
56
|
* delta={4.2}
|
|
51
|
-
*
|
|
57
|
+
* deltaPeriod="MoM"
|
|
58
|
+
* subtitle="Source: events table"
|
|
59
|
+
* sparkline={(size) => <Sparkline ariaLabel="Active users" data={history} {...size} />}
|
|
52
60
|
* />
|
|
53
61
|
*
|
|
54
62
|
* @example
|
|
55
|
-
* // The
|
|
56
|
-
* // slot is a fixed 72×26 there, so the render prop still receives the box it should draw into.
|
|
57
|
-
* <StatCard
|
|
58
|
-
* title="Active Users"
|
|
59
|
-
* value="12,483"
|
|
60
|
-
* delta={4.2}
|
|
61
|
-
* sparklinePlacement="right"
|
|
62
|
-
* sparkline={({ width, height }) => (
|
|
63
|
-
* <MySparkline data={history} width={width} height={height} ariaLabel="Active users trend" />
|
|
64
|
-
* )}
|
|
65
|
-
* />
|
|
66
|
-
*
|
|
67
|
-
* @example
|
|
68
|
-
* // A hero card: the unit on its own muted line, the method behind the info glyph.
|
|
63
|
+
* // The unit inline, the method behind the info glyph.
|
|
69
64
|
* <StatCard
|
|
70
65
|
* title="Training load"
|
|
66
|
+
* qualifier="7-day rolling"
|
|
71
67
|
* value="412"
|
|
72
|
-
*
|
|
68
|
+
* unit="TSS"
|
|
73
69
|
* info="Sum of per-session TSS over the last 7 days, Garmin-reported."
|
|
74
70
|
* />
|
|
75
71
|
*
|
|
76
72
|
* @example
|
|
77
|
-
* //
|
|
78
|
-
* <StatCard title="
|
|
73
|
+
* // A pending card with no query: the skeleton at the card's own footprint.
|
|
74
|
+
* <StatCard title="Active users" value="—" loading sparkline={() => null} />
|
|
79
75
|
*
|
|
80
76
|
* @example
|
|
81
|
-
* //
|
|
82
|
-
* <StatCard title="Downtime
|
|
77
|
+
* // Past a threshold — an accent rail down the leading edge, value untouched.
|
|
78
|
+
* <StatCard title="Downtime" value="29 min" tone="bad" />
|
|
83
79
|
*
|
|
84
80
|
* @example
|
|
85
81
|
* // The honest gate. A zero can be synthesized as well as measured — a downtime figure derived
|
|
@@ -88,33 +84,40 @@
|
|
|
88
84
|
* // about a reading, so the gate belongs on whether a reading exists, not on whether the number
|
|
89
85
|
* // happens to be defined — those are separate facts. Gate on measured coverage instead:
|
|
90
86
|
* <StatCard
|
|
91
|
-
* title="Downtime
|
|
87
|
+
* title="Downtime"
|
|
88
|
+
* qualifier="24 h"
|
|
92
89
|
* value={`${downtimeMinutes} min`}
|
|
93
90
|
* tone={hasCoverage ? (downtimeMinutes === 0 ? 'good' : 'bad') : undefined}
|
|
94
91
|
* />
|
|
95
92
|
*/
|
|
96
93
|
import { Box, Card, VisuallyHidden } from '@mantine/core'
|
|
97
|
-
import { useEffect,
|
|
98
|
-
import type {
|
|
99
|
-
import {
|
|
94
|
+
import { useEffect, useState } from 'react'
|
|
95
|
+
import type { ReactNode } from 'react'
|
|
96
|
+
import {
|
|
97
|
+
BreakdownSkeleton,
|
|
98
|
+
CaptionRow,
|
|
99
|
+
FooterSkeleton,
|
|
100
|
+
Foot,
|
|
101
|
+
ValueSkeleton,
|
|
102
|
+
VisualSkeleton,
|
|
103
|
+
rightSlotStyle,
|
|
104
|
+
} from './stat-card-parts'
|
|
100
105
|
import type {
|
|
101
106
|
WidgetHeaderDeltaProps,
|
|
102
107
|
WidgetHeaderMetricProps,
|
|
103
108
|
WidgetHeaderTitleProps,
|
|
104
109
|
} from './widget-header'
|
|
105
|
-
import {
|
|
110
|
+
import { DeltaBadge } from './delta-badge'
|
|
106
111
|
import { VX } from '../tokens'
|
|
107
112
|
import { cx } from '../common/props'
|
|
108
113
|
import type { BasaltProps, SlotStylesProps, Tone } from '../common/props'
|
|
109
|
-
import { QueryState } from './query-state'
|
|
110
|
-
import type { QueryStateLike } from './query-state'
|
|
111
|
-
import { assertQueryStateLike } from '../common/query-state-like'
|
|
114
|
+
import { ErrorState, QueryState, resolveQueryBranch } from './query-state'
|
|
115
|
+
import type { QueryBranch, QueryStateLike } from './query-state'
|
|
112
116
|
import classes from './stat-card.module.css'
|
|
113
117
|
|
|
114
118
|
/**
|
|
115
|
-
* The
|
|
116
|
-
* `value` is not its own slot: the hero number is painted
|
|
117
|
-
* which does not yet accept a slot class of its own.
|
|
119
|
+
* The boxes `StatCard` paints, and the whole styling seam it offers (`common/props.ts`).
|
|
120
|
+
* `value` is not its own slot: the hero number is painted inside the `header` box.
|
|
118
121
|
*/
|
|
119
122
|
export type StatCardSlot = 'root' | 'header' | 'body' | 'sparkline'
|
|
120
123
|
|
|
@@ -134,15 +137,14 @@ export type StatCardBreakdownRow = {
|
|
|
134
137
|
|
|
135
138
|
/**
|
|
136
139
|
* The `'right'` placement's slot width, in px — a flex BASIS, not a fixed size. 72 is the reference
|
|
137
|
-
* KPI card's trend width and the slot asks for exactly that; when the
|
|
138
|
-
* long formatted value plus a delta
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
* fixed 72 painted over the value instead.
|
|
140
|
+
* KPI card's trend width and the slot asks for exactly that; when the value row needs the space (a
|
|
141
|
+
* long formatted value plus a delta in a 4-up grid) the slot is the side that yields, because the
|
|
142
|
+
* number is the card's content and the trend qualifies it. The render prop is handed the MEASURED
|
|
143
|
+
* width either way, so the bars are drawn at the width they actually got.
|
|
142
144
|
*/
|
|
143
145
|
const SPARKLINE_RIGHT_WIDTH = 72
|
|
144
|
-
/** The
|
|
145
|
-
const
|
|
146
|
+
/** The sparkline slot's height in both placements (SPEC § 6.2: 26 → 22). */
|
|
147
|
+
const SPARKLINE_HEIGHT = 22
|
|
146
148
|
|
|
147
149
|
/**
|
|
148
150
|
* The measured box a `sparkline` render prop receives.
|
|
@@ -156,13 +158,6 @@ const SPARKLINE_RIGHT_HEIGHT = 26
|
|
|
156
158
|
export type StatCardSparklineSize = {
|
|
157
159
|
width: number
|
|
158
160
|
height: number
|
|
159
|
-
/**
|
|
160
|
-
* The card's `query` as a chart state — present only while the sparkline has nothing to draw
|
|
161
|
-
* (pending, or failed with no data), so `<Sparkline {...size} />` forwards it and the tile shows a
|
|
162
|
-
* sized placeholder instead of a hand-rolled `'—'`. Structurally a `ChartState`: this module
|
|
163
|
-
* stays chart-free. Absent without a `query`, and once data has arrived.
|
|
164
|
-
*/
|
|
165
|
-
state?: { pending?: boolean; error?: unknown; empty?: boolean }
|
|
166
161
|
}
|
|
167
162
|
|
|
168
163
|
/**
|
|
@@ -177,10 +172,11 @@ function useSlotWidth(active: boolean): {
|
|
|
177
172
|
width: number
|
|
178
173
|
} {
|
|
179
174
|
const [width, setWidth] = useState(0)
|
|
180
|
-
|
|
175
|
+
// State, not a ref: the slot mounts and unmounts with the card's branch (skeleton → figure), so
|
|
176
|
+
// the effect must re-run when the node itself changes, not only when `active` does.
|
|
177
|
+
const [node, setNode] = useState<HTMLDivElement | null>(null)
|
|
181
178
|
|
|
182
179
|
useEffect(() => {
|
|
183
|
-
const node = nodeRef.current
|
|
184
180
|
if (!active || node === null) return
|
|
185
181
|
const measure = () => {
|
|
186
182
|
setWidth(node.getBoundingClientRect().width)
|
|
@@ -192,26 +188,9 @@ function useSlotWidth(active: boolean): {
|
|
|
192
188
|
return () => {
|
|
193
189
|
observer.disconnect()
|
|
194
190
|
}
|
|
195
|
-
}, [active])
|
|
191
|
+
}, [active, node])
|
|
196
192
|
|
|
197
|
-
return {
|
|
198
|
-
ref: (node) => {
|
|
199
|
-
nodeRef.current = node
|
|
200
|
-
},
|
|
201
|
-
width,
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
/** The `query` as a sparkline state, by the same precedence as {@link QueryState}: an error with no
|
|
206
|
-
* data is an error, no data and not idle is pending, anything else draws. */
|
|
207
|
-
function sparklineState(
|
|
208
|
-
query: QueryStateLike<unknown> | undefined,
|
|
209
|
-
): StatCardSparklineSize['state'] {
|
|
210
|
-
if (query === undefined) return undefined
|
|
211
|
-
assertQueryStateLike('StatCard', query)
|
|
212
|
-
if (query.data !== undefined) return undefined
|
|
213
|
-
if (query.isError) return { error: query.error ?? true }
|
|
214
|
-
return query.fetchStatus === 'idle' ? undefined : { pending: true }
|
|
193
|
+
return { ref: setNode, width }
|
|
215
194
|
}
|
|
216
195
|
|
|
217
196
|
/** The rail's width, in px. Wide enough to read as a deliberate mark at a glance, narrow enough
|
|
@@ -241,12 +220,34 @@ const TONE_LABEL: Record<Tone, string> = {
|
|
|
241
220
|
*/
|
|
242
221
|
export type StatCardProps = BasaltProps &
|
|
243
222
|
SlotStylesProps<StatCardSlot> &
|
|
244
|
-
WidgetHeaderTitleProps &
|
|
223
|
+
Omit<WidgetHeaderTitleProps, 'subtitle'> &
|
|
245
224
|
Omit<WidgetHeaderMetricProps, 'value'> &
|
|
246
225
|
WidgetHeaderDeltaProps & {
|
|
247
|
-
/** Pre-formatted
|
|
248
|
-
*
|
|
226
|
+
/** Pre-formatted hero figure (mono `kpi`, weight 500, ink). Required here, unlike on
|
|
227
|
+
* `WidgetHeader`: see the type's own doc. */
|
|
249
228
|
value: string
|
|
229
|
+
/**
|
|
230
|
+
* Right-aligned on the caption row, `micro` muted: the period, target or source the figure is
|
|
231
|
+
* measured over (`30 days`, `target 99.9%`). Wraps under the caption when the card is too narrow
|
|
232
|
+
* for both. Not a restatement of the caption.
|
|
233
|
+
*/
|
|
234
|
+
qualifier?: string
|
|
235
|
+
/**
|
|
236
|
+
* One muted `sm` line in the foot, under the visual: a source or "as of"
|
|
237
|
+
* (`Source: events table`, `as of 14:02`), never a restatement of the caption. It was a line
|
|
238
|
+
* under the title before; the old placement has no replacement — put the text in `qualifier`
|
|
239
|
+
* (period/target) or `info` (method).
|
|
240
|
+
*/
|
|
241
|
+
subtitle?: string
|
|
242
|
+
/**
|
|
243
|
+
* Shows the skeleton at the card's own footprint (caption stays, value bar, visual slot) without
|
|
244
|
+
* a query — for a streamed or suspended value. With a `query` the pending branch shows it by
|
|
245
|
+
* itself. No spinner ever renders inside a card.
|
|
246
|
+
*/
|
|
247
|
+
loading?: boolean
|
|
248
|
+
/** The one muted line the empty branch shows in place of the figure. Say why it is empty.
|
|
249
|
+
* Default `No data for this period`. */
|
|
250
|
+
emptyText?: string
|
|
250
251
|
/**
|
|
251
252
|
* The parts the hero number is made of — compact rows under it, one line each, no hairlines.
|
|
252
253
|
*
|
|
@@ -262,15 +263,16 @@ export type StatCardProps = BasaltProps &
|
|
|
262
263
|
*/
|
|
263
264
|
breakdown?: readonly StatCardBreakdownRow[]
|
|
264
265
|
/**
|
|
265
|
-
* The async result behind the number. Supplied, the card
|
|
266
|
-
*
|
|
267
|
-
*
|
|
268
|
-
*
|
|
266
|
+
* The async result behind the number. Supplied, the card picks its body from it, at the card's
|
|
267
|
+
* own footprint and with the caption row untouched:
|
|
268
|
+
*
|
|
269
|
+
* - pending → the skeleton (caption, value bar, visual slot), never a spinner;
|
|
270
|
+
* - error with no data → `QueryState`'s error at the `'section'` tier: one sentence and Retry;
|
|
271
|
+
* - empty (`[]`, `{ data: [] }`, or idle with no data) → one muted line, {@link emptyText};
|
|
272
|
+
* - data → the figure, with `breakdown` behind `QueryState`. A failed background refetch shows
|
|
273
|
+
* its "cached data" banner over the breakdown only; the figure path adds no banner.
|
|
269
274
|
*
|
|
270
|
-
*
|
|
271
|
-
* exists to delete, and got it wrong in the direction that renders "no data" over a 500. The
|
|
272
|
-
* BRANCH is basalt's; the number is not — `value` is still whatever you formatted, so pass a
|
|
273
|
-
* placeholder (`'—'`) while the query is pending rather than a stale one.
|
|
275
|
+
* The BRANCH is basalt's; the number is not — `value` is still whatever you formatted.
|
|
274
276
|
*
|
|
275
277
|
* @example
|
|
276
278
|
* <StatCard title="Active users" value={q.data ? fmt(q.data.count) : '—'} query={q} />
|
|
@@ -282,22 +284,23 @@ export type StatCardProps = BasaltProps &
|
|
|
282
284
|
* Prefer the render prop for any SVG sparkline: those take numeric `width`/`height`
|
|
283
285
|
* (SVG attributes), so a plain node has to hardcode a width, and a hardcoded width is not
|
|
284
286
|
* full-bleed on any viewport but the one it was typed on. With `sparklinePlacement="bleed"` the
|
|
285
|
-
* measured width is the card's own inner width including the bled inset
|
|
286
|
-
*
|
|
287
|
+
* measured width is the card's own inner width including the bled inset, 22 px tall; with
|
|
288
|
+
* `'right'` it is the 72×22 slot (see {@link SPARKLINE_RIGHT_WIDTH} for why the width is a basis).
|
|
287
289
|
*
|
|
288
290
|
* A render prop is a sanctioned pattern here, so `react/no-unstable-nested-components` is
|
|
289
|
-
* configured with `allowAsProps` in the shipped preset. Spread the size (`{...size}`)
|
|
290
|
-
*
|
|
291
|
+
* configured with `allowAsProps` in the shipped preset. Spread the size (`{...size}`) into the
|
|
292
|
+
* chart.
|
|
291
293
|
*
|
|
292
294
|
* @example
|
|
293
295
|
* sparkline={(size) => <Sparkline ariaLabel="Active users" data={history} {...size} />}
|
|
294
296
|
*/
|
|
295
297
|
sparkline?: ReactNode | ((size: StatCardSparklineSize) => ReactNode)
|
|
296
|
-
/** Where `sparkline` sits. `'bleed'` (default) is
|
|
297
|
-
* `'right'` sits it beside the
|
|
298
|
+
/** Where `sparkline` sits. `'bleed'` (default) is the foot, full card width, bled to the side
|
|
299
|
+
* edges; `'right'` sits it beside the `breakdown` rows. Collapses to `'bleed'` in a card narrower
|
|
300
|
+
* than 480px. */
|
|
298
301
|
sparklinePlacement?: 'bleed' | 'right'
|
|
299
|
-
/**
|
|
300
|
-
* raw `ActionIcon` with no `size` lands on the 24px step the
|
|
302
|
+
/** Caption-row right slot (e.g. a ghost "..." menu trigger) — wrapped in `CtlSlot tier="widget"`,
|
|
303
|
+
* so a raw `ActionIcon` with no `size` lands on the 24px step the caption row holds (C1/C5). */
|
|
301
304
|
actions?: ReactNode
|
|
302
305
|
/** Threshold verdict — draws an accent rail down the card's leading edge and announces itself to
|
|
303
306
|
* assistive tech. Omitting it is NOT `'good'`: omitted covers a reading that is fine AND one that
|
|
@@ -306,15 +309,90 @@ export type StatCardProps = BasaltProps &
|
|
|
306
309
|
tone?: Tone
|
|
307
310
|
}
|
|
308
311
|
|
|
312
|
+
/**
|
|
313
|
+
* The value row's body per branch (loading > error > pending > empty > ready; the resolver orders the
|
|
314
|
+
* query branches). The caption row above it is identical in all of them.
|
|
315
|
+
*/
|
|
316
|
+
function renderValueBody({
|
|
317
|
+
pending,
|
|
318
|
+
resolved,
|
|
319
|
+
figure,
|
|
320
|
+
emptyText,
|
|
321
|
+
}: {
|
|
322
|
+
pending: boolean
|
|
323
|
+
resolved: QueryBranch<unknown> | undefined
|
|
324
|
+
figure: ReactNode
|
|
325
|
+
emptyText: string
|
|
326
|
+
}): ReactNode {
|
|
327
|
+
if (resolved === undefined) return pending ? <ValueSkeleton /> : figure
|
|
328
|
+
// `loading` with a query still shows the skeleton, but a failed query is never hidden by it.
|
|
329
|
+
if (pending && resolved.kind !== 'error') return <ValueSkeleton />
|
|
330
|
+
switch (resolved.kind) {
|
|
331
|
+
case 'pending':
|
|
332
|
+
return <ValueSkeleton />
|
|
333
|
+
case 'error':
|
|
334
|
+
// The error state itself — not `QueryState` with nothing to wrap, which over cached-empty data
|
|
335
|
+
// would draw its "cached data" banner above an empty region.
|
|
336
|
+
return (
|
|
337
|
+
<ErrorState
|
|
338
|
+
error={resolved.error}
|
|
339
|
+
title="Could not load this figure"
|
|
340
|
+
tier="section"
|
|
341
|
+
onRetry={() => void resolved.query.refetch()}
|
|
342
|
+
retrying={resolved.query.fetchStatus === 'fetching'}
|
|
343
|
+
/>
|
|
344
|
+
)
|
|
345
|
+
case 'empty':
|
|
346
|
+
return <p className={classes.empty}>{emptyText}</p>
|
|
347
|
+
case 'ready':
|
|
348
|
+
return figure
|
|
349
|
+
default:
|
|
350
|
+
return resolved satisfies never
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
function renderVisualNode({
|
|
355
|
+
show,
|
|
356
|
+
pending,
|
|
357
|
+
slot,
|
|
358
|
+
}: {
|
|
359
|
+
show: boolean
|
|
360
|
+
pending: boolean
|
|
361
|
+
slot: ReactNode
|
|
362
|
+
}): ReactNode {
|
|
363
|
+
if (!show) return null
|
|
364
|
+
if (pending) return <VisualSkeleton />
|
|
365
|
+
return slot
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
function renderFooterNode({
|
|
369
|
+
subtitle,
|
|
370
|
+
pending,
|
|
371
|
+
}: {
|
|
372
|
+
subtitle: string | undefined
|
|
373
|
+
pending: boolean
|
|
374
|
+
}): ReactNode {
|
|
375
|
+
if (subtitle === undefined) return null
|
|
376
|
+
if (pending) return <FooterSkeleton />
|
|
377
|
+
return (
|
|
378
|
+
<p className={classes.footer} title={subtitle}>
|
|
379
|
+
{subtitle}
|
|
380
|
+
</p>
|
|
381
|
+
)
|
|
382
|
+
}
|
|
383
|
+
|
|
309
384
|
export function StatCard({
|
|
310
385
|
title,
|
|
311
386
|
icon,
|
|
312
|
-
subtitle,
|
|
313
387
|
info,
|
|
388
|
+
qualifier,
|
|
389
|
+
subtitle,
|
|
314
390
|
value,
|
|
315
391
|
unit,
|
|
316
392
|
breakdown,
|
|
317
393
|
query,
|
|
394
|
+
loading = false,
|
|
395
|
+
emptyText = 'No data for this period',
|
|
318
396
|
delta,
|
|
319
397
|
deltaPeriod,
|
|
320
398
|
deltaPolarity,
|
|
@@ -332,12 +410,11 @@ export function StatCard({
|
|
|
332
410
|
const bleeds = sparklinePlacement === 'bleed'
|
|
333
411
|
// Only a render prop needs a measurement; a plain node sizes itself.
|
|
334
412
|
const { ref: slotRef, width: slotWidth } = useSlotWidth(isRender)
|
|
335
|
-
const
|
|
336
|
-
const
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
}
|
|
413
|
+
const resolved = query === undefined ? undefined : resolveQueryBranch(query, 'StatCard')
|
|
414
|
+
const kind = resolved?.kind ?? 'ready'
|
|
415
|
+
const pending = loading || kind === 'pending'
|
|
416
|
+
const ready = !pending && kind === 'ready'
|
|
417
|
+
const measured: StatCardSparklineSize = { width: slotWidth, height: SPARKLINE_HEIGHT }
|
|
341
418
|
|
|
342
419
|
// A `<dl>`, not a table and not a stack of divs: each row IS a term and its value, which is the
|
|
343
420
|
// one semantic that survives a reader meeting the card out of context.
|
|
@@ -357,9 +434,8 @@ export function StatCard({
|
|
|
357
434
|
</dl>
|
|
358
435
|
)
|
|
359
436
|
|
|
360
|
-
//
|
|
361
|
-
// whichever placement branch below
|
|
362
|
-
// `.metricsRow`), never both.
|
|
437
|
+
// Behind `QueryState` when a query is supplied, so an error WITH data shows its "cached data"
|
|
438
|
+
// banner. Computed once, consumed by whichever placement branch below renders it, never both.
|
|
363
439
|
const breakdownContent: ReactNode =
|
|
364
440
|
query === undefined ? (
|
|
365
441
|
breakdownRows
|
|
@@ -369,26 +445,17 @@ export function StatCard({
|
|
|
369
445
|
</QueryState>
|
|
370
446
|
)
|
|
371
447
|
|
|
372
|
-
|
|
373
|
-
|
|
448
|
+
// Built ONLY when ready: the render prop must not run in a pending / failed / empty branch, where
|
|
449
|
+
// the last measured width is stale.
|
|
450
|
+
const sparklineSlot: ReactNode =
|
|
451
|
+
!ready || sparkline === undefined ? null : (
|
|
374
452
|
<div
|
|
375
453
|
ref={slotRef}
|
|
376
454
|
className={cx(
|
|
377
455
|
bleeds ? classes.sparklineBleed : classes.sparklineRight,
|
|
378
456
|
classNames?.sparkline,
|
|
379
457
|
)}
|
|
380
|
-
{...(!bleeds && {
|
|
381
|
-
// CUSTOM PROPERTIES, not `flexBasis`/`height` directly. A React inline style beats every
|
|
382
|
-
// stylesheet rule, so an inline `flexBasis: 72` also applied in a narrow card — where `'right'`
|
|
383
|
-
// collapses `.metricsRow` to a COLUMN and flex-basis is therefore the main-axis HEIGHT.
|
|
384
|
-
// The mobile sparkline rendered in a 72px-tall box holding 26px of bars, which is the dead
|
|
385
|
-
// band under every KPI value on a phone. Handed to CSS as values instead, the media query
|
|
386
|
-
// can reset the box and the numbers still live in one place.
|
|
387
|
-
style: {
|
|
388
|
-
'--basalt-stat-sparkline-w': `${SPARKLINE_RIGHT_WIDTH}px`,
|
|
389
|
-
'--basalt-stat-sparkline-h': `${SPARKLINE_RIGHT_HEIGHT}px`,
|
|
390
|
-
} as CSSProperties,
|
|
391
|
-
})}
|
|
458
|
+
{...(!bleeds && { style: rightSlotStyle(SPARKLINE_RIGHT_WIDTH, SPARKLINE_HEIGHT) })}
|
|
392
459
|
>
|
|
393
460
|
{/* A measured slot renders nothing on the first commit (width 0) — an SVG at width 0 is a
|
|
394
461
|
visible 0-width box that then jumps, which is worse than one frame of nothing. */}
|
|
@@ -396,6 +463,40 @@ export function StatCard({
|
|
|
396
463
|
</div>
|
|
397
464
|
)
|
|
398
465
|
|
|
466
|
+
const figure = (
|
|
467
|
+
<div className={classes.valueRow}>
|
|
468
|
+
<span className={classes.figure}>
|
|
469
|
+
<span className={classes.value}>{value}</span>
|
|
470
|
+
{unit !== undefined && <span className={classes.unit}>{unit}</span>}
|
|
471
|
+
</span>
|
|
472
|
+
{delta !== undefined && (
|
|
473
|
+
<DeltaBadge
|
|
474
|
+
value={delta}
|
|
475
|
+
period={deltaPeriod}
|
|
476
|
+
{...(deltaPolarity !== undefined && { polarity: deltaPolarity })}
|
|
477
|
+
{...(deltaFormat !== undefined && { format: deltaFormat })}
|
|
478
|
+
{...(deltaGlyph !== undefined && { withGlyph: deltaGlyph })}
|
|
479
|
+
/>
|
|
480
|
+
)}
|
|
481
|
+
</div>
|
|
482
|
+
)
|
|
483
|
+
|
|
484
|
+
const valueBody = renderValueBody({ pending, resolved, figure, emptyText })
|
|
485
|
+
|
|
486
|
+
const breakdownCount = breakdown?.length ?? 0
|
|
487
|
+
const hasBreakdown = breakdownCount > 0
|
|
488
|
+
// `'right'` keeps its row — and the 72×22 slot in it — while pending, so the card does not jump
|
|
489
|
+
// when the reading lands.
|
|
490
|
+
const rightRow =
|
|
491
|
+
!bleeds &&
|
|
492
|
+
(ready
|
|
493
|
+
? breakdownContent !== null || sparklineSlot !== null
|
|
494
|
+
: pending && (hasBreakdown || sparkline !== undefined))
|
|
495
|
+
|
|
496
|
+
const hasBleedVisual = sparkline !== undefined && bleeds
|
|
497
|
+
const visualNode = renderVisualNode({ show: hasBleedVisual, pending, slot: sparklineSlot })
|
|
498
|
+
const footerNode = renderFooterNode({ subtitle, pending })
|
|
499
|
+
|
|
399
500
|
return (
|
|
400
501
|
<Card
|
|
401
502
|
className={cx(classNames?.root, className)}
|
|
@@ -408,21 +509,16 @@ export function StatCard({
|
|
|
408
509
|
//
|
|
409
510
|
// `overflow: hidden` clips the full-bleed sparkline to the card's rounded corners. An
|
|
410
511
|
// element's own `box-shadow` renders outside its border box and is NOT clipped by its own
|
|
411
|
-
// `overflow`, so the shadow-card ring is unaffected
|
|
412
|
-
// clips a descendant's shadow). Mantine's Card root already sets `overflow: hidden`; this
|
|
413
|
-
// is explicit for intent.
|
|
512
|
+
// `overflow`, so the shadow-card ring is unaffected.
|
|
414
513
|
//
|
|
415
|
-
// NO `minHeight
|
|
416
|
-
//
|
|
417
|
-
// body is `height: 100%` and the sparkline is `margin-top: auto`. The content is what states
|
|
418
|
-
// the height now (~88-96px), and four cards in a `SimpleGrid` still match because a grid row
|
|
419
|
-
// stretches its items.
|
|
514
|
+
// NO `minHeight`: the content states the height (the foot reserves its own), and cards in a
|
|
515
|
+
// grid row stretch to the tallest.
|
|
420
516
|
padding: 'var(--vx-space-card-inset-y, 0.75rem) var(--vx-space-card-inset-x, 1rem)',
|
|
421
517
|
overflow: 'hidden',
|
|
422
518
|
// Anchors the tone rail. Set unconditionally so a card's stacking context does not change
|
|
423
519
|
// depending on whether it happens to have crossed a threshold this render.
|
|
424
520
|
position: 'relative',
|
|
425
|
-
// The card's own width drives its chrome (`
|
|
521
|
+
// The card's own width drives its chrome (`stat-card.module.css`).
|
|
426
522
|
containerType: 'inline-size',
|
|
427
523
|
containerName: 'basalt-card',
|
|
428
524
|
...style,
|
|
@@ -452,48 +548,60 @@ export function StatCard({
|
|
|
452
548
|
</>
|
|
453
549
|
)}
|
|
454
550
|
|
|
455
|
-
<div
|
|
551
|
+
<div
|
|
552
|
+
className={cx(classes.body, classNames?.body)}
|
|
553
|
+
data-placement={sparklinePlacement}
|
|
554
|
+
{...(pending && { 'aria-busy': true })}
|
|
555
|
+
>
|
|
556
|
+
{pending && <VisuallyHidden>{`Loading ${title}`}</VisuallyHidden>}
|
|
456
557
|
<div className={cx(classes.header, classNames?.header)}>
|
|
457
|
-
<
|
|
458
|
-
tier="widget"
|
|
558
|
+
<CaptionRow
|
|
459
559
|
title={title}
|
|
460
560
|
{...(icon !== undefined && { icon })}
|
|
461
|
-
{...(subtitle !== undefined && { subtitle })}
|
|
462
561
|
{...(info !== undefined && { info })}
|
|
463
|
-
|
|
464
|
-
{...(
|
|
465
|
-
{...(delta !== undefined && { delta })}
|
|
466
|
-
{...(deltaPeriod !== undefined && { deltaPeriod })}
|
|
467
|
-
{...(deltaPolarity !== undefined && { deltaPolarity })}
|
|
468
|
-
{...(deltaFormat !== undefined && { deltaFormat })}
|
|
469
|
-
{...(deltaGlyph !== undefined && { deltaGlyph })}
|
|
470
|
-
// `tier="widget"`, not the default `ctl`: the header row this slot sits in is 28px
|
|
471
|
-
// (`--vx-space-widget-header-height`) and a 30px `ctl` control grew it to 30, so a card
|
|
472
|
-
// with a kebab sat 2px below a card without one in the same grid row. See
|
|
473
|
-
// `theme/ctl-theme.tsx`'s `WIDGET_THEME`.
|
|
474
|
-
{...(actions !== undefined && {
|
|
475
|
-
actions: <CtlSlot tier="widget">{actions}</CtlSlot>,
|
|
476
|
-
})}
|
|
562
|
+
{...(qualifier !== undefined && { qualifier })}
|
|
563
|
+
{...(actions !== undefined && { actions })}
|
|
477
564
|
/>
|
|
478
565
|
|
|
479
|
-
{
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
the
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
566
|
+
{valueBody}
|
|
567
|
+
|
|
568
|
+
{/* INSIDE `.header` for `bleed` ONLY (`right` puts it beside the sparkline in
|
|
569
|
+
`.metricsRow`, so the header stays the full card width in both placements). */}
|
|
570
|
+
{bleeds &&
|
|
571
|
+
(pending
|
|
572
|
+
? hasBreakdown && <BreakdownSkeleton rows={breakdownCount} />
|
|
573
|
+
: ready && breakdownContent)}
|
|
487
574
|
</div>
|
|
488
575
|
|
|
489
|
-
{
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
576
|
+
{rightRow && (
|
|
577
|
+
<div className={classes.metricsRow}>
|
|
578
|
+
{ready ? (
|
|
579
|
+
<>
|
|
493
580
|
{breakdownContent}
|
|
494
|
-
{
|
|
495
|
-
|
|
581
|
+
{sparklineSlot}
|
|
582
|
+
</>
|
|
583
|
+
) : (
|
|
584
|
+
<>
|
|
585
|
+
{hasBreakdown && <BreakdownSkeleton rows={breakdownCount} />}
|
|
586
|
+
{sparkline !== undefined && (
|
|
587
|
+
<div
|
|
588
|
+
className={classes.sparklineRight}
|
|
589
|
+
style={rightSlotStyle(SPARKLINE_RIGHT_WIDTH, SPARKLINE_HEIGHT)}
|
|
590
|
+
>
|
|
591
|
+
<VisualSkeleton />
|
|
592
|
+
</div>
|
|
593
|
+
)}
|
|
594
|
+
</>
|
|
496
595
|
)}
|
|
596
|
+
</div>
|
|
597
|
+
)}
|
|
598
|
+
|
|
599
|
+
<Foot
|
|
600
|
+
reserve={hasBleedVisual || subtitle !== undefined}
|
|
601
|
+
visualBand={bleeds}
|
|
602
|
+
visualNode={visualNode}
|
|
603
|
+
footerNode={footerNode}
|
|
604
|
+
/>
|
|
497
605
|
</div>
|
|
498
606
|
</Card>
|
|
499
607
|
)
|