basalt-ui 2.18.0 → 2.20.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 (183) hide show
  1. package/CHANGELOG.md +90 -0
  2. package/MIGRATING.md +238 -12
  3. package/agent/agents/basalt-design-reviewer.md +2 -2
  4. package/agent/rules/basalt-charts.md +1 -1
  5. package/agent/rules/basalt-mantine.md +1 -1
  6. package/agent/skills/basalt-app/SKILL.md +1 -1
  7. package/agent/skills/basalt-design/SKILL.md +1 -1
  8. package/agent/templates/DESIGN.md.tpl +1 -1
  9. package/configs/oxlint-plugin.js +33 -19
  10. package/configs/oxlint-plugin.test.ts +32 -2
  11. package/dist/charts/ChartCard.d.ts +28 -3
  12. package/dist/charts/ChartCard.d.ts.map +1 -1
  13. package/dist/charts/ChartCard.js +33 -11
  14. package/dist/charts/Donut.d.ts.map +1 -1
  15. package/dist/charts/Donut.js +13 -1
  16. package/dist/charts/Heatmap.js +1 -1
  17. package/dist/charts/Sparkline.d.ts +7 -1
  18. package/dist/charts/Sparkline.d.ts.map +1 -1
  19. package/dist/charts/Sparkline.js +137 -18
  20. package/dist/charts/box.d.ts +2 -0
  21. package/dist/charts/box.d.ts.map +1 -1
  22. package/dist/charts/box.js +2 -0
  23. package/dist/charts/chart-box.module.css +30 -0
  24. package/dist/charts/chart-box.module.css.d.ts +1 -0
  25. package/dist/charts/chart-card.module.css +47 -0
  26. package/dist/charts/chart-card.module.css.d.ts +7 -0
  27. package/dist/charts/compile.d.ts.map +1 -1
  28. package/dist/charts/compile.js +35 -8
  29. package/dist/charts/host.d.ts.map +1 -1
  30. package/dist/charts/host.js +2 -1
  31. package/dist/charts/index.d.ts +1 -1
  32. package/dist/charts/index.d.ts.map +1 -1
  33. package/dist/charts/sparkline.module.css +59 -0
  34. package/dist/charts/sparkline.module.css.d.ts +13 -0
  35. package/dist/charts/state.d.ts.map +1 -1
  36. package/dist/charts/state.js +32 -4
  37. package/dist/charts/types.d.ts +6 -0
  38. package/dist/charts/types.d.ts.map +1 -1
  39. package/dist/commands/notifications/center.d.ts.map +1 -1
  40. package/dist/commands/notifications/center.js +18 -26
  41. package/dist/content/callout.d.ts +1 -1
  42. package/dist/content/callout.d.ts.map +1 -1
  43. package/dist/content/callout.js +10 -1
  44. package/dist/content/callout.module.css +15 -3
  45. package/dist/content/callout.module.css.d.ts +1 -0
  46. package/dist/controls/sync-button.d.ts +3 -0
  47. package/dist/controls/sync-button.d.ts.map +1 -1
  48. package/dist/dashboard/bar-list.d.ts +15 -4
  49. package/dist/dashboard/bar-list.d.ts.map +1 -1
  50. package/dist/dashboard/bar-list.js +56 -19
  51. package/dist/dashboard/bar-list.module.css +110 -17
  52. package/dist/dashboard/bar-list.module.css.d.ts +2 -0
  53. package/dist/dashboard/delta-badge.d.ts +8 -3
  54. package/dist/dashboard/delta-badge.d.ts.map +1 -1
  55. package/dist/dashboard/delta-badge.js +9 -2
  56. package/dist/dashboard/index.d.ts +2 -0
  57. package/dist/dashboard/index.d.ts.map +1 -1
  58. package/dist/dashboard/meter-model.d.ts +68 -1
  59. package/dist/dashboard/meter-model.d.ts.map +1 -1
  60. package/dist/dashboard/meter-model.js +65 -4
  61. package/dist/dashboard/meter-parts.d.ts +5 -1
  62. package/dist/dashboard/meter-parts.d.ts.map +1 -1
  63. package/dist/dashboard/meter-parts.js +234 -60
  64. package/dist/dashboard/meter.d.ts +38 -6
  65. package/dist/dashboard/meter.d.ts.map +1 -1
  66. package/dist/dashboard/meter.js +4 -1
  67. package/dist/dashboard/meter.module.css +209 -13
  68. package/dist/dashboard/meter.module.css.d.ts +16 -0
  69. package/dist/dashboard/query-state.d.ts.map +1 -1
  70. package/dist/dashboard/query-state.js +14 -9
  71. package/dist/dashboard/settings-section.d.ts.map +1 -1
  72. package/dist/dashboard/settings-section.js +14 -25
  73. package/dist/dashboard/stat-card-parts.d.ts +3 -1
  74. package/dist/dashboard/stat-card-parts.d.ts.map +1 -1
  75. package/dist/dashboard/stat-card-parts.js +18 -3
  76. package/dist/dashboard/stat-card.d.ts +7 -6
  77. package/dist/dashboard/stat-card.d.ts.map +1 -1
  78. package/dist/dashboard/stat-card.js +51 -83
  79. package/dist/dashboard/stat-card.module.css +42 -14
  80. package/dist/dashboard/stat-group.d.ts +11 -2
  81. package/dist/dashboard/stat-group.d.ts.map +1 -1
  82. package/dist/dashboard/stat-group.js +9 -7
  83. package/dist/dashboard/stat-strip.d.ts +50 -0
  84. package/dist/dashboard/stat-strip.d.ts.map +1 -0
  85. package/dist/dashboard/stat-strip.js +85 -0
  86. package/dist/dashboard/stat-strip.module.css +208 -0
  87. package/dist/dashboard/stat-strip.module.css.d.ts +28 -0
  88. package/dist/dashboard/widget-header.d.ts +3 -3
  89. package/dist/dashboard/widget-header.d.ts.map +1 -1
  90. package/dist/dashboard/widget-header.js +2 -1
  91. package/dist/dashboard/widget-header.module.css +38 -7
  92. package/dist/format/date.d.ts.map +1 -1
  93. package/dist/format/date.js +4 -3
  94. package/dist/format/shared.d.ts +6 -0
  95. package/dist/format/shared.d.ts.map +1 -1
  96. package/dist/format/shared.js +6 -2
  97. package/dist/guard/index.d.ts +1 -1
  98. package/dist/guard/index.js +1 -1
  99. package/dist/index.d.ts +3 -1
  100. package/dist/index.d.ts.map +1 -1
  101. package/dist/index.js +4 -0
  102. package/dist/styles.css +6 -0
  103. package/dist/theme/card-inset.module.css +76 -0
  104. package/dist/theme/card-inset.module.css.d.ts +9 -0
  105. package/dist/theme/chrome-vars.d.ts +29 -17
  106. package/dist/theme/chrome-vars.d.ts.map +1 -1
  107. package/dist/theme/chrome-vars.js +18 -8
  108. package/dist/theme/controls.module.css +3 -0
  109. package/dist/theme/index.d.ts.map +1 -1
  110. package/dist/theme/index.js +32 -5
  111. package/dist/theme/nav-link.module.css +8 -10
  112. package/dist/theme/status-dot.d.ts +7 -0
  113. package/dist/theme/status-dot.d.ts.map +1 -0
  114. package/dist/theme/status-dot.js +18 -0
  115. package/dist/theme/status-dot.module.css +9 -0
  116. package/dist/theme/status-dot.module.css.d.ts +8 -0
  117. package/dist/theme/status-verdict.d.ts +10 -0
  118. package/dist/theme/status-verdict.d.ts.map +1 -0
  119. package/dist/theme/status-verdict.js +14 -0
  120. package/dist/theme/status-verdict.module.css +25 -0
  121. package/dist/theme/status-verdict.module.css.d.ts +9 -0
  122. package/llms.txt +30 -6
  123. package/package.json +1 -1
  124. package/src/charts/ChartCard.tsx +70 -4
  125. package/src/charts/Donut.tsx +9 -1
  126. package/src/charts/Heatmap.tsx +1 -1
  127. package/src/charts/Sparkline.tsx +180 -18
  128. package/src/charts/box.tsx +2 -0
  129. package/src/charts/chart-box.module.css +30 -0
  130. package/src/charts/chart-box.module.css.d.ts +1 -0
  131. package/src/charts/chart-card.module.css +47 -0
  132. package/src/charts/chart-card.module.css.d.ts +7 -0
  133. package/src/charts/compile.ts +42 -9
  134. package/src/charts/host.tsx +6 -3
  135. package/src/charts/index.ts +1 -1
  136. package/src/charts/sparkline.module.css +59 -0
  137. package/src/charts/sparkline.module.css.d.ts +13 -0
  138. package/src/charts/state.tsx +44 -4
  139. package/src/charts/types.ts +6 -0
  140. package/src/commands/notifications/center.tsx +29 -32
  141. package/src/content/callout.module.css +15 -3
  142. package/src/content/callout.module.css.d.ts +1 -0
  143. package/src/content/callout.tsx +15 -2
  144. package/src/controls/sync-button.tsx +3 -0
  145. package/src/dashboard/bar-list.module.css +110 -17
  146. package/src/dashboard/bar-list.module.css.d.ts +2 -0
  147. package/src/dashboard/bar-list.tsx +102 -21
  148. package/src/dashboard/delta-badge.tsx +21 -5
  149. package/src/dashboard/index.ts +2 -0
  150. package/src/dashboard/meter-model.ts +132 -4
  151. package/src/dashboard/meter-parts.tsx +305 -25
  152. package/src/dashboard/meter.module.css +209 -13
  153. package/src/dashboard/meter.module.css.d.ts +16 -0
  154. package/src/dashboard/meter.tsx +42 -7
  155. package/src/dashboard/query-state.tsx +28 -19
  156. package/src/dashboard/settings-section.tsx +1 -8
  157. package/src/dashboard/stat-card-parts.tsx +22 -2
  158. package/src/dashboard/stat-card.module.css +42 -14
  159. package/src/dashboard/stat-card.tsx +23 -60
  160. package/src/dashboard/stat-group.tsx +19 -8
  161. package/src/dashboard/stat-strip.module.css +208 -0
  162. package/src/dashboard/stat-strip.module.css.d.ts +28 -0
  163. package/src/dashboard/stat-strip.tsx +183 -0
  164. package/src/dashboard/widget-header.module.css +38 -7
  165. package/src/dashboard/widget-header.tsx +7 -4
  166. package/src/format/date.ts +6 -3
  167. package/src/format/shared.ts +11 -2
  168. package/src/guard/index.ts +1 -1
  169. package/src/index.ts +7 -0
  170. package/src/styles.css +6 -0
  171. package/src/theme/__snapshots__/plain-theme.test.ts.snap +242 -26
  172. package/src/theme/card-inset.module.css +76 -0
  173. package/src/theme/card-inset.module.css.d.ts +9 -0
  174. package/src/theme/chrome-vars.ts +48 -23
  175. package/src/theme/controls.module.css +3 -0
  176. package/src/theme/index.ts +40 -6
  177. package/src/theme/nav-link.module.css +8 -10
  178. package/src/theme/status-dot.module.css +9 -0
  179. package/src/theme/status-dot.module.css.d.ts +8 -0
  180. package/src/theme/status-dot.tsx +31 -0
  181. package/src/theme/status-verdict.module.css +25 -0
  182. package/src/theme/status-verdict.module.css.d.ts +9 -0
  183. package/src/theme/status-verdict.tsx +32 -0
