basalt-ui 2.18.0 → 2.19.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 +40 -0
- package/MIGRATING.md +76 -12
- package/agent/agents/basalt-design-reviewer.md +2 -2
- package/dist/commands/notifications/center.d.ts.map +1 -1
- package/dist/commands/notifications/center.js +18 -26
- package/dist/content/callout.d.ts +1 -1
- package/dist/content/callout.d.ts.map +1 -1
- package/dist/content/callout.js +10 -1
- package/dist/content/callout.module.css +15 -3
- package/dist/content/callout.module.css.d.ts +1 -0
- package/dist/dashboard/bar-list.d.ts.map +1 -1
- package/dist/dashboard/bar-list.js +31 -18
- package/dist/dashboard/bar-list.module.css +33 -15
- package/dist/dashboard/bar-list.module.css.d.ts +1 -0
- package/dist/dashboard/meter-model.d.ts +49 -1
- package/dist/dashboard/meter-model.d.ts.map +1 -1
- package/dist/dashboard/meter-model.js +47 -3
- package/dist/dashboard/meter-parts.d.ts.map +1 -1
- package/dist/dashboard/meter-parts.js +143 -9
- package/dist/dashboard/meter.d.ts +16 -5
- package/dist/dashboard/meter.d.ts.map +1 -1
- package/dist/dashboard/meter.module.css +127 -9
- package/dist/dashboard/meter.module.css.d.ts +11 -0
- package/dist/dashboard/stat-card-parts.d.ts +3 -1
- package/dist/dashboard/stat-card-parts.d.ts.map +1 -1
- package/dist/dashboard/stat-card-parts.js +18 -3
- package/dist/dashboard/stat-card.d.ts +6 -5
- package/dist/dashboard/stat-card.d.ts.map +1 -1
- package/dist/dashboard/stat-card.js +48 -77
- package/dist/dashboard/stat-card.module.css +27 -7
- package/dist/dashboard/widget-header.d.ts.map +1 -1
- package/dist/dashboard/widget-header.js +2 -1
- package/dist/dashboard/widget-header.module.css +28 -1
- package/dist/theme/chrome-vars.d.ts +29 -17
- package/dist/theme/chrome-vars.d.ts.map +1 -1
- package/dist/theme/chrome-vars.js +18 -8
- package/dist/theme/index.d.ts.map +1 -1
- package/dist/theme/index.js +9 -5
- package/dist/theme/status-dot.d.ts +6 -0
- package/dist/theme/status-dot.d.ts.map +1 -0
- package/dist/theme/status-dot.js +9 -0
- package/dist/theme/status-dot.module.css +9 -0
- package/dist/theme/status-dot.module.css.d.ts +8 -0
- package/dist/theme/status-verdict.d.ts +9 -0
- package/dist/theme/status-verdict.d.ts.map +1 -0
- package/dist/theme/status-verdict.js +13 -0
- package/dist/theme/status-verdict.module.css +23 -0
- package/dist/theme/status-verdict.module.css.d.ts +9 -0
- package/llms.txt +2 -2
- package/package.json +1 -1
- package/src/commands/notifications/center.tsx +29 -32
- package/src/content/callout.module.css +15 -3
- package/src/content/callout.module.css.d.ts +1 -0
- package/src/content/callout.tsx +15 -2
- package/src/dashboard/bar-list.module.css +33 -15
- package/src/dashboard/bar-list.module.css.d.ts +1 -0
- package/src/dashboard/bar-list.tsx +29 -16
- package/src/dashboard/meter-model.ts +97 -4
- package/src/dashboard/meter-parts.tsx +195 -11
- package/src/dashboard/meter.module.css +127 -9
- package/src/dashboard/meter.module.css.d.ts +11 -0
- package/src/dashboard/meter.tsx +16 -5
- package/src/dashboard/stat-card-parts.tsx +22 -2
- package/src/dashboard/stat-card.module.css +27 -7
- package/src/dashboard/stat-card.tsx +18 -52
- package/src/dashboard/widget-header.module.css +28 -1
- package/src/dashboard/widget-header.tsx +4 -1
- package/src/theme/__snapshots__/plain-theme.test.ts.snap +88 -16
- package/src/theme/chrome-vars.ts +48 -23
- package/src/theme/index.ts +10 -6
- package/src/theme/status-dot.module.css +9 -0
- package/src/theme/status-dot.module.css.d.ts +8 -0
- package/src/theme/status-dot.tsx +19 -0
- package/src/theme/status-verdict.module.css +23 -0
- package/src/theme/status-verdict.module.css.d.ts +9 -0
- package/src/theme/status-verdict.tsx +27 -0
|
@@ -1,15 +1,35 @@
|
|
|
1
1
|
/** Meter's internal pieces: bar, ring, empty and loading. `meter.tsx` dispatches between them. */
|
|
2
2
|
import { Skeleton, VisuallyHidden } from '@mantine/core'
|
|
3
|
-
import { useId } from 'react'
|
|
4
|
-
import type { CSSProperties, ReactNode } from 'react'
|
|
3
|
+
import { useId, useRef, useState } from 'react'
|
|
4
|
+
import type { CSSProperties, HTMLAttributes, ReactNode, RefObject } from 'react'
|
|
5
|
+
import { useIsomorphicLayoutEffect } from '../common/isomorphic-layout-effect'
|
|
5
6
|
import { cx } from '../common/props'
|
|
6
|
-
import {
|
|
7
|
-
|
|
7
|
+
import {
|
|
8
|
+
ariaValues,
|
|
9
|
+
modelBar,
|
|
10
|
+
ringFraction,
|
|
11
|
+
startCaptionText,
|
|
12
|
+
zoneBand,
|
|
13
|
+
zoneLabelsFit,
|
|
14
|
+
} from './meter-model'
|
|
15
|
+
import type { MeterSegment, MeterZone, Part, ZoneLabel } from './meter-model'
|
|
8
16
|
import classes from './meter.module.css'
|
|
9
17
|
import { toPct } from './scale'
|
|
10
18
|
|
|
11
19
|
export type Shell = { className: string | undefined; style: CSSProperties | undefined }
|
|
12
20
|
|
|
21
|
+
/**
|
|
22
|
+
* The one root contract of every Meter state. `data-basalt-meter` is the handle `StatCard` keys its
|
|
23
|
+
* visual slot on (`:has([data-basalt-meter])`), so every state must carry it.
|
|
24
|
+
*/
|
|
25
|
+
function rootProps(shell: Shell) {
|
|
26
|
+
return {
|
|
27
|
+
className: cx(classes.root, shell.className),
|
|
28
|
+
style: shell.style,
|
|
29
|
+
'data-basalt-meter': '',
|
|
30
|
+
} as const
|
|
31
|
+
}
|
|
32
|
+
|
|
13
33
|
const RING_VIEWBOX = 36
|
|
14
34
|
const RING_STROKE = 4
|
|
15
35
|
const RING_RADIUS = (RING_VIEWBOX - RING_STROKE) / 2
|
|
@@ -52,7 +72,7 @@ export function MeterLoading({
|
|
|
52
72
|
shell: Shell
|
|
53
73
|
}) {
|
|
54
74
|
return (
|
|
55
|
-
<div
|
|
75
|
+
<div {...rootProps(shell)} aria-busy="true">
|
|
56
76
|
<VisuallyHidden>{`Loading ${label}`}</VisuallyHidden>
|
|
57
77
|
{ring ? (
|
|
58
78
|
<Skeleton className={classes.skeletonRing} circle />
|
|
@@ -69,7 +89,7 @@ export function MeterLoading({
|
|
|
69
89
|
export function MeterEmpty(props: { label: string; text: string; ring: boolean; shell: Shell }) {
|
|
70
90
|
const { label, text, ring, shell } = props
|
|
71
91
|
return (
|
|
72
|
-
<output
|
|
92
|
+
<output {...rootProps(shell)} aria-label={label}>
|
|
73
93
|
{ring ? (
|
|
74
94
|
<span className={classes.ringBox}>
|
|
75
95
|
<RingSvg />
|
|
@@ -95,7 +115,7 @@ export function MeterRing(props: {
|
|
|
95
115
|
}) {
|
|
96
116
|
const { label, reading, min, max, color, format, shell } = props
|
|
97
117
|
return (
|
|
98
|
-
<div
|
|
118
|
+
<div {...rootProps(shell)}>
|
|
99
119
|
<span
|
|
100
120
|
className={classes.ringBox}
|
|
101
121
|
aria-label={label}
|
|
@@ -131,6 +151,148 @@ function zoneStyle(zone: MeterZone, index: number, count: number, min: number, s
|
|
|
131
151
|
} satisfies CSSProperties
|
|
132
152
|
}
|
|
133
153
|
|
|
154
|
+
/**
|
|
155
|
+
* Joins the names with a character no label carries, so the effect re-runs only when they change.
|
|
156
|
+
* The holding zone is part of the key: its label is bolder, so a reading that crosses a boundary
|
|
157
|
+
* changes widths with no row resize.
|
|
158
|
+
*/
|
|
159
|
+
const labelsKey = (labels: readonly ZoneLabel[]) =>
|
|
160
|
+
labels.map((l) => l.label + (l.holding ? '*' : '')).join('\u0000')
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Whether the zone names fit on the band, re-measured when the row resizes, when web fonts finish
|
|
164
|
+
* loading (a mono swap changes label widths without resizing the row) and when the names change.
|
|
165
|
+
* Server markup shows the band; the list may appear after mount, when the measurement fails.
|
|
166
|
+
*/
|
|
167
|
+
function useZoneLabelLayout(rowRef: RefObject<HTMLDivElement | null>, key: string): boolean {
|
|
168
|
+
const [fits, setFits] = useState(true)
|
|
169
|
+
|
|
170
|
+
// Keyed on a string of the names, not the `labels` array: the model rebuilds that every render.
|
|
171
|
+
useIsomorphicLayoutEffect(() => {
|
|
172
|
+
const row = rowRef.current
|
|
173
|
+
if (!row) return
|
|
174
|
+
const measure = () => {
|
|
175
|
+
const origin = row.getBoundingClientRect()
|
|
176
|
+
const boxes = [...row.children].map((c) => {
|
|
177
|
+
const r = c.getBoundingClientRect()
|
|
178
|
+
return { left: r.left - origin.left, right: r.right - origin.left }
|
|
179
|
+
})
|
|
180
|
+
setFits(zoneLabelsFit(boxes, origin.width))
|
|
181
|
+
}
|
|
182
|
+
measure()
|
|
183
|
+
const observer = typeof ResizeObserver === 'undefined' ? undefined : new ResizeObserver(measure)
|
|
184
|
+
observer?.observe(row)
|
|
185
|
+
// `document.fonts` is absent (or partial) outside a full browser; every use is guarded.
|
|
186
|
+
const fonts =
|
|
187
|
+
typeof document === 'undefined' ? undefined : (document.fonts as FontFaceSet | undefined)
|
|
188
|
+
let live = true
|
|
189
|
+
void fonts?.ready?.then(() => live && measure())
|
|
190
|
+
fonts?.addEventListener?.('loadingdone', measure)
|
|
191
|
+
return () => {
|
|
192
|
+
live = false
|
|
193
|
+
observer?.disconnect()
|
|
194
|
+
fonts?.removeEventListener?.('loadingdone', measure)
|
|
195
|
+
}
|
|
196
|
+
}, [rowRef, key])
|
|
197
|
+
|
|
198
|
+
return fits
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* The reading on a zoned track, centred on the marker so number and notch are one mark. Measured,
|
|
203
|
+
* its start edge is clamped to the row (a label wider than the row overflows the end, never the
|
|
204
|
+
* start) and placed logically, so it holds under `dir="rtl"`. Observing the label as well as the row
|
|
205
|
+
* catches a font swap that changes its width with no row resize. Until the first measure (server
|
|
206
|
+
* markup) it sits at the marker, centred by a direction-aware translate, and the row clips.
|
|
207
|
+
*/
|
|
208
|
+
function ZoneReading({ pct, children }: { pct: number; children: ReactNode }) {
|
|
209
|
+
const rowRef = useRef<HTMLDivElement>(null)
|
|
210
|
+
const textRef = useRef<HTMLSpanElement>(null)
|
|
211
|
+
const [start, setStart] = useState<number>()
|
|
212
|
+
useIsomorphicLayoutEffect(() => {
|
|
213
|
+
const row = rowRef.current
|
|
214
|
+
const text = textRef.current
|
|
215
|
+
if (!row || !text) return
|
|
216
|
+
const measure = () => {
|
|
217
|
+
const centre = (row.clientWidth * pct) / 100
|
|
218
|
+
setStart(
|
|
219
|
+
Math.max(0, Math.min(centre - text.offsetWidth / 2, row.clientWidth - text.offsetWidth)),
|
|
220
|
+
)
|
|
221
|
+
}
|
|
222
|
+
measure()
|
|
223
|
+
if (typeof ResizeObserver === 'undefined') return
|
|
224
|
+
const observer = new ResizeObserver(measure)
|
|
225
|
+
observer.observe(row)
|
|
226
|
+
observer.observe(text)
|
|
227
|
+
return () => observer.disconnect()
|
|
228
|
+
}, [pct])
|
|
229
|
+
return (
|
|
230
|
+
<div ref={rowRef} className={classes.zoneReadingRow} data-meter-reading-row>
|
|
231
|
+
<span
|
|
232
|
+
ref={textRef}
|
|
233
|
+
className={classes.zoneReading}
|
|
234
|
+
data-measured={start === undefined ? undefined : ''}
|
|
235
|
+
style={{ insetInlineStart: start === undefined ? `${pct}%` : `${start}px` }}
|
|
236
|
+
>
|
|
237
|
+
{children}
|
|
238
|
+
</span>
|
|
239
|
+
</div>
|
|
240
|
+
)
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function ZoneName({ label, ...rest }: { label: ZoneLabel } & HTMLAttributes<HTMLSpanElement>) {
|
|
244
|
+
return (
|
|
245
|
+
<span
|
|
246
|
+
{...rest}
|
|
247
|
+
className={cx(rest.className, label.holding && classes.zoneLabelHolding)}
|
|
248
|
+
data-meter-zone-label={label.label}
|
|
249
|
+
data-holding={label.holding || undefined}
|
|
250
|
+
>
|
|
251
|
+
{label.label}
|
|
252
|
+
</span>
|
|
253
|
+
)
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Names each zone under its band, the holding one in ink and a heavier weight. Labels sit
|
|
258
|
+
* left-aligned at their band start; when two would overlap (or one would leave the row) the band
|
|
259
|
+
* hides and the same names wrap as a list in zone order instead. The band stays laid out (hidden,
|
|
260
|
+
* not removed) so a resize can measure it again. Decorative: the zone names and the holding zone
|
|
261
|
+
* are in the described-by text.
|
|
262
|
+
*/
|
|
263
|
+
function ZoneLabels({ labels }: { labels: readonly ZoneLabel[] }) {
|
|
264
|
+
const rowRef = useRef<HTMLDivElement>(null)
|
|
265
|
+
const fits = useZoneLabelLayout(rowRef, labelsKey(labels))
|
|
266
|
+
|
|
267
|
+
return (
|
|
268
|
+
<>
|
|
269
|
+
<div
|
|
270
|
+
ref={rowRef}
|
|
271
|
+
className={classes.zoneBand}
|
|
272
|
+
data-meter-zone-band
|
|
273
|
+
data-collapsed={fits ? undefined : ''}
|
|
274
|
+
aria-hidden
|
|
275
|
+
>
|
|
276
|
+
{labels.map((l) => (
|
|
277
|
+
<ZoneName
|
|
278
|
+
key={l.key}
|
|
279
|
+
label={l}
|
|
280
|
+
className={classes.zoneLabel}
|
|
281
|
+
style={{ insetInlineStart: `${l.startPct}%` }}
|
|
282
|
+
/>
|
|
283
|
+
))}
|
|
284
|
+
</div>
|
|
285
|
+
{!fits && (
|
|
286
|
+
<div className={classes.zoneList} data-meter-zone-list aria-hidden>
|
|
287
|
+
{labels.map((l) => (
|
|
288
|
+
<ZoneName key={l.key} label={l} className={classes.zoneListItem} />
|
|
289
|
+
))}
|
|
290
|
+
</div>
|
|
291
|
+
)}
|
|
292
|
+
</>
|
|
293
|
+
)
|
|
294
|
+
}
|
|
295
|
+
|
|
134
296
|
export function MeterBar(props: {
|
|
135
297
|
label: string
|
|
136
298
|
reading: number
|
|
@@ -149,14 +311,17 @@ export function MeterBar(props: {
|
|
|
149
311
|
const { label, reading, min, max, format, zones, shell } = props
|
|
150
312
|
const describedId = useId()
|
|
151
313
|
const model = modelBar(props)
|
|
152
|
-
const start =
|
|
314
|
+
const start = startCaptionText(model, props.startCaption)
|
|
153
315
|
const end = props.endCaption === undefined ? model.endText : props.endCaption
|
|
154
|
-
const
|
|
316
|
+
const anchored = model.markerPct !== undefined && start !== null
|
|
317
|
+
const hasCaptions = (start !== null && !anchored) || end !== null || model.forecastText !== null
|
|
318
|
+
const hasParts = model.partCaptions.length > 0
|
|
155
319
|
const describedBy =
|
|
156
320
|
model.describedByText === null ? {} : ({ 'aria-describedby': describedId } as const)
|
|
157
321
|
|
|
322
|
+
const root = rootProps(shell)
|
|
158
323
|
return (
|
|
159
|
-
<div className={cx(
|
|
324
|
+
<div {...root} className={cx(root.className, model.zoneLabels.length > 0 && classes.zoned)}>
|
|
160
325
|
<div
|
|
161
326
|
className={classes.trackBox}
|
|
162
327
|
aria-label={label}
|
|
@@ -186,12 +351,31 @@ export function MeterBar(props: {
|
|
|
186
351
|
<Tick kind="boundary" className={classes.boundaryTick} pct={model.boundaryPct} />
|
|
187
352
|
<Tick kind="target" className={classes.tick} pct={model.targetPct} />
|
|
188
353
|
</div>
|
|
354
|
+
{model.zoneLabels.length > 0 && <ZoneLabels labels={model.zoneLabels} />}
|
|
355
|
+
{anchored && <ZoneReading pct={model.markerPct ?? 0}>{start}</ZoneReading>}
|
|
189
356
|
{model.describedByText !== null && (
|
|
190
357
|
<VisuallyHidden id={describedId}>{model.describedByText}</VisuallyHidden>
|
|
191
358
|
)}
|
|
359
|
+
{hasParts && (
|
|
360
|
+
// The explicit role is deliberate: `list-style: none` makes Safari/VoiceOver drop the implicit one.
|
|
361
|
+
// oxlint-disable-next-line jsx-a11y/no-redundant-roles
|
|
362
|
+
<ul className={classes.partCaptions} role="list" data-meter-parts>
|
|
363
|
+
{model.partCaptions.map((c) => (
|
|
364
|
+
<li key={c.key} className={classes.partCaption}>
|
|
365
|
+
<span
|
|
366
|
+
className={classes.swatch}
|
|
367
|
+
// theme-allow hidden-inline-style — the swatch repeats the part's fill colour (data)
|
|
368
|
+
style={{ background: c.color ?? 'var(--vx-line)' }}
|
|
369
|
+
aria-hidden
|
|
370
|
+
/>
|
|
371
|
+
{c.label} {c.text}
|
|
372
|
+
</li>
|
|
373
|
+
))}
|
|
374
|
+
</ul>
|
|
375
|
+
)}
|
|
192
376
|
{hasCaptions && (
|
|
193
377
|
<div className={classes.captions} data-meter-captions>
|
|
194
|
-
{start !== null && <span className={classes.caption}>{start}</span>}
|
|
378
|
+
{start !== null && !anchored && <span className={classes.caption}>{start}</span>}
|
|
195
379
|
{model.forecastText !== null && (
|
|
196
380
|
<span className={classes.caption}>{model.forecastText}</span>
|
|
197
381
|
)}
|
|
@@ -11,6 +11,10 @@
|
|
|
11
11
|
min-width: 0;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
.root.zoned {
|
|
15
|
+
position: relative;
|
|
16
|
+
}
|
|
17
|
+
|
|
14
18
|
.track {
|
|
15
19
|
position: relative;
|
|
16
20
|
display: flex;
|
|
@@ -41,6 +45,86 @@
|
|
|
41
45
|
inset-block: 0;
|
|
42
46
|
}
|
|
43
47
|
|
|
48
|
+
/*
|
|
49
|
+
* Zone names under the band: absolutely placed at each band start so they stay on the band. When
|
|
50
|
+
* they would collide the band collapses (hidden but still laid out, so it can be re-measured) and the
|
|
51
|
+
* same names wrap as a list. The holding zone is ink, the rest muted.
|
|
52
|
+
*/
|
|
53
|
+
.zoneBand {
|
|
54
|
+
position: relative;
|
|
55
|
+
/* Labels are absolutely placed, so the row needs its own line height. */
|
|
56
|
+
height: 1.25em;
|
|
57
|
+
font-family: var(--basalt-font-mono);
|
|
58
|
+
font-size: var(--vx-text-micro);
|
|
59
|
+
color: var(--vx-muted);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/*
|
|
63
|
+
* Hidden but laid out, so a resize can measure it again. Absolute against `.root.zoned`, which has
|
|
64
|
+
* no inline padding, so `inset-inline: 0` gives the band the same width as when it was in flow.
|
|
65
|
+
*/
|
|
66
|
+
.zoneBand[data-collapsed] {
|
|
67
|
+
position: absolute;
|
|
68
|
+
top: 0;
|
|
69
|
+
inset-inline: 0;
|
|
70
|
+
visibility: hidden;
|
|
71
|
+
pointer-events: none;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.zoneLabel {
|
|
75
|
+
position: absolute;
|
|
76
|
+
top: 0;
|
|
77
|
+
white-space: nowrap;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
.zoneLabelHolding {
|
|
81
|
+
font-weight: 500;
|
|
82
|
+
color: var(--vx-ink);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
.zoneList {
|
|
86
|
+
display: flex;
|
|
87
|
+
flex-wrap: wrap;
|
|
88
|
+
gap: var(--vx-space-stack-xs) var(--vx-space-stack-sm);
|
|
89
|
+
font-family: var(--basalt-font-mono);
|
|
90
|
+
font-size: var(--vx-text-micro);
|
|
91
|
+
color: var(--vx-muted);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
.zoneListItem {
|
|
95
|
+
min-width: 0;
|
|
96
|
+
overflow-wrap: anywhere;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/* The reading under the band, centred on the marker. Clipped so it never widens the row before the first measure. */
|
|
100
|
+
.zoneReadingRow {
|
|
101
|
+
--basalt-reading-dir: 1;
|
|
102
|
+
position: relative;
|
|
103
|
+
height: 1.25em;
|
|
104
|
+
overflow: clip;
|
|
105
|
+
font-family: var(--basalt-font-mono);
|
|
106
|
+
font-size: var(--vx-text-micro);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
.zoneReadingRow:dir(rtl) {
|
|
110
|
+
--basalt-reading-dir: -1;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/* Before the first measure the start edge sits AT the marker, so the label shifts back half its width
|
|
114
|
+
* along the inline axis (the physical `translate` flips sign in RTL). Measured, the start edge is exact. */
|
|
115
|
+
.zoneReading {
|
|
116
|
+
position: absolute;
|
|
117
|
+
top: 0;
|
|
118
|
+
translate: calc(-50% * var(--basalt-reading-dir)) 0;
|
|
119
|
+
white-space: nowrap;
|
|
120
|
+
font-weight: 500;
|
|
121
|
+
color: var(--vx-ink);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
.zoneReading[data-measured] {
|
|
125
|
+
translate: none;
|
|
126
|
+
}
|
|
127
|
+
|
|
44
128
|
/* The reading on a zone track: a notch standing proud of the bands, in ink. */
|
|
45
129
|
.marker {
|
|
46
130
|
position: absolute;
|
|
@@ -48,7 +132,7 @@
|
|
|
48
132
|
bottom: -3px;
|
|
49
133
|
width: 3px;
|
|
50
134
|
margin-inline-start: -1.5px;
|
|
51
|
-
border-radius:
|
|
135
|
+
border-radius: var(--vx-radius-fine);
|
|
52
136
|
background: var(--vx-ink);
|
|
53
137
|
}
|
|
54
138
|
|
|
@@ -58,7 +142,7 @@
|
|
|
58
142
|
bottom: -2px;
|
|
59
143
|
width: 2px;
|
|
60
144
|
margin-inline-start: -1px;
|
|
61
|
-
border-radius:
|
|
145
|
+
border-radius: var(--vx-radius-fine);
|
|
62
146
|
background: var(--vx-ink);
|
|
63
147
|
}
|
|
64
148
|
|
|
@@ -69,6 +153,7 @@
|
|
|
69
153
|
|
|
70
154
|
.captions {
|
|
71
155
|
display: flex;
|
|
156
|
+
flex-wrap: wrap;
|
|
72
157
|
align-items: baseline;
|
|
73
158
|
justify-content: space-between;
|
|
74
159
|
gap: var(--vx-space-control-gap, 0.375rem);
|
|
@@ -77,18 +162,46 @@
|
|
|
77
162
|
color: var(--vx-muted);
|
|
78
163
|
}
|
|
79
164
|
|
|
165
|
+
/* Captions never truncate: the row wraps, and a caption wider than the row wraps inside itself. */
|
|
80
166
|
.caption {
|
|
81
|
-
|
|
167
|
+
min-width: 0;
|
|
168
|
+
overflow-wrap: anywhere;
|
|
82
169
|
}
|
|
83
170
|
|
|
171
|
+
/* Alone in the row, or wrapped onto its own line, the end caption still sits at the end. */
|
|
84
172
|
.captionEnd {
|
|
85
173
|
composes: caption;
|
|
174
|
+
margin-inline-start: auto;
|
|
86
175
|
text-align: end;
|
|
87
176
|
}
|
|
88
177
|
|
|
89
|
-
/*
|
|
90
|
-
.
|
|
91
|
-
|
|
178
|
+
/* Categorical segments: one caption per part under the track, wrapping at narrow widths. */
|
|
179
|
+
.partCaptions {
|
|
180
|
+
display: flex;
|
|
181
|
+
flex-wrap: wrap;
|
|
182
|
+
gap: var(--vx-space-stack-xs, 0.25rem) var(--vx-space-stack-sm);
|
|
183
|
+
margin: 0;
|
|
184
|
+
padding: 0;
|
|
185
|
+
list-style: none;
|
|
186
|
+
font-family: var(--basalt-font-mono);
|
|
187
|
+
font-size: var(--vx-text-micro);
|
|
188
|
+
color: var(--vx-muted);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
.partCaption {
|
|
192
|
+
display: inline-flex;
|
|
193
|
+
align-items: baseline;
|
|
194
|
+
gap: var(--vx-space-control-gap, 0.375rem);
|
|
195
|
+
min-width: 0;
|
|
196
|
+
overflow-wrap: anywhere;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/* A shape cue beside the name, so the part never reads by colour alone. */
|
|
200
|
+
.swatch {
|
|
201
|
+
flex: none;
|
|
202
|
+
width: 0.5rem;
|
|
203
|
+
height: 0.5rem;
|
|
204
|
+
border-radius: var(--vx-radius-fine);
|
|
92
205
|
}
|
|
93
206
|
|
|
94
207
|
.empty {
|
|
@@ -114,8 +227,13 @@
|
|
|
114
227
|
align-items: center;
|
|
115
228
|
justify-content: center;
|
|
116
229
|
align-self: flex-start;
|
|
117
|
-
|
|
118
|
-
|
|
230
|
+
box-sizing: border-box;
|
|
231
|
+
/* 80px, growing (still square) when the value is wider than the ring's inner circle. */
|
|
232
|
+
min-width: 5rem;
|
|
233
|
+
width: max-content;
|
|
234
|
+
aspect-ratio: 1;
|
|
235
|
+
/* 12px at the default step: keeps the value inside the ring's stroke. */
|
|
236
|
+
padding: calc(1.5 * var(--vx-space-stack-sm, 0.5rem));
|
|
119
237
|
}
|
|
120
238
|
|
|
121
239
|
.ring {
|
|
@@ -139,7 +257,7 @@
|
|
|
139
257
|
.ringValue {
|
|
140
258
|
position: relative;
|
|
141
259
|
font-family: var(--basalt-font-mono);
|
|
142
|
-
font-size: var(--vx-text-
|
|
260
|
+
font-size: var(--vx-text-kpi);
|
|
143
261
|
font-weight: 500;
|
|
144
262
|
color: var(--vx-ink);
|
|
145
263
|
}
|
|
@@ -4,17 +4,28 @@
|
|
|
4
4
|
*/
|
|
5
5
|
declare const classes: {
|
|
6
6
|
readonly root: string
|
|
7
|
+
readonly zoned: string
|
|
7
8
|
readonly track: string
|
|
8
9
|
readonly trackBox: string
|
|
9
10
|
readonly fill: string
|
|
10
11
|
readonly forecastFill: string
|
|
11
12
|
readonly zone: string
|
|
13
|
+
readonly zoneBand: string
|
|
14
|
+
readonly zoneLabel: string
|
|
15
|
+
readonly zoneLabelHolding: string
|
|
16
|
+
readonly zoneList: string
|
|
17
|
+
readonly zoneListItem: string
|
|
18
|
+
readonly zoneReadingRow: string
|
|
19
|
+
readonly zoneReading: string
|
|
12
20
|
readonly marker: string
|
|
13
21
|
readonly tick: string
|
|
14
22
|
readonly boundaryTick: string
|
|
15
23
|
readonly captions: string
|
|
16
24
|
readonly caption: string
|
|
17
25
|
readonly captionEnd: string
|
|
26
|
+
readonly partCaptions: string
|
|
27
|
+
readonly partCaption: string
|
|
28
|
+
readonly swatch: string
|
|
18
29
|
readonly empty: string
|
|
19
30
|
readonly skeletonTrack: string
|
|
20
31
|
readonly skeletonCaption: string
|
package/src/dashboard/meter.tsx
CHANGED
|
@@ -11,15 +11,26 @@
|
|
|
11
11
|
* track end; the caption still states the real value.
|
|
12
12
|
*
|
|
13
13
|
* `zones` (bar only) draws the track as contiguous bands (neutral at stepped strengths unless a zone
|
|
14
|
-
* passes a status colour) and the reading becomes a MARKER on the track, not a fill
|
|
15
|
-
* the
|
|
14
|
+
* passes a status colour) and the reading becomes a MARKER on the track, not a fill. Each zone is
|
|
15
|
+
* named under the band at its start, the one holding the value (`from` inclusive) in ink and a
|
|
16
|
+
* heavier weight; names that would collide wrap as a list instead. The fit is measured in the
|
|
17
|
+
* browser, so server markup shows the band and the list may appear after mount. Use it for a
|
|
18
|
+
* reading judged against ranges.
|
|
19
|
+
*
|
|
20
|
+
* Every state (bar, ring, empty, loading) carries `data-basalt-meter` on its root. That attribute is
|
|
21
|
+
* the contract with `StatCard`: a Meter passed as its `sparkline` visual makes the slot size to content
|
|
22
|
+
* and keep the card's inline inset (both placements) instead of the sparkline's fixed height and bleed.
|
|
23
|
+
*
|
|
24
|
+
* Categorical `segments` (no `forecast` part) are captioned one per part — swatch, name, value — under
|
|
25
|
+
* the track and the default start caption is dropped (an explicit `startCaption` still shows);
|
|
26
|
+
* committed/forecast keeps the reading plus the forecast caption.
|
|
16
27
|
*
|
|
17
28
|
* @example
|
|
18
29
|
* import { Meter } from 'basalt-ui'
|
|
19
30
|
*
|
|
20
31
|
* // Spend against a budget: past the target the end caption states the overage.
|
|
21
32
|
* <Meter label="Monthly spend" value={512} max={600} target={450} color="var(--vx-status-bad)" format={usd} />
|
|
22
|
-
* // Training load as a zone band with a marker:
|
|
33
|
+
* // Training load as a zone band with a marker: the zones are named under the band, "Optimal" in ink.
|
|
23
34
|
* <Meter
|
|
24
35
|
* label="Training load"
|
|
25
36
|
* max={1000}
|
|
@@ -65,7 +76,7 @@ type BarCommon = Common & {
|
|
|
65
76
|
shape?: 'bar'
|
|
66
77
|
/** Target position; draws a tick and states it in the end caption (with the overage past it). */
|
|
67
78
|
target?: number
|
|
68
|
-
/** Start caption (default: the formatted reading
|
|
79
|
+
/** Start caption (default: the formatted reading). `null` drops it. */
|
|
69
80
|
startCaption?: ReactNode
|
|
70
81
|
/** End caption (default: `Target <target>`). `null` drops it. */
|
|
71
82
|
endCaption?: ReactNode
|
|
@@ -100,7 +111,7 @@ export type MeterProps =
|
|
|
100
111
|
value?: number | null | undefined
|
|
101
112
|
/**
|
|
102
113
|
* Contiguous bands drawn as the track, positioned from each `from`. The reading becomes a marker
|
|
103
|
-
* and
|
|
114
|
+
* and each band is named under the track, the one that holds it in ink.
|
|
104
115
|
*/
|
|
105
116
|
zones: readonly MeterZone[]
|
|
106
117
|
segments?: never
|
|
@@ -7,6 +7,9 @@ import { Skeleton } from '@mantine/core'
|
|
|
7
7
|
import type { CSSProperties, ReactNode } from 'react'
|
|
8
8
|
import { IconSlot } from '../theme/icon-slot'
|
|
9
9
|
import { CtlSlot } from '../theme'
|
|
10
|
+
import { StatusVerdict } from '../theme/status-verdict'
|
|
11
|
+
import { VX } from '../tokens'
|
|
12
|
+
import type { Tone } from '../common/props'
|
|
10
13
|
import { InfoGlyph } from './widget-header'
|
|
11
14
|
import classes from './stat-card.module.css'
|
|
12
15
|
|
|
@@ -15,25 +18,42 @@ export type CaptionRowProps = {
|
|
|
15
18
|
icon?: ReactNode
|
|
16
19
|
info?: string
|
|
17
20
|
qualifier?: string
|
|
21
|
+
tone?: Tone
|
|
18
22
|
actions?: ReactNode
|
|
19
23
|
}
|
|
20
24
|
|
|
25
|
+
/** Visible verdict word, and the full phrase a screen reader hears instead of a bare "Over". */
|
|
26
|
+
const TONE_WORD: Record<Tone, { word: string; phrase: string }> = {
|
|
27
|
+
good: { word: 'OK', phrase: 'Within the good threshold' },
|
|
28
|
+
warn: { word: 'Watch', phrase: 'Past the warning threshold' },
|
|
29
|
+
bad: { word: 'Over', phrase: 'Past the severe threshold' },
|
|
30
|
+
}
|
|
31
|
+
|
|
21
32
|
/**
|
|
22
33
|
* Title, `info` glyph and `qualifier` in one wrapping group, `actions` pinned at the end. When
|
|
23
34
|
* caption + info + qualifier do not fit, the qualifier wraps UNDER the caption instead of truncating
|
|
24
35
|
* either: the container's width decides, never the viewport's.
|
|
25
36
|
*/
|
|
26
|
-
export function CaptionRow({ title, icon, info, qualifier, actions }: CaptionRowProps) {
|
|
37
|
+
export function CaptionRow({ title, icon, info, qualifier, tone, actions }: CaptionRowProps) {
|
|
27
38
|
return (
|
|
28
39
|
<div className={classes.captionRow}>
|
|
29
40
|
<div className={classes.captionMain}>
|
|
30
41
|
<div className={classes.lead}>
|
|
31
42
|
<h3 className={classes.caption}>
|
|
32
43
|
{icon !== undefined && <IconSlot className={classes.icon}>{icon}</IconSlot>}
|
|
33
|
-
<span className={classes.captionText}
|
|
44
|
+
<span className={classes.captionText} data-widget-title>
|
|
45
|
+
{title}
|
|
46
|
+
</span>
|
|
34
47
|
</h3>
|
|
35
48
|
{/* OUTSIDE the heading on purpose: `info` would otherwise become part of its name. */}
|
|
36
49
|
{info !== undefined && <InfoGlyph text={info} />}
|
|
50
|
+
{tone !== undefined && (
|
|
51
|
+
<StatusVerdict
|
|
52
|
+
color={VX.status[tone]}
|
|
53
|
+
word={TONE_WORD[tone].word}
|
|
54
|
+
phrase={TONE_WORD[tone].phrase}
|
|
55
|
+
/>
|
|
56
|
+
)}
|
|
37
57
|
</div>
|
|
38
58
|
{qualifier !== undefined && <span className={classes.qualifier}>{qualifier}</span>}
|
|
39
59
|
</div>
|
|
@@ -173,15 +173,15 @@
|
|
|
173
173
|
height: var(--basalt-stat-figure-h);
|
|
174
174
|
}
|
|
175
175
|
|
|
176
|
+
/* Inset on both sides, unlike the sparkline at rest (which bleeds): a placeholder that touches one
|
|
177
|
+
* card edge and stops short of the other reads as misaligned, and a Meter in the slot is inset anyway. */
|
|
176
178
|
.skeletonVisual {
|
|
177
179
|
--skeleton-radius: 0;
|
|
178
180
|
height: var(--basalt-stat-visual-h);
|
|
179
|
-
margin-inline: calc(-1 * var(--vx-space-card-inset-x, 1rem));
|
|
180
181
|
}
|
|
181
182
|
|
|
182
183
|
.sparklineRight .skeletonVisual {
|
|
183
184
|
flex: 1 1 auto;
|
|
184
|
-
margin-inline: 0;
|
|
185
185
|
}
|
|
186
186
|
|
|
187
187
|
.skeletonRowBox {
|
|
@@ -318,11 +318,11 @@
|
|
|
318
318
|
}
|
|
319
319
|
|
|
320
320
|
/*
|
|
321
|
-
* A row past a threshold. Same vocabulary and the same per-scheme solids as the card's own tone
|
|
322
|
-
* (`
|
|
323
|
-
*
|
|
324
|
-
*
|
|
325
|
-
*
|
|
321
|
+
* A row past a threshold. Same vocabulary and the same per-scheme solids as the card's own tone dot
|
|
322
|
+
* (`VX.status[tone]`), so a row saying `bad` and a dot saying `bad` are one claim at two scales.
|
|
323
|
+
* Colour is not the only carrier at the CARD level (the dot ships a word); at
|
|
324
|
+
* the ROW level the label is the carrier — a row reading `Paid · 1,204` states its own subject
|
|
325
|
+
* either way, and the tint only ranks it.
|
|
326
326
|
*/
|
|
327
327
|
.breakdownRow[data-tone='good'] .breakdownValue {
|
|
328
328
|
color: var(--vx-status-good);
|
|
@@ -341,6 +341,22 @@
|
|
|
341
341
|
margin-inline: calc(-1 * var(--vx-space-card-inset-x, 1rem));
|
|
342
342
|
}
|
|
343
343
|
|
|
344
|
+
/* A Meter in the visual slot is a block, not a chart: it sizes to its content and keeps the card's
|
|
345
|
+
* inline inset instead of the sparkline's fixed 22px and side bleed. */
|
|
346
|
+
.sparklineBleed:has(> [data-basalt-meter]) {
|
|
347
|
+
height: auto;
|
|
348
|
+
margin-inline: 0;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/* The `right` placement: the fixed basis, 22px height and clip are a sparkline's box. A Meter takes the
|
|
352
|
+
* row's remaining width and its own height, unclipped. */
|
|
353
|
+
.sparklineRight:has(> [data-basalt-meter]) {
|
|
354
|
+
flex: 1 1 auto;
|
|
355
|
+
height: auto;
|
|
356
|
+
overflow: visible;
|
|
357
|
+
align-items: stretch;
|
|
358
|
+
}
|
|
359
|
+
|
|
344
360
|
/* Asks for `StatCard`'s `SPARKLINE_RIGHT_WIDTH`/`_HEIGHT` (handed down as custom properties, so this
|
|
345
361
|
* rule and the narrow-card reset below can both reach them). `align-self: flex-end` is the one alignment
|
|
346
362
|
* this restructure keeps at the SPARKLINE's own level rather than the row's: `.metricsRow` does not
|
|
@@ -375,4 +391,8 @@
|
|
|
375
391
|
margin-top: auto;
|
|
376
392
|
margin-inline: calc(-1 * var(--vx-space-card-inset-x, 1rem));
|
|
377
393
|
}
|
|
394
|
+
|
|
395
|
+
.metricsRow .sparklineRight:has(> [data-basalt-meter], > .skeletonVisual) {
|
|
396
|
+
margin-inline: 0;
|
|
397
|
+
}
|
|
378
398
|
}
|