basalt-ui 2.21.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.
- package/CHANGELOG.md +33 -0
- package/MIGRATING.md +277 -12
- package/agent/agents/basalt-design-reviewer.md +1 -1
- package/agent/rules/basalt-tokens.md +1 -1
- package/agent/skills/basalt-design/SKILL.md +1 -1
- package/agent/skills/basalt-design/references/anti-defaults.md +1 -1
- package/agent/skills/basalt-design/references/catalogue.md +1 -0
- package/dist/charts/BandStrip.d.ts.map +1 -1
- package/dist/charts/BandStrip.js +27 -3
- package/dist/charts/Bars.d.ts.map +1 -1
- package/dist/charts/Bars.js +5 -0
- package/dist/charts/CartesianChart.d.ts +8 -0
- package/dist/charts/CartesianChart.d.ts.map +1 -1
- package/dist/charts/CartesianChart.js +8 -5
- package/dist/charts/ChartCard.d.ts +12 -3
- package/dist/charts/ChartCard.d.ts.map +1 -1
- package/dist/charts/ChartCard.js +29 -8
- package/dist/charts/DualPanel.d.ts.map +1 -1
- package/dist/charts/DualPanel.js +5 -8
- package/dist/charts/Heatmap.d.ts +12 -1
- package/dist/charts/Heatmap.d.ts.map +1 -1
- package/dist/charts/Heatmap.js +34 -5
- package/dist/charts/Lines.d.ts +3 -0
- package/dist/charts/Lines.d.ts.map +1 -1
- package/dist/charts/Lines.js +29 -6
- package/dist/charts/MirroredBars.d.ts.map +1 -1
- package/dist/charts/MirroredBars.js +4 -6
- package/dist/charts/Sparkline.d.ts +7 -1
- package/dist/charts/Sparkline.d.ts.map +1 -1
- package/dist/charts/Sparkline.js +39 -14
- package/dist/charts/StackedArea.d.ts +4 -1
- package/dist/charts/StackedArea.d.ts.map +1 -1
- package/dist/charts/StackedArea.js +9 -3
- package/dist/charts/band-fold.d.ts +20 -1
- package/dist/charts/band-fold.d.ts.map +1 -1
- package/dist/charts/band-fold.js +9 -0
- package/dist/charts/chart-box.module.css +19 -0
- package/dist/charts/chart-card.module.css +25 -0
- package/dist/charts/chart-legend.module.css +7 -0
- package/dist/charts/compile.d.ts +17 -6
- package/dist/charts/compile.d.ts.map +1 -1
- package/dist/charts/compile.js +145 -74
- package/dist/charts/labels.d.ts +15 -4
- package/dist/charts/labels.d.ts.map +1 -1
- package/dist/charts/labels.js +34 -10
- package/dist/charts/legend.d.ts +2 -0
- package/dist/charts/legend.d.ts.map +1 -1
- package/dist/charts/legend.js +7 -21
- package/dist/charts/marks.js +1 -1
- package/dist/charts/panel.d.ts +0 -6
- package/dist/charts/panel.d.ts.map +1 -1
- package/dist/charts/panel.js +1 -10
- package/dist/charts/ref-label.d.ts +26 -0
- package/dist/charts/ref-label.d.ts.map +1 -0
- package/dist/charts/ref-label.js +63 -0
- package/dist/charts/scales.d.ts +4 -1
- package/dist/charts/scales.d.ts.map +1 -1
- package/dist/charts/scales.js +14 -3
- package/dist/charts/sparkline.module.css +10 -11
- package/dist/charts/sparkline.module.css.d.ts +1 -2
- package/dist/charts/state.d.ts +2 -0
- package/dist/charts/state.d.ts.map +1 -1
- package/dist/charts/state.js +2 -1
- package/dist/charts/types.d.ts +14 -5
- package/dist/charts/types.d.ts.map +1 -1
- package/dist/cli/doctor-upgrade.d.ts +1 -0
- package/dist/cli/doctor-upgrade.d.ts.map +1 -1
- package/dist/cli/doctor-upgrade.js +1 -0
- package/dist/cli/init.d.ts +2 -0
- package/dist/cli/init.d.ts.map +1 -1
- package/dist/cli/init.js +68 -4
- package/dist/cli/shot/capture.d.ts +21 -2
- package/dist/cli/shot/capture.d.ts.map +1 -1
- package/dist/cli/shot/capture.js +194 -32
- package/dist/cli/shot/detect.d.ts.map +1 -1
- package/dist/cli/shot/detect.js +14 -1
- package/dist/cli/shot/playwright.d.ts +5 -2
- package/dist/cli/shot/playwright.d.ts.map +1 -1
- package/dist/cli/shot/types.d.ts +2 -0
- package/dist/cli/shot/types.d.ts.map +1 -1
- package/dist/cli/shot/types.js +2 -0
- package/dist/controls/controls.module.css +11 -1
- package/dist/controls/filter-pill.d.ts.map +1 -1
- package/dist/controls/filter-pill.js +1 -0
- package/dist/controls/sync-button.d.ts.map +1 -1
- package/dist/controls/sync-button.js +22 -3
- package/dist/controls/sync-button.module.css +34 -2
- package/dist/controls/sync-button.module.css.d.ts +1 -0
- package/dist/dashboard/bar-list.d.ts.map +1 -1
- package/dist/dashboard/bar-list.js +7 -8
- package/dist/dashboard/bar-list.module.css +53 -0
- package/dist/dashboard/bar-list.module.css.d.ts +1 -0
- package/dist/dashboard/index.d.ts +1 -0
- package/dist/dashboard/index.d.ts.map +1 -1
- package/dist/dashboard/index.js +2 -0
- package/dist/dashboard/meter-model.d.ts +77 -3
- package/dist/dashboard/meter-model.d.ts.map +1 -1
- package/dist/dashboard/meter-model.js +88 -15
- package/dist/dashboard/meter-parts.d.ts +8 -0
- package/dist/dashboard/meter-parts.d.ts.map +1 -1
- package/dist/dashboard/meter-parts.js +238 -71
- package/dist/dashboard/meter.d.ts +43 -60
- package/dist/dashboard/meter.d.ts.map +1 -1
- package/dist/dashboard/meter.js +20 -3
- package/dist/dashboard/meter.module.css +61 -0
- package/dist/dashboard/meter.module.css.d.ts +5 -0
- package/dist/dashboard/page-summary.d.ts +20 -0
- package/dist/dashboard/page-summary.d.ts.map +1 -0
- package/dist/dashboard/page-summary.js +28 -0
- package/dist/dashboard/page-summary.module.css +89 -0
- package/dist/dashboard/page-summary.module.css.d.ts +15 -0
- package/dist/dashboard/section.d.ts +25 -2
- package/dist/dashboard/section.d.ts.map +1 -1
- package/dist/dashboard/section.js +10 -5
- package/dist/dashboard/section.module.css +23 -0
- package/dist/dashboard/section.module.css.d.ts +1 -0
- package/dist/dashboard/stat-card-parts.d.ts.map +1 -1
- package/dist/dashboard/stat-card-parts.js +1 -1
- package/dist/dashboard/stat-card.d.ts +4 -2
- package/dist/dashboard/stat-card.d.ts.map +1 -1
- package/dist/dashboard/stat-card.js +7 -5
- package/dist/dashboard/stat-card.module.css +17 -0
- package/dist/dashboard/stat-strip.d.ts +7 -1
- package/dist/dashboard/stat-strip.d.ts.map +1 -1
- package/dist/dashboard/stat-strip.js +74 -46
- package/dist/dashboard/stat-strip.module.css +67 -20
- package/dist/dashboard/stat-strip.module.css.d.ts +4 -0
- package/dist/dashboard/visual-slot.d.ts +7 -1
- package/dist/dashboard/visual-slot.d.ts.map +1 -1
- package/dist/dashboard/visual-slot.js +3 -1
- package/dist/guard/vx-names.d.ts.map +1 -1
- package/dist/guard/vx-names.js +2 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/styles.css +34 -2
- package/dist/theme/chrome-vars.d.ts +20 -5
- package/dist/theme/chrome-vars.d.ts.map +1 -1
- package/dist/theme/chrome-vars.js +46 -3
- package/dist/theme/controls.module.css +23 -0
- package/dist/theme/controls.module.css.d.ts +1 -0
- package/dist/theme/index.d.ts.map +1 -1
- package/dist/theme/index.js +8 -20
- package/dist/tokens/core.d.ts +2 -1
- package/dist/tokens/core.d.ts.map +1 -1
- package/dist/tokens/core.js +6 -1
- package/dist/tokens/derive.d.ts +3 -1
- package/dist/tokens/derive.d.ts.map +1 -1
- package/dist/tokens/derive.js +16 -1
- package/dist/tokens/palette.d.ts +4 -0
- package/dist/tokens/palette.d.ts.map +1 -1
- package/dist/tokens/palette.js +4 -0
- package/dist/tokens/status-text.d.ts.map +1 -1
- package/dist/tokens/status-text.js +3 -1
- package/llms.txt +38 -20
- package/package.json +1 -1
- package/src/charts/BandStrip.tsx +33 -3
- package/src/charts/Bars.tsx +6 -0
- package/src/charts/CartesianChart.tsx +16 -3
- package/src/charts/ChartCard.tsx +34 -6
- package/src/charts/DualPanel.tsx +3 -6
- package/src/charts/Heatmap.tsx +54 -5
- package/src/charts/Lines.tsx +56 -10
- package/src/charts/MirroredBars.tsx +3 -5
- package/src/charts/Sparkline.tsx +50 -13
- package/src/charts/StackedArea.tsx +14 -4
- package/src/charts/band-fold.ts +31 -1
- package/src/charts/chart-box.module.css +19 -0
- package/src/charts/chart-card.module.css +25 -0
- package/src/charts/chart-legend.module.css +7 -0
- package/src/charts/compile.ts +210 -85
- package/src/charts/labels.ts +48 -14
- package/src/charts/legend.tsx +10 -20
- package/src/charts/marks.ts +1 -1
- package/src/charts/panel.tsx +1 -16
- package/src/charts/ref-label.ts +104 -0
- package/src/charts/scales.ts +22 -2
- package/src/charts/sparkline.module.css +10 -11
- package/src/charts/sparkline.module.css.d.ts +1 -2
- package/src/charts/state.tsx +3 -1
- package/src/charts/types.ts +14 -5
- package/src/cli/doctor-upgrade.ts +1 -1
- package/src/cli/init.ts +100 -3
- package/src/cli/shot/capture.ts +251 -32
- package/src/cli/shot/detect.ts +18 -1
- package/src/cli/shot/playwright.ts +2 -2
- package/src/cli/shot/types.ts +3 -0
- package/src/controls/controls.module.css +11 -1
- package/src/controls/filter-pill.tsx +2 -0
- package/src/controls/sync-button.module.css +34 -2
- package/src/controls/sync-button.module.css.d.ts +1 -0
- package/src/controls/sync-button.tsx +40 -4
- package/src/dashboard/bar-list.module.css +53 -0
- package/src/dashboard/bar-list.module.css.d.ts +1 -0
- package/src/dashboard/bar-list.tsx +78 -69
- package/src/dashboard/index.ts +1 -0
- package/src/dashboard/meter-model.ts +186 -20
- package/src/dashboard/meter-parts.tsx +285 -64
- package/src/dashboard/meter.module.css +61 -0
- package/src/dashboard/meter.module.css.d.ts +5 -0
- package/src/dashboard/meter.tsx +60 -10
- package/src/dashboard/page-summary.module.css +89 -0
- package/src/dashboard/page-summary.module.css.d.ts +15 -0
- package/src/dashboard/page-summary.tsx +95 -0
- package/src/dashboard/section.module.css +23 -0
- package/src/dashboard/section.module.css.d.ts +1 -0
- package/src/dashboard/section.tsx +59 -11
- package/src/dashboard/stat-card-parts.tsx +5 -1
- package/src/dashboard/stat-card.module.css +17 -0
- package/src/dashboard/stat-card.tsx +12 -6
- package/src/dashboard/stat-strip.module.css +67 -20
- package/src/dashboard/stat-strip.module.css.d.ts +4 -0
- package/src/dashboard/stat-strip.tsx +118 -72
- package/src/dashboard/visual-slot.ts +12 -3
- package/src/guard/vx-names.ts +2 -0
- package/src/index.ts +2 -0
- package/src/styles.css +34 -2
- package/src/theme/__snapshots__/plain-theme.test.ts.snap +186 -60
- package/src/theme/chrome-vars.ts +77 -8
- package/src/theme/controls.module.css +23 -0
- package/src/theme/controls.module.css.d.ts +1 -0
- package/src/theme/index.ts +12 -25
- package/src/tokens/core.ts +4 -1
- package/src/tokens/derive.ts +32 -3
- package/src/tokens/palette.ts +4 -0
- package/src/tokens/status-text.ts +2 -0
|
@@ -7,16 +7,22 @@ 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
|
-
placeRowLabels,
|
|
13
16
|
zoneBand,
|
|
17
|
+
zoneFill,
|
|
14
18
|
} from './meter-model'
|
|
15
19
|
import type {
|
|
20
|
+
MarkItem,
|
|
16
21
|
MeterSegment,
|
|
17
22
|
MeterTick,
|
|
18
23
|
MeterZone,
|
|
19
24
|
Part,
|
|
25
|
+
PartCaption,
|
|
20
26
|
RowLabel,
|
|
21
27
|
TickMark,
|
|
22
28
|
ZoneLabel,
|
|
@@ -50,8 +56,20 @@ const RING_RADIUS = (RING_VIEWBOX - RING_STROKE) / 2
|
|
|
50
56
|
const RING_LENGTH = 2 * Math.PI * RING_RADIUS
|
|
51
57
|
const RING_CENTER = RING_VIEWBOX / 2
|
|
52
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
|
+
|
|
53
63
|
/** The one ring drawing: a track and, when there is a reading, its arc (a fraction of the circle). */
|
|
54
|
-
function RingSvg({
|
|
64
|
+
function RingSvg({
|
|
65
|
+
fraction,
|
|
66
|
+
color,
|
|
67
|
+
marks = [],
|
|
68
|
+
}: {
|
|
69
|
+
fraction?: number
|
|
70
|
+
color?: string | undefined
|
|
71
|
+
marks?: readonly { angle: number }[]
|
|
72
|
+
}) {
|
|
55
73
|
return (
|
|
56
74
|
<svg className={classes.ring} viewBox={`0 0 ${RING_VIEWBOX} ${RING_VIEWBOX}`} aria-hidden>
|
|
57
75
|
<circle
|
|
@@ -72,6 +90,22 @@ function RingSvg({ fraction, color }: { fraction?: number; color?: string | unde
|
|
|
72
90
|
{...(color !== undefined && { style: { stroke: color } })}
|
|
73
91
|
/>
|
|
74
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
|
+
))}
|
|
75
109
|
</svg>
|
|
76
110
|
)
|
|
77
111
|
}
|
|
@@ -140,20 +174,30 @@ export function MeterRing(props: {
|
|
|
140
174
|
min: number
|
|
141
175
|
max: number
|
|
142
176
|
color: string | undefined
|
|
177
|
+
target: number | undefined
|
|
178
|
+
ticks: readonly MeterTick[] | undefined
|
|
143
179
|
format: (value: number) => string
|
|
144
180
|
shell: Shell
|
|
145
181
|
}) {
|
|
146
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)
|
|
147
185
|
return (
|
|
148
186
|
<div {...rootProps(shell)}>
|
|
149
187
|
<span
|
|
150
188
|
className={classes.ringBox}
|
|
151
189
|
aria-label={label}
|
|
152
190
|
{...ariaValues(reading, min, max, format)}
|
|
191
|
+
{...(marks.length > 0 && { 'aria-describedby': describedId })}
|
|
153
192
|
>
|
|
154
|
-
<RingSvg fraction={ringFraction(reading, min, max)} color={color} />
|
|
193
|
+
<RingSvg fraction={ringFraction(reading, min, max)} color={color} marks={marks} />
|
|
155
194
|
<span className={classes.ringValue}>{format(reading)}</span>
|
|
156
195
|
</span>
|
|
196
|
+
{marks.length > 0 && (
|
|
197
|
+
<VisuallyHidden id={describedId} className={classes.summary}>
|
|
198
|
+
{marks.map((m) => m.text).join('; ')}
|
|
199
|
+
</VisuallyHidden>
|
|
200
|
+
)}
|
|
157
201
|
</div>
|
|
158
202
|
)
|
|
159
203
|
}
|
|
@@ -162,27 +206,24 @@ function fillStyle(p: Part): CSSProperties {
|
|
|
162
206
|
return { width: `${toPct(p.size)}%`, ...(p.color !== undefined && { background: p.color }) }
|
|
163
207
|
}
|
|
164
208
|
|
|
165
|
-
/** Uncoloured zones step from `MIN` to `MIN + STEP` percent of the neutral, so order reads without hue. */
|
|
166
|
-
const ZONE_STRENGTH_MIN = 15
|
|
167
|
-
const ZONE_STRENGTH_STEP = 45
|
|
168
|
-
const ZONE_STRENGTH_SOLO = 40
|
|
169
209
|
/** Every band after the first gives up its leading pixel, so a boundary never relies on fill strength. */
|
|
170
210
|
const ZONE_GAP = '1px'
|
|
171
211
|
|
|
172
212
|
function zoneStyle(zone: MeterZone, index: number, count: number, min: number, span: number) {
|
|
173
213
|
const band = zoneBand(zone, min, span)
|
|
174
214
|
const gap = index > 0
|
|
175
|
-
const strength =
|
|
176
|
-
count > 1 ? ZONE_STRENGTH_MIN + (index / (count - 1)) * ZONE_STRENGTH_STEP : ZONE_STRENGTH_SOLO
|
|
177
215
|
return {
|
|
178
216
|
insetInlineStart: gap ? `calc(${band.start}% + ${ZONE_GAP})` : `${band.start}%`,
|
|
179
217
|
width: gap ? `calc(${band.width}% - ${ZONE_GAP})` : `${band.width}%`,
|
|
180
|
-
background: zone
|
|
218
|
+
background: zoneFill(zone, index, count),
|
|
181
219
|
} satisfies CSSProperties
|
|
182
220
|
}
|
|
183
221
|
|
|
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
|
+
|
|
184
225
|
/** 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 }
|
|
226
|
+
type RowSlot = { spanPct?: readonly [number, number]; holding?: boolean; end?: boolean }
|
|
186
227
|
|
|
187
228
|
type RowLayout = { shown: boolean[]; short: boolean[]; shift: number[] }
|
|
188
229
|
const sameLayout = (a: RowLayout, b: RowLayout) =>
|
|
@@ -232,6 +273,7 @@ function useRowLabelLayout(
|
|
|
232
273
|
...(a !== undefined &&
|
|
233
274
|
b !== undefined && { span: { left: Math.min(a, b), right: Math.max(a, b) } }),
|
|
234
275
|
...(slot?.holding && { holding: true }),
|
|
276
|
+
...(slot?.end && { end: true }),
|
|
235
277
|
}
|
|
236
278
|
})
|
|
237
279
|
shortOfRef.current.forEach((labelIndex, n) => {
|
|
@@ -239,7 +281,7 @@ function useRowLabelLayout(
|
|
|
239
281
|
const label = labels[labelIndex]
|
|
240
282
|
if (r && label) label.short = { left: r.left - origin.left, right: r.right - origin.left }
|
|
241
283
|
})
|
|
242
|
-
const placed = placeRowLabels(labels, origin.width)
|
|
284
|
+
const placed = placeRowLabels(labels, origin.width, columnGapOf(row))
|
|
243
285
|
// The hook measures on the physical x axis; the margin is logical, so it flips with `dir`.
|
|
244
286
|
const next = {
|
|
245
287
|
shown: placed.shown,
|
|
@@ -321,7 +363,7 @@ const TICK_LABEL_FLIP_PCT = 50
|
|
|
321
363
|
function LabelRow({ zones, ticks }: { zones: readonly ZoneLabel[]; ticks: readonly TickMark[] }) {
|
|
322
364
|
const rowRef = useRef<HTMLDivElement>(null)
|
|
323
365
|
const slots: RowSlot[] = [
|
|
324
|
-
...ticks.map((): RowSlot => ({})),
|
|
366
|
+
...ticks.map((t): RowSlot => (t.pct <= 0 || t.pct >= 100 ? { end: true } : {})),
|
|
325
367
|
...zones.map((z): RowSlot => ({
|
|
326
368
|
spanPct: [z.centrePct - z.widthPct / 2, z.centrePct + z.widthPct / 2],
|
|
327
369
|
holding: z.holding,
|
|
@@ -395,6 +437,155 @@ function LabelRow({ zones, ticks }: { zones: readonly ZoneLabel[]; ticks: readon
|
|
|
395
437
|
)
|
|
396
438
|
}
|
|
397
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
|
+
|
|
459
|
+
/**
|
|
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.
|
|
463
|
+
*/
|
|
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]))
|
|
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
|
+
)
|
|
520
|
+
return (
|
|
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>
|
|
537
|
+
)
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
/**
|
|
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.
|
|
543
|
+
*/
|
|
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
|
+
)
|
|
560
|
+
return (
|
|
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
|
+
>
|
|
576
|
+
<span
|
|
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>
|
|
586
|
+
)
|
|
587
|
+
}
|
|
588
|
+
|
|
398
589
|
export function MeterBar(props: {
|
|
399
590
|
label: string
|
|
400
591
|
reading: number
|
|
@@ -404,6 +595,9 @@ export function MeterBar(props: {
|
|
|
404
595
|
color: string | undefined
|
|
405
596
|
segments: readonly MeterSegment[] | undefined
|
|
406
597
|
zones: readonly MeterZone[] | undefined
|
|
598
|
+
stops: readonly { at: number; color: string }[] | undefined
|
|
599
|
+
track: boolean | undefined
|
|
600
|
+
markerReading: boolean | undefined
|
|
407
601
|
target: number | undefined
|
|
408
602
|
ticks: readonly MeterTick[] | undefined
|
|
409
603
|
tone: 'muted' | undefined
|
|
@@ -412,28 +606,68 @@ export function MeterBar(props: {
|
|
|
412
606
|
endCaption: ReactNode
|
|
413
607
|
shell: Shell
|
|
414
608
|
}) {
|
|
415
|
-
const { label,
|
|
609
|
+
const { label, min, max, format, zones, shell } = props
|
|
416
610
|
const describedId = useId()
|
|
417
611
|
const model = modelBar(props)
|
|
418
612
|
const compact = shell.row
|
|
613
|
+
const hosted = useContext(VisualSlotContext) !== null
|
|
419
614
|
// A host that already shows the value as its hero (StatCard, a strip cell) owns the reading: a
|
|
420
|
-
//
|
|
421
|
-
//
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
const
|
|
430
|
-
|
|
431
|
-
|
|
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
|
|
432
632
|
const tickLabels = compact ? [] : model.ticks.filter((t) => t.label !== undefined)
|
|
433
633
|
const zoneLabels = compact ? [] : model.zoneLabels
|
|
434
634
|
const describedBy =
|
|
435
635
|
model.describedByText === null ? {} : ({ 'aria-describedby': describedId } as const)
|
|
436
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
|
+
|
|
437
671
|
const root = rootProps(shell)
|
|
438
672
|
return (
|
|
439
673
|
<div {...root} className={root.className}>
|
|
@@ -441,21 +675,32 @@ export function MeterBar(props: {
|
|
|
441
675
|
<LabelRow zones={zoneLabels} ticks={tickLabels} />
|
|
442
676
|
)}
|
|
443
677
|
<div
|
|
444
|
-
className={classes.trackBox}
|
|
678
|
+
className={cx(classes.trackBox, trackHidden && classes.trackHidden)}
|
|
679
|
+
data-meter-track-hidden={trackHidden ? '' : undefined}
|
|
445
680
|
aria-label={label}
|
|
446
|
-
{...ariaValues(reading, min, max, format)}
|
|
681
|
+
{...ariaValues(props.reading, min, max, format)}
|
|
447
682
|
{...describedBy}
|
|
448
683
|
>
|
|
449
|
-
<div
|
|
450
|
-
{
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
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
|
+
)}
|
|
459
704
|
{model.parts.map((p, i) => (
|
|
460
705
|
<div
|
|
461
706
|
key={i}
|
|
@@ -482,32 +727,8 @@ export function MeterBar(props: {
|
|
|
482
727
|
{model.describedByText}
|
|
483
728
|
</VisuallyHidden>
|
|
484
729
|
)}
|
|
485
|
-
{hasParts &&
|
|
486
|
-
|
|
487
|
-
// oxlint-disable-next-line jsx-a11y/no-redundant-roles
|
|
488
|
-
<ul className={classes.partCaptions} role="list" data-meter-parts>
|
|
489
|
-
{model.partCaptions.map((c) => (
|
|
490
|
-
<li key={c.key} className={classes.partCaption}>
|
|
491
|
-
<span
|
|
492
|
-
className={classes.swatch}
|
|
493
|
-
// theme-allow hidden-inline-style — the swatch repeats the part's fill colour (data)
|
|
494
|
-
style={{ background: c.color ?? 'var(--vx-line)' }}
|
|
495
|
-
aria-hidden
|
|
496
|
-
/>
|
|
497
|
-
{glueUnits(`${c.label} ${c.text}`)}
|
|
498
|
-
</li>
|
|
499
|
-
))}
|
|
500
|
-
</ul>
|
|
501
|
-
)}
|
|
502
|
-
{hasCaptions && (
|
|
503
|
-
<div className={classes.captions} data-meter-captions>
|
|
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>
|
|
507
|
-
)}
|
|
508
|
-
{end !== null && <span className={classes.captionEnd}>{glue(end)}</span>}
|
|
509
|
-
</div>
|
|
510
|
-
)}
|
|
730
|
+
{hasParts && <PartCaptions captions={model.partCaptions} />}
|
|
731
|
+
{items.length > 0 && <CaptionRow items={items} />}
|
|
511
732
|
</div>
|
|
512
733
|
)
|
|
513
734
|
}
|
|
@@ -28,6 +28,26 @@
|
|
|
28
28
|
position: relative;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
/* A `stops` track is one gradient through the consumer's colours; the reading is a marker on it. */
|
|
32
|
+
.track[data-meter-stops] {
|
|
33
|
+
background: linear-gradient(var(--basalt-stop-dir, to right), var(--basalt-stops));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.trackBox:dir(rtl) {
|
|
37
|
+
--basalt-stop-dir: to left;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/* `track={false}`: no drawn track, still in the accessibility tree (the role and value stay). */
|
|
41
|
+
.trackHidden {
|
|
42
|
+
position: absolute;
|
|
43
|
+
width: 1px;
|
|
44
|
+
height: 1px;
|
|
45
|
+
margin: -1px;
|
|
46
|
+
overflow: hidden;
|
|
47
|
+
clip-path: inset(50%);
|
|
48
|
+
white-space: nowrap;
|
|
49
|
+
}
|
|
50
|
+
|
|
31
51
|
.fill {
|
|
32
52
|
flex: none;
|
|
33
53
|
height: 100%;
|
|
@@ -63,6 +83,8 @@
|
|
|
63
83
|
/* A hidden name keeps its box (so it can be measured again) and may sit past the row's end. */
|
|
64
84
|
overflow-x: clip;
|
|
65
85
|
height: 1.25em;
|
|
86
|
+
/* Read by the layout: the least two captions keep apart (one gap step). */
|
|
87
|
+
column-gap: var(--vx-space-control-gap, 0.375rem);
|
|
66
88
|
font-family: var(--basalt-font-numeral, var(--basalt-font-sans));
|
|
67
89
|
font-variant-numeric: lining-nums;
|
|
68
90
|
font-size: var(--basalt-meter-caption);
|
|
@@ -164,6 +186,20 @@
|
|
|
164
186
|
color: var(--vx-muted);
|
|
165
187
|
}
|
|
166
188
|
|
|
189
|
+
/* Captions at their marks: each is placed (inline `inset-inline-start`) by the measured layout. */
|
|
190
|
+
.captionsAnchored {
|
|
191
|
+
position: relative;
|
|
192
|
+
display: block;
|
|
193
|
+
height: 1lh;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
.captionsAnchored > * {
|
|
197
|
+
position: absolute;
|
|
198
|
+
top: 0;
|
|
199
|
+
margin: 0;
|
|
200
|
+
white-space: nowrap;
|
|
201
|
+
}
|
|
202
|
+
|
|
167
203
|
/* Captions never truncate: the row wraps, and a caption wider than the row wraps inside itself. */
|
|
168
204
|
.caption {
|
|
169
205
|
min-width: 0;
|
|
@@ -207,6 +243,20 @@
|
|
|
207
243
|
overflow-wrap: anywhere;
|
|
208
244
|
}
|
|
209
245
|
|
|
246
|
+
/* Every part's caption fits under its own segment: the list is positioned, not wrapped. */
|
|
247
|
+
.partCaptionsUnder {
|
|
248
|
+
position: relative;
|
|
249
|
+
display: block;
|
|
250
|
+
height: 1lh;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/* Under its segment a caption is one line by construction: it was measured to fit as one. */
|
|
254
|
+
.partCaptionsUnder > .partCaption {
|
|
255
|
+
position: absolute;
|
|
256
|
+
top: 0;
|
|
257
|
+
white-space: nowrap;
|
|
258
|
+
}
|
|
259
|
+
|
|
210
260
|
/* A shape cue beside the name, so the part never reads by colour alone. */
|
|
211
261
|
.swatch {
|
|
212
262
|
flex: none;
|
|
@@ -265,6 +315,17 @@
|
|
|
265
315
|
stroke: var(--vx-line);
|
|
266
316
|
}
|
|
267
317
|
|
|
318
|
+
/* A ring tick: an ink mark with a track-coloured halo, so it reads over the arc and the track. */
|
|
319
|
+
.ringTick {
|
|
320
|
+
stroke: var(--vx-ink);
|
|
321
|
+
stroke-width: 1.5;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
.ringTickHalo {
|
|
325
|
+
stroke: var(--vx-surface-subtle);
|
|
326
|
+
stroke-width: 3;
|
|
327
|
+
}
|
|
328
|
+
|
|
268
329
|
.ringValue {
|
|
269
330
|
position: relative;
|
|
270
331
|
font-family: var(--basalt-font-numeral, var(--basalt-font-sans));
|
|
@@ -7,6 +7,7 @@ declare const classes: {
|
|
|
7
7
|
readonly summary: string
|
|
8
8
|
readonly track: string
|
|
9
9
|
readonly trackBox: string
|
|
10
|
+
readonly trackHidden: string
|
|
10
11
|
readonly fill: string
|
|
11
12
|
readonly forecastFill: string
|
|
12
13
|
readonly zone: string
|
|
@@ -22,8 +23,10 @@ declare const classes: {
|
|
|
22
23
|
readonly captions: string
|
|
23
24
|
readonly caption: string
|
|
24
25
|
readonly captionEnd: string
|
|
26
|
+
readonly captionsAnchored: string
|
|
25
27
|
readonly partCaptions: string
|
|
26
28
|
readonly partCaption: string
|
|
29
|
+
readonly partCaptionsUnder: string
|
|
27
30
|
readonly swatch: string
|
|
28
31
|
readonly empty: string
|
|
29
32
|
readonly skeletonTrack: string
|
|
@@ -32,6 +35,8 @@ declare const classes: {
|
|
|
32
35
|
readonly ring: string
|
|
33
36
|
readonly ringTrack: string
|
|
34
37
|
readonly ringArc: string
|
|
38
|
+
readonly ringTick: string
|
|
39
|
+
readonly ringTickHalo: string
|
|
35
40
|
readonly ringValue: string
|
|
36
41
|
readonly skeletonRing: string
|
|
37
42
|
readonly row: string
|