basalt-ui 2.19.0 → 2.21.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 (234) hide show
  1. package/CHANGELOG.md +89 -0
  2. package/MIGRATING.md +291 -12
  3. package/agent/agents/basalt-design-reviewer.md +22 -5
  4. package/agent/rules/basalt-charts.md +1 -1
  5. package/agent/rules/basalt-mantine.md +1 -1
  6. package/agent/rules/basalt-tokens.md +2 -2
  7. package/agent/skills/basalt-app/SKILL.md +1 -1
  8. package/agent/skills/basalt-design/SKILL.md +10 -23
  9. package/agent/skills/basalt-design/references/anti-defaults.md +24 -0
  10. package/agent/skills/basalt-design/references/catalogue.md +48 -0
  11. package/agent/skills/basalt-design/references/concept.md +36 -0
  12. package/agent/skills/basalt-design/references/encoding-rules.md +45 -0
  13. package/agent/skills/basalt-design/references/stat-tile.md +24 -0
  14. package/agent/templates/AGENTS-block.md.tpl +3 -3
  15. package/agent/templates/DESIGN.md.tpl +1 -1
  16. package/configs/oxlint-plugin.js +34 -19
  17. package/configs/oxlint-plugin.test.ts +32 -2
  18. package/dist/charts/ChartCard.d.ts +33 -4
  19. package/dist/charts/ChartCard.d.ts.map +1 -1
  20. package/dist/charts/ChartCard.js +37 -11
  21. package/dist/charts/Donut.d.ts.map +1 -1
  22. package/dist/charts/Donut.js +13 -1
  23. package/dist/charts/Heatmap.js +1 -1
  24. package/dist/charts/Sparkline.d.ts +7 -1
  25. package/dist/charts/Sparkline.d.ts.map +1 -1
  26. package/dist/charts/Sparkline.js +137 -18
  27. package/dist/charts/box.d.ts +2 -0
  28. package/dist/charts/box.d.ts.map +1 -1
  29. package/dist/charts/box.js +2 -0
  30. package/dist/charts/chart-box.module.css +30 -0
  31. package/dist/charts/chart-box.module.css.d.ts +1 -0
  32. package/dist/charts/chart-card.module.css +47 -0
  33. package/dist/charts/chart-card.module.css.d.ts +7 -0
  34. package/dist/charts/compile.d.ts.map +1 -1
  35. package/dist/charts/compile.js +35 -8
  36. package/dist/charts/host.d.ts.map +1 -1
  37. package/dist/charts/host.js +2 -1
  38. package/dist/charts/index.d.ts +1 -1
  39. package/dist/charts/index.d.ts.map +1 -1
  40. package/dist/charts/sparkline.module.css +59 -0
  41. package/dist/charts/sparkline.module.css.d.ts +13 -0
  42. package/dist/charts/state.d.ts +5 -0
  43. package/dist/charts/state.d.ts.map +1 -1
  44. package/dist/charts/state.js +34 -4
  45. package/dist/charts/types.d.ts +6 -0
  46. package/dist/charts/types.d.ts.map +1 -1
  47. package/dist/cli/check-theme.d.ts.map +1 -1
  48. package/dist/cli/check-theme.js +3 -0
  49. package/dist/cli/help.d.ts.map +1 -1
  50. package/dist/cli/help.js +3 -2
  51. package/dist/cli/index.d.ts +4 -2
  52. package/dist/cli/index.d.ts.map +1 -1
  53. package/dist/cli/index.js +27 -15
  54. package/dist/cli/init.d.ts.map +1 -1
  55. package/dist/cli/init.js +3 -2
  56. package/dist/cli/shot/capture.d.ts.map +1 -1
  57. package/dist/cli/shot/capture.js +6 -1
  58. package/dist/cli/shot/detect.d.ts +51 -0
  59. package/dist/cli/shot/detect.d.ts.map +1 -0
  60. package/dist/cli/shot/detect.js +396 -0
  61. package/dist/cli/shot/index.d.ts.map +1 -1
  62. package/dist/cli/shot/index.js +7 -4
  63. package/dist/cli/shot/measure.d.ts +2 -0
  64. package/dist/cli/shot/measure.d.ts.map +1 -1
  65. package/dist/cli/shot/measure.js +2 -0
  66. package/dist/cli/shot/types.d.ts +4 -1
  67. package/dist/cli/shot/types.d.ts.map +1 -1
  68. package/dist/cli/shot/types.js +2 -0
  69. package/dist/cli/sync.d.ts +2 -0
  70. package/dist/cli/sync.d.ts.map +1 -1
  71. package/dist/cli/sync.js +2 -2
  72. package/dist/common/retry-button.d.ts +12 -0
  73. package/dist/common/retry-button.d.ts.map +1 -0
  74. package/dist/common/retry-button.js +22 -0
  75. package/dist/common/retry-button.module.css +58 -0
  76. package/dist/common/retry-button.module.css.d.ts +8 -0
  77. package/dist/controls/sync-button.d.ts +3 -0
  78. package/dist/controls/sync-button.d.ts.map +1 -1
  79. package/dist/dashboard/bar-list.d.ts +18 -4
  80. package/dist/dashboard/bar-list.d.ts.map +1 -1
  81. package/dist/dashboard/bar-list.js +39 -15
  82. package/dist/dashboard/bar-list.module.css +77 -2
  83. package/dist/dashboard/bar-list.module.css.d.ts +1 -0
  84. package/dist/dashboard/delta-badge.d.ts +8 -3
  85. package/dist/dashboard/delta-badge.d.ts.map +1 -1
  86. package/dist/dashboard/delta-badge.js +9 -2
  87. package/dist/dashboard/index.d.ts +2 -0
  88. package/dist/dashboard/index.d.ts.map +1 -1
  89. package/dist/dashboard/meter-model.d.ts +53 -6
  90. package/dist/dashboard/meter-model.d.ts.map +1 -1
  91. package/dist/dashboard/meter-model.js +62 -14
  92. package/dist/dashboard/meter-parts.d.ts +5 -1
  93. package/dist/dashboard/meter-parts.d.ts.map +1 -1
  94. package/dist/dashboard/meter-parts.js +140 -68
  95. package/dist/dashboard/meter.d.ts +29 -4
  96. package/dist/dashboard/meter.d.ts.map +1 -1
  97. package/dist/dashboard/meter.js +8 -1
  98. package/dist/dashboard/meter.module.css +74 -43
  99. package/dist/dashboard/meter.module.css.d.ts +4 -4
  100. package/dist/dashboard/query-state.d.ts +1 -1
  101. package/dist/dashboard/query-state.d.ts.map +1 -1
  102. package/dist/dashboard/query-state.js +16 -10
  103. package/dist/dashboard/settings-section.d.ts.map +1 -1
  104. package/dist/dashboard/settings-section.js +14 -25
  105. package/dist/dashboard/stat-card-parts.js +1 -1
  106. package/dist/dashboard/stat-card.d.ts +1 -1
  107. package/dist/dashboard/stat-card.d.ts.map +1 -1
  108. package/dist/dashboard/stat-card.js +5 -7
  109. package/dist/dashboard/stat-card.module.css +15 -7
  110. package/dist/dashboard/stat-group.d.ts +11 -2
  111. package/dist/dashboard/stat-group.d.ts.map +1 -1
  112. package/dist/dashboard/stat-group.js +9 -7
  113. package/dist/dashboard/stat-strip.d.ts +67 -0
  114. package/dist/dashboard/stat-strip.d.ts.map +1 -0
  115. package/dist/dashboard/stat-strip.js +115 -0
  116. package/dist/dashboard/stat-strip.module.css +291 -0
  117. package/dist/dashboard/stat-strip.module.css.d.ts +32 -0
  118. package/dist/dashboard/visual-slot.d.ts +2 -0
  119. package/dist/dashboard/visual-slot.d.ts.map +1 -0
  120. package/dist/dashboard/visual-slot.js +5 -0
  121. package/dist/dashboard/widget-header.d.ts +3 -3
  122. package/dist/dashboard/widget-header.module.css +10 -6
  123. package/dist/format/date.d.ts.map +1 -1
  124. package/dist/format/date.js +4 -3
  125. package/dist/format/shared.d.ts +6 -0
  126. package/dist/format/shared.d.ts.map +1 -1
  127. package/dist/format/shared.js +6 -2
  128. package/dist/guard/index.d.ts +16 -3
  129. package/dist/guard/index.d.ts.map +1 -1
  130. package/dist/guard/index.js +15 -1
  131. package/dist/guard/palette.d.ts +51 -0
  132. package/dist/guard/palette.d.ts.map +1 -0
  133. package/dist/guard/palette.js +190 -0
  134. package/dist/guard/series-file.d.ts +15 -0
  135. package/dist/guard/series-file.d.ts.map +1 -0
  136. package/dist/guard/series-file.js +29 -0
  137. package/dist/guard/types.d.ts +3 -3
  138. package/dist/guard/types.d.ts.map +1 -1
  139. package/dist/index.d.ts +3 -1
  140. package/dist/index.d.ts.map +1 -1
  141. package/dist/index.js +4 -0
  142. package/dist/styles.css +6 -0
  143. package/dist/surfaces.d.ts +1 -1
  144. package/dist/surfaces.d.ts.map +1 -1
  145. package/dist/surfaces.js +2 -0
  146. package/dist/theme/card-inset.module.css +76 -0
  147. package/dist/theme/card-inset.module.css.d.ts +9 -0
  148. package/dist/theme/controls.module.css +13 -0
  149. package/dist/theme/index.d.ts.map +1 -1
  150. package/dist/theme/index.js +41 -0
  151. package/dist/theme/nav-link.module.css +8 -10
  152. package/dist/theme/status-dot.d.ts +3 -2
  153. package/dist/theme/status-dot.d.ts.map +1 -1
  154. package/dist/theme/status-dot.js +12 -3
  155. package/dist/theme/status-verdict.d.ts +3 -2
  156. package/dist/theme/status-verdict.d.ts.map +1 -1
  157. package/dist/theme/status-verdict.js +3 -2
  158. package/dist/theme/status-verdict.module.css +4 -2
  159. package/dist/tokens/oklab.d.ts +28 -0
  160. package/dist/tokens/oklab.d.ts.map +1 -0
  161. package/dist/tokens/oklab.js +73 -0
  162. package/llms.txt +33 -7
  163. package/package.json +1 -1
  164. package/src/charts/ChartCard.tsx +79 -5
  165. package/src/charts/Donut.tsx +9 -1
  166. package/src/charts/Heatmap.tsx +1 -1
  167. package/src/charts/Sparkline.tsx +180 -18
  168. package/src/charts/box.tsx +2 -0
  169. package/src/charts/chart-box.module.css +30 -0
  170. package/src/charts/chart-box.module.css.d.ts +1 -0
  171. package/src/charts/chart-card.module.css +47 -0
  172. package/src/charts/chart-card.module.css.d.ts +7 -0
  173. package/src/charts/compile.ts +42 -9
  174. package/src/charts/host.tsx +6 -3
  175. package/src/charts/index.ts +1 -1
  176. package/src/charts/sparkline.module.css +59 -0
  177. package/src/charts/sparkline.module.css.d.ts +13 -0
  178. package/src/charts/state.tsx +53 -4
  179. package/src/charts/types.ts +6 -0
  180. package/src/cli/check-theme.ts +3 -0
  181. package/src/cli/help.ts +18 -1
  182. package/src/cli/index.ts +48 -17
  183. package/src/cli/init.ts +2 -1
  184. package/src/cli/shot/capture.ts +15 -2
  185. package/src/cli/shot/detect.ts +533 -0
  186. package/src/cli/shot/index.ts +8 -4
  187. package/src/cli/shot/measure.ts +4 -0
  188. package/src/cli/shot/types.ts +5 -1
  189. package/src/cli/sync.ts +4 -2
  190. package/src/common/retry-button.module.css +58 -0
  191. package/src/common/retry-button.module.css.d.ts +8 -0
  192. package/src/common/retry-button.tsx +29 -0
  193. package/src/controls/sync-button.tsx +3 -0
  194. package/src/dashboard/bar-list.module.css +77 -2
  195. package/src/dashboard/bar-list.module.css.d.ts +1 -0
  196. package/src/dashboard/bar-list.tsx +89 -18
  197. package/src/dashboard/delta-badge.tsx +21 -5
  198. package/src/dashboard/index.ts +2 -0
  199. package/src/dashboard/meter-model.ts +126 -20
  200. package/src/dashboard/meter-parts.tsx +224 -88
  201. package/src/dashboard/meter.module.css +74 -43
  202. package/src/dashboard/meter.module.css.d.ts +4 -4
  203. package/src/dashboard/meter.tsx +39 -5
  204. package/src/dashboard/query-state.tsx +26 -20
  205. package/src/dashboard/settings-section.tsx +1 -8
  206. package/src/dashboard/stat-card-parts.tsx +1 -1
  207. package/src/dashboard/stat-card.module.css +15 -7
  208. package/src/dashboard/stat-card.tsx +9 -9
  209. package/src/dashboard/stat-group.tsx +19 -8
  210. package/src/dashboard/stat-strip.module.css +291 -0
  211. package/src/dashboard/stat-strip.module.css.d.ts +32 -0
  212. package/src/dashboard/stat-strip.tsx +263 -0
  213. package/src/dashboard/visual-slot.ts +8 -0
  214. package/src/dashboard/widget-header.module.css +10 -6
  215. package/src/dashboard/widget-header.tsx +3 -3
  216. package/src/format/date.ts +6 -3
  217. package/src/format/shared.ts +11 -2
  218. package/src/guard/index.ts +17 -5
  219. package/src/guard/palette.ts +261 -0
  220. package/src/guard/series-file.ts +51 -0
  221. package/src/guard/types.ts +3 -2
  222. package/src/index.ts +7 -0
  223. package/src/styles.css +6 -0
  224. package/src/surfaces.ts +2 -0
  225. package/src/theme/__snapshots__/plain-theme.test.ts.snap +202 -24
  226. package/src/theme/card-inset.module.css +76 -0
  227. package/src/theme/card-inset.module.css.d.ts +9 -0
  228. package/src/theme/controls.module.css +13 -0
  229. package/src/theme/index.ts +56 -0
  230. package/src/theme/nav-link.module.css +8 -10
  231. package/src/theme/status-dot.tsx +17 -5
  232. package/src/theme/status-verdict.module.css +4 -2
  233. package/src/theme/status-verdict.tsx +9 -4
  234. package/src/tokens/oklab.ts +97 -0
