basalt-ui 2.22.0 → 2.24.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 +68 -0
- package/MIGRATING.md +400 -12
- package/agent/agents/basalt-design-reviewer.md +3 -3
- package/agent/skills/basalt-design/SKILL.md +2 -2
- package/agent/skills/basalt-design/references/catalogue.md +22 -19
- package/agent/skills/basalt-design/references/states.md +39 -0
- package/dist/charts/BandStrip.d.ts.map +1 -1
- package/dist/charts/BandStrip.js +51 -5
- package/dist/charts/Bars.d.ts.map +1 -1
- package/dist/charts/Bars.js +19 -3
- package/dist/charts/CartesianChart.d.ts +2 -0
- package/dist/charts/CartesianChart.d.ts.map +1 -1
- package/dist/charts/CartesianChart.js +7 -3
- package/dist/charts/ChartCard.d.ts +1 -1
- package/dist/charts/ChartCard.d.ts.map +1 -1
- package/dist/charts/ChartCard.js +25 -15
- package/dist/charts/Sparkline.d.ts +8 -2
- package/dist/charts/Sparkline.d.ts.map +1 -1
- package/dist/charts/Sparkline.js +95 -15
- package/dist/charts/StackedArea.d.ts.map +1 -1
- package/dist/charts/StackedArea.js +5 -1
- package/dist/charts/band-fold.d.ts +22 -4
- package/dist/charts/band-fold.d.ts.map +1 -1
- package/dist/charts/band-fold.js +10 -2
- package/dist/charts/chart-dates.d.ts +12 -0
- package/dist/charts/chart-dates.d.ts.map +1 -0
- package/dist/charts/chart-dates.js +16 -0
- package/dist/charts/chart-legend.module.css +16 -0
- package/dist/charts/compile.d.ts +10 -0
- package/dist/charts/compile.d.ts.map +1 -1
- package/dist/charts/compile.js +77 -24
- package/dist/charts/date-tick-format.d.ts +5 -5
- package/dist/charts/date-tick-format.d.ts.map +1 -1
- package/dist/charts/date-tick-format.js +3 -7
- package/dist/charts/labels.d.ts +7 -3
- package/dist/charts/labels.d.ts.map +1 -1
- package/dist/charts/labels.js +28 -17
- package/dist/charts/legend.d.ts +0 -6
- package/dist/charts/legend.d.ts.map +1 -1
- package/dist/charts/legend.js +87 -35
- package/dist/charts/ref-label.d.ts +17 -0
- package/dist/charts/ref-label.d.ts.map +1 -1
- package/dist/charts/ref-label.js +13 -1
- package/dist/charts/sparkline.module.css +62 -12
- package/dist/charts/sparkline.module.css.d.ts +1 -0
- package/dist/charts/state.d.ts.map +1 -1
- package/dist/charts/state.js +4 -2
- package/dist/charts/types.d.ts +15 -3
- package/dist/charts/types.d.ts.map +1 -1
- package/dist/cli/shot/capture.d.ts.map +1 -1
- package/dist/cli/shot/capture.js +9 -5
- package/dist/cli/shot/detect.js +8 -5
- package/dist/cli/shot/measure.js +19 -23
- package/dist/cli/shot/playwright.d.ts +8 -0
- package/dist/cli/shot/playwright.d.ts.map +1 -1
- package/dist/cli/shot/playwright.js +5 -1
- package/dist/cli/shot/types.d.ts +2 -0
- package/dist/cli/shot/types.d.ts.map +1 -1
- package/dist/cli/tokens-css.d.ts +5 -7
- package/dist/cli/tokens-css.d.ts.map +1 -1
- package/dist/cli/tokens-css.js +11 -12
- package/dist/dashboard/bar-list.d.ts +6 -1
- package/dist/dashboard/bar-list.d.ts.map +1 -1
- package/dist/dashboard/bar-list.js +8 -0
- package/dist/dashboard/bar-list.module.css +18 -0
- package/dist/dashboard/delta-badge.d.ts.map +1 -1
- package/dist/dashboard/delta-badge.js +2 -2
- package/dist/dashboard/empty-state.d.ts.map +1 -1
- package/dist/dashboard/meter-model.d.ts +55 -21
- package/dist/dashboard/meter-model.d.ts.map +1 -1
- package/dist/dashboard/meter-model.js +98 -17
- package/dist/dashboard/meter-parts.d.ts +9 -2
- package/dist/dashboard/meter-parts.d.ts.map +1 -1
- package/dist/dashboard/meter-parts.js +99 -21
- package/dist/dashboard/meter.d.ts +21 -8
- package/dist/dashboard/meter.d.ts.map +1 -1
- package/dist/dashboard/meter.js +14 -3
- package/dist/dashboard/meter.module.css +57 -2
- package/dist/dashboard/meter.module.css.d.ts +5 -0
- package/dist/dashboard/query-state.d.ts +7 -3
- package/dist/dashboard/query-state.d.ts.map +1 -1
- package/dist/dashboard/query-state.js +15 -7
- package/dist/dashboard/section.d.ts +2 -1
- package/dist/dashboard/section.d.ts.map +1 -1
- package/dist/dashboard/section.module.css +12 -0
- package/dist/dashboard/settings-section.d.ts +1 -1
- package/dist/dashboard/settings-section.d.ts.map +1 -1
- package/dist/dashboard/settings-section.js +3 -3
- package/dist/dashboard/stat-card-parts.js +1 -1
- package/dist/dashboard/stat-card.module.css +43 -10
- package/dist/dashboard/stat-group.module.css +15 -0
- package/dist/dashboard/stat-strip.d.ts +16 -5
- package/dist/dashboard/stat-strip.d.ts.map +1 -1
- package/dist/dashboard/stat-strip.js +100 -74
- package/dist/dashboard/stat-strip.module.css +68 -62
- package/dist/dashboard/stat-strip.module.css.d.ts +1 -0
- package/dist/dashboard/widget-header.d.ts.map +1 -1
- package/dist/dashboard/widget-header.js +19 -1
- package/dist/dashboard/widget-header.module.css +6 -0
- package/dist/guard/index.d.ts +2 -2
- package/dist/guard/index.d.ts.map +1 -1
- package/dist/guard/index.js +1 -17
- package/dist/styles.css +18 -11
- package/dist/table/data-table.js +1 -1
- package/dist/theme/controls.module.css +19 -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 +12 -7
- package/dist/theme/status-verdict.d.ts.map +1 -1
- package/dist/theme/status-verdict.js +9 -1
- package/dist/tokens/palette.d.ts +7 -10
- package/dist/tokens/palette.d.ts.map +1 -1
- package/dist/tokens/palette.js +7 -10
- package/llms.txt +7 -4
- package/package.json +1 -1
- package/src/charts/BandStrip.tsx +55 -5
- package/src/charts/Bars.tsx +31 -3
- package/src/charts/CartesianChart.tsx +9 -3
- package/src/charts/ChartCard.tsx +32 -19
- package/src/charts/Sparkline.tsx +139 -21
- package/src/charts/StackedArea.tsx +12 -1
- package/src/charts/band-fold.ts +25 -6
- package/src/charts/chart-dates.ts +30 -0
- package/src/charts/chart-legend.module.css +16 -0
- package/src/charts/compile.ts +148 -25
- package/src/charts/date-tick-format.ts +10 -13
- package/src/charts/labels.ts +43 -22
- package/src/charts/legend.tsx +70 -3
- package/src/charts/ref-label.ts +27 -0
- package/src/charts/sparkline.module.css +62 -12
- package/src/charts/sparkline.module.css.d.ts +1 -0
- package/src/charts/state.tsx +7 -4
- package/src/charts/types.ts +13 -3
- package/src/cli/shot/capture.ts +15 -3
- package/src/cli/shot/detect.ts +9 -9
- package/src/cli/shot/measure.ts +27 -27
- package/src/cli/shot/playwright.ts +18 -2
- package/src/cli/shot/types.ts +2 -0
- package/src/cli/tokens-css.ts +18 -20
- package/src/dashboard/bar-list.module.css +18 -0
- package/src/dashboard/bar-list.tsx +29 -0
- package/src/dashboard/delta-badge.tsx +6 -2
- package/src/dashboard/empty-state.tsx +4 -2
- package/src/dashboard/meter-model.ts +181 -47
- package/src/dashboard/meter-parts.tsx +187 -30
- package/src/dashboard/meter.module.css +57 -2
- package/src/dashboard/meter.module.css.d.ts +5 -0
- package/src/dashboard/meter.tsx +33 -10
- package/src/dashboard/query-state.tsx +20 -9
- package/src/dashboard/section.module.css +12 -0
- package/src/dashboard/section.tsx +2 -1
- package/src/dashboard/settings-section.tsx +4 -4
- package/src/dashboard/stat-card-parts.tsx +1 -1
- package/src/dashboard/stat-card.module.css +43 -10
- package/src/dashboard/stat-group.module.css +15 -0
- package/src/dashboard/stat-strip.module.css +68 -62
- package/src/dashboard/stat-strip.module.css.d.ts +1 -0
- package/src/dashboard/stat-strip.tsx +118 -59
- package/src/dashboard/widget-header.module.css +6 -0
- package/src/dashboard/widget-header.tsx +28 -1
- package/src/guard/index.ts +3 -19
- package/src/styles.css +18 -11
- package/src/table/data-table.tsx +1 -1
- package/src/theme/__snapshots__/plain-theme.test.ts.snap +14 -8
- package/src/theme/controls.module.css +19 -0
- package/src/theme/controls.module.css.d.ts +1 -0
- package/src/theme/index.ts +12 -7
- package/src/theme/status-verdict.tsx +5 -1
- package/src/tokens/palette.ts +7 -10
|
@@ -7,8 +7,9 @@ import { cx } from '../common/props'
|
|
|
7
7
|
import {
|
|
8
8
|
ariaValues,
|
|
9
9
|
modelBar,
|
|
10
|
+
partColumns,
|
|
10
11
|
partsFitUnder,
|
|
11
|
-
|
|
12
|
+
placeCaptionRow,
|
|
12
13
|
placeRowLabels,
|
|
13
14
|
ringFraction,
|
|
14
15
|
ringMarks,
|
|
@@ -126,13 +127,31 @@ const glueUnits = (text: ReactNode): ReactNode =>
|
|
|
126
127
|
const glue = (text: ReactNode): ReactNode =>
|
|
127
128
|
typeof text === 'string' ? String(glueUnits(text)).replace(SHORT_LAST_WORD, '$1\u00a0$2') : text
|
|
128
129
|
|
|
130
|
+
/**
|
|
131
|
+
* One caption-height line, so a placeholder row stands where the loaded Meter's caption, figure or
|
|
132
|
+
* zone-name row will (a zoned track's rows are `1.25em`, as its label rows). Not announced; the root carries the state.
|
|
133
|
+
*/
|
|
134
|
+
function Line({ zoned, children }: { zoned: boolean; children?: ReactNode }) {
|
|
135
|
+
return (
|
|
136
|
+
<div className={cx(classes.line, zoned && classes.lineZoned)} data-meter-line aria-hidden>
|
|
137
|
+
{children}
|
|
138
|
+
</div>
|
|
139
|
+
)
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* The loaded Meter's footprint at its loaded height: a zoned track keeps the figure row above and the
|
|
144
|
+
* zone-name row below, a plain bar the caption row below, so the card does not jump when data lands.
|
|
145
|
+
*/
|
|
129
146
|
export function MeterLoading({
|
|
130
147
|
label,
|
|
131
148
|
ring,
|
|
149
|
+
zoned,
|
|
132
150
|
shell,
|
|
133
151
|
}: {
|
|
134
152
|
label: string
|
|
135
153
|
ring: boolean
|
|
154
|
+
zoned: boolean
|
|
136
155
|
shell: Shell
|
|
137
156
|
}) {
|
|
138
157
|
return (
|
|
@@ -142,28 +161,59 @@ export function MeterLoading({
|
|
|
142
161
|
<Skeleton className={classes.skeletonRing} circle />
|
|
143
162
|
) : (
|
|
144
163
|
<>
|
|
164
|
+
{zoned && (
|
|
165
|
+
<Line zoned={zoned}>
|
|
166
|
+
<Skeleton className={classes.skeletonCaption} radius="sm" />
|
|
167
|
+
</Line>
|
|
168
|
+
)}
|
|
145
169
|
<Skeleton className={classes.skeletonTrack} />
|
|
146
|
-
<
|
|
170
|
+
<Line zoned={zoned}>
|
|
171
|
+
<Skeleton className={classes.skeletonCaption} radius="sm" />
|
|
172
|
+
</Line>
|
|
147
173
|
</>
|
|
148
174
|
)}
|
|
149
175
|
</div>
|
|
150
176
|
)
|
|
151
177
|
}
|
|
152
178
|
|
|
153
|
-
|
|
154
|
-
|
|
179
|
+
const EMPTY_READING = '—'
|
|
180
|
+
|
|
181
|
+
export function MeterEmpty(props: {
|
|
182
|
+
label: string
|
|
183
|
+
text: string | undefined
|
|
184
|
+
ring: boolean
|
|
185
|
+
zoned: boolean
|
|
186
|
+
shell: Shell
|
|
187
|
+
}) {
|
|
188
|
+
const { label, text, ring, zoned, shell } = props
|
|
189
|
+
// The ring has a reading slot (its centre), so the dash sits there as the reading. A bar states its
|
|
190
|
+
// gap once, and only if the host says so (`text`): otherwise the caption rows a loaded Meter would
|
|
191
|
+
// have stay blank, so the muted track keeps the loaded height without a dash under it.
|
|
155
192
|
return (
|
|
156
193
|
<output {...rootProps(shell)} aria-label={label}>
|
|
157
194
|
{ring ? (
|
|
158
195
|
<span className={classes.ringBox}>
|
|
159
196
|
<RingSvg />
|
|
197
|
+
<span className={classes.ringValue}>{EMPTY_READING}</span>
|
|
160
198
|
</span>
|
|
161
199
|
) : (
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
200
|
+
<>
|
|
201
|
+
{zoned && !shell.row && <Line zoned />}
|
|
202
|
+
<div className={classes.trackBox}>
|
|
203
|
+
<div className={classes.track} data-meter-track />
|
|
204
|
+
</div>
|
|
205
|
+
</>
|
|
206
|
+
)}
|
|
207
|
+
{text !== undefined ? (
|
|
208
|
+
<span className={classes.empty}>{text}</span>
|
|
209
|
+
) : (
|
|
210
|
+
!ring && (
|
|
211
|
+
<>
|
|
212
|
+
<VisuallyHidden className={classes.summary}>No reading</VisuallyHidden>
|
|
213
|
+
{!shell.row && <Line zoned={zoned} />}
|
|
214
|
+
</>
|
|
215
|
+
)
|
|
165
216
|
)}
|
|
166
|
-
<span className={classes.empty}>{text}</span>
|
|
167
217
|
</output>
|
|
168
218
|
)
|
|
169
219
|
}
|
|
@@ -438,19 +488,33 @@ function LabelRow({ zones, ticks }: { zones: readonly ZoneLabel[]; ticks: readon
|
|
|
438
488
|
}
|
|
439
489
|
|
|
440
490
|
/** One caption of the marks row, in flow order: its anchor (`pct`, or the row's `edge`) when it has one. */
|
|
441
|
-
type CaptionItem = {
|
|
491
|
+
type CaptionItem = {
|
|
492
|
+
key: string
|
|
493
|
+
node: ReactNode
|
|
494
|
+
pct?: number
|
|
495
|
+
edge?: 'end'
|
|
496
|
+
end?: boolean
|
|
497
|
+
/** The default target figure: one line, never wrapped. */
|
|
498
|
+
target?: boolean
|
|
499
|
+
align?: 'start' | 'center' | 'end'
|
|
500
|
+
/** Drop rank when the row is too narrow (lowest first); none never drops. */
|
|
501
|
+
drop?: number
|
|
502
|
+
}
|
|
442
503
|
|
|
443
504
|
/** The measurement shared by the marks row and the part list: natural widths, row width, gap step. */
|
|
444
505
|
function measureItems(row: HTMLElement) {
|
|
445
506
|
const kids = [...row.children] as HTMLElement[]
|
|
446
507
|
const widths = kids.map((kid) => {
|
|
447
508
|
// 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
|
|
509
|
+
const { whiteSpace, flex, width: inline } = kid.style
|
|
449
510
|
kid.style.whiteSpace = 'nowrap'
|
|
450
511
|
kid.style.flex = 'none'
|
|
512
|
+
// A grid cell would clamp the box to its column; the natural width is what is measured.
|
|
513
|
+
kid.style.width = 'max-content'
|
|
451
514
|
const width = kid.offsetWidth
|
|
452
515
|
kid.style.whiteSpace = whiteSpace
|
|
453
516
|
kid.style.flex = flex
|
|
517
|
+
kid.style.width = inline
|
|
454
518
|
return width
|
|
455
519
|
})
|
|
456
520
|
return { widths, rowWidth: row.clientWidth, gap: columnGapOf(row) }
|
|
@@ -490,17 +554,24 @@ function useMeasured(
|
|
|
490
554
|
}, [rowRef, key])
|
|
491
555
|
}
|
|
492
556
|
|
|
493
|
-
|
|
494
|
-
|
|
557
|
+
type CaptionPlacement = { starts: (number | undefined)[]; dropped: boolean[] }
|
|
558
|
+
const samePlacement = (a: CaptionPlacement | null, b: CaptionPlacement | null) =>
|
|
559
|
+
a === b ||
|
|
560
|
+
(a !== null &&
|
|
561
|
+
b !== null &&
|
|
562
|
+
a.starts.length === b.starts.length &&
|
|
563
|
+
a.starts.every((v, i) => v === b.starts[i] && a.dropped[i] === b.dropped[i]))
|
|
495
564
|
|
|
496
565
|
/**
|
|
497
566
|
* 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
|
|
499
|
-
*
|
|
567
|
+
* AT that mark, centred and clamped inside the track (the reading ends at its fill end), when every
|
|
568
|
+
* caption fits with a gap step between them. A row that is too narrow drops its droppable captions
|
|
569
|
+
* (`drop` rank, lowest first) before anything wraps; they stay in the described-by text. Only when
|
|
570
|
+
* even the rest do not fit (and in server markup) the row flows and wraps: start, forecast, end.
|
|
500
571
|
*/
|
|
501
572
|
function CaptionRow({ items }: { items: readonly CaptionItem[] }) {
|
|
502
573
|
const rowRef = useRef<HTMLDivElement>(null)
|
|
503
|
-
const [
|
|
574
|
+
const [placed, setPlaced] = useState<CaptionPlacement | null>(null)
|
|
504
575
|
useMeasured(
|
|
505
576
|
rowRef,
|
|
506
577
|
(row) => {
|
|
@@ -509,26 +580,36 @@ function CaptionRow({ items }: { items: readonly CaptionItem[] }) {
|
|
|
509
580
|
width: widths[i] ?? 0,
|
|
510
581
|
...(item.pct !== undefined && { pct: item.pct }),
|
|
511
582
|
...(item.edge !== undefined && { edge: item.edge }),
|
|
583
|
+
...(item.align !== undefined && { align: item.align }),
|
|
584
|
+
...(item.drop !== undefined && { drop: item.drop }),
|
|
512
585
|
}))
|
|
513
|
-
const next =
|
|
514
|
-
|
|
586
|
+
const next = placeCaptionRow(marks, rowWidth, gap)
|
|
587
|
+
setPlaced((prev) => (samePlacement(prev, next) ? prev : next))
|
|
515
588
|
},
|
|
516
589
|
items
|
|
517
|
-
.map(
|
|
590
|
+
.map(
|
|
591
|
+
(i) =>
|
|
592
|
+
`${i.key}@${i.pct ?? i.edge ?? ''}${i.align ?? ''}${i.drop ?? ''}:${typeof i.node === 'string' ? i.node : ''}`,
|
|
593
|
+
)
|
|
518
594
|
.join('\u0000'),
|
|
519
595
|
)
|
|
520
596
|
return (
|
|
521
597
|
<div
|
|
522
598
|
ref={rowRef}
|
|
523
|
-
className={cx(classes.captions,
|
|
599
|
+
className={cx(classes.captions, placed !== null && classes.captionsAnchored)}
|
|
524
600
|
data-meter-captions
|
|
525
|
-
data-anchored={
|
|
601
|
+
data-anchored={placed === null ? undefined : ''}
|
|
526
602
|
>
|
|
527
603
|
{items.map((item, i) => (
|
|
528
604
|
<span
|
|
529
605
|
key={item.key}
|
|
530
|
-
className={
|
|
531
|
-
|
|
606
|
+
className={
|
|
607
|
+
item.target ? classes.captionTarget : item.end ? classes.captionEnd : classes.caption
|
|
608
|
+
}
|
|
609
|
+
data-hidden={placed?.dropped[i] ? '' : undefined}
|
|
610
|
+
{...(placed?.starts[i] !== undefined && {
|
|
611
|
+
style: { insetInlineStart: `${placed.starts[i]}px` },
|
|
612
|
+
})}
|
|
532
613
|
>
|
|
533
614
|
{item.node}
|
|
534
615
|
</span>
|
|
@@ -539,28 +620,42 @@ function CaptionRow({ items }: { items: readonly CaptionItem[] }) {
|
|
|
539
620
|
|
|
540
621
|
/**
|
|
541
622
|
* Categorical part captions (swatch, name, value): each under its own segment when every one fits
|
|
542
|
-
* there on one line, else one
|
|
623
|
+
* there on one line, else a grid from the track's start: one row when every entry fits it, else
|
|
624
|
+
* the most columns that fit with no lone entry on the last row. An entry stays on one line unless
|
|
625
|
+
* it is wider than the row itself.
|
|
543
626
|
*/
|
|
544
627
|
function PartCaptions({ captions }: { captions: readonly PartCaption[] }) {
|
|
545
628
|
const rowRef = useRef<HTMLUListElement>(null)
|
|
546
629
|
const [under, setUnder] = useState(false)
|
|
630
|
+
const [overwide, setOverwide] = useState(false)
|
|
631
|
+
const [cols, setCols] = useState(0)
|
|
547
632
|
useMeasured(
|
|
548
633
|
rowRef,
|
|
549
634
|
(row) => {
|
|
550
635
|
const { widths, rowWidth, gap } = measureItems(row)
|
|
636
|
+
setOverwide(widths.some((w) => w > rowWidth))
|
|
551
637
|
const fits = partsFitUnder(
|
|
552
638
|
captions.map((c, i) => ({ startPct: c.startPct, width: widths[i] ?? 0 })),
|
|
553
639
|
rowWidth,
|
|
554
640
|
gap,
|
|
555
641
|
)
|
|
556
642
|
setUnder(fits)
|
|
643
|
+
setCols(fits ? 0 : partColumns(widths, rowWidth, gap))
|
|
557
644
|
},
|
|
558
645
|
captions.map((c) => `${c.label} ${c.text}@${c.startPct}`).join('\u0000'),
|
|
559
646
|
)
|
|
560
647
|
return (
|
|
561
648
|
<ul
|
|
562
649
|
ref={rowRef}
|
|
563
|
-
className={cx(
|
|
650
|
+
className={cx(
|
|
651
|
+
classes.partCaptions,
|
|
652
|
+
under && classes.partCaptionsUnder,
|
|
653
|
+
overwide && classes.partCaptionsWrap,
|
|
654
|
+
cols > 0 && classes.partCaptionsGrid,
|
|
655
|
+
)}
|
|
656
|
+
style={
|
|
657
|
+
cols > 0 ? { gridTemplateColumns: `repeat(${cols}, minmax(0, max-content))` } : undefined
|
|
658
|
+
}
|
|
564
659
|
// The explicit role is deliberate: `list-style: none` makes Safari/VoiceOver drop the implicit one.
|
|
565
660
|
// oxlint-disable-next-line jsx-a11y/no-redundant-roles
|
|
566
661
|
role="list"
|
|
@@ -604,6 +699,7 @@ export function MeterBar(props: {
|
|
|
604
699
|
forecastCaption: string | undefined
|
|
605
700
|
startCaption: ReactNode
|
|
606
701
|
endCaption: ReactNode
|
|
702
|
+
readingAt: 'fill' | 'start' | undefined
|
|
607
703
|
shell: Shell
|
|
608
704
|
}) {
|
|
609
705
|
const { label, min, max, format, zones, shell } = props
|
|
@@ -629,8 +725,38 @@ export function MeterBar(props: {
|
|
|
629
725
|
props.target === undefined &&
|
|
630
726
|
model.ticks.length === 0
|
|
631
727
|
const hasParts = model.partCaptions.length > 0
|
|
632
|
-
|
|
728
|
+
// A scale's start figure: a Meter with marks or a target labels where its track begins, with its
|
|
729
|
+
// `format`, unless the consumer opted out (`startCaption={null}`) or already labelled that end.
|
|
730
|
+
const zoned = zones !== undefined && zones.length > 0
|
|
731
|
+
const labelled = model.ticks.filter((t) => t.label !== undefined)
|
|
732
|
+
const startFigure =
|
|
733
|
+
!compact &&
|
|
734
|
+
!zoned &&
|
|
735
|
+
props.startCaption !== null &&
|
|
736
|
+
(model.ticks.length > 0 || model.targetPct !== undefined) &&
|
|
737
|
+
!labelled.some((t) => t.pct <= 0)
|
|
738
|
+
const tickLabels: TickMark[] = compact
|
|
739
|
+
? []
|
|
740
|
+
: [
|
|
741
|
+
...(startFigure
|
|
742
|
+
? [
|
|
743
|
+
{
|
|
744
|
+
key: 'start',
|
|
745
|
+
pct: 0,
|
|
746
|
+
label: format(min),
|
|
747
|
+
caption: undefined,
|
|
748
|
+
text: '',
|
|
749
|
+
} satisfies TickMark,
|
|
750
|
+
]
|
|
751
|
+
: []),
|
|
752
|
+
...labelled,
|
|
753
|
+
]
|
|
633
754
|
const zoneLabels = compact ? [] : model.zoneLabels
|
|
755
|
+
// On a zoned track the zone names own the row below; the figures at its two ends sit above the
|
|
756
|
+
// track, where nothing else competes for them. Every other tick label stays with the names.
|
|
757
|
+
const isEnd = (t: TickMark) => t.pct <= 0 || t.pct >= 100
|
|
758
|
+
const aboveTicks = zoneLabels.length > 0 ? tickLabels.filter(isEnd) : tickLabels
|
|
759
|
+
const belowTicks = zoneLabels.length > 0 ? tickLabels.filter((t) => !isEnd(t)) : []
|
|
634
760
|
const describedBy =
|
|
635
761
|
model.describedByText === null ? {} : ({ 'aria-describedby': describedId } as const)
|
|
636
762
|
|
|
@@ -643,23 +769,52 @@ export function MeterBar(props: {
|
|
|
643
769
|
? []
|
|
644
770
|
: [
|
|
645
771
|
...(start !== null && !anchored
|
|
646
|
-
? [
|
|
772
|
+
? [
|
|
773
|
+
{
|
|
774
|
+
key: 'start',
|
|
775
|
+
node: glue(start),
|
|
776
|
+
// The reading sits at its fill's end (clamped inside the track); `readingAt="start"` keeps the old start edge.
|
|
777
|
+
...(props.readingAt !== 'start' &&
|
|
778
|
+
model.fillEndPct !== undefined && {
|
|
779
|
+
pct: model.fillEndPct,
|
|
780
|
+
align: 'end' as const,
|
|
781
|
+
}),
|
|
782
|
+
} satisfies CaptionItem,
|
|
783
|
+
]
|
|
647
784
|
: []),
|
|
648
785
|
...(model.forecastText !== null
|
|
649
786
|
? [
|
|
650
787
|
{
|
|
651
788
|
key: 'forecast',
|
|
652
789
|
node: glue(model.forecastText),
|
|
790
|
+
drop: 2,
|
|
791
|
+
// The reading ends at the boundary, the forecast begins there.
|
|
792
|
+
...(props.readingAt !== 'start' && start !== null && { align: 'start' as const }),
|
|
653
793
|
...(model.boundaryPct !== undefined && { pct: model.boundaryPct }),
|
|
654
794
|
} satisfies CaptionItem,
|
|
655
795
|
]
|
|
656
796
|
: []),
|
|
797
|
+
...(compact
|
|
798
|
+
? []
|
|
799
|
+
: model.ticks.flatMap((t) =>
|
|
800
|
+
t.caption === undefined
|
|
801
|
+
? []
|
|
802
|
+
: [
|
|
803
|
+
{
|
|
804
|
+
key: `tick${t.key}`,
|
|
805
|
+
node: glue(t.caption),
|
|
806
|
+
pct: t.pct,
|
|
807
|
+
drop: 1,
|
|
808
|
+
} satisfies CaptionItem,
|
|
809
|
+
],
|
|
810
|
+
)),
|
|
657
811
|
...(end !== null
|
|
658
812
|
? [
|
|
659
813
|
{
|
|
660
814
|
key: 'end',
|
|
661
815
|
node: glue(end),
|
|
662
816
|
end: true,
|
|
817
|
+
...(targetHere && { target: true }),
|
|
663
818
|
...(targetHere && model.targetPct !== undefined
|
|
664
819
|
? { pct: model.targetPct }
|
|
665
820
|
: { edge: 'end' as const }),
|
|
@@ -671,9 +826,7 @@ export function MeterBar(props: {
|
|
|
671
826
|
const root = rootProps(shell)
|
|
672
827
|
return (
|
|
673
828
|
<div {...root} className={root.className}>
|
|
674
|
-
{
|
|
675
|
-
<LabelRow zones={zoneLabels} ticks={tickLabels} />
|
|
676
|
-
)}
|
|
829
|
+
{aboveTicks.length > 0 && <LabelRow zones={[]} ticks={aboveTicks} />}
|
|
677
830
|
<div
|
|
678
831
|
className={cx(classes.trackBox, trackHidden && classes.trackHidden)}
|
|
679
832
|
data-meter-track-hidden={trackHidden ? '' : undefined}
|
|
@@ -697,6 +850,9 @@ export function MeterBar(props: {
|
|
|
697
850
|
key={i}
|
|
698
851
|
className={classes.zone}
|
|
699
852
|
data-meter-zone={z.label}
|
|
853
|
+
{...(i > 0 &&
|
|
854
|
+
zones[i - 1]?.tone === 'muted' &&
|
|
855
|
+
z.tone === 'muted' && { 'data-meter-zone-seam': '' })}
|
|
700
856
|
style={zoneStyle(z, i, zones.length, min, model.span)}
|
|
701
857
|
/>
|
|
702
858
|
),
|
|
@@ -706,6 +862,7 @@ export function MeterBar(props: {
|
|
|
706
862
|
key={i}
|
|
707
863
|
className={cx(classes.fill, p.forecast && classes.forecastFill)}
|
|
708
864
|
data-meter-fill={p.forecast ? 'forecast' : 'committed'}
|
|
865
|
+
{...(p.seam && { 'data-meter-seam': '' })}
|
|
709
866
|
data-tone={
|
|
710
867
|
props.tone === 'muted' && p.color === undefined && !p.forecast ? 'muted' : undefined
|
|
711
868
|
}
|
|
@@ -720,7 +877,7 @@ export function MeterBar(props: {
|
|
|
720
877
|
))}
|
|
721
878
|
<Tick kind="target" className={classes.tick} pct={model.targetPct} />
|
|
722
879
|
</div>
|
|
723
|
-
{zoneLabels.length > 0 && <LabelRow zones={zoneLabels} ticks={
|
|
880
|
+
{zoneLabels.length > 0 && <LabelRow zones={zoneLabels} ticks={belowTicks} />}
|
|
724
881
|
{anchored && <ZoneReading pct={model.markerPct ?? 0}>{start}</ZoneReading>}
|
|
725
882
|
{model.describedByText !== null && (
|
|
726
883
|
<VisuallyHidden id={describedId} className={classes.summary}>
|
|
@@ -62,6 +62,12 @@
|
|
|
62
62
|
background: color-mix(in srgb, var(--vx-muted) 65%, transparent);
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
+
/* Muted parts share one flat fill: a track-coloured hairline at the shared edge tells them apart. */
|
|
66
|
+
.fill[data-meter-seam] {
|
|
67
|
+
box-sizing: border-box;
|
|
68
|
+
border-inline-start: 1px solid var(--vx-surface-subtle);
|
|
69
|
+
}
|
|
70
|
+
|
|
65
71
|
/* The committed/forecast pair: the same neutral at two strengths. Flat, never hatched. */
|
|
66
72
|
.forecastFill {
|
|
67
73
|
background: color-mix(in srgb, var(--vx-line) 45%, transparent);
|
|
@@ -200,6 +206,14 @@
|
|
|
200
206
|
white-space: nowrap;
|
|
201
207
|
}
|
|
202
208
|
|
|
209
|
+
/* `text-wrap` sets the same longhand as `white-space: nowrap`: `.caption`'s `balance`, declared below,
|
|
210
|
+
* would win on source order and let a caption placed at its measured width wrap on a sub-pixel
|
|
211
|
+
* difference. One class more outranks it. */
|
|
212
|
+
.captionsAnchored > :is(.caption) {
|
|
213
|
+
white-space: nowrap;
|
|
214
|
+
text-wrap: nowrap;
|
|
215
|
+
}
|
|
216
|
+
|
|
203
217
|
/* Captions never truncate: the row wraps, and a caption wider than the row wraps inside itself. */
|
|
204
218
|
.caption {
|
|
205
219
|
min-width: 0;
|
|
@@ -214,6 +228,19 @@
|
|
|
214
228
|
text-align: end;
|
|
215
229
|
}
|
|
216
230
|
|
|
231
|
+
/* The target figure is one line: it never wraps (the row drops other captions first). A consumer's
|
|
232
|
+
* own end caption is prose and may still wrap. */
|
|
233
|
+
.captionTarget {
|
|
234
|
+
composes: captionEnd;
|
|
235
|
+
flex: none;
|
|
236
|
+
white-space: nowrap;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/* A caption the row has no room for: still laid out (so a resize can measure it again), not shown. */
|
|
240
|
+
.captionsAnchored > [data-hidden] {
|
|
241
|
+
visibility: hidden;
|
|
242
|
+
}
|
|
243
|
+
|
|
217
244
|
/* The visually-hidden summary and loading text are still text: they read the caption size, not the
|
|
218
245
|
* body size they would inherit. */
|
|
219
246
|
.root .summary {
|
|
@@ -235,11 +262,26 @@
|
|
|
235
262
|
color: var(--vx-muted);
|
|
236
263
|
}
|
|
237
264
|
|
|
265
|
+
/* An entry is one line: swatch, name and value never break apart; the row wraps between entries. */
|
|
238
266
|
.partCaption {
|
|
239
267
|
display: inline-flex;
|
|
268
|
+
flex: none;
|
|
240
269
|
align-items: baseline;
|
|
241
270
|
gap: var(--vx-space-control-gap, 0.375rem);
|
|
271
|
+
white-space: nowrap;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/* Not every entry fits one row: a grid with the measured column count, never one entry alone. */
|
|
275
|
+
.partCaptionsGrid {
|
|
276
|
+
display: grid;
|
|
277
|
+
justify-content: start;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/* Only an entry wider than the whole row may break (measured), so nothing overflows the card. */
|
|
281
|
+
.partCaptionsWrap > .partCaption {
|
|
282
|
+
flex: 0 1 auto;
|
|
242
283
|
min-width: 0;
|
|
284
|
+
white-space: normal;
|
|
243
285
|
overflow-wrap: anywhere;
|
|
244
286
|
}
|
|
245
287
|
|
|
@@ -270,7 +312,20 @@
|
|
|
270
312
|
color: var(--vx-muted);
|
|
271
313
|
}
|
|
272
314
|
|
|
273
|
-
/*
|
|
315
|
+
/* One caption-height line: a blank caption row (empty) or the home of a skeleton line (loading), so
|
|
316
|
+
* both stand at the loaded Meter's height. */
|
|
317
|
+
.line {
|
|
318
|
+
display: flex;
|
|
319
|
+
align-items: center;
|
|
320
|
+
height: 1lh;
|
|
321
|
+
font-size: var(--basalt-meter-caption);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
.lineZoned {
|
|
325
|
+
height: 1.25em;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/* The skeleton holds the loaded footprint: figure row (zoned), track, caption / zone-name row. */
|
|
274
329
|
.skeletonTrack {
|
|
275
330
|
height: 0.375rem;
|
|
276
331
|
}
|
|
@@ -355,6 +410,6 @@
|
|
|
355
410
|
height: 1lh;
|
|
356
411
|
}
|
|
357
412
|
|
|
358
|
-
.row .
|
|
413
|
+
.row .line {
|
|
359
414
|
display: none;
|
|
360
415
|
}
|
|
@@ -23,12 +23,17 @@ declare const classes: {
|
|
|
23
23
|
readonly captions: string
|
|
24
24
|
readonly caption: string
|
|
25
25
|
readonly captionEnd: string
|
|
26
|
+
readonly captionTarget: string
|
|
26
27
|
readonly captionsAnchored: string
|
|
27
28
|
readonly partCaptions: string
|
|
28
29
|
readonly partCaption: string
|
|
29
30
|
readonly partCaptionsUnder: string
|
|
31
|
+
readonly partCaptionsWrap: string
|
|
32
|
+
readonly partCaptionsGrid: string
|
|
30
33
|
readonly swatch: string
|
|
31
34
|
readonly empty: string
|
|
35
|
+
readonly line: string
|
|
36
|
+
readonly lineZoned: string
|
|
32
37
|
readonly skeletonTrack: string
|
|
33
38
|
readonly skeletonCaption: string
|
|
34
39
|
readonly ringBox: string
|
package/src/dashboard/meter.tsx
CHANGED
|
@@ -72,7 +72,7 @@ type Common = BasaltProps & {
|
|
|
72
72
|
format?: (value: number) => string
|
|
73
73
|
/** Renders a skeleton with the meter's footprint. */
|
|
74
74
|
loading?: boolean
|
|
75
|
-
/** Muted line shown when there is no reading
|
|
75
|
+
/** Muted line shown when there is no reading; none by default (the muted track stands alone, caption rows blank). */
|
|
76
76
|
emptyText?: string
|
|
77
77
|
}
|
|
78
78
|
|
|
@@ -82,10 +82,13 @@ type BarCommon = Common & {
|
|
|
82
82
|
target?: number
|
|
83
83
|
/**
|
|
84
84
|
* More marks on the track (cut-offs, a window mean). Each is drawn at `at`; a `label` is captioned
|
|
85
|
-
* above the track, or on a zoned Meter in the zone-name row (the end ticks at the row's ends)
|
|
86
|
-
* caption
|
|
87
|
-
*
|
|
88
|
-
* and `target`.
|
|
85
|
+
* above the track, or on a zoned Meter in the zone-name row (the end ticks at the row's ends); a
|
|
86
|
+
* `caption` sits under the track, centred on the mark and clamped inside it. A label that would
|
|
87
|
+
* collide with another hides. A tick outside `[min, max]` is dropped, not clamped. All are listed
|
|
88
|
+
* in the accessible description. Works with `value`, `zones`, `segments` and `target`.
|
|
89
|
+
*
|
|
90
|
+
* Given `ticks` (or a `target`), a plain or segmented bar also labels where its track starts: the
|
|
91
|
+
* start figure `format(min)`, above the track. `startCaption={null}` drops it.
|
|
89
92
|
*/
|
|
90
93
|
ticks?: readonly MeterTick[]
|
|
91
94
|
/**
|
|
@@ -102,11 +105,14 @@ type BarCommon = Common & {
|
|
|
102
105
|
* Put the value beside it in your own layout.
|
|
103
106
|
*/
|
|
104
107
|
size?: 'row'
|
|
105
|
-
/**
|
|
108
|
+
/**
|
|
109
|
+
* Start caption (default: the formatted reading). `null` drops it, and the start figure that
|
|
110
|
+
* `ticks`/`target` add above the track; zone labels stay.
|
|
111
|
+
*/
|
|
106
112
|
startCaption?: ReactNode
|
|
107
113
|
/**
|
|
108
|
-
* End caption (default: `Target <target
|
|
109
|
-
* when it fits). `null` drops it; zone labels stay.
|
|
114
|
+
* End caption (default: `Target <target>` with the Meter's `format`, drawn at the target's tick
|
|
115
|
+
* rather than the track end when it fits). `null` drops it; zone labels stay.
|
|
110
116
|
*/
|
|
111
117
|
endCaption?: ReactNode
|
|
112
118
|
/**
|
|
@@ -116,6 +122,12 @@ type BarCommon = Common & {
|
|
|
116
122
|
* to print it inside a host. A `stops` track prints it only when `true`.
|
|
117
123
|
*/
|
|
118
124
|
reading?: boolean
|
|
125
|
+
/**
|
|
126
|
+
* Where the reading caption sits under a plain or segmented bar. `'fill'` (default): at the end of
|
|
127
|
+
* the fill, clamped inside the track (at the start when the fill is too short to hold it).
|
|
128
|
+
* `'start'`: at the track's start, as before 2.24.
|
|
129
|
+
*/
|
|
130
|
+
readingAt?: 'fill' | 'start'
|
|
119
131
|
}
|
|
120
132
|
|
|
121
133
|
/**
|
|
@@ -186,6 +198,7 @@ export type MeterProps =
|
|
|
186
198
|
startCaption?: never
|
|
187
199
|
endCaption?: never
|
|
188
200
|
reading?: never
|
|
201
|
+
readingAt?: never
|
|
189
202
|
stops?: never
|
|
190
203
|
track?: never
|
|
191
204
|
})
|
|
@@ -215,13 +228,22 @@ export function Meter(props: MeterProps) {
|
|
|
215
228
|
const hostTone = useContext(VisualSlotContext)?.tone
|
|
216
229
|
const hostColor = hostTone === undefined ? undefined : VX.status[hostTone]
|
|
217
230
|
|
|
218
|
-
if (props.loading === true)
|
|
231
|
+
if (props.loading === true)
|
|
232
|
+
return (
|
|
233
|
+
<MeterLoading label={label} ring={ring} zoned={props.zones !== undefined} shell={shell} />
|
|
234
|
+
)
|
|
219
235
|
|
|
220
236
|
const segments = props.segments === undefined ? undefined : normalizeSegments(props.segments)
|
|
221
237
|
const reading = segments === undefined ? props.value : segmentReading(segments, min)
|
|
222
238
|
if (!isReading(reading) || segments?.length === 0) {
|
|
223
239
|
return (
|
|
224
|
-
<MeterEmpty
|
|
240
|
+
<MeterEmpty
|
|
241
|
+
label={label}
|
|
242
|
+
text={props.emptyText}
|
|
243
|
+
ring={ring}
|
|
244
|
+
zoned={props.zones !== undefined}
|
|
245
|
+
shell={shell}
|
|
246
|
+
/>
|
|
225
247
|
)
|
|
226
248
|
}
|
|
227
249
|
|
|
@@ -252,6 +274,7 @@ export function Meter(props: MeterProps) {
|
|
|
252
274
|
forecastCaption={props.segments === undefined ? undefined : props.forecastCaption}
|
|
253
275
|
startCaption={props.startCaption}
|
|
254
276
|
endCaption={props.endCaption}
|
|
277
|
+
readingAt={props.readingAt}
|
|
255
278
|
/>
|
|
256
279
|
)
|
|
257
280
|
}
|