basalt-ui 2.25.0 → 2.27.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 +57 -0
- package/MIGRATING.md +227 -19
- package/configs/oxlint-basalt.json +1 -1
- package/configs/oxlint-plugin.js +3 -9
- package/configs/oxlint-plugin.test.ts +6 -0
- package/dist/charts/Bars.d.ts.map +1 -1
- package/dist/charts/Bars.js +37 -1
- package/dist/charts/ChartCard.d.ts +13 -5
- package/dist/charts/ChartCard.d.ts.map +1 -1
- package/dist/charts/ChartCard.js +12 -2
- package/dist/charts/Sparkline.d.ts.map +1 -1
- package/dist/charts/Sparkline.js +106 -10
- package/dist/charts/chart-box.module.css +123 -5
- package/dist/charts/chart-box.module.css.d.ts +3 -0
- package/dist/charts/chart-card.module.css +34 -0
- package/dist/charts/chart-card.module.css.d.ts +2 -0
- package/dist/charts/chart-legend.module.css +1 -16
- package/dist/charts/compile.d.ts +20 -0
- package/dist/charts/compile.d.ts.map +1 -1
- package/dist/charts/compile.js +99 -3
- package/dist/charts/legend.d.ts.map +1 -1
- package/dist/charts/legend.js +54 -71
- package/dist/charts/sparkline.module.css +13 -9
- package/dist/charts/state.d.ts +7 -0
- package/dist/charts/state.d.ts.map +1 -1
- package/dist/charts/state.js +17 -1
- package/dist/cli/shot/capture.d.ts +32 -3
- package/dist/cli/shot/capture.d.ts.map +1 -1
- package/dist/cli/shot/capture.js +17 -7
- package/dist/dashboard/meter-model.d.ts +19 -3
- package/dist/dashboard/meter-model.d.ts.map +1 -1
- package/dist/dashboard/meter-model.js +155 -13
- package/dist/dashboard/meter-parts.d.ts +4 -7
- package/dist/dashboard/meter-parts.d.ts.map +1 -1
- package/dist/dashboard/meter-parts.js +130 -90
- package/dist/dashboard/meter.d.ts +1 -1
- package/dist/dashboard/meter.d.ts.map +1 -1
- package/dist/dashboard/meter.js +10 -7
- package/dist/dashboard/meter.module.css +55 -13
- package/dist/dashboard/meter.module.css.d.ts +1 -2
- package/dist/dashboard/section.d.ts +1 -2
- package/dist/dashboard/section.d.ts.map +1 -1
- package/dist/dashboard/section.module.css +8 -7
- package/dist/dashboard/stat-card.module.css +17 -0
- package/dist/dashboard/stat-strip.d.ts +9 -1
- package/dist/dashboard/stat-strip.d.ts.map +1 -1
- package/dist/dashboard/stat-strip.js +121 -27
- package/dist/dashboard/stat-strip.module.css +51 -3
- package/dist/dashboard/stat-strip.module.css.d.ts +4 -0
- package/dist/dashboard/visual-slot.d.ts +4 -0
- package/dist/dashboard/visual-slot.d.ts.map +1 -1
- package/dist/dashboard/visual-slot.js +2 -0
- package/dist/dashboard/widget-header.module.css +9 -0
- package/llms.txt +3 -2
- package/package.json +1 -1
- package/src/charts/Bars.tsx +50 -2
- package/src/charts/ChartCard.tsx +32 -5
- package/src/charts/Sparkline.tsx +166 -13
- package/src/charts/chart-box.module.css +123 -5
- package/src/charts/chart-box.module.css.d.ts +3 -0
- package/src/charts/chart-card.module.css +34 -0
- package/src/charts/chart-card.module.css.d.ts +2 -0
- package/src/charts/chart-legend.module.css +1 -16
- package/src/charts/compile.ts +153 -3
- package/src/charts/legend.tsx +33 -49
- package/src/charts/sparkline.module.css +13 -9
- package/src/charts/state.tsx +43 -1
- package/src/cli/shot/capture.ts +25 -9
- package/src/dashboard/meter-model.ts +248 -22
- package/src/dashboard/meter-parts.tsx +124 -69
- package/src/dashboard/meter.module.css +55 -13
- package/src/dashboard/meter.module.css.d.ts +1 -2
- package/src/dashboard/meter.tsx +22 -9
- package/src/dashboard/section.module.css +8 -7
- package/src/dashboard/section.tsx +1 -2
- package/src/dashboard/stat-card.module.css +17 -0
- package/src/dashboard/stat-strip.module.css +51 -3
- package/src/dashboard/stat-strip.module.css.d.ts +4 -0
- package/src/dashboard/stat-strip.tsx +162 -33
- package/src/dashboard/visual-slot.ts +5 -0
- package/src/dashboard/widget-header.module.css +9 -0
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
zoneFill,
|
|
19
19
|
} from './meter-model'
|
|
20
20
|
import type {
|
|
21
|
+
LabelBox,
|
|
21
22
|
MarkItem,
|
|
22
23
|
MeterSegment,
|
|
23
24
|
MeterTick,
|
|
@@ -139,39 +140,12 @@ function Line({ zoned, children }: { zoned: boolean; children?: ReactNode }) {
|
|
|
139
140
|
)
|
|
140
141
|
}
|
|
141
142
|
|
|
142
|
-
/**
|
|
143
|
-
|
|
144
|
-
* zone-name row below, a plain bar the caption row below, so the card does not jump when data lands.
|
|
145
|
-
*/
|
|
146
|
-
export function MeterLoading({
|
|
147
|
-
label,
|
|
148
|
-
ring,
|
|
149
|
-
zoned,
|
|
150
|
-
shell,
|
|
151
|
-
}: {
|
|
152
|
-
label: string
|
|
153
|
-
ring: boolean
|
|
154
|
-
zoned: boolean
|
|
155
|
-
shell: Shell
|
|
156
|
-
}) {
|
|
143
|
+
/** The ring's loading state: one skeleton disc at the ring's size. A bar loads through `MeterBar`. */
|
|
144
|
+
export function MeterRingLoading({ label, shell }: { label: string; shell: Shell }) {
|
|
157
145
|
return (
|
|
158
146
|
<div {...rootProps(shell)} aria-busy="true">
|
|
159
147
|
<VisuallyHidden className={classes.summary}>{`Loading ${label}`}</VisuallyHidden>
|
|
160
|
-
{
|
|
161
|
-
<Skeleton className={classes.skeletonRing} circle />
|
|
162
|
-
) : (
|
|
163
|
-
<>
|
|
164
|
-
{zoned && (
|
|
165
|
-
<Line zoned={zoned}>
|
|
166
|
-
<Skeleton className={classes.skeletonCaption} radius="sm" />
|
|
167
|
-
</Line>
|
|
168
|
-
)}
|
|
169
|
-
<Skeleton className={classes.skeletonTrack} />
|
|
170
|
-
<Line zoned={zoned}>
|
|
171
|
-
<Skeleton className={classes.skeletonCaption} radius="sm" />
|
|
172
|
-
</Line>
|
|
173
|
-
</>
|
|
174
|
-
)}
|
|
148
|
+
<Skeleton className={classes.skeletonRing} circle />
|
|
175
149
|
</div>
|
|
176
150
|
)
|
|
177
151
|
}
|
|
@@ -273,13 +247,22 @@ function zoneStyle(zone: MeterZone, index: number, count: number, min: number, s
|
|
|
273
247
|
const columnGapOf = (el: Element): number => Number.parseFloat(getComputedStyle(el).columnGap) || 0
|
|
274
248
|
|
|
275
249
|
/** One label on the row: its span in percent of the row (a zone name) or none (an end tick). */
|
|
276
|
-
type RowSlot = {
|
|
250
|
+
type RowSlot = {
|
|
251
|
+
spanPct?: readonly [number, number]
|
|
252
|
+
holding?: boolean
|
|
253
|
+
end?: boolean
|
|
254
|
+
figure?: boolean
|
|
255
|
+
}
|
|
277
256
|
|
|
278
|
-
type RowLayout = { shown: boolean[]; short: boolean[]; shift: number[] }
|
|
257
|
+
type RowLayout = { shown: boolean[]; short: boolean[]; shift: number[]; row: (0 | 1)[] }
|
|
279
258
|
const sameLayout = (a: RowLayout, b: RowLayout) =>
|
|
280
259
|
a.shown.length === b.shown.length &&
|
|
281
260
|
a.shown.every(
|
|
282
|
-
(v, i) =>
|
|
261
|
+
(v, i) =>
|
|
262
|
+
v === b.shown[i] &&
|
|
263
|
+
a.short[i] === b.short[i] &&
|
|
264
|
+
a.shift[i] === b.shift[i] &&
|
|
265
|
+
a.row[i] === b.row[i],
|
|
283
266
|
)
|
|
284
267
|
|
|
285
268
|
/**
|
|
@@ -295,7 +278,7 @@ function useRowLabelLayout(
|
|
|
295
278
|
shortOf: readonly number[],
|
|
296
279
|
key: string,
|
|
297
280
|
): RowLayout {
|
|
298
|
-
const [layout, setLayout] = useState<RowLayout>({ shown: [], short: [], shift: [] })
|
|
281
|
+
const [layout, setLayout] = useState<RowLayout>({ shown: [], short: [], shift: [], row: [] })
|
|
299
282
|
const slotsRef = useRef(slots)
|
|
300
283
|
const shortOfRef = useRef(shortOf)
|
|
301
284
|
// Declared before the measuring effect so it reads this render's slots.
|
|
@@ -313,30 +296,41 @@ function useRowLabelLayout(
|
|
|
313
296
|
const rtl = getComputedStyle(row).direction === 'rtl'
|
|
314
297
|
const edge = (pct: number) => (origin.width * (rtl ? 100 - pct : pct)) / 100
|
|
315
298
|
const children = [...row.children]
|
|
316
|
-
|
|
299
|
+
// A label's natural box: the physical offset a previous placement applied (`--basalt-nudge`) is
|
|
300
|
+
// taken back out, so a re-measure (a resize, a font swap, the second row changing the height)
|
|
301
|
+
// never compounds it.
|
|
302
|
+
const naturalBox = (c: Element): LabelBox => {
|
|
317
303
|
const r = c.getBoundingClientRect()
|
|
304
|
+
const by =
|
|
305
|
+
Number.parseFloat((c as HTMLElement).style.getPropertyValue('--basalt-nudge')) || 0
|
|
306
|
+
return { left: r.left - origin.left - by, right: r.right - origin.left - by }
|
|
307
|
+
}
|
|
308
|
+
const labels: RowLabel[] = children.slice(0, slotsRef.current.length).map((c, i) => {
|
|
318
309
|
const slot = slotsRef.current[i]
|
|
319
310
|
const pct = slot?.spanPct
|
|
320
311
|
const [a, b] = pct ? [edge(pct[0]), edge(pct[1])] : []
|
|
321
312
|
return {
|
|
322
|
-
box:
|
|
313
|
+
box: naturalBox(c),
|
|
323
314
|
...(a !== undefined &&
|
|
324
315
|
b !== undefined && { span: { left: Math.min(a, b), right: Math.max(a, b) } }),
|
|
325
316
|
...(slot?.holding && { holding: true }),
|
|
326
317
|
...(slot?.end && { end: true }),
|
|
318
|
+
...(slot?.figure && { figure: true }),
|
|
327
319
|
}
|
|
328
320
|
})
|
|
329
321
|
shortOfRef.current.forEach((labelIndex, n) => {
|
|
330
|
-
const
|
|
322
|
+
const twin = children[slotsRef.current.length + n]
|
|
331
323
|
const label = labels[labelIndex]
|
|
332
|
-
if (
|
|
324
|
+
if (twin && label) label.short = naturalBox(twin)
|
|
333
325
|
})
|
|
334
326
|
const placed = placeRowLabels(labels, origin.width, columnGapOf(row))
|
|
335
|
-
//
|
|
327
|
+
// Measured and applied on the physical x axis (`--basalt-nudge` is a physical `translate`), so
|
|
328
|
+
// it needs no flip under `dir="rtl"`.
|
|
336
329
|
const next = {
|
|
337
330
|
shown: placed.shown,
|
|
338
331
|
short: placed.short,
|
|
339
|
-
shift: placed.shift
|
|
332
|
+
shift: placed.shift,
|
|
333
|
+
row: placed.row,
|
|
340
334
|
}
|
|
341
335
|
setLayout((prev) => (sameLayout(prev, next) ? prev : next))
|
|
342
336
|
}
|
|
@@ -405,15 +399,20 @@ function ZoneReading({ pct, children }: { pct: number; children: ReactNode }) {
|
|
|
405
399
|
const TICK_LABEL_FLIP_PCT = 50
|
|
406
400
|
|
|
407
401
|
/**
|
|
408
|
-
* The
|
|
409
|
-
* marks (the end ticks sit at the row's ends), all on one baseline. A
|
|
410
|
-
*
|
|
411
|
-
*
|
|
402
|
+
* The label row: each zone name centred under its own span and the labelled ticks hugging their
|
|
403
|
+
* marks (the end ticks sit at the row's ends), all on one baseline. A label that cannot hold its place
|
|
404
|
+
* there stands on a second row directly under it, only while one needs it; it hides (still laid out,
|
|
405
|
+
* so a resize can measure it again, and named in the described-by text) when neither row holds it.
|
|
406
|
+
* The holding zone is ink and heavier. Decorative.
|
|
412
407
|
*/
|
|
413
408
|
function LabelRow({ zones, ticks }: { zones: readonly ZoneLabel[]; ticks: readonly TickMark[] }) {
|
|
414
409
|
const rowRef = useRef<HTMLDivElement>(null)
|
|
415
410
|
const slots: RowSlot[] = [
|
|
416
|
-
|
|
411
|
+
// The scale's own start figure (key `start`) drops before it wraps: it never takes the second row.
|
|
412
|
+
...ticks.map((t): RowSlot => ({
|
|
413
|
+
...(t.pct <= 0 || t.pct >= 100 ? { end: true } : {}),
|
|
414
|
+
...(t.key === 'start' && { figure: true }),
|
|
415
|
+
})),
|
|
417
416
|
...zones.map((z): RowSlot => ({
|
|
418
417
|
spanPct: [z.centrePct - z.widthPct / 2, z.centrePct + z.widthPct / 2],
|
|
419
418
|
holding: z.holding,
|
|
@@ -425,19 +424,24 @@ function LabelRow({ zones, ticks }: { zones: readonly ZoneLabel[]; ticks: readon
|
|
|
425
424
|
].join('\u0000')
|
|
426
425
|
// The holding name never shortens, so its zone has no twin.
|
|
427
426
|
const twins = zones.flatMap((z, i) => (z.short !== undefined && !z.holding ? [i] : []))
|
|
428
|
-
const { shown, short, shift } = useRowLabelLayout(
|
|
427
|
+
const { shown, short, shift, row } = useRowLabelLayout(
|
|
429
428
|
rowRef,
|
|
430
429
|
slots,
|
|
431
430
|
twins.map((i) => ticks.length + i),
|
|
432
431
|
`${key}\u0001${twins.map((i) => zones[i]?.short).join('\u0000')}`,
|
|
433
432
|
)
|
|
434
433
|
const hidden = (i: number) => (shown[i] === false || short[i] === true ? '' : undefined)
|
|
434
|
+
// The second row exists only while a shown label stands on it.
|
|
435
|
+
const second = (i: number) => (shown[i] === true && row[i] === 1 ? '' : undefined)
|
|
436
|
+
const rows = row.some((r, i) => r === 1 && shown[i] === true) ? 2 : 1
|
|
437
|
+
// theme-allow hidden-inline-style — the placement's offset is measured data, applied by `translate`
|
|
435
438
|
const nudge = (i: number): CSSProperties =>
|
|
436
|
-
shift[i] ? {
|
|
439
|
+
shift[i] ? ({ '--basalt-nudge': `${shift[i]}px` } as CSSProperties) : {}
|
|
437
440
|
return (
|
|
438
441
|
<div
|
|
439
442
|
ref={rowRef}
|
|
440
443
|
className={classes.labelRow}
|
|
444
|
+
data-meter-rows={rows}
|
|
441
445
|
{...(zones.length > 0 ? { 'data-meter-zone-band': '' } : { 'data-meter-tick-band': '' })}
|
|
442
446
|
aria-hidden
|
|
443
447
|
>
|
|
@@ -447,10 +451,11 @@ function LabelRow({ zones, ticks }: { zones: readonly ZoneLabel[]; ticks: readon
|
|
|
447
451
|
className={classes.rowLabel}
|
|
448
452
|
data-meter-tick-label=""
|
|
449
453
|
data-hidden={hidden(i)}
|
|
454
|
+
data-row2={second(i)}
|
|
450
455
|
style={
|
|
451
456
|
t.pct > TICK_LABEL_FLIP_PCT
|
|
452
|
-
? { insetInlineEnd: `${100 - t.pct}
|
|
453
|
-
: { insetInlineStart: `${t.pct}
|
|
457
|
+
? { insetInlineEnd: `${100 - t.pct}%`, ...nudge(i) }
|
|
458
|
+
: { insetInlineStart: `${t.pct}%`, ...nudge(i) }
|
|
454
459
|
}
|
|
455
460
|
>
|
|
456
461
|
{t.label}
|
|
@@ -463,6 +468,7 @@ function LabelRow({ zones, ticks }: { zones: readonly ZoneLabel[]; ticks: readon
|
|
|
463
468
|
data-meter-zone-label={z.label}
|
|
464
469
|
data-holding={z.holding || undefined}
|
|
465
470
|
data-hidden={hidden(ticks.length + i)}
|
|
471
|
+
data-row2={second(ticks.length + i)}
|
|
466
472
|
style={{ insetInlineStart: `${z.centrePct}%`, ...nudge(ticks.length + i) }}
|
|
467
473
|
>
|
|
468
474
|
{z.label}
|
|
@@ -477,6 +483,7 @@ function LabelRow({ zones, ticks }: { zones: readonly ZoneLabel[]; ticks: readon
|
|
|
477
483
|
className={cx(classes.rowLabel, classes.zoneLabel)}
|
|
478
484
|
data-meter-zone-short={z.label}
|
|
479
485
|
data-hidden={short[i] === true ? undefined : ''}
|
|
486
|
+
data-row2={second(i)}
|
|
480
487
|
style={{ insetInlineStart: `${z.centrePct}%`, ...nudge(i) }}
|
|
481
488
|
>
|
|
482
489
|
{z.short}
|
|
@@ -499,6 +506,8 @@ type CaptionItem = {
|
|
|
499
506
|
align?: 'start' | 'center' | 'end'
|
|
500
507
|
/** Drop rank when the row is too narrow (lowest first); none never drops. */
|
|
501
508
|
drop?: number
|
|
509
|
+
/** Tried when the primary anchor drops the caption; the caption drops only if this fails too. */
|
|
510
|
+
alt?: { pct: number; align?: 'start' | 'center' | 'end' }
|
|
502
511
|
}
|
|
503
512
|
|
|
504
513
|
/** The measurement shared by the marks row and the part list: natural widths, row width, gap step. */
|
|
@@ -583,13 +592,23 @@ function CaptionRow({ items }: { items: readonly CaptionItem[] }) {
|
|
|
583
592
|
...(item.align !== undefined && { align: item.align }),
|
|
584
593
|
...(item.drop !== undefined && { drop: item.drop }),
|
|
585
594
|
}))
|
|
586
|
-
|
|
595
|
+
let next = placeCaptionRow(marks, rowWidth, gap)
|
|
596
|
+
// A caption that dropped at its preferred anchor gets its fallback before it is given up.
|
|
597
|
+
items.forEach((item, i) => {
|
|
598
|
+
if (item.alt === undefined || !next?.dropped[i]) return
|
|
599
|
+
const retry = placeCaptionRow(
|
|
600
|
+
marks.map((m, j) => (j === i ? { ...m, ...item.alt } : m)),
|
|
601
|
+
rowWidth,
|
|
602
|
+
gap,
|
|
603
|
+
)
|
|
604
|
+
if (retry !== null && !retry.dropped[i]) next = retry
|
|
605
|
+
})
|
|
587
606
|
setPlaced((prev) => (samePlacement(prev, next) ? prev : next))
|
|
588
607
|
},
|
|
589
608
|
items
|
|
590
609
|
.map(
|
|
591
610
|
(i) =>
|
|
592
|
-
`${i.key}@${i.pct ?? i.edge ?? ''}${i.align ?? ''}${i.drop ?? ''}:${typeof i.node === 'string' ? i.node : ''}`,
|
|
611
|
+
`${i.key}@${i.pct ?? i.edge ?? ''}${i.align ?? ''}${i.drop ?? ''}${i.alt?.pct ?? ''}:${typeof i.node === 'string' ? i.node : ''}`,
|
|
593
612
|
)
|
|
594
613
|
.join('\u0000'),
|
|
595
614
|
)
|
|
@@ -700,9 +719,12 @@ export function MeterBar(props: {
|
|
|
700
719
|
startCaption: ReactNode
|
|
701
720
|
endCaption: ReactNode
|
|
702
721
|
readingAt: 'fill' | 'start' | undefined
|
|
722
|
+
/** The loaded structure with its text painted as skeleton: the footprint IS the loaded one. */
|
|
723
|
+
loading?: boolean
|
|
703
724
|
shell: Shell
|
|
704
725
|
}) {
|
|
705
726
|
const { label, min, max, format, zones, shell } = props
|
|
727
|
+
const loading = props.loading === true
|
|
706
728
|
const describedId = useId()
|
|
707
729
|
const model = modelBar(props)
|
|
708
730
|
const compact = shell.row
|
|
@@ -788,9 +810,20 @@ export function MeterBar(props: {
|
|
|
788
810
|
key: 'forecast',
|
|
789
811
|
node: glue(model.forecastText),
|
|
790
812
|
drop: 2,
|
|
791
|
-
// The reading ends at the boundary, the forecast
|
|
792
|
-
|
|
793
|
-
...(
|
|
813
|
+
// The reading ends at the boundary, the forecast ends where its fill does.
|
|
814
|
+
// If that collides, it falls back to starting at the boundary before it drops.
|
|
815
|
+
...(props.readingAt !== 'start' && model.forecastEndPct !== undefined
|
|
816
|
+
? {
|
|
817
|
+
pct: model.forecastEndPct,
|
|
818
|
+
align: 'end' as const,
|
|
819
|
+
...(model.boundaryPct !== undefined && {
|
|
820
|
+
alt: {
|
|
821
|
+
pct: model.boundaryPct,
|
|
822
|
+
...(start !== null && { align: 'start' as const }),
|
|
823
|
+
},
|
|
824
|
+
}),
|
|
825
|
+
}
|
|
826
|
+
: model.boundaryPct !== undefined && { pct: model.boundaryPct }),
|
|
794
827
|
} satisfies CaptionItem,
|
|
795
828
|
]
|
|
796
829
|
: []),
|
|
@@ -824,15 +857,32 @@ export function MeterBar(props: {
|
|
|
824
857
|
]
|
|
825
858
|
|
|
826
859
|
const root = rootProps(shell)
|
|
860
|
+
// Loading is the loaded tree: every caption row stands where it will, its text is painted as
|
|
861
|
+
// skeleton (CSS) and hidden from assistive tech; the root announces the state once.
|
|
862
|
+
const quiet = (node: ReactNode) =>
|
|
863
|
+
loading ? (
|
|
864
|
+
<div className={classes.hold} aria-hidden>
|
|
865
|
+
{node}
|
|
866
|
+
</div>
|
|
867
|
+
) : (
|
|
868
|
+
node
|
|
869
|
+
)
|
|
827
870
|
return (
|
|
828
|
-
<div
|
|
871
|
+
<div
|
|
872
|
+
{...root}
|
|
873
|
+
className={root.className}
|
|
874
|
+
{...(loading && { 'aria-busy': 'true', 'data-meter-loading': '' })}
|
|
875
|
+
>
|
|
876
|
+
{loading && <VisuallyHidden className={classes.summary}>{`Loading ${label}`}</VisuallyHidden>}
|
|
829
877
|
{aboveTicks.length > 0 && <LabelRow zones={[]} ticks={aboveTicks} />}
|
|
830
878
|
<div
|
|
831
879
|
className={cx(classes.trackBox, trackHidden && classes.trackHidden)}
|
|
832
880
|
data-meter-track-hidden={trackHidden ? '' : undefined}
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
881
|
+
{...(!loading && {
|
|
882
|
+
'aria-label': label,
|
|
883
|
+
...ariaValues(props.reading, min, max, format),
|
|
884
|
+
...describedBy,
|
|
885
|
+
})}
|
|
836
886
|
>
|
|
837
887
|
<div
|
|
838
888
|
className={classes.track}
|
|
@@ -845,6 +895,7 @@ export function MeterBar(props: {
|
|
|
845
895
|
>
|
|
846
896
|
{zones?.map(
|
|
847
897
|
(z, i) =>
|
|
898
|
+
!loading &&
|
|
848
899
|
model.markerPct !== undefined && (
|
|
849
900
|
<div
|
|
850
901
|
key={i}
|
|
@@ -857,7 +908,7 @@ export function MeterBar(props: {
|
|
|
857
908
|
/>
|
|
858
909
|
),
|
|
859
910
|
)}
|
|
860
|
-
{model.parts.map((p, i) => (
|
|
911
|
+
{(loading ? [] : model.parts).map((p, i) => (
|
|
861
912
|
<div
|
|
862
913
|
key={i}
|
|
863
914
|
className={cx(classes.fill, p.forecast && classes.forecastFill)}
|
|
@@ -870,22 +921,26 @@ export function MeterBar(props: {
|
|
|
870
921
|
/>
|
|
871
922
|
))}
|
|
872
923
|
</div>
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
924
|
+
{!loading && (
|
|
925
|
+
<>
|
|
926
|
+
<Tick kind="marker" className={classes.marker} pct={model.markerPct} />
|
|
927
|
+
<Tick kind="boundary" className={classes.boundaryTick} pct={model.boundaryPct} />
|
|
928
|
+
{model.ticks.map((t) => (
|
|
929
|
+
<Tick key={t.key} kind="tick" className={classes.tick} pct={t.pct} />
|
|
930
|
+
))}
|
|
931
|
+
<Tick kind="target" className={classes.tick} pct={model.targetPct} />
|
|
932
|
+
</>
|
|
933
|
+
)}
|
|
879
934
|
</div>
|
|
880
935
|
{zoneLabels.length > 0 && <LabelRow zones={zoneLabels} ticks={belowTicks} />}
|
|
881
|
-
{anchored && <ZoneReading pct={model.markerPct ?? 0}>{start}</ZoneReading>}
|
|
882
|
-
{model.describedByText !== null && (
|
|
936
|
+
{anchored && quiet(<ZoneReading pct={model.markerPct ?? 0}>{start}</ZoneReading>)}
|
|
937
|
+
{!loading && model.describedByText !== null && (
|
|
883
938
|
<VisuallyHidden id={describedId} className={classes.summary}>
|
|
884
939
|
{model.describedByText}
|
|
885
940
|
</VisuallyHidden>
|
|
886
941
|
)}
|
|
887
|
-
{hasParts && <PartCaptions captions={model.partCaptions} />}
|
|
888
|
-
{items.length > 0 && <CaptionRow items={items} />}
|
|
942
|
+
{hasParts && quiet(<PartCaptions captions={model.partCaptions} />)}
|
|
943
|
+
{items.length > 0 && quiet(<CaptionRow items={items} />)}
|
|
889
944
|
</div>
|
|
890
945
|
)
|
|
891
946
|
}
|
|
@@ -101,10 +101,21 @@
|
|
|
101
101
|
--basalt-reading-dir: -1;
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
+
/* A label that cannot hold its place on the first row stands on a second, directly under it. */
|
|
105
|
+
.labelRow[data-meter-rows='2'] {
|
|
106
|
+
height: 2.5em;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
.rowLabel[data-row2] {
|
|
110
|
+
top: 1.25em;
|
|
111
|
+
}
|
|
112
|
+
|
|
104
113
|
.rowLabel {
|
|
105
114
|
position: absolute;
|
|
106
115
|
top: 0;
|
|
107
116
|
white-space: nowrap;
|
|
117
|
+
/* The placement's physical offset (a label kept inside the row): both anchors, either direction. */
|
|
118
|
+
translate: var(--basalt-nudge, 0px) 0;
|
|
108
119
|
}
|
|
109
120
|
|
|
110
121
|
.rowLabel[data-hidden] {
|
|
@@ -113,7 +124,7 @@
|
|
|
113
124
|
|
|
114
125
|
/* A zone name is centred on its span: the physical `translate` flips sign in RTL. */
|
|
115
126
|
.zoneLabel {
|
|
116
|
-
translate: calc(-50% * var(--basalt-reading-dir)) 0;
|
|
127
|
+
translate: calc(-50% * var(--basalt-reading-dir) + var(--basalt-nudge, 0px)) 0;
|
|
117
128
|
}
|
|
118
129
|
|
|
119
130
|
.zoneLabelHolding {
|
|
@@ -312,8 +323,7 @@
|
|
|
312
323
|
color: var(--vx-muted);
|
|
313
324
|
}
|
|
314
325
|
|
|
315
|
-
/* One caption-height line: a blank caption row
|
|
316
|
-
* both stand at the loaded Meter's height. */
|
|
326
|
+
/* One caption-height line: a blank caption row of an empty Meter, so it stands at the loaded height. */
|
|
317
327
|
.line {
|
|
318
328
|
display: flex;
|
|
319
329
|
align-items: center;
|
|
@@ -325,14 +335,50 @@
|
|
|
325
335
|
height: 1.25em;
|
|
326
336
|
}
|
|
327
337
|
|
|
328
|
-
/*
|
|
329
|
-
.
|
|
330
|
-
|
|
338
|
+
/* Loading is the loaded tree (`MeterBar` with `loading`): every row stands where it will and the
|
|
339
|
+
* height is the loaded one. Text is painted as skeleton in place: transparent ink on a pulsing pill
|
|
340
|
+
* the width of the caption, the track a pulsing bar. A caption the layout dropped stays hidden. */
|
|
341
|
+
.hold {
|
|
342
|
+
display: contents;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
[data-meter-loading] {
|
|
346
|
+
--basalt-meter-skeleton: color-mix(in srgb, var(--vx-muted) 28%, transparent);
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
[data-meter-loading]
|
|
350
|
+
:is(.rowLabel, .caption, .captionEnd, .captionTarget, .zoneReading, .partCaption) {
|
|
351
|
+
color: transparent;
|
|
352
|
+
background: var(--basalt-meter-skeleton);
|
|
353
|
+
border-radius: var(--vx-radius-fine);
|
|
354
|
+
animation: meterPulse 1500ms linear infinite;
|
|
331
355
|
}
|
|
332
356
|
|
|
333
|
-
.
|
|
334
|
-
|
|
335
|
-
|
|
357
|
+
[data-meter-loading] .swatch {
|
|
358
|
+
visibility: hidden;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
[data-meter-loading] .track {
|
|
362
|
+
background: var(--basalt-meter-skeleton);
|
|
363
|
+
animation: meterPulse 1500ms linear infinite;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
@keyframes meterPulse {
|
|
367
|
+
0%,
|
|
368
|
+
100% {
|
|
369
|
+
opacity: 0.4;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
50% {
|
|
373
|
+
opacity: 1;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
@media (prefers-reduced-motion: reduce) {
|
|
378
|
+
[data-meter-loading]
|
|
379
|
+
:is(.rowLabel, .caption, .captionEnd, .captionTarget, .zoneReading, .partCaption, .track) {
|
|
380
|
+
animation: none;
|
|
381
|
+
}
|
|
336
382
|
}
|
|
337
383
|
|
|
338
384
|
/* ── ring ────────────────────────────────────────────────────────────────────────────────────── */
|
|
@@ -406,10 +452,6 @@
|
|
|
406
452
|
height: 1lh;
|
|
407
453
|
}
|
|
408
454
|
|
|
409
|
-
.row .skeletonTrack {
|
|
410
|
-
height: 1lh;
|
|
411
|
-
}
|
|
412
|
-
|
|
413
455
|
.row .line {
|
|
414
456
|
display: none;
|
|
415
457
|
}
|
|
@@ -34,8 +34,7 @@ declare const classes: {
|
|
|
34
34
|
readonly empty: string
|
|
35
35
|
readonly line: string
|
|
36
36
|
readonly lineZoned: string
|
|
37
|
-
readonly
|
|
38
|
-
readonly skeletonCaption: string
|
|
37
|
+
readonly hold: string
|
|
39
38
|
readonly ringBox: string
|
|
40
39
|
readonly ring: string
|
|
41
40
|
readonly ringTrack: string
|
package/src/dashboard/meter.tsx
CHANGED
|
@@ -57,7 +57,7 @@ import type { BasaltProps } from '../common/props'
|
|
|
57
57
|
import { VX } from '../tokens'
|
|
58
58
|
import { isReading, normalizeSegments, segmentReading, spanOf } from './meter-model'
|
|
59
59
|
import type { MeterSegment, MeterTick, MeterZone } from './meter-model'
|
|
60
|
-
import { MeterBar, MeterEmpty,
|
|
60
|
+
import { MeterBar, MeterEmpty, MeterRing, MeterRingLoading } from './meter-parts'
|
|
61
61
|
import { asText } from './scale'
|
|
62
62
|
import { VisualSlotContext } from './visual-slot'
|
|
63
63
|
|
|
@@ -162,7 +162,7 @@ export type MeterProps =
|
|
|
162
162
|
| (BarCommon & {
|
|
163
163
|
/** Ordered parts, accumulated from `min`; their sum is the reading. `forecast` parts render lighter. */
|
|
164
164
|
segments: readonly MeterSegment[]
|
|
165
|
-
/** Names the forecast
|
|
165
|
+
/** Names the forecast, ending where its fill ends (default: `Forecast: <labels>`). */
|
|
166
166
|
forecastCaption?: string
|
|
167
167
|
value?: never
|
|
168
168
|
color?: never
|
|
@@ -225,16 +225,28 @@ export function Meter(props: MeterProps) {
|
|
|
225
225
|
const shell = { className, style, row }
|
|
226
226
|
const ring = props.shape === 'ring'
|
|
227
227
|
warnInvalidTrack(min, max)
|
|
228
|
-
const
|
|
228
|
+
const host = useContext(VisualSlotContext)
|
|
229
|
+
const hostTone = host?.tone
|
|
229
230
|
const hostColor = hostTone === undefined ? undefined : VX.status[hostTone]
|
|
230
231
|
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
<MeterLoading label={label} ring={ring} zoned={props.zones !== undefined} shell={shell} />
|
|
234
|
-
)
|
|
232
|
+
const loading = props.loading === true || host?.loading === true
|
|
233
|
+
if (loading && ring) return <MeterRingLoading label={label} shell={shell} />
|
|
235
234
|
|
|
236
|
-
|
|
237
|
-
|
|
235
|
+
// A loading bar is the loaded bar on a placeholder reading (its captions painted as skeleton), so
|
|
236
|
+
// it has the loaded rows and height: zoned bars mid-track, plain bars at the start.
|
|
237
|
+
const segments =
|
|
238
|
+
props.segments === undefined || (loading && props.segments.length === 0)
|
|
239
|
+
? undefined
|
|
240
|
+
: normalizeSegments(props.segments)
|
|
241
|
+
const placeholder =
|
|
242
|
+
props.zones !== undefined && props.zones.length > 0 ? min + spanOf(min, max).span / 2 : min
|
|
243
|
+
const reading = loading
|
|
244
|
+
? segments === undefined
|
|
245
|
+
? placeholder
|
|
246
|
+
: segmentReading(segments, min)
|
|
247
|
+
: segments === undefined
|
|
248
|
+
? props.value
|
|
249
|
+
: segmentReading(segments, min)
|
|
238
250
|
if (!isReading(reading) || segments?.length === 0) {
|
|
239
251
|
return (
|
|
240
252
|
<MeterEmpty
|
|
@@ -275,6 +287,7 @@ export function Meter(props: MeterProps) {
|
|
|
275
287
|
startCaption={props.startCaption}
|
|
276
288
|
endCaption={props.endCaption}
|
|
277
289
|
readingAt={props.readingAt}
|
|
290
|
+
loading={loading}
|
|
278
291
|
/>
|
|
279
292
|
)
|
|
280
293
|
}
|
|
@@ -76,15 +76,16 @@
|
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
/*
|
|
79
|
-
* A
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
* so
|
|
83
|
-
*
|
|
84
|
-
*
|
|
79
|
+
* A `Text` summary line (argo's strength diagnostics shell: title 15 + chart-card title 13 + summary
|
|
80
|
+
* 12 + chart ticks and legend 11 = four sizes) joins the chart text step, so the shell stays at
|
|
81
|
+
* three: 15, 13, 11. The cap is the `--text-fz` variable Mantine's `Text` reads for its font size,
|
|
82
|
+
* pinned `!important` so it outranks the inline value a `size` prop writes; a `Text` sized by the
|
|
83
|
+
* consumer's own CLASS sets `font-size` directly, never reads the variable, and keeps that size
|
|
84
|
+
* (argo's reading backlog `.facts`, 13). Only a direct `Text` child is capped; a `Group` of stats
|
|
85
|
+
* keeps the sizes its own parts ask for.
|
|
85
86
|
*/
|
|
86
87
|
.summary > :global(.mantine-Text-root) {
|
|
87
|
-
|
|
88
|
+
--text-fz: var(--vx-text-micro) !important;
|
|
88
89
|
}
|
|
89
90
|
|
|
90
91
|
/*
|
|
@@ -137,8 +137,7 @@ type SectionBaseProps = Omit<
|
|
|
137
137
|
defaultOpen?: boolean
|
|
138
138
|
/** Rendered directly under the header and ALWAYS visible, collapsed or not: a collapsed section
|
|
139
139
|
* still states its headline figures, which is what makes collapsing it a real option. Keep it to
|
|
140
|
-
* one row — the body is what `children` is for.
|
|
141
|
-
* chart-text step): a `size` prop on a bare `Text` here is ignored — wrap it to opt out. */
|
|
140
|
+
* one row — the body is what `children` is for. A `Text` here renders at 11 (the chart-text step); wrap it to opt out. */
|
|
142
141
|
summary?: ReactNode
|
|
143
142
|
/** Turns the root into a scroll anchor (`id` + `scroll-margin-top`). Inside `BasaltShell` the
|
|
144
143
|
* offset is the clearance token; without a shell it also clears `PageBar`, which assumes the
|
|
@@ -194,6 +194,23 @@
|
|
|
194
194
|
}
|
|
195
195
|
}
|
|
196
196
|
|
|
197
|
+
/* Cards of one StatGroup share ONE figure size. In the two-column phone state the last odd card spans the
|
|
198
|
+
* row, so its own width would size its numeral 22 against its row-mates' 16; the group's columns (a
|
|
199
|
+
* narrow card's size) set it for every card instead, whether or not a qualifier sits on its own line.
|
|
200
|
+
* `--basalt-stat-group-figure` on the group (or a wrapper) replaces that size. */
|
|
201
|
+
@container basalt-grid (max-width: 479.9px) {
|
|
202
|
+
[data-sm-cols] .body {
|
|
203
|
+
--basalt-stat-figure-size: var(--basalt-stat-group-figure, var(--vx-text-lg));
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/* A one-column group (under 260px) has no spanning card: each keeps its own width's clamp. */
|
|
208
|
+
@container basalt-grid (max-width: 259.9px) {
|
|
209
|
+
[data-sm-cols] .body {
|
|
210
|
+
--basalt-stat-figure-size: clamp(var(--vx-text-lg), 8cqi, var(--vx-text-kpi));
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
197
214
|
/* ── states ──────────────────────────────────────────────────────────────────────────────────── */
|
|
198
215
|
|
|
199
216
|
/* The empty branch: one muted line in the figure's place, at the figure row's height. */
|