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.
- package/CHANGELOG.md +72 -0
- package/MIGRATING.md +394 -12
- package/agent/agents/basalt-design-reviewer.md +22 -5
- package/agent/rules/basalt-tokens.md +3 -3
- package/agent/skills/basalt-design/SKILL.md +10 -23
- package/agent/skills/basalt-design/references/anti-defaults.md +24 -0
- package/agent/skills/basalt-design/references/catalogue.md +49 -0
- package/agent/skills/basalt-design/references/concept.md +36 -0
- package/agent/skills/basalt-design/references/encoding-rules.md +45 -0
- package/agent/skills/basalt-design/references/stat-tile.md +24 -0
- package/agent/templates/AGENTS-block.md.tpl +3 -3
- package/configs/oxlint-plugin.js +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 +17 -4
- package/dist/charts/ChartCard.d.ts.map +1 -1
- package/dist/charts/ChartCard.js +33 -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 +7 -0
- package/dist/charts/state.d.ts.map +1 -1
- package/dist/charts/state.js +4 -1
- package/dist/charts/types.d.ts +14 -5
- package/dist/charts/types.d.ts.map +1 -1
- package/dist/cli/check-theme.d.ts.map +1 -1
- package/dist/cli/check-theme.js +3 -0
- 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/help.d.ts.map +1 -1
- package/dist/cli/help.js +3 -2
- package/dist/cli/index.d.ts +4 -2
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +27 -15
- package/dist/cli/init.d.ts +2 -0
- package/dist/cli/init.d.ts.map +1 -1
- package/dist/cli/init.js +71 -6
- 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 +200 -33
- package/dist/cli/shot/detect.d.ts +51 -0
- package/dist/cli/shot/detect.d.ts.map +1 -0
- package/dist/cli/shot/detect.js +409 -0
- package/dist/cli/shot/index.d.ts.map +1 -1
- package/dist/cli/shot/index.js +7 -4
- package/dist/cli/shot/measure.d.ts +2 -0
- package/dist/cli/shot/measure.d.ts.map +1 -1
- package/dist/cli/shot/measure.js +2 -0
- 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 +6 -1
- package/dist/cli/shot/types.d.ts.map +1 -1
- package/dist/cli/shot/types.js +4 -0
- package/dist/cli/sync.d.ts +2 -0
- package/dist/cli/sync.d.ts.map +1 -1
- package/dist/cli/sync.js +2 -2
- package/dist/common/retry-button.d.ts +12 -0
- package/dist/common/retry-button.d.ts.map +1 -0
- package/dist/common/retry-button.js +22 -0
- package/dist/common/retry-button.module.css +58 -0
- package/dist/common/retry-button.module.css.d.ts +8 -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 +5 -2
- package/dist/dashboard/bar-list.d.ts.map +1 -1
- package/dist/dashboard/bar-list.js +9 -10
- 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 +108 -6
- package/dist/dashboard/meter-model.d.ts.map +1 -1
- package/dist/dashboard/meter-model.js +123 -19
- 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 +345 -146
- package/dist/dashboard/meter.d.ts +50 -63
- package/dist/dashboard/meter.d.ts.map +1 -1
- package/dist/dashboard/meter.js +24 -3
- package/dist/dashboard/meter.module.css +79 -65
- package/dist/dashboard/meter.module.css.d.ts +7 -7
- 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/query-state.d.ts +1 -1
- package/dist/dashboard/query-state.d.ts.map +1 -1
- package/dist/dashboard/query-state.js +3 -2
- 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 -4
- package/dist/dashboard/stat-card.module.css +17 -0
- package/dist/dashboard/stat-strip.d.ts +24 -1
- package/dist/dashboard/stat-strip.d.ts.map +1 -1
- package/dist/dashboard/stat-strip.js +97 -39
- package/dist/dashboard/stat-strip.module.css +147 -17
- package/dist/dashboard/stat-strip.module.css.d.ts +8 -0
- package/dist/dashboard/visual-slot.d.ts +8 -0
- package/dist/dashboard/visual-slot.d.ts.map +1 -0
- package/dist/dashboard/visual-slot.js +7 -0
- package/dist/guard/index.d.ts +15 -2
- package/dist/guard/index.d.ts.map +1 -1
- package/dist/guard/index.js +14 -0
- package/dist/guard/palette.d.ts +51 -0
- package/dist/guard/palette.d.ts.map +1 -0
- package/dist/guard/palette.js +190 -0
- package/dist/guard/series-file.d.ts +15 -0
- package/dist/guard/series-file.d.ts.map +1 -0
- package/dist/guard/series-file.js +29 -0
- package/dist/guard/types.d.ts +3 -3
- package/dist/guard/types.d.ts.map +1 -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/surfaces.d.ts +1 -1
- package/dist/surfaces.d.ts.map +1 -1
- package/dist/surfaces.js +2 -0
- 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 +33 -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 +11 -5
- 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/oklab.d.ts +28 -0
- package/dist/tokens/oklab.d.ts.map +1 -0
- package/dist/tokens/oklab.js +73 -0
- 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 +43 -23
- 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 +43 -7
- 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 +12 -1
- package/src/charts/types.ts +14 -5
- package/src/cli/check-theme.ts +3 -0
- package/src/cli/doctor-upgrade.ts +1 -1
- package/src/cli/help.ts +18 -1
- package/src/cli/index.ts +48 -17
- package/src/cli/init.ts +102 -4
- package/src/cli/shot/capture.ts +266 -34
- package/src/cli/shot/detect.ts +550 -0
- package/src/cli/shot/index.ts +8 -4
- package/src/cli/shot/measure.ts +4 -0
- package/src/cli/shot/playwright.ts +2 -2
- package/src/cli/shot/types.ts +8 -1
- package/src/cli/sync.ts +4 -2
- package/src/common/retry-button.module.css +58 -0
- package/src/common/retry-button.module.css.d.ts +8 -0
- package/src/common/retry-button.tsx +29 -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 +88 -76
- package/src/dashboard/index.ts +1 -0
- package/src/dashboard/meter-model.ts +265 -28
- package/src/dashboard/meter-parts.tsx +424 -163
- package/src/dashboard/meter.module.css +79 -65
- package/src/dashboard/meter.module.css.d.ts +7 -7
- package/src/dashboard/meter.tsx +77 -17
- 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/query-state.tsx +4 -7
- 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 +14 -5
- package/src/dashboard/stat-strip.module.css +147 -17
- package/src/dashboard/stat-strip.module.css.d.ts +8 -0
- package/src/dashboard/stat-strip.tsx +182 -56
- package/src/dashboard/visual-slot.ts +17 -0
- package/src/guard/index.ts +16 -4
- package/src/guard/palette.ts +261 -0
- package/src/guard/series-file.ts +51 -0
- package/src/guard/types.ts +3 -2
- package/src/guard/vx-names.ts +2 -0
- package/src/index.ts +2 -0
- package/src/styles.css +34 -2
- package/src/surfaces.ts +2 -0
- package/src/theme/__snapshots__/plain-theme.test.ts.snap +220 -60
- package/src/theme/chrome-vars.ts +77 -8
- package/src/theme/controls.module.css +33 -0
- package/src/theme/controls.module.css.d.ts +1 -0
- package/src/theme/index.ts +18 -5
- package/src/tokens/core.ts +4 -1
- package/src/tokens/derive.ts +32 -3
- package/src/tokens/oklab.ts +97 -0
- package/src/tokens/palette.ts +4 -0
- 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,
|
|
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
|
-
|
|
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({
|
|
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
|
|
218
|
+
background: zoneFill(zone, index, count),
|
|
172
219
|
} satisfies CSSProperties
|
|
173
220
|
}
|
|
174
221
|
|
|
175
|
-
/**
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
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
|
-
*
|
|
185
|
-
*
|
|
186
|
-
*
|
|
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
|
|
189
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
<
|
|
267
|
-
{
|
|
268
|
-
className={
|
|
269
|
-
data-meter-zone-
|
|
270
|
-
|
|
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
|
-
{
|
|
273
|
-
|
|
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
|
-
*
|
|
279
|
-
*
|
|
280
|
-
*
|
|
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
|
|
285
|
-
|
|
286
|
-
|
|
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
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
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
|
-
*
|
|
322
|
-
*
|
|
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
|
|
326
|
-
const rowRef = useRef<
|
|
327
|
-
const
|
|
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
|
-
<
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
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
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
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,
|
|
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
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
const
|
|
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
|
-
{
|
|
400
|
-
|
|
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
|
|
410
|
-
{
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
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
|
-
{
|
|
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
|
-
|
|
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
|
}
|