basalt-ui 2.20.0 → 2.22.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 (289) hide show
  1. package/CHANGELOG.md +72 -0
  2. package/MIGRATING.md +394 -12
  3. package/agent/agents/basalt-design-reviewer.md +22 -5
  4. package/agent/rules/basalt-tokens.md +3 -3
  5. package/agent/skills/basalt-design/SKILL.md +10 -23
  6. package/agent/skills/basalt-design/references/anti-defaults.md +24 -0
  7. package/agent/skills/basalt-design/references/catalogue.md +49 -0
  8. package/agent/skills/basalt-design/references/concept.md +36 -0
  9. package/agent/skills/basalt-design/references/encoding-rules.md +45 -0
  10. package/agent/skills/basalt-design/references/stat-tile.md +24 -0
  11. package/agent/templates/AGENTS-block.md.tpl +3 -3
  12. package/configs/oxlint-plugin.js +1 -0
  13. package/dist/charts/BandStrip.d.ts.map +1 -1
  14. package/dist/charts/BandStrip.js +27 -3
  15. package/dist/charts/Bars.d.ts.map +1 -1
  16. package/dist/charts/Bars.js +5 -0
  17. package/dist/charts/CartesianChart.d.ts +8 -0
  18. package/dist/charts/CartesianChart.d.ts.map +1 -1
  19. package/dist/charts/CartesianChart.js +8 -5
  20. package/dist/charts/ChartCard.d.ts +17 -4
  21. package/dist/charts/ChartCard.d.ts.map +1 -1
  22. package/dist/charts/ChartCard.js +33 -8
  23. package/dist/charts/DualPanel.d.ts.map +1 -1
  24. package/dist/charts/DualPanel.js +5 -8
  25. package/dist/charts/Heatmap.d.ts +12 -1
  26. package/dist/charts/Heatmap.d.ts.map +1 -1
  27. package/dist/charts/Heatmap.js +34 -5
  28. package/dist/charts/Lines.d.ts +3 -0
  29. package/dist/charts/Lines.d.ts.map +1 -1
  30. package/dist/charts/Lines.js +29 -6
  31. package/dist/charts/MirroredBars.d.ts.map +1 -1
  32. package/dist/charts/MirroredBars.js +4 -6
  33. package/dist/charts/Sparkline.d.ts +7 -1
  34. package/dist/charts/Sparkline.d.ts.map +1 -1
  35. package/dist/charts/Sparkline.js +39 -14
  36. package/dist/charts/StackedArea.d.ts +4 -1
  37. package/dist/charts/StackedArea.d.ts.map +1 -1
  38. package/dist/charts/StackedArea.js +9 -3
  39. package/dist/charts/band-fold.d.ts +20 -1
  40. package/dist/charts/band-fold.d.ts.map +1 -1
  41. package/dist/charts/band-fold.js +9 -0
  42. package/dist/charts/chart-box.module.css +19 -0
  43. package/dist/charts/chart-card.module.css +25 -0
  44. package/dist/charts/chart-legend.module.css +7 -0
  45. package/dist/charts/compile.d.ts +17 -6
  46. package/dist/charts/compile.d.ts.map +1 -1
  47. package/dist/charts/compile.js +145 -74
  48. package/dist/charts/labels.d.ts +15 -4
  49. package/dist/charts/labels.d.ts.map +1 -1
  50. package/dist/charts/labels.js +34 -10
  51. package/dist/charts/legend.d.ts +2 -0
  52. package/dist/charts/legend.d.ts.map +1 -1
  53. package/dist/charts/legend.js +7 -21
  54. package/dist/charts/marks.js +1 -1
  55. package/dist/charts/panel.d.ts +0 -6
  56. package/dist/charts/panel.d.ts.map +1 -1
  57. package/dist/charts/panel.js +1 -10
  58. package/dist/charts/ref-label.d.ts +26 -0
  59. package/dist/charts/ref-label.d.ts.map +1 -0
  60. package/dist/charts/ref-label.js +63 -0
  61. package/dist/charts/scales.d.ts +4 -1
  62. package/dist/charts/scales.d.ts.map +1 -1
  63. package/dist/charts/scales.js +14 -3
  64. package/dist/charts/sparkline.module.css +10 -11
  65. package/dist/charts/sparkline.module.css.d.ts +1 -2
  66. package/dist/charts/state.d.ts +7 -0
  67. package/dist/charts/state.d.ts.map +1 -1
  68. package/dist/charts/state.js +4 -1
  69. package/dist/charts/types.d.ts +14 -5
  70. package/dist/charts/types.d.ts.map +1 -1
  71. package/dist/cli/check-theme.d.ts.map +1 -1
  72. package/dist/cli/check-theme.js +3 -0
  73. package/dist/cli/doctor-upgrade.d.ts +1 -0
  74. package/dist/cli/doctor-upgrade.d.ts.map +1 -1
  75. package/dist/cli/doctor-upgrade.js +1 -0
  76. package/dist/cli/help.d.ts.map +1 -1
  77. package/dist/cli/help.js +3 -2
  78. package/dist/cli/index.d.ts +4 -2
  79. package/dist/cli/index.d.ts.map +1 -1
  80. package/dist/cli/index.js +27 -15
  81. package/dist/cli/init.d.ts +2 -0
  82. package/dist/cli/init.d.ts.map +1 -1
  83. package/dist/cli/init.js +71 -6
  84. package/dist/cli/shot/capture.d.ts +21 -2
  85. package/dist/cli/shot/capture.d.ts.map +1 -1
  86. package/dist/cli/shot/capture.js +200 -33
  87. package/dist/cli/shot/detect.d.ts +51 -0
  88. package/dist/cli/shot/detect.d.ts.map +1 -0
  89. package/dist/cli/shot/detect.js +409 -0
  90. package/dist/cli/shot/index.d.ts.map +1 -1
  91. package/dist/cli/shot/index.js +7 -4
  92. package/dist/cli/shot/measure.d.ts +2 -0
  93. package/dist/cli/shot/measure.d.ts.map +1 -1
  94. package/dist/cli/shot/measure.js +2 -0
  95. package/dist/cli/shot/playwright.d.ts +5 -2
  96. package/dist/cli/shot/playwright.d.ts.map +1 -1
  97. package/dist/cli/shot/types.d.ts +6 -1
  98. package/dist/cli/shot/types.d.ts.map +1 -1
  99. package/dist/cli/shot/types.js +4 -0
  100. package/dist/cli/sync.d.ts +2 -0
  101. package/dist/cli/sync.d.ts.map +1 -1
  102. package/dist/cli/sync.js +2 -2
  103. package/dist/common/retry-button.d.ts +12 -0
  104. package/dist/common/retry-button.d.ts.map +1 -0
  105. package/dist/common/retry-button.js +22 -0
  106. package/dist/common/retry-button.module.css +58 -0
  107. package/dist/common/retry-button.module.css.d.ts +8 -0
  108. package/dist/controls/controls.module.css +11 -1
  109. package/dist/controls/filter-pill.d.ts.map +1 -1
  110. package/dist/controls/filter-pill.js +1 -0
  111. package/dist/controls/sync-button.d.ts.map +1 -1
  112. package/dist/controls/sync-button.js +22 -3
  113. package/dist/controls/sync-button.module.css +34 -2
  114. package/dist/controls/sync-button.module.css.d.ts +1 -0
  115. package/dist/dashboard/bar-list.d.ts +5 -2
  116. package/dist/dashboard/bar-list.d.ts.map +1 -1
  117. package/dist/dashboard/bar-list.js +9 -10
  118. package/dist/dashboard/bar-list.module.css +53 -0
  119. package/dist/dashboard/bar-list.module.css.d.ts +1 -0
  120. package/dist/dashboard/index.d.ts +1 -0
  121. package/dist/dashboard/index.d.ts.map +1 -1
  122. package/dist/dashboard/index.js +2 -0
  123. package/dist/dashboard/meter-model.d.ts +108 -6
  124. package/dist/dashboard/meter-model.d.ts.map +1 -1
  125. package/dist/dashboard/meter-model.js +123 -19
  126. package/dist/dashboard/meter-parts.d.ts +8 -0
  127. package/dist/dashboard/meter-parts.d.ts.map +1 -1
  128. package/dist/dashboard/meter-parts.js +345 -146
  129. package/dist/dashboard/meter.d.ts +50 -63
  130. package/dist/dashboard/meter.d.ts.map +1 -1
  131. package/dist/dashboard/meter.js +24 -3
  132. package/dist/dashboard/meter.module.css +79 -65
  133. package/dist/dashboard/meter.module.css.d.ts +7 -7
  134. package/dist/dashboard/page-summary.d.ts +20 -0
  135. package/dist/dashboard/page-summary.d.ts.map +1 -0
  136. package/dist/dashboard/page-summary.js +28 -0
  137. package/dist/dashboard/page-summary.module.css +89 -0
  138. package/dist/dashboard/page-summary.module.css.d.ts +15 -0
  139. package/dist/dashboard/query-state.d.ts +1 -1
  140. package/dist/dashboard/query-state.d.ts.map +1 -1
  141. package/dist/dashboard/query-state.js +3 -2
  142. package/dist/dashboard/section.d.ts +25 -2
  143. package/dist/dashboard/section.d.ts.map +1 -1
  144. package/dist/dashboard/section.js +10 -5
  145. package/dist/dashboard/section.module.css +23 -0
  146. package/dist/dashboard/section.module.css.d.ts +1 -0
  147. package/dist/dashboard/stat-card-parts.d.ts.map +1 -1
  148. package/dist/dashboard/stat-card-parts.js +1 -1
  149. package/dist/dashboard/stat-card.d.ts +4 -2
  150. package/dist/dashboard/stat-card.d.ts.map +1 -1
  151. package/dist/dashboard/stat-card.js +7 -4
  152. package/dist/dashboard/stat-card.module.css +17 -0
  153. package/dist/dashboard/stat-strip.d.ts +24 -1
  154. package/dist/dashboard/stat-strip.d.ts.map +1 -1
  155. package/dist/dashboard/stat-strip.js +97 -39
  156. package/dist/dashboard/stat-strip.module.css +147 -17
  157. package/dist/dashboard/stat-strip.module.css.d.ts +8 -0
  158. package/dist/dashboard/visual-slot.d.ts +8 -0
  159. package/dist/dashboard/visual-slot.d.ts.map +1 -0
  160. package/dist/dashboard/visual-slot.js +7 -0
  161. package/dist/guard/index.d.ts +15 -2
  162. package/dist/guard/index.d.ts.map +1 -1
  163. package/dist/guard/index.js +14 -0
  164. package/dist/guard/palette.d.ts +51 -0
  165. package/dist/guard/palette.d.ts.map +1 -0
  166. package/dist/guard/palette.js +190 -0
  167. package/dist/guard/series-file.d.ts +15 -0
  168. package/dist/guard/series-file.d.ts.map +1 -0
  169. package/dist/guard/series-file.js +29 -0
  170. package/dist/guard/types.d.ts +3 -3
  171. package/dist/guard/types.d.ts.map +1 -1
  172. package/dist/guard/vx-names.d.ts.map +1 -1
  173. package/dist/guard/vx-names.js +2 -0
  174. package/dist/index.d.ts +1 -1
  175. package/dist/index.d.ts.map +1 -1
  176. package/dist/index.js +3 -1
  177. package/dist/styles.css +34 -2
  178. package/dist/surfaces.d.ts +1 -1
  179. package/dist/surfaces.d.ts.map +1 -1
  180. package/dist/surfaces.js +2 -0
  181. package/dist/theme/chrome-vars.d.ts +20 -5
  182. package/dist/theme/chrome-vars.d.ts.map +1 -1
  183. package/dist/theme/chrome-vars.js +46 -3
  184. package/dist/theme/controls.module.css +33 -0
  185. package/dist/theme/controls.module.css.d.ts +1 -0
  186. package/dist/theme/index.d.ts.map +1 -1
  187. package/dist/theme/index.js +11 -5
  188. package/dist/tokens/core.d.ts +2 -1
  189. package/dist/tokens/core.d.ts.map +1 -1
  190. package/dist/tokens/core.js +6 -1
  191. package/dist/tokens/derive.d.ts +3 -1
  192. package/dist/tokens/derive.d.ts.map +1 -1
  193. package/dist/tokens/derive.js +16 -1
  194. package/dist/tokens/oklab.d.ts +28 -0
  195. package/dist/tokens/oklab.d.ts.map +1 -0
  196. package/dist/tokens/oklab.js +73 -0
  197. package/dist/tokens/palette.d.ts +4 -0
  198. package/dist/tokens/palette.d.ts.map +1 -1
  199. package/dist/tokens/palette.js +4 -0
  200. package/dist/tokens/status-text.d.ts.map +1 -1
  201. package/dist/tokens/status-text.js +3 -1
  202. package/llms.txt +43 -23
  203. package/package.json +1 -1
  204. package/src/charts/BandStrip.tsx +33 -3
  205. package/src/charts/Bars.tsx +6 -0
  206. package/src/charts/CartesianChart.tsx +16 -3
  207. package/src/charts/ChartCard.tsx +43 -7
  208. package/src/charts/DualPanel.tsx +3 -6
  209. package/src/charts/Heatmap.tsx +54 -5
  210. package/src/charts/Lines.tsx +56 -10
  211. package/src/charts/MirroredBars.tsx +3 -5
  212. package/src/charts/Sparkline.tsx +50 -13
  213. package/src/charts/StackedArea.tsx +14 -4
  214. package/src/charts/band-fold.ts +31 -1
  215. package/src/charts/chart-box.module.css +19 -0
  216. package/src/charts/chart-card.module.css +25 -0
  217. package/src/charts/chart-legend.module.css +7 -0
  218. package/src/charts/compile.ts +210 -85
  219. package/src/charts/labels.ts +48 -14
  220. package/src/charts/legend.tsx +10 -20
  221. package/src/charts/marks.ts +1 -1
  222. package/src/charts/panel.tsx +1 -16
  223. package/src/charts/ref-label.ts +104 -0
  224. package/src/charts/scales.ts +22 -2
  225. package/src/charts/sparkline.module.css +10 -11
  226. package/src/charts/sparkline.module.css.d.ts +1 -2
  227. package/src/charts/state.tsx +12 -1
  228. package/src/charts/types.ts +14 -5
  229. package/src/cli/check-theme.ts +3 -0
  230. package/src/cli/doctor-upgrade.ts +1 -1
  231. package/src/cli/help.ts +18 -1
  232. package/src/cli/index.ts +48 -17
  233. package/src/cli/init.ts +102 -4
  234. package/src/cli/shot/capture.ts +266 -34
  235. package/src/cli/shot/detect.ts +550 -0
  236. package/src/cli/shot/index.ts +8 -4
  237. package/src/cli/shot/measure.ts +4 -0
  238. package/src/cli/shot/playwright.ts +2 -2
  239. package/src/cli/shot/types.ts +8 -1
  240. package/src/cli/sync.ts +4 -2
  241. package/src/common/retry-button.module.css +58 -0
  242. package/src/common/retry-button.module.css.d.ts +8 -0
  243. package/src/common/retry-button.tsx +29 -0
  244. package/src/controls/controls.module.css +11 -1
  245. package/src/controls/filter-pill.tsx +2 -0
  246. package/src/controls/sync-button.module.css +34 -2
  247. package/src/controls/sync-button.module.css.d.ts +1 -0
  248. package/src/controls/sync-button.tsx +40 -4
  249. package/src/dashboard/bar-list.module.css +53 -0
  250. package/src/dashboard/bar-list.module.css.d.ts +1 -0
  251. package/src/dashboard/bar-list.tsx +88 -76
  252. package/src/dashboard/index.ts +1 -0
  253. package/src/dashboard/meter-model.ts +265 -28
  254. package/src/dashboard/meter-parts.tsx +424 -163
  255. package/src/dashboard/meter.module.css +79 -65
  256. package/src/dashboard/meter.module.css.d.ts +7 -7
  257. package/src/dashboard/meter.tsx +77 -17
  258. package/src/dashboard/page-summary.module.css +89 -0
  259. package/src/dashboard/page-summary.module.css.d.ts +15 -0
  260. package/src/dashboard/page-summary.tsx +95 -0
  261. package/src/dashboard/query-state.tsx +4 -7
  262. package/src/dashboard/section.module.css +23 -0
  263. package/src/dashboard/section.module.css.d.ts +1 -0
  264. package/src/dashboard/section.tsx +59 -11
  265. package/src/dashboard/stat-card-parts.tsx +5 -1
  266. package/src/dashboard/stat-card.module.css +17 -0
  267. package/src/dashboard/stat-card.tsx +14 -5
  268. package/src/dashboard/stat-strip.module.css +147 -17
  269. package/src/dashboard/stat-strip.module.css.d.ts +8 -0
  270. package/src/dashboard/stat-strip.tsx +182 -56
  271. package/src/dashboard/visual-slot.ts +17 -0
  272. package/src/guard/index.ts +16 -4
  273. package/src/guard/palette.ts +261 -0
  274. package/src/guard/series-file.ts +51 -0
  275. package/src/guard/types.ts +3 -2
  276. package/src/guard/vx-names.ts +2 -0
  277. package/src/index.ts +2 -0
  278. package/src/styles.css +34 -2
  279. package/src/surfaces.ts +2 -0
  280. package/src/theme/__snapshots__/plain-theme.test.ts.snap +220 -60
  281. package/src/theme/chrome-vars.ts +77 -8
  282. package/src/theme/controls.module.css +33 -0
  283. package/src/theme/controls.module.css.d.ts +1 -0
  284. package/src/theme/index.ts +18 -5
  285. package/src/tokens/core.ts +4 -1
  286. package/src/tokens/derive.ts +32 -3
  287. package/src/tokens/oklab.ts +97 -0
  288. package/src/tokens/palette.ts +4 -0
  289. package/src/tokens/status-text.ts +2 -0
