basalt-ui 2.22.0 → 2.23.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 +27 -0
- package/MIGRATING.md +187 -12
- package/agent/agents/basalt-design-reviewer.md +1 -1
- package/agent/skills/basalt-design/SKILL.md +1 -1
- 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 +2 -1
- package/dist/charts/CartesianChart.d.ts +2 -0
- package/dist/charts/CartesianChart.d.ts.map +1 -1
- 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 +67 -13
- 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/compile.d.ts +8 -0
- package/dist/charts/compile.d.ts.map +1 -1
- package/dist/charts/compile.js +30 -21
- 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/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 +8 -11
- package/dist/charts/state.d.ts.map +1 -1
- package/dist/charts/state.js +3 -1
- package/dist/charts/types.d.ts +4 -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/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 +30 -0
- package/dist/dashboard/delta-badge.d.ts.map +1 -1
- package/dist/dashboard/delta-badge.js +2 -2
- package/dist/dashboard/meter-model.d.ts +25 -20
- package/dist/dashboard/meter-model.d.ts.map +1 -1
- package/dist/dashboard/meter-model.js +24 -12
- package/dist/dashboard/meter-parts.d.ts +1 -1
- package/dist/dashboard/meter-parts.d.ts.map +1 -1
- package/dist/dashboard/meter-parts.js +39 -4
- package/dist/dashboard/meter.d.ts +14 -8
- package/dist/dashboard/meter.d.ts.map +1 -1
- package/dist/dashboard/meter.js +1 -1
- package/dist/dashboard/meter.module.css +15 -0
- package/dist/dashboard/meter.module.css.d.ts +1 -0
- package/dist/dashboard/query-state.d.ts.map +1 -1
- package/dist/dashboard/query-state.js +1 -1
- package/dist/dashboard/stat-card-parts.js +1 -1
- package/dist/dashboard/stat-card.module.css +25 -6
- package/dist/dashboard/stat-group.module.css +7 -0
- package/dist/dashboard/stat-strip.d.ts +15 -5
- package/dist/dashboard/stat-strip.d.ts.map +1 -1
- package/dist/dashboard/stat-strip.js +50 -34
- package/dist/dashboard/stat-strip.module.css +83 -61
- package/dist/guard/index.d.ts.map +1 -1
- package/dist/guard/index.js +0 -5
- package/dist/styles.css +18 -11
- package/dist/theme/controls.module.css +14 -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 +10 -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 +6 -4
- package/package.json +1 -1
- package/src/charts/BandStrip.tsx +55 -5
- package/src/charts/Bars.tsx +2 -1
- package/src/charts/CartesianChart.tsx +2 -0
- package/src/charts/ChartCard.tsx +32 -19
- package/src/charts/Sparkline.tsx +92 -19
- package/src/charts/band-fold.ts +25 -6
- package/src/charts/chart-dates.ts +30 -0
- package/src/charts/compile.ts +64 -23
- package/src/charts/date-tick-format.ts +10 -13
- package/src/charts/labels.ts +43 -22
- package/src/charts/ref-label.ts +27 -0
- package/src/charts/sparkline.module.css +8 -11
- package/src/charts/state.tsx +6 -3
- package/src/charts/types.ts +4 -3
- package/src/cli/shot/capture.ts +15 -3
- package/src/cli/shot/detect.ts +9 -9
- 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 +30 -0
- package/src/dashboard/bar-list.tsx +29 -0
- package/src/dashboard/delta-badge.tsx +6 -2
- package/src/dashboard/meter-model.ts +58 -41
- package/src/dashboard/meter-parts.tsx +66 -5
- package/src/dashboard/meter.module.css +15 -0
- package/src/dashboard/meter.module.css.d.ts +1 -0
- package/src/dashboard/meter.tsx +15 -11
- package/src/dashboard/query-state.tsx +1 -1
- package/src/dashboard/stat-card-parts.tsx +1 -1
- package/src/dashboard/stat-card.module.css +25 -6
- package/src/dashboard/stat-group.module.css +7 -0
- package/src/dashboard/stat-strip.module.css +83 -61
- package/src/dashboard/stat-strip.tsx +93 -54
- package/src/guard/index.ts +0 -5
- package/src/styles.css +18 -11
- package/src/theme/__snapshots__/plain-theme.test.ts.snap +14 -8
- package/src/theme/controls.module.css +14 -0
- package/src/theme/controls.module.css.d.ts +1 -0
- package/src/theme/index.ts +10 -7
- package/src/theme/status-verdict.tsx +5 -1
- package/src/tokens/palette.ts +7 -10
package/src/cli/shot/types.ts
CHANGED
|
@@ -72,6 +72,8 @@ export type ShotRecord = {
|
|
|
72
72
|
/** `absent`: the anchor declared itself missing in this state (`data-shot-absent`): not a defect. */
|
|
73
73
|
status: 'ok' | 'not-declared' | 'absent' | 'skipped' | 'error'
|
|
74
74
|
note?: string
|
|
75
|
+
/** The anchor renders a basalt state surface (a ChartCard, StatCard or chart state): set on the `not-declared` shots of a route that declares no `data-shot-states`. */
|
|
76
|
+
stateful?: true
|
|
75
77
|
}
|
|
76
78
|
|
|
77
79
|
/** The theme's resolved steps (px) for one scheme × viewport; a missing custom property is omitted. */
|
package/src/cli/tokens-css.ts
CHANGED
|
@@ -183,17 +183,17 @@ export function tokensCss(flags: string[], cwd: string = process.cwd()): number
|
|
|
183
183
|
}
|
|
184
184
|
|
|
185
185
|
/** Every `--basalt-font-*` declaration in the shipped stylesheet, in source order. */
|
|
186
|
-
function readShippedFontDecls(pkgRoot: string): {
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
}
|
|
196
|
-
return decls
|
|
186
|
+
function readShippedFontDecls(pkgRoot: string): {
|
|
187
|
+
face: string
|
|
188
|
+
decls: { name: string; value: string }[]
|
|
189
|
+
} {
|
|
190
|
+
const css = readSource(pkgRoot, 'dist/styles.css') ?? readSource(pkgRoot, 'src/styles.css') ?? ''
|
|
191
|
+
const face = css.match(/@font-face\s*\{[^}]*'Basalt Head Digits'[^}]*\}\n*/)?.[0] ?? ''
|
|
192
|
+
const decls = [...css.matchAll(/(--basalt-font[\w-]*)\s*:\s*([^;]+);/g)].map((m) => ({
|
|
193
|
+
name: m[1] as string,
|
|
194
|
+
value: (m[2] as string).replace(/\s+/g, ' ').trim(),
|
|
195
|
+
}))
|
|
196
|
+
return { face: face && `${face.trim()}\n\n`, decls }
|
|
197
197
|
}
|
|
198
198
|
|
|
199
199
|
/**
|
|
@@ -202,17 +202,15 @@ function readShippedFontDecls(pkgRoot: string): { name: string; value: string }[
|
|
|
202
202
|
* The typeface half of the framework-free route, which had no supported path at all: `tokens.css`
|
|
203
203
|
* emits no font vars, `styles.css` is the one place the defaults live and a framework-free consumer
|
|
204
204
|
* is told not to import it, and `buildFontsCss` returns `''` unless the caller already knows the
|
|
205
|
-
* stacks. The one non-Mantine consumer lost its font identity entirely and hardcoded the stacks
|
|
206
|
-
*
|
|
207
|
-
*
|
|
208
|
-
* The
|
|
209
|
-
*
|
|
210
|
-
* `@fontsource-variable/*` packages: without them the stacks fall through to their own system
|
|
211
|
-
* fallbacks, which is the intended framework-free behaviour.
|
|
205
|
+
* stacks. The one non-Mantine consumer lost its font identity entirely and hardcoded the stacks.
|
|
206
|
+
* The declarations (and the `Basalt Head Digits` face the head stack leads with) are READ from the
|
|
207
|
+
* shipped stylesheet, so this command and `basalt-ui/styles.css` can never name different
|
|
208
|
+
* typefaces. The fonts are `@fontsource-variable/*` packages (the face's `url()` is a bare package
|
|
209
|
+
* specifier for a bundler); without them the stacks fall back to system fonts.
|
|
212
210
|
*/
|
|
213
211
|
export function fontsCss(flags: string[], cwd: string = process.cwd()): number {
|
|
214
212
|
const pkgRoot = packageRoot()
|
|
215
|
-
const decls = readShippedFontDecls(pkgRoot)
|
|
213
|
+
const { face, decls } = readShippedFontDecls(pkgRoot)
|
|
216
214
|
if (decls.length === 0) {
|
|
217
215
|
console.error(
|
|
218
216
|
'fonts:css: could not read the shipped font stacks from styles.css — this is a packaging ' +
|
|
@@ -220,7 +218,7 @@ export function fontsCss(flags: string[], cwd: string = process.cwd()): number {
|
|
|
220
218
|
)
|
|
221
219
|
return 1
|
|
222
220
|
}
|
|
223
|
-
const body =
|
|
221
|
+
const body = `${face}:root {\n${decls.map((d) => ` ${d.name}: ${d.value};`).join('\n')}\n}\n`
|
|
224
222
|
const header = generatedHeader(readFrameworkVersion(pkgRoot), 'fonts:css', flags)
|
|
225
223
|
return emitGeneratedCss(`${header}${body}`, flags, cwd, 'fonts:css')
|
|
226
224
|
}
|
|
@@ -171,6 +171,11 @@
|
|
|
171
171
|
text-overflow: ellipsis;
|
|
172
172
|
}
|
|
173
173
|
|
|
174
|
+
/* The dot + word never outgrows its cell: the word truncates (its cell carries the full text in `title`). */
|
|
175
|
+
.root[data-variant='thin'] .secondary > :first-child {
|
|
176
|
+
max-inline-size: 100%;
|
|
177
|
+
}
|
|
178
|
+
|
|
174
179
|
.root[data-variant='thin'] .secondary [data-verdict-word] {
|
|
175
180
|
min-width: 0;
|
|
176
181
|
overflow: hidden;
|
|
@@ -216,4 +221,29 @@
|
|
|
216
221
|
.root[data-variant='thin'] .secondary {
|
|
217
222
|
text-align: end;
|
|
218
223
|
}
|
|
224
|
+
|
|
225
|
+
.root[data-variant='thin'][data-secondary-align='start'] .secondary {
|
|
226
|
+
text-align: start;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/*
|
|
231
|
+
* A column of DeltaBadges: a two-column grid, the glyph in a fixed-width slot and the figure (the badge's
|
|
232
|
+
* bare text) end-aligned in a tabular slot of four characters, so "▲ 9%" and "▲13%" share both their glyph
|
|
233
|
+
* x and their right edge. A zero delta has no glyph; an empty `::before` holds its slot. Scoped here because
|
|
234
|
+
* a hero metric has no column to line up with (D33: tabular figures only in a table-like column).
|
|
235
|
+
*/
|
|
236
|
+
.secondary [data-delta] {
|
|
237
|
+
display: inline-grid;
|
|
238
|
+
grid-template-columns: 1em minmax(4ch, auto);
|
|
239
|
+
justify-items: end;
|
|
240
|
+
font-variant-numeric: tabular-nums;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
.secondary [data-delta]:not(:has([data-delta-glyph]))::before {
|
|
244
|
+
content: '';
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
.secondary [data-delta-glyph] {
|
|
248
|
+
justify-self: center;
|
|
219
249
|
}
|
|
@@ -17,6 +17,11 @@
|
|
|
17
17
|
* label, the value and secondary columns are right-aligned and shared, and the track takes the rest on
|
|
18
18
|
* the one scale, so a name stays beside its value and a full-scale bar ends at the track end.
|
|
19
19
|
*
|
|
20
|
+
* The secondary column aligns by content (override: `secondaryAlign`): a text secondary (a status word,
|
|
21
|
+
* `StatusVerdict`/`StatusDot`) starts on one x so the dots line up; figures ("41%", "+€7"), numbers and a
|
|
22
|
+
* `DeltaBadge` end. A delta column also gets a fixed-width glyph slot and a tabular figure slot, so the
|
|
23
|
+
* glyphs AND the figures' right edges line up (a column of deltas is table-like, D33 allows tabular there).
|
|
24
|
+
*
|
|
20
25
|
* Colour law: bars are neutral. `accentLeader` (opt-in) lets the top row take the accent — the
|
|
21
26
|
* leader bar, and nothing else. Each value is rendered as text, never only a bar length.
|
|
22
27
|
*
|
|
@@ -41,10 +46,13 @@
|
|
|
41
46
|
* />
|
|
42
47
|
*/
|
|
43
48
|
import { Skeleton, VisuallyHidden } from '@mantine/core'
|
|
49
|
+
import { isValidElement } from 'react'
|
|
44
50
|
import type { ReactNode } from 'react'
|
|
45
51
|
import { cx } from '../common/props'
|
|
46
52
|
import type { BasaltProps } from '../common/props'
|
|
47
53
|
import classes from './bar-list.module.css'
|
|
54
|
+
import { StatusDot } from '../theme/status-dot'
|
|
55
|
+
import { StatusVerdict } from '../theme/status-verdict'
|
|
48
56
|
import { asText, barPercent } from './scale'
|
|
49
57
|
|
|
50
58
|
type BarListItem = {
|
|
@@ -79,6 +87,11 @@ export type BarListProps = BasaltProps & {
|
|
|
79
87
|
variant?: 'thin' | 'inline'
|
|
80
88
|
/** The first row's bar takes the accent. Off by default. */
|
|
81
89
|
accentLeader?: boolean
|
|
90
|
+
/**
|
|
91
|
+
* Which edge the secondary column aligns to. Default: by content — text (a status word, a status
|
|
92
|
+
* mark) starts, figures and other elements end.
|
|
93
|
+
*/
|
|
94
|
+
secondaryAlign?: 'start' | 'end'
|
|
82
95
|
/** Renders row-shaped skeletons. */
|
|
83
96
|
loading?: boolean
|
|
84
97
|
/** Skeleton rows while loading. Default 5. */
|
|
@@ -91,6 +104,19 @@ export type BarListProps = BasaltProps & {
|
|
|
91
104
|
const hasContent = (node: ReactNode): boolean =>
|
|
92
105
|
node !== undefined && node !== null && typeof node !== 'boolean'
|
|
93
106
|
|
|
107
|
+
const isFigure = (node: ReactNode): boolean =>
|
|
108
|
+
typeof node === 'number' || (typeof node === 'string' && /^[\s+\-−±▲▼]*[€$£¥]?\d/.test(node))
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* The column's edge by content. A string that is not a figure and a status mark (`StatusVerdict`,
|
|
112
|
+
* `StatusDot`) are text and start on one x so the dots line up; a number, a numeric string and any other
|
|
113
|
+
* element (a `DeltaBadge`) are figures and keep the end edge.
|
|
114
|
+
*/
|
|
115
|
+
const isText = (node: ReactNode): boolean =>
|
|
116
|
+
typeof node === 'string'
|
|
117
|
+
? !isFigure(node)
|
|
118
|
+
: isValidElement(node) && (node.type === StatusVerdict || node.type === StatusDot)
|
|
119
|
+
|
|
94
120
|
export function BarList({
|
|
95
121
|
label,
|
|
96
122
|
items,
|
|
@@ -98,6 +124,7 @@ export function BarList({
|
|
|
98
124
|
max,
|
|
99
125
|
variant = 'thin',
|
|
100
126
|
accentLeader = false,
|
|
127
|
+
secondaryAlign,
|
|
101
128
|
loading = false,
|
|
102
129
|
loadingRows = 5,
|
|
103
130
|
emptyText = 'No data',
|
|
@@ -134,6 +161,7 @@ export function BarList({
|
|
|
134
161
|
)
|
|
135
162
|
const thin = variant === 'thin'
|
|
136
163
|
const hasSecondary = items.some((i) => hasContent(i.secondary))
|
|
164
|
+
const align = secondaryAlign ?? (items.some((i) => isText(i.secondary)) ? 'start' : 'end')
|
|
137
165
|
return (
|
|
138
166
|
// The frame is the width container the wide layout keys on (a container cannot restyle its own grid).
|
|
139
167
|
<div className={cx(classes.frame, className)} style={style}>
|
|
@@ -144,6 +172,7 @@ export function BarList({
|
|
|
144
172
|
role="list"
|
|
145
173
|
aria-label={label}
|
|
146
174
|
data-secondary={hasSecondary ? '' : undefined}
|
|
175
|
+
data-secondary-align={hasSecondary ? align : undefined}
|
|
147
176
|
data-variant={variant}
|
|
148
177
|
>
|
|
149
178
|
{items.map((item, i) => {
|
|
@@ -87,8 +87,12 @@ export function DeltaBadge({
|
|
|
87
87
|
const showGlyph = withGlyph && glyph !== undefined
|
|
88
88
|
|
|
89
89
|
return (
|
|
90
|
-
<span className={classes.deltaBadge} style={{ color: tone }}>
|
|
91
|
-
{showGlyph &&
|
|
90
|
+
<span className={classes.deltaBadge} style={{ color: tone }} data-delta="">
|
|
91
|
+
{showGlyph && (
|
|
92
|
+
<span className={classes.deltaGlyph} data-delta-glyph="">
|
|
93
|
+
{glyph}
|
|
94
|
+
</span>
|
|
95
|
+
)}
|
|
92
96
|
{format(value)}
|
|
93
97
|
{period !== undefined && ' '}
|
|
94
98
|
{period !== undefined && (
|
|
@@ -10,8 +10,8 @@ export type MeterSegment = {
|
|
|
10
10
|
label: string
|
|
11
11
|
color?: string
|
|
12
12
|
/**
|
|
13
|
-
* `'muted'`: the part takes
|
|
14
|
-
*
|
|
13
|
+
* `'muted'`: the part takes the one flat muted fill every muted part shares, a hairline seam
|
|
14
|
+
* between neighbours (never a lightness step). A `color` wins.
|
|
15
15
|
*/
|
|
16
16
|
tone?: 'muted'
|
|
17
17
|
forecast?: boolean
|
|
@@ -21,8 +21,8 @@ export type MeterZone = {
|
|
|
21
21
|
to: number
|
|
22
22
|
label: string
|
|
23
23
|
/**
|
|
24
|
-
* `'muted'`: the band takes
|
|
25
|
-
*
|
|
24
|
+
* `'muted'`: the band takes the one flat muted fill every muted zone shares, a hairline gap
|
|
25
|
+
* between neighbours (never a lightness step): a non-verdict band is not a value bar. A `color` wins.
|
|
26
26
|
*/
|
|
27
27
|
tone?: 'muted'
|
|
28
28
|
/**
|
|
@@ -32,22 +32,27 @@ export type MeterZone = {
|
|
|
32
32
|
short?: string
|
|
33
33
|
color?: string
|
|
34
34
|
}
|
|
35
|
-
/**
|
|
36
|
-
|
|
35
|
+
/**
|
|
36
|
+
* A mark on the track at `at` (in the reading's units). A `label` is captioned beside it, above the
|
|
37
|
+
* track; a `caption` sits under the track, centred on the mark and clamped inside the track.
|
|
38
|
+
*/
|
|
39
|
+
export type MeterTick = { at: number; label?: string; caption?: string }
|
|
37
40
|
|
|
38
41
|
/** A colour of a `stops` gradient at `at` (in the reading's units); the colour is the consumer's. */
|
|
39
42
|
type MeterStop = { at: number; color: string }
|
|
40
43
|
|
|
41
44
|
/** A ramp step's strength in percent of its neutral: from `lo`, spread over `step` across the steps. */
|
|
42
45
|
export const RAMP_ZONE = { lo: 15, step: 45, solo: 40 }
|
|
43
|
-
|
|
46
|
+
/** The flat muted fill, in percent of `--vx-muted`: a zone band (argo's alpha) and a segment (clears 3:1 on the track). */
|
|
47
|
+
const MUTED_ZONE = 35
|
|
48
|
+
const MUTED_PART = 65
|
|
44
49
|
/** Neighbouring steps stay at least this far apart (the contrast the zone ramp always had), up to `RAMP_MAX`. */
|
|
45
50
|
export const RAMP_MIN_STEP = 15
|
|
46
51
|
export const RAMP_MAX = 95
|
|
47
52
|
|
|
48
53
|
/**
|
|
49
54
|
* Step `index` of `count`. The spread is floored at `RAMP_MIN_STEP` per step, so a ramp stays
|
|
50
|
-
* distinguishable by lightness up to six zones
|
|
55
|
+
* distinguishable by lightness up to six zones; past that the last steps clamp at
|
|
51
56
|
* `RAMP_MAX` and merge, which is the cue to group parts.
|
|
52
57
|
*/
|
|
53
58
|
export function rampStrength(index: number, count: number, ramp: typeof RAMP_ZONE): number {
|
|
@@ -55,22 +60,26 @@ export function rampStrength(index: number, count: number, ramp: typeof RAMP_ZON
|
|
|
55
60
|
return Math.min(RAMP_MAX, ramp.lo + index * Math.max(RAMP_MIN_STEP, ramp.step / (count - 1)))
|
|
56
61
|
}
|
|
57
62
|
|
|
58
|
-
function rampFill(
|
|
59
|
-
base: 'line' | 'muted',
|
|
60
|
-
index: number,
|
|
61
|
-
count: number,
|
|
62
|
-
ramp: typeof RAMP_ZONE,
|
|
63
|
-
): string {
|
|
63
|
+
function rampFill(base: 'line', index: number, count: number, ramp: typeof RAMP_ZONE): string {
|
|
64
64
|
return `color-mix(in srgb, var(--vx-${base}) ${rampStrength(index, count, ramp)}%, transparent)`
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
|
|
67
|
+
const mutedFill = (pct: number) => `color-mix(in srgb, var(--vx-muted) ${pct}%, transparent)`
|
|
68
|
+
|
|
69
|
+
/** A zone's fill: its own colour, else the one flat muted fill (`tone="muted"`), else its step of the line ramp. */
|
|
68
70
|
export function zoneFill(zone: MeterZone, index: number, count: number): string {
|
|
69
|
-
|
|
71
|
+
if (zone.color !== undefined) return zone.color
|
|
72
|
+
return zone.tone === 'muted' ? mutedFill(MUTED_ZONE) : rampFill('line', index, count, RAMP_ZONE)
|
|
70
73
|
}
|
|
71
74
|
|
|
72
75
|
/** One tick on the track: its percent position and what it says (caption `label`, aria `text`). */
|
|
73
|
-
export type TickMark = {
|
|
76
|
+
export type TickMark = {
|
|
77
|
+
key: string
|
|
78
|
+
pct: number
|
|
79
|
+
label: string | undefined
|
|
80
|
+
caption: string | undefined
|
|
81
|
+
text: string
|
|
82
|
+
}
|
|
74
83
|
|
|
75
84
|
/** A fill on the track, as fractions (0–1) of the span, with the segment it was laid out from. */
|
|
76
85
|
export type Part = {
|
|
@@ -78,6 +87,8 @@ export type Part = {
|
|
|
78
87
|
readonly size: number
|
|
79
88
|
readonly color: string | undefined
|
|
80
89
|
readonly forecast: boolean
|
|
90
|
+
/** A muted part right after another muted part: a hairline seam keeps the shared fill apart. */
|
|
91
|
+
readonly seam: boolean
|
|
81
92
|
readonly label: string
|
|
82
93
|
/** The segment's own (normalised) amount, in the reading's units — what its caption states. */
|
|
83
94
|
readonly amount: number
|
|
@@ -130,6 +141,7 @@ export function tickMarks(
|
|
|
130
141
|
key: String(i),
|
|
131
142
|
pct: toPct((t.at - min) / span),
|
|
132
143
|
label: t.label,
|
|
144
|
+
caption: t.caption,
|
|
133
145
|
text: `${t.label ?? 'Tick'} ${format(t.at)}`,
|
|
134
146
|
},
|
|
135
147
|
]
|
|
@@ -197,8 +209,7 @@ export function normalizeSegments(segments: readonly MeterSegment[]): MeterSegme
|
|
|
197
209
|
export function layoutSegments(segments: readonly MeterSegment[], span: number): Part[] {
|
|
198
210
|
let cursor = 0
|
|
199
211
|
const isMuted = (s: MeterSegment) => s.tone === 'muted' && s.color === undefined && !s.forecast
|
|
200
|
-
|
|
201
|
-
let muted = 0
|
|
212
|
+
let prevMuted = false
|
|
202
213
|
return segments.map((s) => {
|
|
203
214
|
const size = Math.max(0, Math.min(clamp01(s.value / span), 1 - cursor))
|
|
204
215
|
const forecast = s.forecast === true
|
|
@@ -206,16 +217,14 @@ export function layoutSegments(segments: readonly MeterSegment[], span: number):
|
|
|
206
217
|
const part = {
|
|
207
218
|
start: cursor,
|
|
208
219
|
size,
|
|
209
|
-
color: forecast
|
|
210
|
-
? undefined
|
|
211
|
-
: isMuted(s)
|
|
212
|
-
? rampFill('muted', muted++, mutedCount, RAMP_PART)
|
|
213
|
-
: s.color,
|
|
220
|
+
color: forecast ? undefined : isMuted(s) ? mutedFill(MUTED_PART) : s.color,
|
|
214
221
|
forecast,
|
|
222
|
+
seam: isMuted(s) && prevMuted,
|
|
215
223
|
label: s.label,
|
|
216
224
|
amount: s.value,
|
|
217
225
|
}
|
|
218
226
|
cursor += size
|
|
227
|
+
prevMuted = isMuted(s)
|
|
219
228
|
return part
|
|
220
229
|
})
|
|
221
230
|
}
|
|
@@ -240,7 +249,7 @@ export type RowLabel = {
|
|
|
240
249
|
box: LabelBox
|
|
241
250
|
span?: LabelBox
|
|
242
251
|
holding?: boolean
|
|
243
|
-
/** A tick at the track's start or end: it
|
|
252
|
+
/** A tick at the track's start or end: it keeps its place over every zone name it would touch. */
|
|
244
253
|
end?: boolean
|
|
245
254
|
short?: LabelBox
|
|
246
255
|
}
|
|
@@ -257,11 +266,12 @@ export type RowPlacement = {
|
|
|
257
266
|
/**
|
|
258
267
|
* Which labels of the row show, in input order. The holding zone's name claims its place first (it
|
|
259
268
|
* is the reading's verdict, so it never hides for width: it may spill past its span, shifted inside
|
|
260
|
-
* the row); the other ticks go next
|
|
261
|
-
* when it lies inside the row and its own span and
|
|
262
|
-
* name
|
|
263
|
-
*
|
|
264
|
-
*
|
|
269
|
+
* the row); the other ticks go next, then the end ticks (at the track's start or end: a scale's
|
|
270
|
+
* figures); every other zone name then shows only when it lies inside the row and its own span and
|
|
271
|
+
* clears every label already kept, trying its full name, then its `short` box, then hiding. An end
|
|
272
|
+
* figure hides only when it cannot clear the holding name, an interior tick or the other end. A tick
|
|
273
|
+
* keeps at least `gap` px (one gap step of the host's spacing) from every other label; zone names
|
|
274
|
+
* among themselves only must not touch. A hidden name is still named in the described-by text.
|
|
265
275
|
*/
|
|
266
276
|
export function placeRowLabels(
|
|
267
277
|
labels: readonly RowLabel[],
|
|
@@ -272,7 +282,7 @@ export function placeRowLabels(
|
|
|
272
282
|
const short = labels.map(() => false)
|
|
273
283
|
const shift = labels.map(() => 0)
|
|
274
284
|
const kept: { box: LabelBox; tick: boolean }[] = []
|
|
275
|
-
const rank = (l: RowLabel) => (l.holding ? 0 : l.
|
|
285
|
+
const rank = (l: RowLabel) => (l.holding ? 0 : l.span ? 3 : l.end ? 2 : 1)
|
|
276
286
|
const order = labels
|
|
277
287
|
.map((_, i) => i)
|
|
278
288
|
.toSorted((a, b) => rank(labels[a] as RowLabel) - rank(labels[b] as RowLabel))
|
|
@@ -482,8 +492,10 @@ export type MarkItem = { width: number; pct?: number; edge?: 'end' }
|
|
|
482
492
|
/**
|
|
483
493
|
* Where each caption of the marks row starts (px, logical start edge), index-aligned with `items`: an
|
|
484
494
|
* anchored caption is centred on its mark and clamped inside the row, the others sit at the start (or,
|
|
485
|
-
* `edge: 'end'`, the end). `
|
|
486
|
-
*
|
|
495
|
+
* `edge: 'end'`, the end). Two captions closer than `gap` are pushed apart, in order, the least that
|
|
496
|
+
* clears them, so a caption stays as near its mark as the row allows. `null` when nothing is anchored,
|
|
497
|
+
* the row is unmeasured, a caption is wider than the row, or the captions cannot all clear each other
|
|
498
|
+
* inside the row: the row then flows and wraps instead.
|
|
487
499
|
*/
|
|
488
500
|
export function placeMarkCaptions(
|
|
489
501
|
items: readonly MarkItem[],
|
|
@@ -497,14 +509,19 @@ export function placeMarkCaptions(
|
|
|
497
509
|
return Math.max(0, Math.min((rowWidth * i.pct) / 100 - i.width / 2, rowWidth - i.width))
|
|
498
510
|
})
|
|
499
511
|
const order = lefts.map((_, i) => i).toSorted((a, b) => (lefts[a] ?? 0) - (lefts[b] ?? 0))
|
|
500
|
-
const
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
512
|
+
const widthOf = (i: number) => items[i]?.width ?? 0
|
|
513
|
+
for (const [n, i] of order.entries()) {
|
|
514
|
+
const prev = order[n - 1]
|
|
515
|
+
if (prev !== undefined)
|
|
516
|
+
lefts[i] = Math.max(lefts[i] ?? 0, (lefts[prev] ?? 0) + widthOf(prev) + gap)
|
|
517
|
+
}
|
|
518
|
+
for (const [n, i] of order.toReversed().entries()) {
|
|
519
|
+
const next = order.toReversed()[n - 1]
|
|
520
|
+
const limit = next === undefined ? rowWidth : (lefts[next] ?? 0) - gap
|
|
521
|
+
lefts[i] = Math.min(lefts[i] ?? 0, limit - widthOf(i))
|
|
522
|
+
}
|
|
523
|
+
const first = order[0]
|
|
524
|
+
return first !== undefined && (lefts[first] ?? 0) < -LABEL_SUBPIXEL ? null : lefts
|
|
508
525
|
}
|
|
509
526
|
|
|
510
527
|
/**
|
|
@@ -150,20 +150,32 @@ export function MeterLoading({
|
|
|
150
150
|
)
|
|
151
151
|
}
|
|
152
152
|
|
|
153
|
-
|
|
153
|
+
const EMPTY_READING = '—'
|
|
154
|
+
|
|
155
|
+
export function MeterEmpty(props: {
|
|
156
|
+
label: string
|
|
157
|
+
text: string | undefined
|
|
158
|
+
ring: boolean
|
|
159
|
+
shell: Shell
|
|
160
|
+
}) {
|
|
154
161
|
const { label, text, ring, shell } = props
|
|
162
|
+
// The ring has a reading slot (its centre), so the dash sits there as the reading; a bar prints
|
|
163
|
+
// its reading in the caption row, so the dash is that row's muted line. A `text` is the caption.
|
|
155
164
|
return (
|
|
156
165
|
<output {...rootProps(shell)} aria-label={label}>
|
|
157
166
|
{ring ? (
|
|
158
167
|
<span className={classes.ringBox}>
|
|
159
168
|
<RingSvg />
|
|
169
|
+
<span className={classes.ringValue}>{EMPTY_READING}</span>
|
|
160
170
|
</span>
|
|
161
171
|
) : (
|
|
162
172
|
<div className={classes.trackBox}>
|
|
163
173
|
<div className={classes.track} data-meter-track />
|
|
164
174
|
</div>
|
|
165
175
|
)}
|
|
166
|
-
|
|
176
|
+
{(!ring || text !== undefined) && (
|
|
177
|
+
<span className={classes.empty}>{text ?? EMPTY_READING}</span>
|
|
178
|
+
)}
|
|
167
179
|
</output>
|
|
168
180
|
)
|
|
169
181
|
}
|
|
@@ -539,15 +551,18 @@ function CaptionRow({ items }: { items: readonly CaptionItem[] }) {
|
|
|
539
551
|
|
|
540
552
|
/**
|
|
541
553
|
* Categorical part captions (swatch, name, value): each under its own segment when every one fits
|
|
542
|
-
* there on one line, else
|
|
554
|
+
* there on one line, else a wrapping row of entries from the track's start. An entry stays on one
|
|
555
|
+
* line unless it is wider than the row itself.
|
|
543
556
|
*/
|
|
544
557
|
function PartCaptions({ captions }: { captions: readonly PartCaption[] }) {
|
|
545
558
|
const rowRef = useRef<HTMLUListElement>(null)
|
|
546
559
|
const [under, setUnder] = useState(false)
|
|
560
|
+
const [overwide, setOverwide] = useState(false)
|
|
547
561
|
useMeasured(
|
|
548
562
|
rowRef,
|
|
549
563
|
(row) => {
|
|
550
564
|
const { widths, rowWidth, gap } = measureItems(row)
|
|
565
|
+
setOverwide(widths.some((w) => w > rowWidth))
|
|
551
566
|
const fits = partsFitUnder(
|
|
552
567
|
captions.map((c, i) => ({ startPct: c.startPct, width: widths[i] ?? 0 })),
|
|
553
568
|
rowWidth,
|
|
@@ -560,7 +575,11 @@ function PartCaptions({ captions }: { captions: readonly PartCaption[] }) {
|
|
|
560
575
|
return (
|
|
561
576
|
<ul
|
|
562
577
|
ref={rowRef}
|
|
563
|
-
className={cx(
|
|
578
|
+
className={cx(
|
|
579
|
+
classes.partCaptions,
|
|
580
|
+
under && classes.partCaptionsUnder,
|
|
581
|
+
overwide && classes.partCaptionsWrap,
|
|
582
|
+
)}
|
|
564
583
|
// The explicit role is deliberate: `list-style: none` makes Safari/VoiceOver drop the implicit one.
|
|
565
584
|
// oxlint-disable-next-line jsx-a11y/no-redundant-roles
|
|
566
585
|
role="list"
|
|
@@ -629,7 +648,32 @@ export function MeterBar(props: {
|
|
|
629
648
|
props.target === undefined &&
|
|
630
649
|
model.ticks.length === 0
|
|
631
650
|
const hasParts = model.partCaptions.length > 0
|
|
632
|
-
|
|
651
|
+
// A scale's start figure: a Meter with marks or a target labels where its track begins, with its
|
|
652
|
+
// `format`, unless the consumer opted out (`startCaption={null}`) or already labelled that end.
|
|
653
|
+
const zoned = zones !== undefined && zones.length > 0
|
|
654
|
+
const labelled = model.ticks.filter((t) => t.label !== undefined)
|
|
655
|
+
const startFigure =
|
|
656
|
+
!compact &&
|
|
657
|
+
!zoned &&
|
|
658
|
+
props.startCaption !== null &&
|
|
659
|
+
(model.ticks.length > 0 || model.targetPct !== undefined) &&
|
|
660
|
+
!labelled.some((t) => t.pct <= 0)
|
|
661
|
+
const tickLabels: TickMark[] = compact
|
|
662
|
+
? []
|
|
663
|
+
: [
|
|
664
|
+
...(startFigure
|
|
665
|
+
? [
|
|
666
|
+
{
|
|
667
|
+
key: 'start',
|
|
668
|
+
pct: 0,
|
|
669
|
+
label: format(min),
|
|
670
|
+
caption: undefined,
|
|
671
|
+
text: '',
|
|
672
|
+
} satisfies TickMark,
|
|
673
|
+
]
|
|
674
|
+
: []),
|
|
675
|
+
...labelled,
|
|
676
|
+
]
|
|
633
677
|
const zoneLabels = compact ? [] : model.zoneLabels
|
|
634
678
|
const describedBy =
|
|
635
679
|
model.describedByText === null ? {} : ({ 'aria-describedby': describedId } as const)
|
|
@@ -654,6 +698,19 @@ export function MeterBar(props: {
|
|
|
654
698
|
} satisfies CaptionItem,
|
|
655
699
|
]
|
|
656
700
|
: []),
|
|
701
|
+
...(compact
|
|
702
|
+
? []
|
|
703
|
+
: model.ticks.flatMap((t) =>
|
|
704
|
+
t.caption === undefined
|
|
705
|
+
? []
|
|
706
|
+
: [
|
|
707
|
+
{
|
|
708
|
+
key: `tick${t.key}`,
|
|
709
|
+
node: glue(t.caption),
|
|
710
|
+
pct: t.pct,
|
|
711
|
+
} satisfies CaptionItem,
|
|
712
|
+
],
|
|
713
|
+
)),
|
|
657
714
|
...(end !== null
|
|
658
715
|
? [
|
|
659
716
|
{
|
|
@@ -697,6 +754,9 @@ export function MeterBar(props: {
|
|
|
697
754
|
key={i}
|
|
698
755
|
className={classes.zone}
|
|
699
756
|
data-meter-zone={z.label}
|
|
757
|
+
{...(i > 0 &&
|
|
758
|
+
zones[i - 1]?.tone === 'muted' &&
|
|
759
|
+
z.tone === 'muted' && { 'data-meter-zone-seam': '' })}
|
|
700
760
|
style={zoneStyle(z, i, zones.length, min, model.span)}
|
|
701
761
|
/>
|
|
702
762
|
),
|
|
@@ -706,6 +766,7 @@ export function MeterBar(props: {
|
|
|
706
766
|
key={i}
|
|
707
767
|
className={cx(classes.fill, p.forecast && classes.forecastFill)}
|
|
708
768
|
data-meter-fill={p.forecast ? 'forecast' : 'committed'}
|
|
769
|
+
{...(p.seam && { 'data-meter-seam': '' })}
|
|
709
770
|
data-tone={
|
|
710
771
|
props.tone === 'muted' && p.color === undefined && !p.forecast ? 'muted' : undefined
|
|
711
772
|
}
|
|
@@ -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);
|
|
@@ -235,11 +241,20 @@
|
|
|
235
241
|
color: var(--vx-muted);
|
|
236
242
|
}
|
|
237
243
|
|
|
244
|
+
/* An entry is one line: swatch, name and value never break apart; the row wraps between entries. */
|
|
238
245
|
.partCaption {
|
|
239
246
|
display: inline-flex;
|
|
247
|
+
flex: none;
|
|
240
248
|
align-items: baseline;
|
|
241
249
|
gap: var(--vx-space-control-gap, 0.375rem);
|
|
250
|
+
white-space: nowrap;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/* Only an entry wider than the whole row may break (measured), so nothing overflows the card. */
|
|
254
|
+
.partCaptionsWrap > .partCaption {
|
|
255
|
+
flex: 0 1 auto;
|
|
242
256
|
min-width: 0;
|
|
257
|
+
white-space: normal;
|
|
243
258
|
overflow-wrap: anywhere;
|
|
244
259
|
}
|
|
245
260
|
|