basalt-ui 2.17.0 → 2.19.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 (120) hide show
  1. package/CHANGELOG.md +58 -0
  2. package/MIGRATING.md +108 -12
  3. package/agent/agents/basalt-design-reviewer.md +2 -2
  4. package/agent/skills/basalt-design/SKILL.md +1 -1
  5. package/dist/cli/help.d.ts +1 -0
  6. package/dist/cli/help.d.ts.map +1 -1
  7. package/dist/cli/help.js +8 -2
  8. package/dist/cli/shot/capture.d.ts +12 -1
  9. package/dist/cli/shot/capture.d.ts.map +1 -1
  10. package/dist/cli/shot/capture.js +72 -10
  11. package/dist/cli/shot/index.d.ts +10 -1
  12. package/dist/cli/shot/index.d.ts.map +1 -1
  13. package/dist/cli/shot/index.js +40 -5
  14. package/dist/cli/shot/real-data.d.ts +35 -0
  15. package/dist/cli/shot/real-data.d.ts.map +1 -0
  16. package/dist/cli/shot/real-data.js +120 -0
  17. package/dist/cli/shot/serve.d.ts +2 -2
  18. package/dist/cli/shot/serve.d.ts.map +1 -1
  19. package/dist/cli/shot/serve.js +16 -2
  20. package/dist/commands/notifications/center.d.ts.map +1 -1
  21. package/dist/commands/notifications/center.js +18 -26
  22. package/dist/content/callout.d.ts +1 -1
  23. package/dist/content/callout.d.ts.map +1 -1
  24. package/dist/content/callout.js +10 -1
  25. package/dist/content/callout.module.css +15 -3
  26. package/dist/content/callout.module.css.d.ts +1 -0
  27. package/dist/dashboard/bar-list.d.ts +29 -0
  28. package/dist/dashboard/bar-list.d.ts.map +1 -0
  29. package/dist/dashboard/bar-list.js +65 -0
  30. package/dist/dashboard/bar-list.module.css +91 -0
  31. package/dist/dashboard/bar-list.module.css.d.ts +17 -0
  32. package/dist/dashboard/index.d.ts +2 -0
  33. package/dist/dashboard/index.d.ts.map +1 -1
  34. package/dist/dashboard/index.js +4 -0
  35. package/dist/dashboard/meter-model.d.ts +126 -0
  36. package/dist/dashboard/meter-model.d.ts.map +1 -0
  37. package/dist/dashboard/meter-model.js +135 -0
  38. package/dist/dashboard/meter-parts.d.ts +42 -0
  39. package/dist/dashboard/meter-parts.d.ts.map +1 -0
  40. package/dist/dashboard/meter-parts.js +297 -0
  41. package/dist/dashboard/meter.d.ts +123 -0
  42. package/dist/dashboard/meter.d.ts.map +1 -0
  43. package/dist/dashboard/meter.js +43 -0
  44. package/dist/dashboard/meter.module.css +268 -0
  45. package/dist/dashboard/meter.module.css.d.ts +39 -0
  46. package/dist/dashboard/scale.d.ts +9 -0
  47. package/dist/dashboard/scale.d.ts.map +1 -0
  48. package/dist/dashboard/scale.js +10 -0
  49. package/dist/dashboard/stat-card-parts.d.ts +3 -1
  50. package/dist/dashboard/stat-card-parts.d.ts.map +1 -1
  51. package/dist/dashboard/stat-card-parts.js +18 -3
  52. package/dist/dashboard/stat-card.d.ts +6 -5
  53. package/dist/dashboard/stat-card.d.ts.map +1 -1
  54. package/dist/dashboard/stat-card.js +48 -77
  55. package/dist/dashboard/stat-card.module.css +27 -7
  56. package/dist/dashboard/widget-header.d.ts.map +1 -1
  57. package/dist/dashboard/widget-header.js +2 -1
  58. package/dist/dashboard/widget-header.module.css +28 -1
  59. package/dist/index.d.ts +1 -1
  60. package/dist/index.d.ts.map +1 -1
  61. package/dist/index.js +5 -1
  62. package/dist/theme/chrome-vars.d.ts +29 -17
  63. package/dist/theme/chrome-vars.d.ts.map +1 -1
  64. package/dist/theme/chrome-vars.js +18 -8
  65. package/dist/theme/index.d.ts.map +1 -1
  66. package/dist/theme/index.js +9 -5
  67. package/dist/theme/status-dot.d.ts +6 -0
  68. package/dist/theme/status-dot.d.ts.map +1 -0
  69. package/dist/theme/status-dot.js +9 -0
  70. package/dist/theme/status-dot.module.css +9 -0
  71. package/dist/theme/status-dot.module.css.d.ts +8 -0
  72. package/dist/theme/status-verdict.d.ts +9 -0
  73. package/dist/theme/status-verdict.d.ts.map +1 -0
  74. package/dist/theme/status-verdict.js +13 -0
  75. package/dist/theme/status-verdict.module.css +23 -0
  76. package/dist/theme/status-verdict.module.css.d.ts +9 -0
  77. package/dist/tokens/derive.d.ts +11 -1
  78. package/dist/tokens/derive.d.ts.map +1 -1
  79. package/dist/tokens/derive.js +9 -24
  80. package/dist/tokens/status-text.d.ts +26 -0
  81. package/dist/tokens/status-text.d.ts.map +1 -0
  82. package/dist/tokens/status-text.js +68 -0
  83. package/llms.txt +32 -3
  84. package/package.json +1 -1
  85. package/src/cli/help.ts +22 -2
  86. package/src/cli/shot/capture.ts +98 -9
  87. package/src/cli/shot/index.ts +50 -4
  88. package/src/cli/shot/real-data.ts +165 -0
  89. package/src/cli/shot/serve.ts +28 -3
  90. package/src/commands/notifications/center.tsx +29 -32
  91. package/src/content/callout.module.css +15 -3
  92. package/src/content/callout.module.css.d.ts +1 -0
  93. package/src/content/callout.tsx +15 -2
  94. package/src/dashboard/bar-list.module.css +91 -0
  95. package/src/dashboard/bar-list.module.css.d.ts +17 -0
  96. package/src/dashboard/bar-list.tsx +125 -0
  97. package/src/dashboard/index.ts +2 -0
  98. package/src/dashboard/meter-model.ts +254 -0
  99. package/src/dashboard/meter-parts.tsx +407 -0
  100. package/src/dashboard/meter.module.css +268 -0
  101. package/src/dashboard/meter.module.css.d.ts +39 -0
  102. package/src/dashboard/meter.tsx +173 -0
  103. package/src/dashboard/scale.ts +13 -0
  104. package/src/dashboard/stat-card-parts.tsx +22 -2
  105. package/src/dashboard/stat-card.module.css +27 -7
  106. package/src/dashboard/stat-card.tsx +18 -52
  107. package/src/dashboard/widget-header.module.css +28 -1
  108. package/src/dashboard/widget-header.tsx +4 -1
  109. package/src/index.ts +4 -0
  110. package/src/theme/__snapshots__/plain-theme.test.ts.snap +88 -16
  111. package/src/theme/chrome-vars.ts +48 -23
  112. package/src/theme/index.ts +10 -6
  113. package/src/theme/status-dot.module.css +9 -0
  114. package/src/theme/status-dot.module.css.d.ts +8 -0
  115. package/src/theme/status-dot.tsx +19 -0
  116. package/src/theme/status-verdict.module.css +23 -0
  117. package/src/theme/status-verdict.module.css.d.ts +9 -0
  118. package/src/theme/status-verdict.tsx +27 -0
  119. package/src/tokens/derive.ts +19 -31
  120. package/src/tokens/status-text.ts +85 -0