@@ -1,14 +1,39 @@
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 } from 'react'
4
- import type { CSSProperties, ReactNode } from 'react'
3
+ import { useId, useRef, useState } from 'react'
4
+ import type { CSSProperties, HTMLAttributes, ReactNode, RefObject } from 'react'
5
+ import { useIsomorphicLayoutEffect } from '../common/isomorphic-layout-effect'
5
6
  import { cx } from '../common/props'
6
- import { ariaValues, modelBar, ringFraction, zoneBand } from './meter-model'
7
- import type { MeterSegment, MeterZone, Part } from './meter-model'
7
+ import {
8
+ ariaValues,
9
+ modelBar,
10
+ ringFraction,
11
+ startCaptionText,
12
+ zoneBand,
13
+ zoneLabelsFit,
14
+ } from './meter-model'
15
+ import type { MeterSegment, MeterTick, MeterZone, Part, TickMark, ZoneLabel } from './meter-model'
8
16
  import classes from './meter.module.css'
9
17
  import { toPct } from './scale'
10
18
 
11
- export type Shell = { className: string | undefined; style: CSSProperties | undefined }
19
+ export type Shell = {
20
+ className: string | undefined
21
+ style: CSSProperties | undefined
22
+ /** `size="row"`: one text line tall, no caption rows. */
23
+ row: boolean
24
+ }
25
+
26
+ /**
27
+ * The one root contract of every Meter state. `data-basalt-meter` is the handle `StatCard` keys its
28
+ * visual slot on (`:has([data-basalt-meter])`), so every state must carry it.
29
+ */
30
+ function rootProps(shell: Shell) {
31
+ return {
32
+ className: cx(classes.root, shell.row && classes.row, shell.className),
33
+ style: shell.style,
34
+ 'data-basalt-meter': '',
35
+ } as const
36
+ }
12
37
 