@@ -1,19 +1,34 @@
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 {
8
8
  ariaValues,
9
9
  modelBar,
10
+ partsFitUnder,
11
+ placeMarkCaptions,
12
+ placeRowLabels,
10
13
  ringFraction,
14
+ ringMarks,
11
15
  startCaptionText,
12
16
  zoneBand,
13
- zoneLabelsFit,
17
+ zoneFill,
18
+ } from './meter-model'
19
+ import type {
20
+ MarkItem,
21
+ MeterSegment,
22
+ MeterTick,
23
+ MeterZone,
24
+ Part,
25
+ PartCaption,
26
+ RowLabel,
27
+ TickMark,
28
+ ZoneLabel,
14
29
  } from './meter-model'
15
- import type { MeterSegment, MeterTick, MeterZone, Part, TickMark, ZoneLabel } from './meter-model'
16
30
  import classes from './meter.module.css'
31
+ import { VisualSlotContext } from './visual-slot'
17
32
  import { toPct } from './scale'
18
33
 
19
34
  export type Shell = {
@@ -41,8 +56,20 @@ const RING_RADIUS = (RING_VIEWBOX - RING_STROKE) / 2
41
56
  const RING_LENGTH = 2 * Math.PI * RING_RADIUS
42
57
  const RING_CENTER = RING_VIEWBOX / 2
43
58
 
59
+ /** A ring tick spans from just inside the stroke's inner edge to just inside the box. */
60
+ const RING_TICK_INNER = RING_RADIUS - RING_STROKE / 2 - 0.75
61
+ const RING_TICK_OUTER = RING_VIEWBOX / 2 - 0.5
62
+
44
63
  /** The one ring drawing: a track and, when there is a reading, its arc (a fraction of the circle). */
45
- function RingSvg({ fraction, color }: { fraction?: number; color?: string | undefined }) {
64
+ function RingSvg({
65
+ fraction,
66
+ color,
67
+ marks = [],
68
+ }: {
69
+ fraction?: number
70
+ color?: string | undefined
71
+ marks?: readonly { angle: number }[]
72
+ }) {
46
73
  return (
47
74
  <svg className={classes.ring} viewBox={`0 0 ${RING_VIEWBOX} ${RING_VIEWBOX}`} aria-hidden>
48
75
  <circle
@@ -63,6 +90,22 @@ function RingSvg({ fraction, color }: { fraction?: number; color?: string | unde
63
90
  {...(color !== undefined && { style: { stroke: color } })}
64
91
  />
65
92
  )}
93
+ {marks.map((m, i) => (
94
+ // The svg is rotated so 0° is the top: a horizontal line at the rim, turned `angle` clockwise.
95
+ <g key={i} data-meter-ring-tick="">
96
+ {[classes.ringTickHalo, classes.ringTick].map((cls, n) => (
97
+ <line
98
+ key={n}
99
+ className={cls}
100
+ x1={RING_CENTER + RING_TICK_INNER}
101
+ x2={RING_CENTER + RING_TICK_OUTER}
102
+ y1={RING_CENTER}
103
+ y2={RING_CENTER}
104
+ transform={`rotate(${m.angle} ${RING_CENTER} ${RING_CENTER})`}
105
+ />
106
+ ))}
107
+ </g>
108
+ ))}
66
109
  </svg>
67
110
  )
68
111
  }
@@ -131,20 +174,30 @@ export function MeterRing(props: {
131
174
  min: number
132
175
  max: number
133
176
  color: string | undefined
177
+ target: number | undefined
178
+ ticks: readonly MeterTick[] | undefined
134
179
  format: (value: number) => string
135
180
  shell: Shell
136
181
  }) {
137
182
  const { label, reading, min, max, color, format, shell } = props
183
+ const describedId = useId()
184
+ const marks = ringMarks(props.target, props.ticks, min, max, format)
138
185
  return (
139
186
  <div {...rootProps(shell)}>
140
187
  <span
141
188
  className={classes.ringBox}
142
189
  aria-label={label}
143
190
  {...ariaValues(reading, min, max, format)}
191
+ {...(marks.length > 0 && { 'aria-describedby': describedId })}
144
192
  >
145
- <RingSvg fraction={ringFraction(reading, min, max)} color={color} />
193
+ <RingSvg fraction={ringFraction(reading, min, max)} color={color} marks={marks} />
146
194
  <span className={classes.ringValue}>{format(reading)}</span>
147
195
  </span>
196
+ {marks.length > 0 && (
197
+ <VisuallyHidden id={describedId} className={classes.summary}>
198
+ {marks.map((m) => m.text).join('; ')}
199
+ </VisuallyHidden>
200
+ )}
148
201
  </div>
149
202
  )
150
203
  }
@@ -153,52 +206,89 @@ function fillStyle(p: Part): CSSProperties {
153
206
  return { width: `${toPct(p.size)}%`, ...(p.color !== undefined && { background: p.color }) }
154
207
  }
155
208
 
156
- /** Uncoloured zones step from `MIN` to `MIN + STEP` percent of the neutral, so order reads without hue. */
157
- const ZONE_STRENGTH_MIN = 15
158
- const ZONE_STRENGTH_STEP = 45
159
- const ZONE_STRENGTH_SOLO = 40
160
209
  /** Every band after the first gives up its leading pixel, so a boundary never relies on fill strength. */
161
210
  const ZONE_GAP = '1px'
162
211
 
163
212
  function zoneStyle(zone: MeterZone, index: number, count: number, min: number, span: number) {
164
213
  const band = zoneBand(zone, min, span)
165
214
  const gap = index > 0
166
- const strength =
167
- count > 1 ? ZONE_STRENGTH_MIN + (index / (count - 1)) * ZONE_STRENGTH_STEP : ZONE_STRENGTH_SOLO
168
215
  return {
169
216
  insetInlineStart: gap ? `calc(${band.start}% + ${ZONE_GAP})` : `${band.start}%`,
170
217
  width: gap ? `calc(${band.width}% - ${ZONE_GAP})` : `${band.width}%`,
171
- background: zone.color ?? `color-mix(in srgb, var(--vx-line) ${strength}%, transparent)`,
218
+ background: zoneFill(zone, index, count),
172
219
  } satisfies CSSProperties
173
220
  }
174
221
 
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')
222
+ /** The row's `column-gap` in px: one gap step of the host's spacing, the least two captions keep apart. */
223
+ const columnGapOf = (el: Element): number => Number.parseFloat(getComputedStyle(el).columnGap) || 0
224
+
225
+ /** One label on the row: its span in percent of the row (a zone name) or none (an end tick). */
226
+ type RowSlot = { spanPct?: readonly [number, number]; holding?: boolean; end?: boolean }
227
+
228
+ type RowLayout = { shown: boolean[]; short: boolean[]; shift: number[] }
229
+ const sameLayout = (a: RowLayout, b: RowLayout) =>
230
+ a.shown.length === b.shown.length &&
231
+ a.shown.every(
232
+ (v, i) => v === b.shown[i] && a.short[i] === b.short[i] && a.shift[i] === b.shift[i],
233
+ )
182
234
 
183
235
  /**
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.
236
+ * Which row labels show, re-measured when the row resizes, when web fonts finish loading (a swap
237
+ * changes label widths without resizing the row) and when the labels change. Server markup shows
238
+ * every label; a name that does not fit its span (or clashes with a tick) hides after measuring.
239
+ * `slots` is index-aligned with the row's first children; the children after them are the short
240
+ * twins, `shortOf[n]` being the label index the n-th twin stands in for.
187
241
  */
188
- function useZoneLabelLayout(rowRef: RefObject<HTMLDivElement | null>, key: string): boolean {
189
- const [fits, setFits] = useState(true)
242
+ function useRowLabelLayout(
243
+ rowRef: RefObject<HTMLDivElement | null>,
244
+ slots: readonly RowSlot[],
245
+ shortOf: readonly number[],
246
+ key: string,
247
+ ): RowLayout {
248
+ const [layout, setLayout] = useState<RowLayout>({ shown: [], short: [], shift: [] })
249
+ const slotsRef = useRef(slots)
250
+ const shortOfRef = useRef(shortOf)
251
+ // Declared before the measuring effect so it reads this render's slots.
252
+ useIsomorphicLayoutEffect(() => {
253
+ slotsRef.current = slots
254
+ shortOfRef.current = shortOf
255
+ })
190
256
 
191
- // Keyed on a string of the names, not the `labels` array: the model rebuilds that every render.
257
+ // Keyed on a string of the labels, not the `slots` array: the model rebuilds that every render.
192
258
  useIsomorphicLayoutEffect(() => {
193
259
  const row = rowRef.current
194
260
  if (!row) return
195
261
  const measure = () => {
196
262
  const origin = row.getBoundingClientRect()
197
- const boxes = [...row.children].map((c) => {
263
+ const rtl = getComputedStyle(row).direction === 'rtl'
264
+ const edge = (pct: number) => (origin.width * (rtl ? 100 - pct : pct)) / 100
265
+ const children = [...row.children]
266
+ const labels: RowLabel[] = children.slice(0, slotsRef.current.length).map((c, i) => {
198
267
  const r = c.getBoundingClientRect()
199
- return { left: r.left - origin.left, right: r.right - origin.left }
268
+ const slot = slotsRef.current[i]
269
+ const pct = slot?.spanPct
270
+ const [a, b] = pct ? [edge(pct[0]), edge(pct[1])] : []
271
+ return {
272
+ box: { left: r.left - origin.left, right: r.right - origin.left },
273
+ ...(a !== undefined &&
274
+ b !== undefined && { span: { left: Math.min(a, b), right: Math.max(a, b) } }),
275
+ ...(slot?.holding && { holding: true }),
276
+ ...(slot?.end && { end: true }),
277
+ }
200
278
  })
201
- setFits(zoneLabelsFit(boxes, origin.width))
279
+ shortOfRef.current.forEach((labelIndex, n) => {
280
+ const r = children[slotsRef.current.length + n]?.getBoundingClientRect()
281
+ const label = labels[labelIndex]
282
+ if (r && label) label.short = { left: r.left - origin.left, right: r.right - origin.left }
283
+ })
284
+ const placed = placeRowLabels(labels, origin.width, columnGapOf(row))
285
+ // The hook measures on the physical x axis; the margin is logical, so it flips with `dir`.
286
+ const next = {
287
+ shown: placed.shown,
288
+ short: placed.short,
289
+ shift: placed.shift.map((v) => (rtl ? -v : v)),
290
+ }
291
+ setLayout((prev) => (sameLayout(prev, next) ? prev : next))
202
292
  }
203
293
  measure()
204
294
  const observer = typeof ResizeObserver === 'undefined' ? undefined : new ResizeObserver(measure)
@@ -216,7 +306,7 @@ function useZoneLabelLayout(rowRef: RefObject<HTMLDivElement | null>, key: strin
216
306
  }
217
307
  }, [rowRef, key])
218
308
 
219
- return fits
309
+ return layout
220
310
  }
221
311
 
222
312
  /**
@@ -261,104 +351,238 @@ function ZoneReading({ pct, children }: { pct: number; children: ReactNode }) {
261
351
  )
262
352
  }
263
353
 
264
- function ZoneName({ label, ...rest }: { label: ZoneLabel } & HTMLAttributes<HTMLSpanElement>) {
354
+ /** Ticks past the middle caption to the left of their mark, so a caption near the end stays on the row. */
355
+ const TICK_LABEL_FLIP_PCT = 50
356
+
357
+ /**
358
+ * The one label row: each zone name centred under its own span and the labelled ticks hugging their
359
+ * marks (the end ticks sit at the row's ends), all on one baseline. A name wider than its span, or
360
+ * clashing with a tick or a neighbour, hides (still laid out, so a resize can measure it again) and is
361
+ * still named in the described-by text; the holding zone is ink and heavier. Decorative.
362
+ */
363
+ function LabelRow({ zones, ticks }: { zones: readonly ZoneLabel[]; ticks: readonly TickMark[] }) {
364
+ const rowRef = useRef<HTMLDivElement>(null)
365
+ const slots: RowSlot[] = [
366
+ ...ticks.map((t): RowSlot => (t.pct <= 0 || t.pct >= 100 ? { end: true } : {})),
367
+ ...zones.map((z): RowSlot => ({
368
+ spanPct: [z.centrePct - z.widthPct / 2, z.centrePct + z.widthPct / 2],
369
+ holding: z.holding,
370
+ })),
371
+ ]
372
+ const key = [
373
+ ...ticks.map((t) => `${t.label}@${t.pct}`),
374
+ ...zones.map((z) => `${z.label}${z.holding ? '*' : ''}@${z.centrePct}`),
375
+ ].join('\u0000')
376
+ // The holding name never shortens, so its zone has no twin.
377
+ const twins = zones.flatMap((z, i) => (z.short !== undefined && !z.holding ? [i] : []))
378
+ const { shown, short, shift } = useRowLabelLayout(
379
+ rowRef,
380
+ slots,
381
+ twins.map((i) => ticks.length + i),
382
+ `${key}\u0001${twins.map((i) => zones[i]?.short).join('\u0000')}`,
383
+ )
384
+ const hidden = (i: number) => (shown[i] === false || short[i] === true ? '' : undefined)
385
+ const nudge = (i: number): CSSProperties =>
386
+ shift[i] ? { marginInlineStart: `${shift[i]}px` } : {}
265
387
  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}
388
+ <div
389
+ ref={rowRef}
390
+ className={classes.labelRow}
391
+ {...(zones.length > 0 ? { 'data-meter-zone-band': '' } : { 'data-meter-tick-band': '' })}
392
+ aria-hidden
271
393
  >
272
- {label.label}
273
- </span>
394
+ {ticks.map((t, i) => (
395
+ <span
396
+ key={`t${t.key}`}
397
+ className={classes.rowLabel}
398
+ data-meter-tick-label=""
399
+ data-hidden={hidden(i)}
400
+ style={
401
+ t.pct > TICK_LABEL_FLIP_PCT
402
+ ? { insetInlineEnd: `${100 - t.pct}%` }
403
+ : { insetInlineStart: `${t.pct}%` }
404
+ }
405
+ >
406
+ {t.label}
407
+ </span>
408
+ ))}
409
+ {zones.map((z, i) => (
410
+ <span
411
+ key={`z${z.key}`}
412
+ className={cx(classes.rowLabel, classes.zoneLabel, z.holding && classes.zoneLabelHolding)}
413
+ data-meter-zone-label={z.label}
414
+ data-holding={z.holding || undefined}
415
+ data-hidden={hidden(ticks.length + i)}
416
+ style={{ insetInlineStart: `${z.centrePct}%`, ...nudge(ticks.length + i) }}
417
+ >
418
+ {z.label}
419
+ </span>
420
+ ))}
421
+ {twins.map((zi) => {
422
+ const z = zones[zi] as ZoneLabel
423
+ const i = ticks.length + zi
424
+ return (
425
+ <span
426
+ key={`s${z.key}`}
427
+ className={cx(classes.rowLabel, classes.zoneLabel)}
428
+ data-meter-zone-short={z.label}
429
+ data-hidden={short[i] === true ? undefined : ''}
430
+ style={{ insetInlineStart: `${z.centrePct}%`, ...nudge(i) }}
431
+ >
432
+ {z.short}
433
+ </span>
434
+ )
435
+ })}
436
+ </div>
274
437
  )
275
438
  }
276
439
 
440
+ /** One caption of the marks row, in flow order: its anchor (`pct`, or the row's `edge`) when it has one. */
441
+ type CaptionItem = { key: string; node: ReactNode; pct?: number; edge?: 'end'; end?: boolean }
442
+
443
+ /** The measurement shared by the marks row and the part list: natural widths, row width, gap step. */
444
+ function measureItems(row: HTMLElement) {
445
+ const kids = [...row.children] as HTMLElement[]
446
+ const widths = kids.map((kid) => {
447
+ // In the flow a caption may shrink and wrap inside itself; its anchored width is its one-line one.
448
+ const { whiteSpace, flex } = kid.style
449
+ kid.style.whiteSpace = 'nowrap'
450
+ kid.style.flex = 'none'
451
+ const width = kid.offsetWidth
452
+ kid.style.whiteSpace = whiteSpace
453
+ kid.style.flex = flex
454
+ return width
455
+ })
456
+ return { widths, rowWidth: row.clientWidth, gap: columnGapOf(row) }
457
+ }
458
+
277
459
  /**
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.
460
+ * Runs `measure` when `key` (what the row says) changes, when the row resizes and when web fonts
461
+ * load (a swap changes widths without resizing the row). Without layout (server markup, happy-dom)
462
+ * nothing is measured and the row keeps its flow.
283
463
  */
284
- function ZoneLabels({ labels }: { labels: readonly ZoneLabel[] }) {
285
- const rowRef = useRef<HTMLDivElement>(null)
286
- const fits = useZoneLabelLayout(rowRef, labelsKey(labels))
464
+ function useMeasured(
465
+ rowRef: RefObject<HTMLElement | null>,
466
+ measure: (row: HTMLElement) => void,
467
+ key: string,
468
+ ) {
469
+ const measureRef = useRef(measure)
470
+ // Declared first so the effect below reads this render's closure.
471
+ useIsomorphicLayoutEffect(() => {
472
+ measureRef.current = measure
473
+ })
474
+ useIsomorphicLayoutEffect(() => {
475
+ const row = rowRef.current
476
+ if (!row) return
477
+ const run = () => measureRef.current(row)
478
+ run()
479
+ const observer = typeof ResizeObserver === 'undefined' ? undefined : new ResizeObserver(run)
480
+ observer?.observe(row)
481
+ // A caption's own size changes with its content, whatever it is (a ReactNode has no string key).
482
+ for (const kid of row.children) observer?.observe(kid)
483
+ const fonts =
484
+ typeof document === 'undefined' ? undefined : (document.fonts as FontFaceSet | undefined)
485
+ fonts?.addEventListener?.('loadingdone', run)
486
+ return () => {
487
+ observer?.disconnect()
488
+ fonts?.removeEventListener?.('loadingdone', run)
489
+ }
490
+ }, [rowRef, key])
491
+ }
492
+
493
+ const sameStarts = (a: number[] | null, b: number[] | null) =>
494
+ a === b || (a !== null && b !== null && a.length === b.length && a.every((v, i) => v === b[i]))
287
495
 
496
+ /**
497
+ * The captions under the track. A caption that names a mark (the forecast boundary, the target) sits
498
+ * AT that mark, centred and clamped inside the track, when every caption fits with a gap step between
499
+ * them; otherwise (and in server markup) the row flows and wraps: start, forecast, end.
500
+ */
501
+ function CaptionRow({ items }: { items: readonly CaptionItem[] }) {
502
+ const rowRef = useRef<HTMLDivElement>(null)
503
+ const [starts, setStarts] = useState<number[] | null>(null)
504
+ useMeasured(
505
+ rowRef,
506
+ (row) => {
507
+ const { widths, rowWidth, gap } = measureItems(row)
508
+ const marks: MarkItem[] = items.map((item, i) => ({
509
+ width: widths[i] ?? 0,
510
+ ...(item.pct !== undefined && { pct: item.pct }),
511
+ ...(item.edge !== undefined && { edge: item.edge }),
512
+ }))
513
+ const next = placeMarkCaptions(marks, rowWidth, gap)
514
+ setStarts((prev) => (sameStarts(prev, next) ? prev : next))
515
+ },
516
+ items
517
+ .map((i) => `${i.key}@${i.pct ?? i.edge ?? ''}:${typeof i.node === 'string' ? i.node : ''}`)
518
+ .join('\u0000'),
519
+ )
288
520
  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
- </>
521
+ <div
522
+ ref={rowRef}
523
+ className={cx(classes.captions, starts !== null && classes.captionsAnchored)}
524
+ data-meter-captions
525
+ data-anchored={starts === null ? undefined : ''}
526
+ >
527
+ {items.map((item, i) => (
528
+ <span
529
+ key={item.key}
530
+ className={item.end ? classes.captionEnd : classes.caption}
531
+ {...(starts?.[i] !== undefined && { style: { insetInlineStart: `${starts[i]}px` } })}
532
+ >
533
+ {item.node}
534
+ </span>
535
+ ))}
536
+ </div>
314
537
  )
315
538
  }
316
539
 
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
540
  /**
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.
541
+ * Categorical part captions (swatch, name, value): each under its own segment when every one fits
542
+ * there on one line, else one wrapped list. A caption never wraps inside itself.
324
543
  */
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'))
544
+ function PartCaptions({ captions }: { captions: readonly PartCaption[] }) {
545
+ const rowRef = useRef<HTMLUListElement>(null)
546
+ const [under, setUnder] = useState(false)
547
+ useMeasured(
548
+ rowRef,
549
+ (row) => {
550
+ const { widths, rowWidth, gap } = measureItems(row)
551
+ const fits = partsFitUnder(
552
+ captions.map((c, i) => ({ startPct: c.startPct, width: widths[i] ?? 0 })),
553
+ rowWidth,
554
+ gap,
555
+ )
556
+ setUnder(fits)
557
+ },
558
+ captions.map((c) => `${c.label} ${c.text}@${c.startPct}`).join('\u0000'),
559
+ )
328
560
  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) => (
561
+ <ul
562
+ ref={rowRef}
563
+ className={cx(classes.partCaptions, under && classes.partCaptionsUnder)}
564
+ // The explicit role is deliberate: `list-style: none` makes Safari/VoiceOver drop the implicit one.
565
+ // oxlint-disable-next-line jsx-a11y/no-redundant-roles
566
+ role="list"
567
+ data-meter-parts
568
+ data-anchored={under ? '' : undefined}
569
+ >
570
+ {captions.map((c) => (
571
+ <li
572
+ key={c.key}
573
+ className={classes.partCaption}
574
+ {...(under && { style: { insetInlineStart: `${c.startPct}%` } })}
575
+ >
338
576
  <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>
577
+ className={classes.swatch}
578
+ // theme-allow hidden-inline-style — the swatch repeats the part's fill colour (data)
579
+ style={{ background: c.color ?? 'var(--vx-line)' }}
580
+ aria-hidden
581
+ />
582
+ {glueUnits(`${c.label} ${c.text}`)}
583
+ </li>
584
+ ))}
585
+ </ul>
362
586
  )
363
587
  }
364
588
 
@@ -371,6 +595,9 @@ export function MeterBar(props: {
371
595
  color: string | undefined
372
596
  segments: readonly MeterSegment[] | undefined
373
597
  zones: readonly MeterZone[] | undefined
598
+ stops: readonly { at: number; color: string }[] | undefined
599
+ track: boolean | undefined
600
+ markerReading: boolean | undefined
374
601
  target: number | undefined
375
602
  ticks: readonly MeterTick[] | undefined
376
603
  tone: 'muted' | undefined
@@ -379,43 +606,101 @@ export function MeterBar(props: {
379
606
  endCaption: ReactNode
380
607
  shell: Shell
381
608
  }) {
382
- const { label, reading, min, max, format, zones, shell } = props
609
+ const { label, min, max, format, zones, shell } = props
383
610
  const describedId = useId()
384
611
  const model = modelBar(props)
385
612
  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
613
+ const hosted = useContext(VisualSlotContext) !== null
614
+ // A host that already shows the value as its hero (StatCard, a strip cell) owns the reading: a
615
+ // marked track keeps its marker and labels but does not print the number a second time, and a
616
+ // stops track prints it only on request. `reading` overrides either way. A consumer's own
617
+ // `startCaption` is not the reading and still renders.
618
+ const marked = model.markerPct !== undefined
619
+ const readingOn = props.markerReading ?? (model.zoneLabels.length > 0 && !hosted)
620
+ const start =
621
+ compact || (marked && !readingOn && props.startCaption === undefined)
622
+ ? null
623
+ : startCaptionText(model, props.startCaption)
624
+ const anchored = marked && start !== null
625
+ const trackHidden =
626
+ props.track === false &&
627
+ model.parts.length === 1 &&
628
+ props.segments === undefined &&
629
+ props.target === undefined &&
630
+ model.ticks.length === 0
631
+ const hasParts = model.partCaptions.length > 0
392
632
  const tickLabels = compact ? [] : model.ticks.filter((t) => t.label !== undefined)
633
+ const zoneLabels = compact ? [] : model.zoneLabels
393
634
  const describedBy =
394
635
  model.describedByText === null ? {} : ({ 'aria-describedby': describedId } as const)
395
636
 
637
+ // The caption row, in flow order. The target's caption sits at its tick unless the consumer
638
+ // supplied an end caption (theirs goes at the end, as written).
639
+ const endOverride = props.endCaption !== undefined
640
+ const targetHere = !endOverride && model.targetPct !== undefined && model.endText !== null
641
+ const end = compact ? null : endOverride ? props.endCaption : model.endText
642
+ const items: CaptionItem[] = compact
643
+ ? []
644
+ : [
645
+ ...(start !== null && !anchored
646
+ ? [{ key: 'start', node: glue(start) } satisfies CaptionItem]
647
+ : []),
648
+ ...(model.forecastText !== null
649
+ ? [
650
+ {
651
+ key: 'forecast',
652
+ node: glue(model.forecastText),
653
+ ...(model.boundaryPct !== undefined && { pct: model.boundaryPct }),
654
+ } satisfies CaptionItem,
655
+ ]
656
+ : []),
657
+ ...(end !== null
658
+ ? [
659
+ {
660
+ key: 'end',
661
+ node: glue(end),
662
+ end: true,
663
+ ...(targetHere && model.targetPct !== undefined
664
+ ? { pct: model.targetPct }
665
+ : { edge: 'end' as const }),
666
+ } satisfies CaptionItem,
667
+ ]
668
+ : []),
669
+ ]
670
+
396
671
  const root = rootProps(shell)
397
672
  return (
398
- <div
399
- {...root}
400
- className={cx(root.className, !compact && model.zoneLabels.length > 0 && classes.zoned)}
401
- >
402
- {tickLabels.length > 0 && <TickLabels ticks={tickLabels} />}
673
+ <div {...root} className={root.className}>
674
+ {tickLabels.length > 0 && zoneLabels.length === 0 && (
675
+ <LabelRow zones={zoneLabels} ticks={tickLabels} />
676
+ )}
403
677
  <div
404
- className={classes.trackBox}
678
+ className={cx(classes.trackBox, trackHidden && classes.trackHidden)}
679
+ data-meter-track-hidden={trackHidden ? '' : undefined}
405
680
  aria-label={label}
406
- {...ariaValues(reading, min, max, format)}
681
+ {...ariaValues(props.reading, min, max, format)}
407
682
  {...describedBy}
408
683
  >
409
- <div className={classes.track} data-meter-track>
410
- {model.markerPct !== undefined &&
411
- zones?.map((z, i) => (
412
- <div
413
- key={i}
414
- className={classes.zone}
415
- data-meter-zone={z.label}
416
- style={zoneStyle(z, i, zones.length, min, model.span)}
417
- />
418
- ))}
684
+ <div
685
+ className={classes.track}
686
+ data-meter-track
687
+ {...(model.stopsCss !== undefined && {
688
+ 'data-meter-stops': '',
689
+ // theme-allow hidden-inline-style — the gradient is the consumer's colour data
690
+ style: { '--basalt-stops': model.stopsCss } as CSSProperties,
691
+ })}
692
+ >
693
+ {zones?.map(
694
+ (z, i) =>
695
+ model.markerPct !== undefined && (
696
+ <div
697
+ key={i}
698
+ className={classes.zone}
699
+ data-meter-zone={z.label}
700
+ style={zoneStyle(z, i, zones.length, min, model.span)}
701
+ />
702
+ ),
703
+ )}
419
704
  {model.parts.map((p, i) => (
420
705
  <div
421
706
  key={i}
@@ -435,39 +720,15 @@ export function MeterBar(props: {
435
720
  ))}
436
721
  <Tick kind="target" className={classes.tick} pct={model.targetPct} />
437
722
  </div>
438
- {!compact && model.zoneLabels.length > 0 && <ZoneLabels labels={model.zoneLabels} />}
723
+ {zoneLabels.length > 0 && <LabelRow zones={zoneLabels} ticks={tickLabels} />}
439
724
  {anchored && <ZoneReading pct={model.markerPct ?? 0}>{start}</ZoneReading>}
440
725
  {model.describedByText !== null && (
441
726
  <VisuallyHidden id={describedId} className={classes.summary}>
442
727
  {model.describedByText}
443
728
  </VisuallyHidden>
444
729
  )}
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>
461
- )}
462
- {hasCaptions && (
463
- <div className={classes.captions} data-meter-captions>
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>
467
- )}
468
- {end !== null && <span className={classes.captionEnd}>{glue(end)}</span>}
469
- </div>
470
- )}
730
+ {hasParts && <PartCaptions captions={model.partCaptions} />}
731
+ {items.length > 0 && <CaptionRow items={items} />}
471
732
  </div>
472
733
  )
473
734
  }