@@ -0,0 +1,173 @@
1
+ /**
2
+ * Meter — one bounded quantity on a track: progress to a target, a committed/forecast split, a
3
+ * part-of-a-whole strip (`segments`), or a single headline ratio as a `ring`. Choose it for "how far
4
+ * along is this against a limit"; choose `BarList` for a ranking and a chart for a trend. An HTML/CSS
5
+ * primitive, not a chart kind (no scale, axis or tooltip).
6
+ *
7
+ * Colour law: the fill is neutral (`VX.line`). `color` is for a VERDICT only (over budget, below
8
+ * target) and is a status colour the consumer passes; categorical `segments` take the consumer's
9
+ * series colours. Committed vs forecast is the same neutral at two strengths — never colour alone: a
10
+ * tick marks the boundary and a caption names the forecast. A value past `max` clamps the fill at the
11
+ * track end; the caption still states the real value.
12
+ *
13
+ * `zones` (bar only) draws the track as contiguous bands (neutral at stepped strengths unless a zone
14
+ * passes a status colour) and the reading becomes a MARKER on the track, not a fill. Each zone is
15
+ * named under the band at its start, the one holding the value (`from` inclusive) in ink and a
16
+ * heavier weight; names that would collide wrap as a list instead. The fit is measured in the
17
+ * browser, so server markup shows the band and the list may appear after mount. Use it for a
18
+ * reading judged against ranges.
19
+ *
20
+ * Every state (bar, ring, empty, loading) carries `data-basalt-meter` on its root. That attribute is
21
+ * the contract with `StatCard`: a Meter passed as its `sparkline` visual makes the slot size to content
22
+ * and keep the card's inline inset (both placements) instead of the sparkline's fixed height and bleed.
23
+ *
24
+ * Categorical `segments` (no `forecast` part) are captioned one per part — swatch, name, value — under
25
+ * the track and the default start caption is dropped (an explicit `startCaption` still shows);
26
+ * committed/forecast keeps the reading plus the forecast caption.
27
+ *
28
+ * @example
29
+ * import { Meter } from 'basalt-ui'
30
+ *
31
+ * // Spend against a budget: past the target the end caption states the overage.
32
+ * <Meter label="Monthly spend" value={512} max={600} target={450} color="var(--vx-status-bad)" format={usd} />
33
+ * // Training load as a zone band with a marker: the zones are named under the band, "Optimal" in ink.
34
+ * <Meter
35
+ * label="Training load"
36
+ * max={1000}
37
+ * value={612}
38
+ * zones={[
39
+ * { from: 0, to: 300, label: 'Low' },
40
+ * { from: 300, to: 750, label: 'Optimal' },
41
+ * { from: 750, to: 1000, label: 'High' },
42
+ * ]}
43
+ * />
44
+ * // A readiness score on its 0–100 scale (its contributors: <BarList max={100} … secondary="Good" />).
45
+ * <Meter label="Recovery" value={72} max={100} />
46
+ * <Meter
47
+ * label="Course progress"
48
+ * max={120}
49
+ * segments={[{ value: 70, label: 'Done' }, { value: 25, label: 'Planned', forecast: true }]}
50
+ * />
51
+ * <Meter shape="ring" label="Cache hit rate" value={87} max={100} format={(v) => `${v}%`} />
52
+ */
53
+ import type { ReactNode } from 'react'
54
+ import type { BasaltProps } from '../common/props'
55
+ import { isReading, normalizeSegments, segmentReading, spanOf } from './meter-model'
56
+ import type { MeterSegment, MeterZone } from './meter-model'
57
+ import { MeterBar, MeterEmpty, MeterLoading, MeterRing } from './meter-parts'
58
+ import { asText } from './scale'
59
+
60
+ type Common = BasaltProps & {
61
+ /** Accessible name (`aria-label`). Required: a meter without one is announced as a bare number. */
62
+ label: string
63
+ /** Track start. Default 0. */
64
+ min?: number
65
+ /** Track end. Default 100. */
66
+ max?: number
67
+ /** Formats values in captions and the accessible text. Default: the number as written. */
68
+ format?: (value: number) => string
69
+ /** Renders a skeleton with the meter's footprint. */
70
+ loading?: boolean
71
+ /** Muted line shown when there is no reading. The track stays so the footprint holds. */
72
+ emptyText?: string
73
+ }
74
+
75
+ type BarCommon = Common & {
76
+ shape?: 'bar'
77
+ /** Target position; draws a tick and states it in the end caption (with the overage past it). */
78
+ target?: number
79
+ /** Start caption (default: the formatted reading). `null` drops it. */
80
+ startCaption?: ReactNode
81
+ /** End caption (default: `Target <target>`). `null` drops it. */
82
+ endCaption?: ReactNode
83
+ }
84
+
85
+ /**
86
+ * One of four forms; mixing them is a compile error.
87
+ * - Bar `value` (+ `target`, `color`): one reading on a neutral track.
88
+ * - Bar `segments`: ordered parts that sum to the reading (committed/forecast, part of a whole).
89
+ * - Bar `value` + `zones`: the reading is a marker against contiguous bands.
90
+ * - Ring (`shape: 'ring'`) `value` (+ `color`): one headline ratio; no target, captions, segments or zones.
91
+ */
92
+ export type MeterProps =
93
+ | (BarCommon & {
94
+ /** The reading. `null`/`undefined` (or non-finite) renders the empty state. */
95
+ value?: number | null | undefined
96
+ /** A status colour, for a verdict only. Omit for the neutral fill. */
97
+ color?: string
98
+ segments?: never
99
+ zones?: never
100
+ })
101
+ | (BarCommon & {
102
+ /** Ordered parts, accumulated from `min`; their sum is the reading. `forecast` parts render lighter. */
103
+ segments: readonly MeterSegment[]
104
+ /** Names the forecast beside the boundary tick (default: `Forecast: <labels>`). */
105
+ forecastCaption?: string
106
+ value?: never
107
+ color?: never
108
+ zones?: never
109
+ })
110
+ | (BarCommon & {
111
+ value?: number | null | undefined
112
+ /**
113
+ * Contiguous bands drawn as the track, positioned from each `from`. The reading becomes a marker
114
+ * and each band is named under the track, the one that holds it in ink.
115
+ */
116
+ zones: readonly MeterZone[]
117
+ segments?: never
118
+ color?: never
119
+ })
120
+ | (Common & {
121
+ shape: 'ring'
122
+ value?: number | null | undefined
123
+ /** A status colour, for a verdict only. */
124
+ color?: string
125
+ segments?: never
126
+ zones?: never
127
+ target?: never
128
+ startCaption?: never
129
+ endCaption?: never
130
+ })
131
+
132
+ let warnedTrack = false
133
+ /** One dev warning per page load for a track that ends at or before its start. */
134
+ function warnInvalidTrack(min: number, max: number) {
135
+ if (warnedTrack || spanOf(min, max).valid || process.env.NODE_ENV === 'production') return
136
+ warnedTrack = true
137
+ console.warn(
138
+ `[basalt] Meter: max (${max}) must be greater than min (${min}); drawing an empty track`,
139
+ )
140
+ }
141
+
142
+ export function Meter(props: MeterProps) {
143
+ const { label, min = 0, max = 100, format = asText, className, style } = props
144
+ const shell = { className, style }
145
+ const ring = props.shape === 'ring'
146
+ warnInvalidTrack(min, max)
147
+
148
+ if (props.loading === true) return <MeterLoading label={label} ring={ring} shell={shell} />
149
+
150
+ const segments = props.segments === undefined ? undefined : normalizeSegments(props.segments)
151
+ const reading = segments === undefined ? props.value : segmentReading(segments, min)
152
+ if (!isReading(reading) || segments?.length === 0) {
153
+ return (
154
+ <MeterEmpty label={label} text={props.emptyText ?? 'No data'} ring={ring} shell={shell} />
155
+ )
156
+ }
157
+
158
+ if (props.shape === 'ring') {
159
+ return <MeterRing {...{ label, reading, min, max, format, shell }} color={props.color} />
160
+ }
161
+ return (
162
+ <MeterBar
163
+ {...{ label, reading, min, max, format, shell }}
164
+ color={props.color}
165
+ segments={segments}
166
+ zones={props.zones}
167
+ target={isReading(props.target) ? props.target : undefined}
168
+ forecastCaption={props.segments === undefined ? undefined : props.forecastCaption}
169
+ startCaption={props.startCaption}
170
+ endCaption={props.endCaption}
171
+ />
172
+ )
173
+ }
@@ -0,0 +1,13 @@
1
+ /** Shared by `Meter` and `BarList`: the one place a value becomes a track percentage. Internal. */
2
+
3
+ /** Clamps to 0–1; a non-finite fraction is 0. */
4
+ export const clamp01 = (n: number): number => (Number.isFinite(n) ? Math.min(1, Math.max(0, n)) : 0)
5
+
6
+ /** A 0–1 fraction as a percent, rounded so float noise never reaches the DOM. */
7
+ export const toPct = (n: number): number => Math.round(clamp01(n) * 10000) / 100
8
+
9
+ /** A value on a track that ends at `scale`; a non-finite value or an empty scale draws nothing. */
10
+ export const barPercent = (value: number, scale: number): number =>
11
+ Number.isFinite(value) && Number.isFinite(scale) && scale > 0 ? toPct(value / scale) : 0
12
+
13
+ export const asText = (n: number): string => String(n)
@@ -7,6 +7,9 @@ import { Skeleton } from '@mantine/core'
7
7
  import type { CSSProperties, ReactNode } from 'react'