13
38
  const RING_VIEWBOX = 36
14
39
  const RING_STROKE = 4
@@ -42,6 +67,22 @@ function RingSvg({ fraction, color }: { fraction?: number; color?: string | unde
42
67
  )
43
68
  }
44
69
 
70
+ /**
71
+ * A value and its unit stay on one line: a no-break space replaces the space between a digit and a
72
+ * known unit ("24 h", "7 d", "5 min", "40 %"), so a caption never wraps to a lone "d". Any other
73
+ * word ("3 of 7", "250 over") keeps its ordinary space.
74
+ */
75
+ const UNITS = 'h|d|w|mo|y|s|ms|min|m|km|mi|g|kg|%|€|pts|bpm|AU|kcal|KB|MB|GB|TB'
76
+ const UNIT_AFTER_NUMBER = new RegExp(`(\\d) (?=(?:${UNITS})(?![\\p{L}\\d]))`, 'gu')
77
+ /** The last two words of a caption Meter composes are one unit when the last is short, so no
78
+ * line ends on a lone "budget" or "d". */
79
+ // Ordinary spaces only: an already-glued unit (`7\u00a0d`) counts as one word.
80
+ const SHORT_LAST_WORD = /([^ ]) ([^ ]{1,6})$/u
81
+ const glueUnits = (text: ReactNode): ReactNode =>
82
+ typeof text === 'string' ? text.replace(UNIT_AFTER_NUMBER, '$1\u00a0') : text
83
+ const glue = (text: ReactNode): ReactNode =>
84
+ typeof text === 'string' ? String(glueUnits(text)).replace(SHORT_LAST_WORD, '$1\u00a0$2') : text
85
+
45
86
  export function MeterLoading({
46
87
  label,
47
88
  ring,
@@ -52,8 +93,8 @@ export function MeterLoading({
52
93
  shell: Shell
53
94
  }) {
54
95
  return (
55
- <div className={cx(classes.root, shell.className)} style={shell.style} aria-busy="true">
56
- <VisuallyHidden>{`Loading ${label}`}</VisuallyHidden>
96
+ <div {...rootProps(shell)} aria-busy="true">
97
+ <VisuallyHidden className={classes.summary}>{`Loading ${label}`}</VisuallyHidden>
57
98
  {ring ? (
58
99
  <Skeleton className={classes.skeletonRing} circle />
59
100
  ) : (
@@ -69,7 +110,7 @@ export function MeterLoading({
69
110
  export function MeterEmpty(props: { label: string; text: string; ring: boolean; shell: Shell }) {
70
111
  const { label, text, ring, shell } = props
71
112
  return (
72
- <output className={cx(classes.root, shell.className)} style={shell.style} aria-label={label}>
113
+ <output {...rootProps(shell)} aria-label={label}>
73
114
  {ring ? (
74
115
  <span className={classes.ringBox}>
75
116
  <RingSvg />
@@ -95,7 +136,7 @@ export function MeterRing(props: {
95
136
  }) {
96
137
  const { label, reading, min, max, color, format, shell } = props
97
138
  return (
98
- <div className={cx(classes.root, shell.className)} style={shell.style}>
139
+ <div {...rootProps(shell)}>
99
140
  <span
100
141
  className={classes.ringBox}
101
142
  aria-label={label}
@@ -131,6 +172,196 @@ function zoneStyle(zone: MeterZone, index: number, count: number, min: number, s
131
172
  } satisfies CSSProperties
132
173
  }
133
174
 
175
+ /**
176
+ * Joins the names with a character no label carries, so the effect re-runs only when they change.
177
+ * The holding zone is part of the key: its label is bolder, so a reading that crosses a boundary
178
+ * changes widths with no row resize.
179
+ */
180
+ const labelsKey = (labels: readonly ZoneLabel[]) =>
181
+ labels.map((l) => l.label + (l.holding ? '*' : '')).join('\u0000')
182
+
183
+ /**
184
+ * Whether the zone names fit on the band, re-measured when the row resizes, when web fonts finish
185
+ * loading (a mono swap changes label widths without resizing the row) and when the names change.
186
+ * Server markup shows the band; the list may appear after mount, when the measurement fails.
187
+ */
188
+ function useZoneLabelLayout(rowRef: RefObject<HTMLDivElement | null>, key: string): boolean {
189
+ const [fits, setFits] = useState(true)
190
+
191
+ // Keyed on a string of the names, not the `labels` array: the model rebuilds that every render.
192
+ useIsomorphicLayoutEffect(() => {
193
+ const row = rowRef.current
194
+ if (!row) return
195
+ const measure = () => {
196
+ const origin = row.getBoundingClientRect()
197
+ const boxes = [...row.children].map((c) => {
198
+ const r = c.getBoundingClientRect()
199
+ return { left: r.left - origin.left, right: r.right - origin.left }
200
+ })
201
+ setFits(zoneLabelsFit(boxes, origin.width))
202
+ }
203
+ measure()
204
+ const observer = typeof ResizeObserver === 'undefined' ? undefined : new ResizeObserver(measure)
205
+ observer?.observe(row)
206
+ // `document.fonts` is absent (or partial) outside a full browser; every use is guarded.
207
+ const fonts =
208
+ typeof document === 'undefined' ? undefined : (document.fonts as FontFaceSet | undefined)
209
+ let live = true
210
+ void fonts?.ready?.then(() => live && measure())
211
+ fonts?.addEventListener?.('loadingdone', measure)
212
+ return () => {
213
+ live = false
214
+ observer?.disconnect()
215
+ fonts?.removeEventListener?.('loadingdone', measure)
216
+ }
217
+ }, [rowRef, key])
218
+
219
+ return fits
220
+ }
221
+
222
+ /**
223
+ * The reading on a zoned track, centred on the marker so number and notch are one mark. Measured,
224
+ * its start edge is clamped to the row (a label wider than the row overflows the end, never the
225
+ * start) and placed logically, so it holds under `dir="rtl"`. Observing the label as well as the row
226
+ * catches a font swap that changes its width with no row resize. Until the first measure (server
227
+ * markup) it sits at the marker, centred by a direction-aware translate, and the row clips.
228
+ */
229
+ function ZoneReading({ pct, children }: { pct: number; children: ReactNode }) {
230
+ const rowRef = useRef<HTMLDivElement>(null)
231
+ const textRef = useRef<HTMLSpanElement>(null)
232
+ const [start, setStart] = useState<number>()
233
+ useIsomorphicLayoutEffect(() => {
234
+ const row = rowRef.current
235
+ const text = textRef.current
236
+ if (!row || !text) return
237
+ const measure = () => {
238
+ const centre = (row.clientWidth * pct) / 100
239
+ setStart(
240
+ Math.max(0, Math.min(centre - text.offsetWidth / 2, row.clientWidth - text.offsetWidth)),
241
+ )
242
+ }
243
+ measure()
244
+ if (typeof ResizeObserver === 'undefined') return
245
+ const observer = new ResizeObserver(measure)
246
+ observer.observe(row)
247
+ observer.observe(text)
248
+ return () => observer.disconnect()
249
+ }, [pct])
250
+ return (
251
+ <div ref={rowRef} className={classes.zoneReadingRow} data-meter-reading-row>
252
+ <span
253
+ ref={textRef}
254
+ className={classes.zoneReading}
255
+ data-measured={start === undefined ? undefined : ''}
256
+ style={{ insetInlineStart: start === undefined ? `${pct}%` : `${start}px` }}
257
+ >
258
+ {children}
259
+ </span>
260
+ </div>
261
+ )
262
+ }
263
+
264
+ function ZoneName({ label, ...rest }: { label: ZoneLabel } & HTMLAttributes<HTMLSpanElement>) {
265
+ return (
266
+ <span
267
+ {...rest}
268
+ className={cx(rest.className, label.holding && classes.zoneLabelHolding)}
269
+ data-meter-zone-label={label.label}
270
+ data-holding={label.holding || undefined}
271
+ >
272
+ {label.label}
273
+ </span>
274
+ )
275
+ }
276
+
277
+ /**
278
+ * Names each zone under its band, the holding one in ink and a heavier weight. Labels sit
279
+ * left-aligned at their band start; when two would overlap (or one would leave the row) the band
280
+ * hides and the same names wrap as a list in zone order instead. The band stays laid out (hidden,
281
+ * not removed) so a resize can measure it again. Decorative: the zone names and the holding zone
282
+ * are in the described-by text.
283
+ */
284
+ function ZoneLabels({ labels }: { labels: readonly ZoneLabel[] }) {
285
+ const rowRef = useRef<HTMLDivElement>(null)
286
+ const fits = useZoneLabelLayout(rowRef, labelsKey(labels))
287
+
288
+ return (
289
+ <>
290
+ <div
291
+ ref={rowRef}
292
+ className={classes.zoneBand}
293
+ data-meter-zone-band
294
+ data-collapsed={fits ? undefined : ''}
295
+ aria-hidden
296
+ >
297
+ {labels.map((l) => (
298
+ <ZoneName
299
+ key={l.key}
300
+ label={l}
301
+ className={classes.zoneLabel}
302
+ style={{ insetInlineStart: `${l.startPct}%` }}
303
+ />
304
+ ))}
305
+ </div>
306
+ {!fits && (
307
+ <div className={classes.zoneList} data-meter-zone-list aria-hidden>
308
+ {labels.map((l) => (
309
+ <ZoneName key={l.key} label={l} className={classes.zoneListItem} />
310
+ ))}
311
+ </div>
312
+ )}
313
+ </>
314
+ )
315
+ }
316
+
317
+ /** Ticks past the middle caption to the left of their mark, so a caption near the end stays on the row. */
318
+ const TICK_LABEL_FLIP_PCT = 50
319
+
320
+ /**
321
+ * Captions the labelled ticks above the track, each hugging its mark. Same fit rule as the zone names:
322
+ * when two would overlap (or one would leave the row) the band hides and the labels wrap as a list in
323
+ * tick order. Decorative: the ticks are in the described-by text.
324
+ */
325
+ function TickLabels({ ticks }: { ticks: readonly TickMark[] }) {
326
+ const rowRef = useRef<HTMLDivElement>(null)
327
+ const fits = useZoneLabelLayout(rowRef, ticks.map((t) => `${t.label}@${t.pct}`).join('\u0000'))
328
+ return (
329
+ <div className={classes.tickLabels}>
330
+ <div
331
+ ref={rowRef}
332
+ className={classes.tickBand}
333
+ data-meter-tick-band
334
+ data-collapsed={fits ? undefined : ''}
335
+ aria-hidden
336
+ >
337
+ {ticks.map((t) => (
338
+ <span
339
+ key={t.key}
340
+ className={classes.tickLabel}
341
+ data-meter-tick-label=""
342
+ style={
343
+ t.pct > TICK_LABEL_FLIP_PCT
344
+ ? { insetInlineEnd: `${100 - t.pct}%` }
345
+ : { insetInlineStart: `${t.pct}%` }
346
+ }
347
+ >
348
+ {t.label}
349
+ </span>
350
+ ))}
351
+ </div>
352
+ {!fits && (
353
+ <div className={classes.zoneList} data-meter-tick-list aria-hidden>
354
+ {ticks.map((t) => (
355
+ <span key={t.key} className={classes.zoneListItem}>
356
+ {t.label}
357
+ </span>
358
+ ))}
359
+ </div>
360
+ )}
361
+ </div>
362
+ )
363
+ }
364
+
134
365
  export function MeterBar(props: {
135
366
  label: string
136
367
  reading: number
@@ -141,6 +372,8 @@ export function MeterBar(props: {
141
372
  segments: readonly MeterSegment[] | undefined
142
373
  zones: readonly MeterZone[] | undefined
143
374
  target: number | undefined
375
+ ticks: readonly MeterTick[] | undefined
376
+ tone: 'muted' | undefined
144
377
  forecastCaption: string | undefined
145
378
  startCaption: ReactNode
146
379
  endCaption: ReactNode
@@ -149,14 +382,24 @@ export function MeterBar(props: {
149
382
  const { label, reading, min, max, format, zones, shell } = props
150
383
  const describedId = useId()
151
384
  const model = modelBar(props)
152
- const start = props.startCaption === undefined ? model.startText : props.startCaption
153
- const end = props.endCaption === undefined ? model.endText : props.endCaption
154
- const hasCaptions = start !== null || end !== null || model.forecastText !== null
385
+ const compact = shell.row
386
+ const start = compact ? null : startCaptionText(model, props.startCaption)
387
+ const end = compact ? null : props.endCaption === undefined ? model.endText : props.endCaption
388
+ const anchored = model.markerPct !== undefined && start !== null
389
+ const hasCaptions =
390
+ (start !== null && !anchored) || end !== null || (!compact && model.forecastText !== null)
391
+ const hasParts = !compact && model.partCaptions.length > 0
392
+ const tickLabels = compact ? [] : model.ticks.filter((t) => t.label !== undefined)
155
393
  const describedBy =
156
394
  model.describedByText === null ? {} : ({ 'aria-describedby': describedId } as const)
157
395
 
396
+ const root = rootProps(shell)
158
397
  return (
159
- <div className={cx(classes.root, shell.className)} style={shell.style}>
398
+ <div
399
+ {...root}
400
+ className={cx(root.className, !compact && model.zoneLabels.length > 0 && classes.zoned)}
401
+ >
402
+ {tickLabels.length > 0 && <TickLabels ticks={tickLabels} />}
160
403
  <div
161
404
  className={classes.trackBox}
162
405
  aria-label={label}
@@ -178,46 +421,83 @@ export function MeterBar(props: {
178
421
  key={i}
179
422
  className={cx(classes.fill, p.forecast && classes.forecastFill)}
180
423
  data-meter-fill={p.forecast ? 'forecast' : 'committed'}
424
+ data-tone={
425
+ props.tone === 'muted' && p.color === undefined && !p.forecast ? 'muted' : undefined
426
+ }
181
427
  style={fillStyle(p)}
182
428
  />
183
429
  ))}
184
430
  </div>
185
431
  <Tick kind="marker" className={classes.marker} pct={model.markerPct} />
186
432
  <Tick kind="boundary" className={classes.boundaryTick} pct={model.boundaryPct} />
433
+ {model.ticks.map((t) => (
434
+ <Tick key={t.key} kind="tick" className={classes.tick} pct={t.pct} />
435
+ ))}
187
436
  <Tick kind="target" className={classes.tick} pct={model.targetPct} />
188
437
  </div>
438
+ {!compact && model.zoneLabels.length > 0 && <ZoneLabels labels={model.zoneLabels} />}
439
+ {anchored && <ZoneReading pct={model.markerPct ?? 0}>{start}</ZoneReading>}
189
440
  {model.describedByText !== null && (
190
- <VisuallyHidden id={describedId}>{model.describedByText}</VisuallyHidden>
441
+ <VisuallyHidden id={describedId} className={classes.summary}>
442
+ {model.describedByText}
443
+ </VisuallyHidden>
444
+ )}
445
+ {hasParts && (
446
+ // The explicit role is deliberate: `list-style: none` makes Safari/VoiceOver drop the implicit one.
447
+ // oxlint-disable-next-line jsx-a11y/no-redundant-roles
448
+ <ul className={classes.partCaptions} role="list" data-meter-parts>
449
+ {model.partCaptions.map((c) => (
450
+ <li key={c.key} className={classes.partCaption}>
451
+ <span
452
+ className={classes.swatch}
453
+ // theme-allow hidden-inline-style — the swatch repeats the part's fill colour (data)
454
+ style={{ background: c.color ?? 'var(--vx-line)' }}
455
+ aria-hidden
456
+ />
457
+ {glueUnits(`${c.label} ${c.text}`)}
458
+ </li>
459
+ ))}
460
+ </ul>
191
461
  )}
192
462
  {hasCaptions && (
193
463
  <div className={classes.captions} data-meter-captions>
194
- {start !== null && <span className={classes.caption}>{start}</span>}
195
- {model.forecastText !== null && (
196
- <span className={classes.caption}>{model.forecastText}</span>
464
+ {start !== null && !anchored && <span className={classes.caption}>{glue(start)}</span>}
465
+ {!compact && model.forecastText !== null && (
466
+ <span className={classes.caption}>{glue(model.forecastText)}</span>
197
467
  )}
198
- {end !== null && <span className={classes.captionEnd}>{end}</span>}
468
+ {end !== null && <span className={classes.captionEnd}>{glue(end)}</span>}
199
469
  </div>
200
470
  )}
201
471
  </div>
202
472
  )
203
473
  }
204
474
 
475
+ /** A tick's width: the end tick's start edge sits this far inside the track. */
476
+ const TICK_WIDTH = '2px'
477
+
478
+ /**
479
+ * Centred on its percent. A target or tick AT the track end is the exception: centred there it is
480
+ * half outside the track (and hidden by a full fill), so its end edge sits ON the track end and it
481
+ * reads inside. The marker is the reading itself and stays centred.
482
+ */
483
+ function tickPosition(kind: TickKind, pct: number): CSSProperties {
484
+ if (pct < 100 || kind === 'marker' || kind === 'boundary') return { insetInlineStart: `${pct}%` }
485
+ return { insetInlineStart: `calc(100% - ${TICK_WIDTH})`, marginInlineStart: 0 }
486
+ }
487
+
488
+ type TickKind = 'marker' | 'boundary' | 'target' | 'tick'
489
+
205
490
  function Tick({
206
491
  kind,
207
492
  className,
208
493
  pct,
209
494
  }: {
210
- kind: 'marker' | 'boundary' | 'target'
495
+ kind: TickKind
211
496
  className: string
212
497
  pct: number | undefined
213
498
  }) {
214
499
  if (pct === undefined) return null
215
500
  return (
216
- <div
217
- className={className}
218
- data-meter-tick={kind}
219
- style={{ insetInlineStart: `${pct}%` }}
220
- aria-hidden
221
- />
501
+ <div className={className} data-meter-tick={kind} style={tickPosition(kind, pct)} aria-hidden />
222
502
  )
223
503
  }