@@ -1,7 +1,7 @@
1
1
  /** Meter's internal pieces: bar, ring, empty and loading. `meter.tsx` dispatches between them. */
2
2
  import { Skeleton, VisuallyHidden } from '@mantine/core'
3
- import { useId, useRef, useState } from 'react'
4
- import type { CSSProperties, HTMLAttributes, ReactNode, RefObject } from 'react'
3
+ import { useContext, useId, useRef, useState } from 'react'
4
+ import type { CSSProperties, ReactNode, RefObject } from 'react'
5
5
  import { useIsomorphicLayoutEffect } from '../common/isomorphic-layout-effect'
6
6
  import { cx } from '../common/props'
7
7
  import {
@@ -9,14 +9,28 @@ import {
9
9
  modelBar,
10
10
  ringFraction,
11
11
  startCaptionText,
12
+ placeRowLabels,
12
13
  zoneBand,
13
- zoneLabelsFit,
14
14
  } from './meter-model'
15
- import type { MeterSegment, MeterZone, Part, ZoneLabel } from './meter-model'
15
+ import type {
16
+ MeterSegment,
17
+ MeterTick,
18
+ MeterZone,
19
+ Part,
20
+ RowLabel,
21
+ TickMark,
22
+ ZoneLabel,
23
+ } from './meter-model'
16
24
  import classes from './meter.module.css'
25
+ import { VisualSlotContext } from './visual-slot'
17
26
  import { toPct } from './scale'
18
27
 
19
- export type Shell = { className: string | undefined; style: CSSProperties | undefined }
28
+ export type Shell = {
29
+ className: string | undefined
30
+ style: CSSProperties | undefined
31
+ /** `size="row"`: one text line tall, no caption rows. */
32
+ row: boolean
33
+ }
20
34
 
21
35
  /**
22
36
  * The one root contract of every Meter state. `data-basalt-meter` is the handle `StatCard` keys its
@@ -24,7 +38,7 @@ export type Shell = { className: string | undefined; style: CSSProperties | unde
24
38
  */
25
39
  function rootProps(shell: Shell) {
26
40
  return {
27
- className: cx(classes.root, shell.className),
41
+ className: cx(classes.root, shell.row && classes.row, shell.className),
28
42
  style: shell.style,
29
43
  'data-basalt-meter': '',
30
44
  } as const
@@ -62,6 +76,22 @@ function RingSvg({ fraction, color }: { fraction?: number; color?: string | unde
62
76
  )
63
77
  }
64
78
 
79
+ /**
80
+ * A value and its unit stay on one line: a no-break space replaces the space between a digit and a
81
+ * known unit ("24 h", "7 d", "5 min", "40 %"), so a caption never wraps to a lone "d". Any other
82
+ * word ("3 of 7", "250 over") keeps its ordinary space.
83
+ */
84
+ const UNITS = 'h|d|w|mo|y|s|ms|min|m|km|mi|g|kg|%|€|pts|bpm|AU|kcal|KB|MB|GB|TB'
85
+ const UNIT_AFTER_NUMBER = new RegExp(`(\\d) (?=(?:${UNITS})(?![\\p{L}\\d]))`, 'gu')
86
+ /** The last two words of a caption Meter composes are one unit when the last is short, so no
87
+ * line ends on a lone "budget" or "d". */
88
+ // Ordinary spaces only: an already-glued unit (`7\u00a0d`) counts as one word.
89
+ const SHORT_LAST_WORD = /([^ ]) ([^ ]{1,6})$/u
90
+ const glueUnits = (text: ReactNode): ReactNode =>
91
+ typeof text === 'string' ? text.replace(UNIT_AFTER_NUMBER, '$1\u00a0') : text
92
+ const glue = (text: ReactNode): ReactNode =>
93
+ typeof text === 'string' ? String(glueUnits(text)).replace(SHORT_LAST_WORD, '$1\u00a0$2') : text
94
+
65
95
  export function MeterLoading({
66
96
  label,
67
97
  ring,
@@ -73,7 +103,7 @@ export function MeterLoading({
73
103
  }) {
74
104
  return (
75
105
  <div {...rootProps(shell)} aria-busy="true">
76
- <VisuallyHidden>{`Loading ${label}`}</VisuallyHidden>
106
+ <VisuallyHidden className={classes.summary}>{`Loading ${label}`}</VisuallyHidden>
77
107
  {ring ? (
78
108
  <Skeleton className={classes.skeletonRing} circle />
79
109
  ) : (
@@ -151,33 +181,72 @@ function zoneStyle(zone: MeterZone, index: number, count: number, min: number, s
151
181
  } satisfies CSSProperties
152
182
  }
153
183
 
154
- /**
155
- * Joins the names with a character no label carries, so the effect re-runs only when they change.
156
- * The holding zone is part of the key: its label is bolder, so a reading that crosses a boundary
157
- * changes widths with no row resize.
158
- */
159
- const labelsKey = (labels: readonly ZoneLabel[]) =>
160
- labels.map((l) => l.label + (l.holding ? '*' : '')).join('\u0000')
184
+ /** One label on the row: its span in percent of the row (a zone name) or none (an end tick). */
185
+ type RowSlot = { spanPct?: readonly [number, number]; holding?: boolean }
186
+
187
+ type RowLayout = { shown: boolean[]; short: boolean[]; shift: number[] }
188
+ const sameLayout = (a: RowLayout, b: RowLayout) =>
189
+ a.shown.length === b.shown.length &&
190
+ a.shown.every(
191
+ (v, i) => v === b.shown[i] && a.short[i] === b.short[i] && a.shift[i] === b.shift[i],
192
+ )
161
193
 
162
194
  /**
163
- * Whether the zone names fit on the band, re-measured when the row resizes, when web fonts finish
164
- * loading (a mono swap changes label widths without resizing the row) and when the names change.
165
- * Server markup shows the band; the list may appear after mount, when the measurement fails.
195
+ * Which row labels show, re-measured when the row resizes, when web fonts finish loading (a swap
196
+ * changes label widths without resizing the row) and when the labels change. Server markup shows
197
+ * every label; a name that does not fit its span (or clashes with a tick) hides after measuring.
198
+ * `slots` is index-aligned with the row's first children; the children after them are the short
199
+ * twins, `shortOf[n]` being the label index the n-th twin stands in for.
166
200
  */
167
- function useZoneLabelLayout(rowRef: RefObject<HTMLDivElement | null>, key: string): boolean {
168
- const [fits, setFits] = useState(true)
201
+ function useRowLabelLayout(
202
+ rowRef: RefObject<HTMLDivElement | null>,
203
+ slots: readonly RowSlot[],
204
+ shortOf: readonly number[],
205
+ key: string,
206
+ ): RowLayout {
207
+ const [layout, setLayout] = useState<RowLayout>({ shown: [], short: [], shift: [] })
208
+ const slotsRef = useRef(slots)
209
+ const shortOfRef = useRef(shortOf)
210
+ // Declared before the measuring effect so it reads this render's slots.
211
+ useIsomorphicLayoutEffect(() => {
212
+ slotsRef.current = slots
213
+ shortOfRef.current = shortOf
214
+ })
169
215
 
170
- // Keyed on a string of the names, not the `labels` array: the model rebuilds that every render.
216
+ // Keyed on a string of the labels, not the `slots` array: the model rebuilds that every render.
171
217
  useIsomorphicLayoutEffect(() => {
172
218
  const row = rowRef.current
173
219
  if (!row) return
174
220
  const measure = () => {
175
221
  const origin = row.getBoundingClientRect()
176
- const boxes = [...row.children].map((c) => {
222
+ const rtl = getComputedStyle(row).direction === 'rtl'
223
+ const edge = (pct: number) => (origin.width * (rtl ? 100 - pct : pct)) / 100
224
+ const children = [...row.children]
225
+ const labels: RowLabel[] = children.slice(0, slotsRef.current.length).map((c, i) => {
177
226
  const r = c.getBoundingClientRect()
178
- return { left: r.left - origin.left, right: r.right - origin.left }
227
+ const slot = slotsRef.current[i]
228
+ const pct = slot?.spanPct
229
+ const [a, b] = pct ? [edge(pct[0]), edge(pct[1])] : []
230
+ return {
231
+ box: { left: r.left - origin.left, right: r.right - origin.left },
232
+ ...(a !== undefined &&
233
+ b !== undefined && { span: { left: Math.min(a, b), right: Math.max(a, b) } }),
234
+ ...(slot?.holding && { holding: true }),
235
+ }
179
236
  })
180
- setFits(zoneLabelsFit(boxes, origin.width))
237
+ shortOfRef.current.forEach((labelIndex, n) => {
238
+ const r = children[slotsRef.current.length + n]?.getBoundingClientRect()
239
+ const label = labels[labelIndex]
240
+ if (r && label) label.short = { left: r.left - origin.left, right: r.right - origin.left }
241
+ })
242
+ const placed = placeRowLabels(labels, origin.width)
243
+ // The hook measures on the physical x axis; the margin is logical, so it flips with `dir`.
244
+ const next = {
245
+ shown: placed.shown,
246
+ short: placed.short,
247
+ shift: placed.shift.map((v) => (rtl ? -v : v)),
248
+ }
249
+ setLayout((prev) => (sameLayout(prev, next) ? prev : next))
181
250
  }
182
251
  measure()
183
252
  const observer = typeof ResizeObserver === 'undefined' ? undefined : new ResizeObserver(measure)
@@ -195,7 +264,7 @@ function useZoneLabelLayout(rowRef: RefObject<HTMLDivElement | null>, key: strin
195
264
  }
196
265
  }, [rowRef, key])
197
266
 
198
- return fits
267
+ return layout
199
268
  }
200
269
 
201
270
  /**
@@ -240,56 +309,89 @@ function ZoneReading({ pct, children }: { pct: number; children: ReactNode }) {
240
309
  )
241
310
  }
242
311
 
243
- function ZoneName({ label, ...rest }: { label: ZoneLabel } & HTMLAttributes<HTMLSpanElement>) {
244
- return (
245
- <span
246
- {...rest}
247
- className={cx(rest.className, label.holding && classes.zoneLabelHolding)}
248
- data-meter-zone-label={label.label}
249
- data-holding={label.holding || undefined}
250
- >
251
- {label.label}
252
- </span>
253
- )
254
- }
312
+ /** Ticks past the middle caption to the left of their mark, so a caption near the end stays on the row. */
313
+ const TICK_LABEL_FLIP_PCT = 50
255
314
 
256
315
  /**
257
- * Names each zone under its band, the holding one in ink and a heavier weight. Labels sit
258
- * left-aligned at their band start; when two would overlap (or one would leave the row) the band
259
- * hides and the same names wrap as a list in zone order instead. The band stays laid out (hidden,
260
- * not removed) so a resize can measure it again. Decorative: the zone names and the holding zone
261
- * are in the described-by text.
316
+ * The one label row: each zone name centred under its own span and the labelled ticks hugging their
317
+ * marks (the end ticks sit at the row's ends), all on one baseline. A name wider than its span, or
318
+ * clashing with a tick or a neighbour, hides (still laid out, so a resize can measure it again) and is
319
+ * still named in the described-by text; the holding zone is ink and heavier. Decorative.
262
320
  */
263
- function ZoneLabels({ labels }: { labels: readonly ZoneLabel[] }) {
321
+ function LabelRow({ zones, ticks }: { zones: readonly ZoneLabel[]; ticks: readonly TickMark[] }) {
264
322
  const rowRef = useRef<HTMLDivElement>(null)
265
- const fits = useZoneLabelLayout(rowRef, labelsKey(labels))
266
-
323
+ const slots: RowSlot[] = [
324
+ ...ticks.map((): RowSlot => ({})),
325
+ ...zones.map((z): RowSlot => ({
326
+ spanPct: [z.centrePct - z.widthPct / 2, z.centrePct + z.widthPct / 2],
327
+ holding: z.holding,
328
+ })),
329
+ ]
330
+ const key = [
331
+ ...ticks.map((t) => `${t.label}@${t.pct}`),
332
+ ...zones.map((z) => `${z.label}${z.holding ? '*' : ''}@${z.centrePct}`),
333
+ ].join('\u0000')
334
+ // The holding name never shortens, so its zone has no twin.
335
+ const twins = zones.flatMap((z, i) => (z.short !== undefined && !z.holding ? [i] : []))
336
+ const { shown, short, shift } = useRowLabelLayout(
337
+ rowRef,
338
+ slots,
339
+ twins.map((i) => ticks.length + i),
340
+ `${key}\u0001${twins.map((i) => zones[i]?.short).join('\u0000')}`,
341
+ )
342
+ const hidden = (i: number) => (shown[i] === false || short[i] === true ? '' : undefined)
343
+ const nudge = (i: number): CSSProperties =>
344
+ shift[i] ? { marginInlineStart: `${shift[i]}px` } : {}
267
345
  return (
268
- <>
269
- <div
270
- ref={rowRef}
271
- className={classes.zoneBand}
272
- data-meter-zone-band
273
- data-collapsed={fits ? undefined : ''}
274
- aria-hidden
275
- >
276
- {labels.map((l) => (
277
- <ZoneName
278
- key={l.key}
279
- label={l}
280
- className={classes.zoneLabel}
281
- style={{ insetInlineStart: `${l.startPct}%` }}
282
- />
283
- ))}
284
- </div>
285
- {!fits && (
286
- <div className={classes.zoneList} data-meter-zone-list aria-hidden>
287
- {labels.map((l) => (
288
- <ZoneName key={l.key} label={l} className={classes.zoneListItem} />
289
- ))}
290
- </div>
291
- )}
292
- </>
346
+ <div
347
+ ref={rowRef}
348
+ className={classes.labelRow}
349
+ {...(zones.length > 0 ? { 'data-meter-zone-band': '' } : { 'data-meter-tick-band': '' })}
350
+ aria-hidden
351
+ >
352
+ {ticks.map((t, i) => (
353
+ <span
354
+ key={`t${t.key}`}
355
+ className={classes.rowLabel}
356
+ data-meter-tick-label=""
357
+ data-hidden={hidden(i)}
358
+ style={
359
+ t.pct > TICK_LABEL_FLIP_PCT
360
+ ? { insetInlineEnd: `${100 - t.pct}%` }
361
+ : { insetInlineStart: `${t.pct}%` }
362
+ }
363
+ >
364
+ {t.label}
365
+ </span>
366
+ ))}
367
+ {zones.map((z, i) => (
368
+ <span
369
+ key={`z${z.key}`}
370
+ className={cx(classes.rowLabel, classes.zoneLabel, z.holding && classes.zoneLabelHolding)}
371
+ data-meter-zone-label={z.label}
372
+ data-holding={z.holding || undefined}
373
+ data-hidden={hidden(ticks.length + i)}
374
+ style={{ insetInlineStart: `${z.centrePct}%`, ...nudge(ticks.length + i) }}
375
+ >
376
+ {z.label}
377
+ </span>
378
+ ))}
379
+ {twins.map((zi) => {
380
+ const z = zones[zi] as ZoneLabel
381
+ const i = ticks.length + zi
382
+ return (
383
+ <span
384
+ key={`s${z.key}`}
385
+ className={cx(classes.rowLabel, classes.zoneLabel)}
386
+ data-meter-zone-short={z.label}
387
+ data-hidden={short[i] === true ? undefined : ''}
388
+ style={{ insetInlineStart: `${z.centrePct}%`, ...nudge(i) }}
389
+ >
390
+ {z.short}
391
+ </span>
392
+ )
393
+ })}
394
+ </div>
293
395
  )
294
396
  }
295
397
 
@@ -303,6 +405,8 @@ export function MeterBar(props: {
303
405
  segments: readonly MeterSegment[] | undefined
304
406
  zones: readonly MeterZone[] | undefined
305
407
  target: number | undefined
408
+ ticks: readonly MeterTick[] | undefined
409
+ tone: 'muted' | undefined
306
410
  forecastCaption: string | undefined
307
411
  startCaption: ReactNode
308
412
  endCaption: ReactNode
@@ -311,17 +415,31 @@ export function MeterBar(props: {
311
415
  const { label, reading, min, max, format, zones, shell } = props
312
416
  const describedId = useId()
313
417
  const model = modelBar(props)
314
- const start = startCaptionText(model, props.startCaption)
315
- const end = props.endCaption === undefined ? model.endText : props.endCaption
418
+ const compact = shell.row
419
+ // A host that already shows the value as its hero (StatCard, a strip cell) owns the reading: a
420
+ // zoned track keeps its marker and zone labels but does not print the number a second time. A
421
+ // consumer's own `startCaption` is not the reading and still renders.
422
+ const hosted =
423
+ useContext(VisualSlotContext) &&
424
+ model.markerPct !== undefined &&
425
+ props.startCaption === undefined
426
+ const start = compact || hosted ? null : startCaptionText(model, props.startCaption)
427
+ const end = compact ? null : props.endCaption === undefined ? model.endText : props.endCaption
316
428
  const anchored = model.markerPct !== undefined && start !== null
317
- const hasCaptions = (start !== null && !anchored) || end !== null || model.forecastText !== null
318
- const hasParts = model.partCaptions.length > 0
429
+ const hasCaptions =
430
+ (start !== null && !anchored) || end !== null || (!compact && model.forecastText !== null)
431
+ const hasParts = !compact && model.partCaptions.length > 0
432
+ const tickLabels = compact ? [] : model.ticks.filter((t) => t.label !== undefined)
433
+ const zoneLabels = compact ? [] : model.zoneLabels
319
434
  const describedBy =
320
435
  model.describedByText === null ? {} : ({ 'aria-describedby': describedId } as const)
321
436
 
322
437
  const root = rootProps(shell)
323
438
  return (
324
- <div {...root} className={cx(root.className, model.zoneLabels.length > 0 && classes.zoned)}>
439
+ <div {...root} className={root.className}>
440
+ {tickLabels.length > 0 && zoneLabels.length === 0 && (
441
+ <LabelRow zones={zoneLabels} ticks={tickLabels} />
442
+ )}
325
443
  <div
326
444
  className={classes.trackBox}
327
445
  aria-label={label}
@@ -343,18 +461,26 @@ export function MeterBar(props: {
343
461
  key={i}
344
462
  className={cx(classes.fill, p.forecast && classes.forecastFill)}
345
463
  data-meter-fill={p.forecast ? 'forecast' : 'committed'}
464
+ data-tone={
465
+ props.tone === 'muted' && p.color === undefined && !p.forecast ? 'muted' : undefined
466
+ }
346
467
  style={fillStyle(p)}
347
468
  />
348
469
  ))}
349
470
  </div>
350
471
  <Tick kind="marker" className={classes.marker} pct={model.markerPct} />
351
472
  <Tick kind="boundary" className={classes.boundaryTick} pct={model.boundaryPct} />
473
+ {model.ticks.map((t) => (
474
+ <Tick key={t.key} kind="tick" className={classes.tick} pct={t.pct} />
475
+ ))}
352
476
  <Tick kind="target" className={classes.tick} pct={model.targetPct} />
353
477
  </div>
354
- {model.zoneLabels.length > 0 && <ZoneLabels labels={model.zoneLabels} />}
478
+ {zoneLabels.length > 0 && <LabelRow zones={zoneLabels} ticks={tickLabels} />}
355
479
  {anchored && <ZoneReading pct={model.markerPct ?? 0}>{start}</ZoneReading>}
356
480
  {model.describedByText !== null && (
357
- <VisuallyHidden id={describedId}>{model.describedByText}</VisuallyHidden>
481
+ <VisuallyHidden id={describedId} className={classes.summary}>
482
+ {model.describedByText}
483
+ </VisuallyHidden>
358
484
  )}
359
485
  {hasParts && (
360
486
  // The explicit role is deliberate: `list-style: none` makes Safari/VoiceOver drop the implicit one.
@@ -368,40 +494,50 @@ export function MeterBar(props: {
368
494
  style={{ background: c.color ?? 'var(--vx-line)' }}
369
495
  aria-hidden
370
496
  />
371
- {c.label} {c.text}
497
+ {glueUnits(`${c.label} ${c.text}`)}
372
498
  </li>
373
499
  ))}
374
500
  </ul>
375
501
  )}
376
502
  {hasCaptions && (
377
503
  <div className={classes.captions} data-meter-captions>
378
- {start !== null && !anchored && <span className={classes.caption}>{start}</span>}
379
- {model.forecastText !== null && (
380
- <span className={classes.caption}>{model.forecastText}</span>
504
+ {start !== null && !anchored && <span className={classes.caption}>{glue(start)}</span>}
505
+ {!compact && model.forecastText !== null && (
506
+ <span className={classes.caption}>{glue(model.forecastText)}</span>
381
507
  )}
382
- {end !== null && <span className={classes.captionEnd}>{end}</span>}
508
+ {end !== null && <span className={classes.captionEnd}>{glue(end)}</span>}
383
509
  </div>
384
510
  )}
385
511
  </div>
386
512
  )
387
513
  }
388
514
 
515
+ /** A tick's width: the end tick's start edge sits this far inside the track. */
516
+ const TICK_WIDTH = '2px'
517
+
518
+ /**
519
+ * Centred on its percent. A target or tick AT the track end is the exception: centred there it is
520
+ * half outside the track (and hidden by a full fill), so its end edge sits ON the track end and it
521
+ * reads inside. The marker is the reading itself and stays centred.
522
+ */
523
+ function tickPosition(kind: TickKind, pct: number): CSSProperties {
524
+ if (pct < 100 || kind === 'marker' || kind === 'boundary') return { insetInlineStart: `${pct}%` }
525
+ return { insetInlineStart: `calc(100% - ${TICK_WIDTH})`, marginInlineStart: 0 }
526
+ }
527
+
528
+ type TickKind = 'marker' | 'boundary' | 'target' | 'tick'
529
+
389
530
  function Tick({
390
531
  kind,
391
532
  className,
392
533
  pct,
393
534
  }: {
394
- kind: 'marker' | 'boundary' | 'target'
535
+ kind: TickKind
395
536
  className: string
396
537
  pct: number | undefined
397
538
  }) {
398
539
  if (pct === undefined) return null
399
540
  return (
400
- <div
401
- className={className}
402
- data-meter-tick={kind}
403
- style={{ insetInlineStart: `${pct}%` }}
404
- aria-hidden
405
- />
541
+ <div className={className} data-meter-tick={kind} style={tickPosition(kind, pct)} aria-hidden />
406
542
  )
407
543
  }
@@ -9,10 +9,9 @@
9
9
  flex-direction: column;
10
10
  gap: var(--vx-space-stack-xs, 0.25rem);
11
11
  min-width: 0;
12
- }
13
-
14
- .root.zoned {
15
- position: relative;
12
+ /* The ONE caption size: every caption below reads it. A host that wants captions at its own text
13
+ * size sets `--basalt-meter-caption: 1em` on the Meter. */
14
+ --basalt-meter-caption: var(--vx-text-micro);
16
15
  }
17
16
 
18
17
  .track {
@@ -35,6 +34,14 @@
35
34
  background: var(--vx-line);
36
35
  }
37
36
 
37
+ /*
38
+ * A non-verdict reading: --vx-muted at 65%. 35% (argo's alpha) measures 1.7:1 (light) / 2.4:1 (dark)
39
+ * against the track; 65% clears 3:1 in both, and is not the near-white of --vx-line in dark.
40
+ */
41
+ .fill[data-tone='muted'] {
42
+ background: color-mix(in srgb, var(--vx-muted) 65%, transparent);
43
+ }
44
+
38
45
  /* The committed/forecast pair: the same neutral at two strengths. Flat, never hatched. */
39
46
  .forecastFill {
40
47
  background: color-mix(in srgb, var(--vx-line) 45%, transparent);
@@ -46,54 +53,44 @@
46
53
  }
47
54
 
48
55
  /*
49
- * Zone names under the band: absolutely placed at each band start so they stay on the band. When
50
- * they would collide the band collapses (hidden but still laid out, so it can be re-measured) and the
51
- * same names wrap as a list. The holding zone is ink, the rest muted.
56
+ * The one label row under (or, for a plain tick Meter, above) the track: zone names centred on their
57
+ * spans, labelled ticks hugging their marks, all absolutely placed on one baseline. A label that does
58
+ * not fit is hidden but stays laid out, so a resize can measure it again.
52
59
  */
53
- .zoneBand {
60
+ .labelRow {
61
+ --basalt-reading-dir: 1;
54
62
  position: relative;
55
- /* Labels are absolutely placed, so the row needs its own line height. */
63
+ /* A hidden name keeps its box (so it can be measured again) and may sit past the row's end. */
64
+ overflow-x: clip;
56
65
  height: 1.25em;
57
- font-family: var(--basalt-font-mono);
58
- font-size: var(--vx-text-micro);
66
+ font-family: var(--basalt-font-numeral, var(--basalt-font-sans));
67
+ font-variant-numeric: lining-nums;
68
+ font-size: var(--basalt-meter-caption);
59
69
  color: var(--vx-muted);
60
70
  }
61
71
 
62
- /*
63
- * Hidden but laid out, so a resize can measure it again. Absolute against `.root.zoned`, which has
64
- * no inline padding, so `inset-inline: 0` gives the band the same width as when it was in flow.
65
- */
66
- .zoneBand[data-collapsed] {
67
- position: absolute;
68
- top: 0;
69
- inset-inline: 0;
70
- visibility: hidden;
71
- pointer-events: none;
72
+ .labelRow:dir(rtl) {
73
+ --basalt-reading-dir: -1;
72
74
  }
73
75
 
74
- .zoneLabel {
76
+ .rowLabel {
75
77
  position: absolute;
76
78
  top: 0;
77
79
  white-space: nowrap;
78
80
  }
79
81
 
80
- .zoneLabelHolding {
81
- font-weight: 500;
82
- color: var(--vx-ink);
82
+ .rowLabel[data-hidden] {
83
+ visibility: hidden;
83
84
  }
84
85
 
85
- .zoneList {
86
- display: flex;
87
- flex-wrap: wrap;
88
- gap: var(--vx-space-stack-xs) var(--vx-space-stack-sm);
89
- font-family: var(--basalt-font-mono);
90
- font-size: var(--vx-text-micro);
91
- color: var(--vx-muted);
86
+ /* A zone name is centred on its span: the physical `translate` flips sign in RTL. */
87
+ .zoneLabel {
88
+ translate: calc(-50% * var(--basalt-reading-dir)) 0;
92
89
  }
93
90
 
94
- .zoneListItem {
95
- min-width: 0;
96
- overflow-wrap: anywhere;
91
+ .zoneLabelHolding {
92
+ font-weight: 500;
93
+ color: var(--vx-ink);
97
94
  }
98
95
 
99
96
  /* The reading under the band, centred on the marker. Clipped so it never widens the row before the first measure. */
@@ -102,8 +99,9 @@
102
99
  position: relative;
103
100
  height: 1.25em;
104
101
  overflow: clip;
105
- font-family: var(--basalt-font-mono);
106
- font-size: var(--vx-text-micro);
102
+ font-family: var(--basalt-font-numeral, var(--basalt-font-sans));
103
+ font-variant-numeric: lining-nums;
104
+ font-size: var(--basalt-meter-caption);
107
105
  }
108
106
 
109
107
  .zoneReadingRow:dir(rtl) {
@@ -144,6 +142,8 @@
144
142
  margin-inline-start: -1px;
145
143
  border-radius: var(--vx-radius-fine);
146
144
  background: var(--vx-ink);
145
+ /* A track-coloured halo keeps an ink tick readable on a fill that is itself near-ink (dark). */
146
+ box-shadow: 0 0 0 1px var(--vx-surface-subtle);
147
147
  }
148
148
 
149
149
  .boundaryTick {
@@ -157,14 +157,17 @@
157
157
  align-items: baseline;
158
158
  justify-content: space-between;
159
159
  gap: var(--vx-space-control-gap, 0.375rem);
160
- font-family: var(--basalt-font-mono);
161
- font-size: var(--vx-text-micro);
160
+ font-family: var(--basalt-font-numeral, var(--basalt-font-sans));
161
+ font-variant-numeric: lining-nums;
162
+ font-size: var(--basalt-meter-caption);
163
+ text-wrap: balance;
162
164
  color: var(--vx-muted);
163
165
  }
164
166
 
165
167
  /* Captions never truncate: the row wraps, and a caption wider than the row wraps inside itself. */
166
168
  .caption {
167
169
  min-width: 0;
170
+ text-wrap: balance;
168
171
  overflow-wrap: anywhere;
169
172
  }
170
173
 
@@ -175,6 +178,12 @@
175
178
  text-align: end;
176
179
  }
177
180
 
181
+ /* The visually-hidden summary and loading text are still text: they read the caption size, not the
182
+ * body size they would inherit. */
183
+ .root .summary {
184
+ font-size: var(--basalt-meter-caption);
185
+ }
186
+
178
187
  /* Categorical segments: one caption per part under the track, wrapping at narrow widths. */
179
188
  .partCaptions {
180
189
  display: flex;
@@ -183,8 +192,10 @@
183
192
  margin: 0;
184
193
  padding: 0;
185
194
  list-style: none;
186
- font-family: var(--basalt-font-mono);
187
- font-size: var(--vx-text-micro);
195
+ font-family: var(--basalt-font-numeral, var(--basalt-font-sans));
196
+ font-variant-numeric: lining-nums;
197
+ font-size: var(--basalt-meter-caption);
198
+ text-wrap: balance;
188
199
  color: var(--vx-muted);
189
200
  }
190
201
 
@@ -205,7 +216,7 @@
205
216
  }
206
217
 
207
218
  .empty {
208
- font-size: var(--vx-text-sm);
219
+ font-size: var(--basalt-meter-caption);
209
220
  color: var(--vx-muted);
210
221
  }
211
222
 
@@ -256,7 +267,8 @@
256
267
 
257
268
  .ringValue {
258
269
  position: relative;
259
- font-family: var(--basalt-font-mono);
270
+ font-family: var(--basalt-font-numeral, var(--basalt-font-sans));
271
+ font-variant-numeric: lining-nums;
260
272
  font-size: var(--vx-text-kpi);
261
273
  font-weight: 500;
262
274
  color: var(--vx-ink);
@@ -266,3 +278,22 @@
266
278
  width: 5rem;
267
279
  height: 5rem;
268
280
  }
281
+
282
+ /* ── size="row" ──────────────────────────────────────────────────────────────────────────────── */
283
+
284
+ .row {
285
+ gap: 0;
286
+ justify-content: center;
287
+ }
288
+
289
+ .row .track {
290
+ height: 1lh;
291
+ }
292
+
293
+ .row .skeletonTrack {
294
+ height: 1lh;
295
+ }
296
+
297
+ .row .skeletonCaption {
298
+ display: none;
299
+ }