8
8
  import { IconSlot } from '../theme/icon-slot'
9
9
  import { CtlSlot } from '../theme'
10
+ import { StatusVerdict } from '../theme/status-verdict'
11
+ import { VX } from '../tokens'
12
+ import type { Tone } from '../common/props'
10
13
  import { InfoGlyph } from './widget-header'
11
14
  import classes from './stat-card.module.css'
12
15
 
@@ -15,25 +18,42 @@ export type CaptionRowProps = {
15
18
  icon?: ReactNode
16
19
  info?: string
17
20
  qualifier?: string
21
+ tone?: Tone
18
22
  actions?: ReactNode
19
23
  }
20
24
 
25
+ /** Visible verdict word, and the full phrase a screen reader hears instead of a bare "Over". */
26
+ const TONE_WORD: Record<Tone, { word: string; phrase: string }> = {
27
+ good: { word: 'OK', phrase: 'Within the good threshold' },
28
+ warn: { word: 'Watch', phrase: 'Past the warning threshold' },
29
+ bad: { word: 'Over', phrase: 'Past the severe threshold' },
30
+ }
31
+
21
32
  /**
22
33
  * Title, `info` glyph and `qualifier` in one wrapping group, `actions` pinned at the end. When
23
34
  * caption + info + qualifier do not fit, the qualifier wraps UNDER the caption instead of truncating
24
35
  * either: the container's width decides, never the viewport's.
25
36
  */
26
- export function CaptionRow({ title, icon, info, qualifier, actions }: CaptionRowProps) {
37
+ export function CaptionRow({ title, icon, info, qualifier, tone, actions }: CaptionRowProps) {
27
38
  return (
28
39
  <div className={classes.captionRow}>
29
40
  <div className={classes.captionMain}>
30
41
  <div className={classes.lead}>
31
42
  <h3 className={classes.caption}>
32
43
  {icon !== undefined && <IconSlot className={classes.icon}>{icon}</IconSlot>}
33
- <span className={classes.captionText}>{title}</span>
44
+ <span className={classes.captionText} data-widget-title>
45
+ {title}
46
+ </span>
34
47
  </h3>
35
48
  {/* OUTSIDE the heading on purpose: `info` would otherwise become part of its name. */}
36
49
  {info !== undefined && <InfoGlyph text={info} />}
50
+ {tone !== undefined && (
51
+ <StatusVerdict
52
+ color={VX.status[tone]}
53
+ word={TONE_WORD[tone].word}
54
+ phrase={TONE_WORD[tone].phrase}
55
+ />
56
+ )}
37
57
  </div>
38
58
  {qualifier !== undefined && <span className={classes.qualifier}>{qualifier}</span>}
39
59
  </div>
@@ -173,15 +173,15 @@
173
173
  height: var(--basalt-stat-figure-h);
174
174
  }
175
175
 
176
+ /* Inset on both sides, unlike the sparkline at rest (which bleeds): a placeholder that touches one
177
+ * card edge and stops short of the other reads as misaligned, and a Meter in the slot is inset anyway. */
176
178
  .skeletonVisual {
177
179
  --skeleton-radius: 0;
178
180
  height: var(--basalt-stat-visual-h);
179
- margin-inline: calc(-1 * var(--vx-space-card-inset-x, 1rem));
180
181
  }
181
182
 
182
183
  .sparklineRight .skeletonVisual {
183
184
  flex: 1 1 auto;
184
- margin-inline: 0;
185
185
  }
186
186
 
187
187
  .skeletonRowBox {
@@ -318,11 +318,11 @@
318
318
  }
319
319
 
320
320
  /*
321
- * A row past a threshold. Same vocabulary and the same per-scheme solids as the card's own tone rail
322
- * (`stat-card.tsx`'s `VX.status[tone]`), so a row saying `bad` and a rail saying `bad` are one claim
323
- * at two scales. Colour is not the only carrier at the CARD level (the rail ships a
324
- * `VisuallyHidden` verdict); at the ROW level the label is the carrier — a row reading
325
- * `Paid · 1,204` states its own subject either way, and the tint only ranks it.
321
+ * A row past a threshold. Same vocabulary and the same per-scheme solids as the card's own tone dot
322
+ * (`VX.status[tone]`), so a row saying `bad` and a dot saying `bad` are one claim at two scales.
323
+ * Colour is not the only carrier at the CARD level (the dot ships a word); at
324
+ * the ROW level the label is the carrier — a row reading `Paid · 1,204` states its own subject
325
+ * either way, and the tint only ranks it.
326
326
  */
327
327
  .breakdownRow[data-tone='good'] .breakdownValue {
328
328
  color: var(--vx-status-good);
@@ -341,6 +341,22 @@
341
341
  margin-inline: calc(-1 * var(--vx-space-card-inset-x, 1rem));
342
342
  }
343
343
 
344
+ /* A Meter in the visual slot is a block, not a chart: it sizes to its content and keeps the card's
345
+ * inline inset instead of the sparkline's fixed 22px and side bleed. */
346
+ .sparklineBleed:has(> [data-basalt-meter]) {
347
+ height: auto;
348
+ margin-inline: 0;
349
+ }
350
+
351
+ /* The `right` placement: the fixed basis, 22px height and clip are a sparkline's box. A Meter takes the
352
+ * row's remaining width and its own height, unclipped. */
353
+ .sparklineRight:has(> [data-basalt-meter]) {
354
+ flex: 1 1 auto;
355
+ height: auto;
356
+ overflow: visible;
357
+ align-items: stretch;
358
+ }
359
+
344
360
  /* Asks for `StatCard`'s `SPARKLINE_RIGHT_WIDTH`/`_HEIGHT` (handed down as custom properties, so this
345
361
  * rule and the narrow-card reset below can both reach them). `align-self: flex-end` is the one alignment
346
362
  * this restructure keeps at the SPARKLINE's own level rather than the row's: `.metricsRow` does not
@@ -375,4 +391,8 @@
375
391
  margin-top: auto;
376
392
  margin-inline: calc(-1 * var(--vx-space-card-inset-x, 1rem));
377
393
  }
394
+
395
+ .metricsRow .sparklineRight:has(> [data-basalt-meter], > .skeletonVisual) {
396
+ margin-inline: 0;
397
+ }
378
398
  }
@@ -31,15 +31,14 @@
31
31
  * (`emptyText`). `loading` shows the same skeleton with no query at all. The caption row stays put
32
32
  * in every branch.
33
33
  *
34
- * `tone` marks the card as past a threshold with an accent rail down its leading edge. It exists
35
- * because `value` is typed `string`: without it, a card whose number has crossed a threshold reads
36
- * exactly as calm as one that hasn't, and the only way out from the consumer side is to wrap the
37
- * card in a hand-rolled positioned `<Box>` — which is a second card idiom in the app, drawn by code
38
- * the guard has no way to recognize as one. The rail is the largest signal available without
39
- * touching the value's own type: full card height, overlaying the card's edge rather than adding to
40
- * it, so layout is unchanged. `undefined` renders nothing at all — absence of a reading is neither a
41
- * good one nor a bad one, and must never be tinted. `'good'` is a deliberate positive verdict, never
42
- * the meaning of omission: it exists for the threshold where the calm number IS the finding (zero
34
+ * `tone` states a threshold verdict as a status dot plus a short word on the caption row (`OK`,
35
+ * `Watch`, `Over`), with the full phrase for assistive tech. The dot carries the colour and the word
36
+ * the meaning, so the verdict never rides on colour alone. It exists because `value` is typed
37
+ * `string`: without it, a card whose number has crossed a threshold reads exactly as calm as one
38
+ * that hasn't. A coloured edge stripe is not the form — it reads as generic dashboard decoration
39
+ * (Wave 34). `undefined` renders nothing at all — absence of a reading is neither a good one nor a
40
+ * bad one, and must never be tinted. `'good'` is a deliberate positive verdict, never the meaning
41
+ * of omission: it exists for the threshold where the calm number IS the finding (zero
43
42
  * downtime over the window), and a card that has measured nothing must not be able to reach green by
44
43
  * leaving the prop off.
45
44
  *
@@ -74,7 +73,7 @@
74
73
  * <StatCard title="Active users" value="—" loading sparkline={() => null} />
75
74
  *
76
75
  * @example
77
- * // Past a threshold — an accent rail down the leading edge, value untouched.
76
+ * // Past a threshold — a status dot and the word "Over" on the caption row, value untouched.
78
77
  * <StatCard title="Downtime" value="29 min" tone="bad" />
79
78
  *
80
79
  * @example
@@ -90,7 +89,7 @@
90
89
  * tone={hasCoverage ? (downtimeMinutes === 0 ? 'good' : 'bad') : undefined}
91
90
  * />
92
91
  */
93
- import { Box, Card, VisuallyHidden } from '@mantine/core'
92
+ import { Card, VisuallyHidden } from '@mantine/core'
94
93
  import { useEffect, useState } from 'react'
95
94
  import type { ReactNode } from 'react'
96
95
  import {
@@ -108,7 +107,6 @@ import type {
108
107
  WidgetHeaderTitleProps,
109
108
  } from './widget-header'
110
109
  import { DeltaBadge } from './delta-badge'
111
- import { VX } from '../tokens'
112
110
  import { cx } from '../common/props'
113
111
  import type { BasaltProps, SlotStylesProps, Tone } from '../common/props'
114
112
  import { ErrorState, QueryState, resolveQueryBranch } from './query-state'
@@ -126,7 +124,7 @@ export type StatCardSlot = 'root' | 'header' | 'body' | 'sparkline'
126
124
  *
127
125
  * `value` is a pre-formatted `string` for the same reason the hero's is: the card cannot know the
128
126
  * locale, the currency or the precision the number was measured at. `tone` marks ONE row as past a
129
- * threshold and is the same vocabulary as the card's own `tone`, so a row saying `bad` and a rail
127
+ * threshold and is the same vocabulary as the card's own `tone`, so a row saying `bad` and a dot
130
128
  * saying `bad` are the same claim at two scales; omitting it is untinted, never `'good'`.
131
129
  */
132
130
  export type StatCardBreakdownRow = {
@@ -193,16 +191,6 @@ function useSlotWidth(active: boolean): {
193
191
  return { ref: setNode, width }
194
192
  }
195
193
 
196
- /** The rail's width, in px. Wide enough to read as a deliberate mark at a glance, narrow enough
197
- * that it cannot be mistaken for the card's own edge. */
198
- const TONE_RAIL_WIDTH = 3
199
-
200
- const TONE_LABEL: Record<Tone, string> = {
201
- good: 'Within the good threshold',
202
- warn: 'Past the warning threshold',
203
- bad: 'Past the severe threshold',
204
- }
205
-
206
194
  /**
207
195
  * `StatCard` re-publishes three NAMED `WidgetHeader` slices (`WidgetHeaderTitleProps` /
208
196
  * `WidgetHeaderMetricProps` / `WidgetHeaderDeltaProps`, audit B #2) rather than re-declaring the
@@ -302,10 +290,11 @@ export type StatCardProps = BasaltProps &
302
290
  /** Caption-row right slot (e.g. a ghost "..." menu trigger) — wrapped in `CtlSlot tier="widget"`,
303
291
  * so a raw `ActionIcon` with no `size` lands on the 24px step the caption row holds (C1/C5). */
304
292
  actions?: ReactNode
305
- /** Threshold verdict — draws an accent rail down the card's leading edge and announces itself to
306
- * assistive tech. Omitting it is NOT `'good'`: omitted covers a reading that is fine AND one that
307
- * is absent, and stays untinted so a card with nothing measured can never render green. Pass
308
- * `'good'` only to assert a measured value that has earned the verdict. */
293
+ /** Threshold verdict — a status dot plus a short word (`OK` / `Watch` / `Over`) on the caption
294
+ * row, with the full phrase for assistive tech. Omitting it is NOT `'good'`: omitted covers a
295
+ * reading that is fine AND one that is absent, and stays untinted so a card with nothing
296
+ * measured can never render green. Pass `'good'` only to assert a measured value that has
297
+ * earned the verdict. */
309
298
  tone?: Tone
310
299
  }
311
300
 
@@ -515,8 +504,7 @@ export function StatCard({
515
504
  // grid row stretch to the tallest.
516
505
  padding: 'var(--vx-space-card-inset-y, 0.75rem) var(--vx-space-card-inset-x, 1rem)',
517
506
  overflow: 'hidden',
518
- // Anchors the tone rail. Set unconditionally so a card's stacking context does not change
519
- // depending on whether it happens to have crossed a threshold this render.
507
+ // Consumers may anchor overlays (badges, menus) to the card, so it stays a positioned box.
520
508
  position: 'relative',
521
509
  // The card's own width drives its chrome (`stat-card.module.css`).
522
510
  containerType: 'inline-size',
@@ -525,29 +513,6 @@ export function StatCard({
525
513
  }}
526
514
  data-tone={tone}
527
515
  >
528
- {tone !== undefined && (
529
- <>
530
- {/* The rail is decoration; the verdict it encodes is real information, so it is also
531
- stated in text for anyone who cannot see a 3px colour bar. Colour alone is never the
532
- only carrier of a threshold. */}
533
- <VisuallyHidden>{TONE_LABEL[tone]}</VisuallyHidden>
534
- <Box
535
- aria-hidden="true"
536
- style={{
537
- position: 'absolute',
538
- insetBlock: 0,
539
- insetInlineStart: 0,
540
- width: TONE_RAIL_WIDTH,
541
- // `Tone`'s members are `VX.status` keys by construction, so the rail reads the
542
- // per-scheme `--vx-status-*` solid directly — never a hex, so it re-resolves in both
543
- // schemes and under a consumer's `derive` retune. Contrast against
544
- // `--vx-surface-panel` is measured in `theme/contrast.test.ts`.
545
- background: VX.status[tone],
546
- }}
547
- />
548
- </>
549
- )}
550
-
551
516
  <div
552
517
  className={cx(classes.body, classNames?.body)}
553
518
  data-placement={sparklinePlacement}
@@ -560,6 +525,7 @@ export function StatCard({
560
525
  {...(icon !== undefined && { icon })}
561
526
  {...(info !== undefined && { info })}
562
527
  {...(qualifier !== undefined && { qualifier })}
528
+ {...(tone !== undefined && { tone })}
563
529
  {...(actions !== undefined && { actions })}
564
530
  />
565
531
 
@@ -247,12 +247,16 @@
247
247
  * overlay — axe and assistive tech measure the element. The negative margin hands the extra
248
248
  * (24 - 11) / 2 back on every side, so the glyph and the row around it keep their drawn size. */
249
249
  .infoTrigger {
250
+ --basalt-info-glyph: 11px;
251
+ --basalt-info-ring-offset: 2px;
252
+ --basalt-info-ring-width: 2px;
250
253
  display: inline-flex;
251
254
  align-items: center;
252
255
  justify-content: center;
253
256
  min-width: 24px;
254
257
  min-height: 24px;
255
- margin: calc((11px - 24px) / 2);
258
+ margin: calc((var(--basalt-info-glyph) - 24px) / 2);
259
+ position: relative;
256
260
  appearance: none;
257
261
  padding: 0;
258
262
  border: none;
@@ -261,6 +265,29 @@
261
265
  cursor: help;
262
266
  }
263
267
 
268
+ /* The keyboard ring hugs the glyph, not the 24px hit box: drawn on the box it reached 6.5px past
269
+ * the glyph and painted over the title's last letter and a neighbouring status dot. The `::before`
270
+ * is the glyph + the offset on each side, outlined by the ring width, so the ring ends 4px from the
271
+ * glyph — inside the 6px control gap. (`::after` is the hit overlay's.)
272
+ * Forced colors: the ring is an `outline`, which the UA keeps and recolours to a system colour, so
273
+ * it stays visible without a `forced-colors` override. */
274
+ .infoTrigger:focus-visible {
275
+ outline: none;
276
+
277
+ &::before {
278
+ content: '';
279
+ position: absolute;
280
+ top: 50%;
281
+ left: 50%;
282
+ translate: -50% -50%;
283
+ width: calc(var(--basalt-info-glyph) + 2 * var(--basalt-info-ring-offset));
284
+ height: calc(var(--basalt-info-glyph) + 2 * var(--basalt-info-ring-offset));
285
+ border-radius: var(--vx-radius-fine);
286
+ outline: var(--basalt-info-ring-width) solid var(--vx-accent);
287
+ pointer-events: none;
288
+ }
289
+ }
290
+
264
291
  .infoTrigger:hover,
265
292
  .infoTrigger:focus-visible,
266
293
  .infoTrigger[data-open='true'] {
@@ -290,6 +290,7 @@ export function InfoGlyph({
290
290
  ref={triggerRef}
291
291
  type="button"
292
292
  data-basalt-hit
293
+ data-info-trigger
293
294
  className={classes.infoTrigger}
294
295
  // The GLYPH is named, not the text — `text` reaches AT through `aria-describedby` below, so
295
296
  // it never lands in the heading's or the button's accessible name.
@@ -372,7 +373,9 @@ export function WidgetHeader({
372
373
  {icon !== undefined && (
373
374
  <IconSlot className={cx(classes.icon, classNames?.icon)}>{icon}</IconSlot>
374
375
  )}
375
- <span className={classes.titleText}>{title}</span>
376
+ <span className={classes.titleText} data-widget-title>
377
+ {title}
378
+ </span>
376
379
  </Heading>
377
380
  {/* OUTSIDE the heading on purpose — see `info`'s own doc. */}
378
381
  {info !== undefined && (
package/src/index.ts CHANGED
@@ -48,6 +48,10 @@ export {
48
48
  SettingsSection,
49
49
  SettingsRow,
50
50
  DangerZone,
51
+ Meter,
52
+ type MeterProps,
53
+ BarList,
54
+ type BarListProps,
51
55
  } from './dashboard'
52
56
  export { unwrap } from './unwrap'
53
57