basalt-ui 2.17.0 → 2.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. package/CHANGELOG.md +58 -0
  2. package/MIGRATING.md +108 -12
  3. package/agent/agents/basalt-design-reviewer.md +2 -2
  4. package/agent/skills/basalt-design/SKILL.md +1 -1
  5. package/dist/cli/help.d.ts +1 -0
  6. package/dist/cli/help.d.ts.map +1 -1
  7. package/dist/cli/help.js +8 -2
  8. package/dist/cli/shot/capture.d.ts +12 -1
  9. package/dist/cli/shot/capture.d.ts.map +1 -1
  10. package/dist/cli/shot/capture.js +72 -10
  11. package/dist/cli/shot/index.d.ts +10 -1
  12. package/dist/cli/shot/index.d.ts.map +1 -1
  13. package/dist/cli/shot/index.js +40 -5
  14. package/dist/cli/shot/real-data.d.ts +35 -0
  15. package/dist/cli/shot/real-data.d.ts.map +1 -0
  16. package/dist/cli/shot/real-data.js +120 -0
  17. package/dist/cli/shot/serve.d.ts +2 -2
  18. package/dist/cli/shot/serve.d.ts.map +1 -1
  19. package/dist/cli/shot/serve.js +16 -2
  20. package/dist/commands/notifications/center.d.ts.map +1 -1
  21. package/dist/commands/notifications/center.js +18 -26
  22. package/dist/content/callout.d.ts +1 -1
  23. package/dist/content/callout.d.ts.map +1 -1
  24. package/dist/content/callout.js +10 -1
  25. package/dist/content/callout.module.css +15 -3
  26. package/dist/content/callout.module.css.d.ts +1 -0
  27. package/dist/dashboard/bar-list.d.ts +29 -0
  28. package/dist/dashboard/bar-list.d.ts.map +1 -0
  29. package/dist/dashboard/bar-list.js +65 -0
  30. package/dist/dashboard/bar-list.module.css +91 -0
  31. package/dist/dashboard/bar-list.module.css.d.ts +17 -0
  32. package/dist/dashboard/index.d.ts +2 -0
  33. package/dist/dashboard/index.d.ts.map +1 -1
  34. package/dist/dashboard/index.js +4 -0
  35. package/dist/dashboard/meter-model.d.ts +126 -0
  36. package/dist/dashboard/meter-model.d.ts.map +1 -0
  37. package/dist/dashboard/meter-model.js +135 -0
  38. package/dist/dashboard/meter-parts.d.ts +42 -0
  39. package/dist/dashboard/meter-parts.d.ts.map +1 -0
  40. package/dist/dashboard/meter-parts.js +297 -0
  41. package/dist/dashboard/meter.d.ts +123 -0
  42. package/dist/dashboard/meter.d.ts.map +1 -0
  43. package/dist/dashboard/meter.js +43 -0
  44. package/dist/dashboard/meter.module.css +268 -0
  45. package/dist/dashboard/meter.module.css.d.ts +39 -0
  46. package/dist/dashboard/scale.d.ts +9 -0
  47. package/dist/dashboard/scale.d.ts.map +1 -0
  48. package/dist/dashboard/scale.js +10 -0
  49. package/dist/dashboard/stat-card-parts.d.ts +3 -1
  50. package/dist/dashboard/stat-card-parts.d.ts.map +1 -1
  51. package/dist/dashboard/stat-card-parts.js +18 -3
  52. package/dist/dashboard/stat-card.d.ts +6 -5
  53. package/dist/dashboard/stat-card.d.ts.map +1 -1
  54. package/dist/dashboard/stat-card.js +48 -77
  55. package/dist/dashboard/stat-card.module.css +27 -7
  56. package/dist/dashboard/widget-header.d.ts.map +1 -1
  57. package/dist/dashboard/widget-header.js +2 -1
  58. package/dist/dashboard/widget-header.module.css +28 -1
  59. package/dist/index.d.ts +1 -1
  60. package/dist/index.d.ts.map +1 -1
  61. package/dist/index.js +5 -1
  62. package/dist/theme/chrome-vars.d.ts +29 -17
  63. package/dist/theme/chrome-vars.d.ts.map +1 -1
  64. package/dist/theme/chrome-vars.js +18 -8
  65. package/dist/theme/index.d.ts.map +1 -1
  66. package/dist/theme/index.js +9 -5
  67. package/dist/theme/status-dot.d.ts +6 -0
  68. package/dist/theme/status-dot.d.ts.map +1 -0
  69. package/dist/theme/status-dot.js +9 -0
  70. package/dist/theme/status-dot.module.css +9 -0
  71. package/dist/theme/status-dot.module.css.d.ts +8 -0
  72. package/dist/theme/status-verdict.d.ts +9 -0
  73. package/dist/theme/status-verdict.d.ts.map +1 -0
  74. package/dist/theme/status-verdict.js +13 -0
  75. package/dist/theme/status-verdict.module.css +23 -0
  76. package/dist/theme/status-verdict.module.css.d.ts +9 -0
  77. package/dist/tokens/derive.d.ts +11 -1
  78. package/dist/tokens/derive.d.ts.map +1 -1
  79. package/dist/tokens/derive.js +9 -24
  80. package/dist/tokens/status-text.d.ts +26 -0
  81. package/dist/tokens/status-text.d.ts.map +1 -0
  82. package/dist/tokens/status-text.js +68 -0
  83. package/llms.txt +32 -3
  84. package/package.json +1 -1
  85. package/src/cli/help.ts +22 -2
  86. package/src/cli/shot/capture.ts +98 -9
  87. package/src/cli/shot/index.ts +50 -4
  88. package/src/cli/shot/real-data.ts +165 -0
  89. package/src/cli/shot/serve.ts +28 -3
  90. package/src/commands/notifications/center.tsx +29 -32
  91. package/src/content/callout.module.css +15 -3
  92. package/src/content/callout.module.css.d.ts +1 -0
  93. package/src/content/callout.tsx +15 -2
  94. package/src/dashboard/bar-list.module.css +91 -0
  95. package/src/dashboard/bar-list.module.css.d.ts +17 -0
  96. package/src/dashboard/bar-list.tsx +125 -0
  97. package/src/dashboard/index.ts +2 -0
  98. package/src/dashboard/meter-model.ts +254 -0
  99. package/src/dashboard/meter-parts.tsx +407 -0
  100. package/src/dashboard/meter.module.css +268 -0
  101. package/src/dashboard/meter.module.css.d.ts +39 -0
  102. package/src/dashboard/meter.tsx +173 -0
  103. package/src/dashboard/scale.ts +13 -0
  104. package/src/dashboard/stat-card-parts.tsx +22 -2
  105. package/src/dashboard/stat-card.module.css +27 -7
  106. package/src/dashboard/stat-card.tsx +18 -52
  107. package/src/dashboard/widget-header.module.css +28 -1
  108. package/src/dashboard/widget-header.tsx +4 -1
  109. package/src/index.ts +4 -0
  110. package/src/theme/__snapshots__/plain-theme.test.ts.snap +88 -16
  111. package/src/theme/chrome-vars.ts +48 -23
  112. package/src/theme/index.ts +10 -6
  113. package/src/theme/status-dot.module.css +9 -0
  114. package/src/theme/status-dot.module.css.d.ts +8 -0
  115. package/src/theme/status-dot.tsx +19 -0
  116. package/src/theme/status-verdict.module.css +23 -0
  117. package/src/theme/status-verdict.module.css.d.ts +9 -0
  118. package/src/theme/status-verdict.tsx +27 -0
  119. package/src/tokens/derive.ts +19 -31
  120. package/src/tokens/status-text.ts +85 -0
@@ -0,0 +1,297 @@
1
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
+ import { Skeleton, VisuallyHidden } from "@mantine/core";
3
+ import { useId, useRef, useState } from "react";
4
+ import { useIsomorphicLayoutEffect } from "../common/isomorphic-layout-effect.js";
5
+ import { cx } from "../common/props.js";
6
+ import {
7
+ ariaValues,
8
+ modelBar,
9
+ ringFraction,
10
+ startCaptionText,
11
+ zoneBand,
12
+ zoneLabelsFit
13
+ } from "./meter-model.js";
14
+ import classes from "./meter.module.css";
15
+ import { toPct } from "./scale.js";
16
+ function rootProps(shell) {
17
+ return {
18
+ className: cx(classes.root, shell.className),
19
+ style: shell.style,
20
+ "data-basalt-meter": ""
21
+ };
22
+ }
23
+ const RING_VIEWBOX = 36;
24
+ const RING_STROKE = 4;
25
+ const RING_RADIUS = (RING_VIEWBOX - RING_STROKE) / 2;
26
+ const RING_LENGTH = 2 * Math.PI * RING_RADIUS;
27
+ const RING_CENTER = RING_VIEWBOX / 2;
28
+ function RingSvg({ fraction, color }) {
29
+ return /* @__PURE__ */ jsxs("svg", { className: classes.ring, viewBox: `0 0 ${RING_VIEWBOX} ${RING_VIEWBOX}`, "aria-hidden": true, children: [
30
+ /* @__PURE__ */ jsx(
31
+ "circle",
32
+ {
33
+ className: classes.ringTrack,
34
+ cx: RING_CENTER,
35
+ cy: RING_CENTER,
36
+ r: RING_RADIUS,
37
+ strokeWidth: RING_STROKE
38
+ }
39
+ ),
40
+ fraction !== void 0 && /* @__PURE__ */ jsx(
41
+ "circle",
42
+ {
43
+ className: classes.ringArc,
44
+ cx: RING_CENTER,
45
+ cy: RING_CENTER,
46
+ r: RING_RADIUS,
47
+ strokeWidth: RING_STROKE,
48
+ strokeDasharray: `${fraction * RING_LENGTH} ${RING_LENGTH}`,
49
+ ...color !== void 0 && { style: { stroke: color } }
50
+ }
51
+ )
52
+ ] });
53
+ }
54
+ function MeterLoading({
55
+ label,
56
+ ring,
57
+ shell
58
+ }) {
59
+ return /* @__PURE__ */ jsxs("div", { ...rootProps(shell), "aria-busy": "true", children: [
60
+ /* @__PURE__ */ jsx(VisuallyHidden, { children: `Loading ${label}` }),
61
+ ring ? /* @__PURE__ */ jsx(Skeleton, { className: classes.skeletonRing, circle: true }) : /* @__PURE__ */ jsxs(Fragment, { children: [
62
+ /* @__PURE__ */ jsx(Skeleton, { className: classes.skeletonTrack }),
63
+ /* @__PURE__ */ jsx(Skeleton, { className: classes.skeletonCaption, radius: "sm" })
64
+ ] })
65
+ ] });
66
+ }
67
+ function MeterEmpty(props) {
68
+ const { label, text, ring, shell } = props;
69
+ return /* @__PURE__ */ jsxs("output", { ...rootProps(shell), "aria-label": label, children: [
70
+ ring ? /* @__PURE__ */ jsx("span", { className: classes.ringBox, children: /* @__PURE__ */ jsx(RingSvg, {}) }) : /* @__PURE__ */ jsx("div", { className: classes.trackBox, children: /* @__PURE__ */ jsx("div", { className: classes.track, "data-meter-track": true }) }),
71
+ /* @__PURE__ */ jsx("span", { className: classes.empty, children: text })
72
+ ] });
73
+ }
74
+ function MeterRing(props) {
75
+ const { label, reading, min, max, color, format, shell } = props;
76
+ return /* @__PURE__ */ jsx("div", { ...rootProps(shell), children: /* @__PURE__ */ jsxs(
77
+ "span",
78
+ {
79
+ className: classes.ringBox,
80
+ "aria-label": label,
81
+ ...ariaValues(reading, min, max, format),
82
+ children: [
83
+ /* @__PURE__ */ jsx(RingSvg, { fraction: ringFraction(reading, min, max), color }),
84
+ /* @__PURE__ */ jsx("span", { className: classes.ringValue, children: format(reading) })
85
+ ]
86
+ }
87
+ ) });
88
+ }
89
+ function fillStyle(p) {
90
+ return { width: `${toPct(p.size)}%`, ...p.color !== void 0 && { background: p.color } };
91
+ }
92
+ const ZONE_STRENGTH_MIN = 15;
93
+ const ZONE_STRENGTH_STEP = 45;
94
+ const ZONE_STRENGTH_SOLO = 40;
95
+ const ZONE_GAP = "1px";
96
+ function zoneStyle(zone, index, count, min, span) {
97
+ const band = zoneBand(zone, min, span);
98
+ const gap = index > 0;
99
+ const strength = count > 1 ? ZONE_STRENGTH_MIN + index / (count - 1) * ZONE_STRENGTH_STEP : ZONE_STRENGTH_SOLO;
100
+ return {
101
+ insetInlineStart: gap ? `calc(${band.start}% + ${ZONE_GAP})` : `${band.start}%`,
102
+ width: gap ? `calc(${band.width}% - ${ZONE_GAP})` : `${band.width}%`,
103
+ background: zone.color ?? `color-mix(in srgb, var(--vx-line) ${strength}%, transparent)`
104
+ };
105
+ }
106
+ const labelsKey = (labels) => labels.map((l) => l.label + (l.holding ? "*" : "")).join("\0");
107
+ function useZoneLabelLayout(rowRef, key) {
108
+ const [fits, setFits] = useState(true);
109
+ useIsomorphicLayoutEffect(() => {
110
+ const row = rowRef.current;
111
+ if (!row) return;
112
+ const measure = () => {
113
+ const origin = row.getBoundingClientRect();
114
+ const boxes = [...row.children].map((c) => {
115
+ const r = c.getBoundingClientRect();
116
+ return { left: r.left - origin.left, right: r.right - origin.left };
117
+ });
118
+ setFits(zoneLabelsFit(boxes, origin.width));
119
+ };
120
+ measure();
121
+ const observer = typeof ResizeObserver === "undefined" ? void 0 : new ResizeObserver(measure);
122
+ observer?.observe(row);
123
+ const fonts = typeof document === "undefined" ? void 0 : document.fonts;
124
+ let live = true;
125
+ void fonts?.ready?.then(() => live && measure());
126
+ fonts?.addEventListener?.("loadingdone", measure);
127
+ return () => {
128
+ live = false;
129
+ observer?.disconnect();
130
+ fonts?.removeEventListener?.("loadingdone", measure);
131
+ };
132
+ }, [rowRef, key]);
133
+ return fits;
134
+ }
135
+ function ZoneReading({ pct, children }) {
136
+ const rowRef = useRef(null);
137
+ const textRef = useRef(null);
138
+ const [start, setStart] = useState();
139
+ useIsomorphicLayoutEffect(() => {
140
+ const row = rowRef.current;
141
+ const text = textRef.current;
142
+ if (!row || !text) return;
143
+ const measure = () => {
144
+ const centre = row.clientWidth * pct / 100;
145
+ setStart(
146
+ Math.max(0, Math.min(centre - text.offsetWidth / 2, row.clientWidth - text.offsetWidth))
147
+ );
148
+ };
149
+ measure();
150
+ if (typeof ResizeObserver === "undefined") return;
151
+ const observer = new ResizeObserver(measure);
152
+ observer.observe(row);
153
+ observer.observe(text);
154
+ return () => observer.disconnect();
155
+ }, [pct]);
156
+ return /* @__PURE__ */ jsx("div", { ref: rowRef, className: classes.zoneReadingRow, "data-meter-reading-row": true, children: /* @__PURE__ */ jsx(
157
+ "span",
158
+ {
159
+ ref: textRef,
160
+ className: classes.zoneReading,
161
+ "data-measured": start === void 0 ? void 0 : "",
162
+ style: { insetInlineStart: start === void 0 ? `${pct}%` : `${start}px` },
163
+ children
164
+ }
165
+ ) });
166
+ }
167
+ function ZoneName({ label, ...rest }) {
168
+ return /* @__PURE__ */ jsx(
169
+ "span",
170
+ {
171
+ ...rest,
172
+ className: cx(rest.className, label.holding && classes.zoneLabelHolding),
173
+ "data-meter-zone-label": label.label,
174
+ "data-holding": label.holding || void 0,
175
+ children: label.label
176
+ }
177
+ );
178
+ }
179
+ function ZoneLabels({ labels }) {
180
+ const rowRef = useRef(null);
181
+ const fits = useZoneLabelLayout(rowRef, labelsKey(labels));
182
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
183
+ /* @__PURE__ */ jsx(
184
+ "div",
185
+ {
186
+ ref: rowRef,
187
+ className: classes.zoneBand,
188
+ "data-meter-zone-band": true,
189
+ "data-collapsed": fits ? void 0 : "",
190
+ "aria-hidden": true,
191
+ children: labels.map((l) => /* @__PURE__ */ jsx(
192
+ ZoneName,
193
+ {
194
+ label: l,
195
+ className: classes.zoneLabel,
196
+ style: { insetInlineStart: `${l.startPct}%` }
197
+ },
198
+ l.key
199
+ ))
200
+ }
201
+ ),
202
+ !fits && /* @__PURE__ */ jsx("div", { className: classes.zoneList, "data-meter-zone-list": true, "aria-hidden": true, children: labels.map((l) => /* @__PURE__ */ jsx(ZoneName, { label: l, className: classes.zoneListItem }, l.key)) })
203
+ ] });
204
+ }
205
+ function MeterBar(props) {
206
+ const { label, reading, min, max, format, zones, shell } = props;
207
+ const describedId = useId();
208
+ const model = modelBar(props);
209
+ const start = startCaptionText(model, props.startCaption);
210
+ const end = props.endCaption === void 0 ? model.endText : props.endCaption;
211
+ const anchored = model.markerPct !== void 0 && start !== null;
212
+ const hasCaptions = start !== null && !anchored || end !== null || model.forecastText !== null;
213
+ const hasParts = model.partCaptions.length > 0;
214
+ const describedBy = model.describedByText === null ? {} : { "aria-describedby": describedId };
215
+ const root = rootProps(shell);
216
+ return /* @__PURE__ */ jsxs("div", { ...root, className: cx(root.className, model.zoneLabels.length > 0 && classes.zoned), children: [
217
+ /* @__PURE__ */ jsxs(
218
+ "div",
219
+ {
220
+ className: classes.trackBox,
221
+ "aria-label": label,
222
+ ...ariaValues(reading, min, max, format),
223
+ ...describedBy,
224
+ children: [
225
+ /* @__PURE__ */ jsxs("div", { className: classes.track, "data-meter-track": true, children: [
226
+ model.markerPct !== void 0 && zones?.map((z, i) => /* @__PURE__ */ jsx(
227
+ "div",
228
+ {
229
+ className: classes.zone,
230
+ "data-meter-zone": z.label,
231
+ style: zoneStyle(z, i, zones.length, min, model.span)
232
+ },
233
+ i
234
+ )),
235
+ model.parts.map((p, i) => /* @__PURE__ */ jsx(
236
+ "div",
237
+ {
238
+ className: cx(classes.fill, p.forecast && classes.forecastFill),
239
+ "data-meter-fill": p.forecast ? "forecast" : "committed",
240
+ style: fillStyle(p)
241
+ },
242
+ i
243
+ ))
244
+ ] }),
245
+ /* @__PURE__ */ jsx(Tick, { kind: "marker", className: classes.marker, pct: model.markerPct }),
246
+ /* @__PURE__ */ jsx(Tick, { kind: "boundary", className: classes.boundaryTick, pct: model.boundaryPct }),
247
+ /* @__PURE__ */ jsx(Tick, { kind: "target", className: classes.tick, pct: model.targetPct })
248
+ ]
249
+ }
250
+ ),
251
+ model.zoneLabels.length > 0 && /* @__PURE__ */ jsx(ZoneLabels, { labels: model.zoneLabels }),
252
+ anchored && /* @__PURE__ */ jsx(ZoneReading, { pct: model.markerPct ?? 0, children: start }),
253
+ model.describedByText !== null && /* @__PURE__ */ jsx(VisuallyHidden, { id: describedId, children: model.describedByText }),
254
+ hasParts && // The explicit role is deliberate: `list-style: none` makes Safari/VoiceOver drop the implicit one.
255
+ // oxlint-disable-next-line jsx-a11y/no-redundant-roles
256
+ /* @__PURE__ */ jsx("ul", { className: classes.partCaptions, role: "list", "data-meter-parts": true, children: model.partCaptions.map((c) => /* @__PURE__ */ jsxs("li", { className: classes.partCaption, children: [
257
+ /* @__PURE__ */ jsx(
258
+ "span",
259
+ {
260
+ className: classes.swatch,
261
+ style: { background: c.color ?? "var(--vx-line)" },
262
+ "aria-hidden": true
263
+ }
264
+ ),
265
+ c.label,
266
+ " ",
267
+ c.text
268
+ ] }, c.key)) }),
269
+ hasCaptions && /* @__PURE__ */ jsxs("div", { className: classes.captions, "data-meter-captions": true, children: [
270
+ start !== null && !anchored && /* @__PURE__ */ jsx("span", { className: classes.caption, children: start }),
271
+ model.forecastText !== null && /* @__PURE__ */ jsx("span", { className: classes.caption, children: model.forecastText }),
272
+ end !== null && /* @__PURE__ */ jsx("span", { className: classes.captionEnd, children: end })
273
+ ] })
274
+ ] });
275
+ }
276
+ function Tick({
277
+ kind,
278
+ className,
279
+ pct
280
+ }) {
281
+ if (pct === void 0) return null;
282
+ return /* @__PURE__ */ jsx(
283
+ "div",
284
+ {
285
+ className,
286
+ "data-meter-tick": kind,
287
+ style: { insetInlineStart: `${pct}%` },
288
+ "aria-hidden": true
289
+ }
290
+ );
291
+ }
292
+ export {
293
+ MeterBar,
294
+ MeterEmpty,
295
+ MeterLoading,
296
+ MeterRing
297
+ };
@@ -0,0 +1,123 @@
1
+ /**
2
+ * Meter — one bounded quantity on a track: progress to a target, a committed/forecast split, a
3
+ * part-of-a-whole strip (`segments`), or a single headline ratio as a `ring`. Choose it for "how far
4
+ * along is this against a limit"; choose `BarList` for a ranking and a chart for a trend. An HTML/CSS
5
+ * primitive, not a chart kind (no scale, axis or tooltip).
6
+ *
7
+ * Colour law: the fill is neutral (`VX.line`). `color` is for a VERDICT only (over budget, below
8
+ * target) and is a status colour the consumer passes; categorical `segments` take the consumer's
9
+ * series colours. Committed vs forecast is the same neutral at two strengths — never colour alone: a
10
+ * tick marks the boundary and a caption names the forecast. A value past `max` clamps the fill at the
11
+ * track end; the caption still states the real value.
12
+ *
13
+ * `zones` (bar only) draws the track as contiguous bands (neutral at stepped strengths unless a zone
14
+ * passes a status colour) and the reading becomes a MARKER on the track, not a fill. Each zone is
15
+ * named under the band at its start, the one holding the value (`from` inclusive) in ink and a
16
+ * heavier weight; names that would collide wrap as a list instead. The fit is measured in the
17
+ * browser, so server markup shows the band and the list may appear after mount. Use it for a
18
+ * reading judged against ranges.
19
+ *
20
+ * Every state (bar, ring, empty, loading) carries `data-basalt-meter` on its root. That attribute is
21
+ * the contract with `StatCard`: a Meter passed as its `sparkline` visual makes the slot size to content
22
+ * and keep the card's inline inset (both placements) instead of the sparkline's fixed height and bleed.
23
+ *
24
+ * Categorical `segments` (no `forecast` part) are captioned one per part — swatch, name, value — under
25
+ * the track and the default start caption is dropped (an explicit `startCaption` still shows);
26
+ * committed/forecast keeps the reading plus the forecast caption.
27
+ *
28
+ * @example
29
+ * import { Meter } from 'basalt-ui'
30
+ *
31
+ * // Spend against a budget: past the target the end caption states the overage.
32
+ * <Meter label="Monthly spend" value={512} max={600} target={450} color="var(--vx-status-bad)" format={usd} />
33
+ * // Training load as a zone band with a marker: the zones are named under the band, "Optimal" in ink.
34
+ * <Meter
35
+ * label="Training load"
36
+ * max={1000}
37
+ * value={612}
38
+ * zones={[
39
+ * { from: 0, to: 300, label: 'Low' },
40
+ * { from: 300, to: 750, label: 'Optimal' },
41
+ * { from: 750, to: 1000, label: 'High' },
42
+ * ]}
43
+ * />
44
+ * // A readiness score on its 0–100 scale (its contributors: <BarList max={100} … secondary="Good" />).
45
+ * <Meter label="Recovery" value={72} max={100} />
46
+ * <Meter
47
+ * label="Course progress"
48
+ * max={120}
49
+ * segments={[{ value: 70, label: 'Done' }, { value: 25, label: 'Planned', forecast: true }]}
50
+ * />
51
+ * <Meter shape="ring" label="Cache hit rate" value={87} max={100} format={(v) => `${v}%`} />
52
+ */
53
+ import type { ReactNode } from 'react';
54
+ import type { BasaltProps } from '../common/props.js';
55
+ import type { MeterSegment, MeterZone } from './meter-model.js';
56
+ type Common = BasaltProps & {
57
+ /** Accessible name (`aria-label`). Required: a meter without one is announced as a bare number. */
58
+ label: string;
59
+ /** Track start. Default 0. */
60
+ min?: number;
61
+ /** Track end. Default 100. */
62
+ max?: number;
63
+ /** Formats values in captions and the accessible text. Default: the number as written. */
64
+ format?: (value: number) => string;
65
+ /** Renders a skeleton with the meter's footprint. */
66
+ loading?: boolean;
67
+ /** Muted line shown when there is no reading. The track stays so the footprint holds. */
68
+ emptyText?: string;
69
+ };
70
+ type BarCommon = Common & {
71
+ shape?: 'bar';
72
+ /** Target position; draws a tick and states it in the end caption (with the overage past it). */
73
+ target?: number;
74
+ /** Start caption (default: the formatted reading). `null` drops it. */
75
+ startCaption?: ReactNode;
76
+ /** End caption (default: `Target <target>`). `null` drops it. */
77
+ endCaption?: ReactNode;
78
+ };
79
+ /**
80
+ * One of four forms; mixing them is a compile error.
81
+ * - Bar `value` (+ `target`, `color`): one reading on a neutral track.
82
+ * - Bar `segments`: ordered parts that sum to the reading (committed/forecast, part of a whole).
83
+ * - Bar `value` + `zones`: the reading is a marker against contiguous bands.
84
+ * - Ring (`shape: 'ring'`) `value` (+ `color`): one headline ratio; no target, captions, segments or zones.
85
+ */
86
+ export type MeterProps = (BarCommon & {
87
+ /** The reading. `null`/`undefined` (or non-finite) renders the empty state. */
88
+ value?: number | null | undefined;
89
+ /** A status colour, for a verdict only. Omit for the neutral fill. */
90
+ color?: string;
91
+ segments?: never;
92
+ zones?: never;
93
+ }) | (BarCommon & {
94
+ /** Ordered parts, accumulated from `min`; their sum is the reading. `forecast` parts render lighter. */
95
+ segments: readonly MeterSegment[];
96
+ /** Names the forecast beside the boundary tick (default: `Forecast: <labels>`). */
97
+ forecastCaption?: string;
98
+ value?: never;
99
+ color?: never;
100
+ zones?: never;
101
+ }) | (BarCommon & {
102
+ value?: number | null | undefined;
103
+ /**
104
+ * Contiguous bands drawn as the track, positioned from each `from`. The reading becomes a marker
105
+ * and each band is named under the track, the one that holds it in ink.
106
+ */
107
+ zones: readonly MeterZone[];
108
+ segments?: never;
109
+ color?: never;
110
+ }) | (Common & {
111
+ shape: 'ring';
112
+ value?: number | null | undefined;
113
+ /** A status colour, for a verdict only. */
114
+ color?: string;
115
+ segments?: never;
116
+ zones?: never;
117
+ target?: never;
118
+ startCaption?: never;
119
+ endCaption?: never;
120
+ });
121
+ export declare function Meter(props: MeterProps): import("react").JSX.Element;
122
+ export {};
123
+ //# sourceMappingURL=meter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"meter.d.ts","sourceRoot":"","sources":["../../src/dashboard/meter.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AACtC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAElD,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAI5D,KAAK,MAAM,GAAG,WAAW,GAAG;IAC1B,mGAAmG;IACnG,KAAK,EAAE,MAAM,CAAA;IACb,8BAA8B;IAC9B,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,8BAA8B;IAC9B,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,0FAA0F;IAC1F,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAA;IAClC,qDAAqD;IACrD,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,yFAAyF;IACzF,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,CAAA;AAED,KAAK,SAAS,GAAG,MAAM,GAAG;IACxB,KAAK,CAAC,EAAE,KAAK,CAAA;IACb,iGAAiG;IACjG,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,uEAAuE;IACvE,YAAY,CAAC,EAAE,SAAS,CAAA;IACxB,iEAAiE;IACjE,UAAU,CAAC,EAAE,SAAS,CAAA;CACvB,CAAA;AAED;;;;;;GAMG;AACH,MAAM,MAAM,UAAU,GAClB,CAAC,SAAS,GAAG;IACX,+EAA+E;IAC/E,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAA;IACjC,sEAAsE;IACtE,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,QAAQ,CAAC,EAAE,KAAK,CAAA;IAChB,KAAK,CAAC,EAAE,KAAK,CAAA;CACd,CAAC,GACF,CAAC,SAAS,GAAG;IACX,wGAAwG;IACxG,QAAQ,EAAE,SAAS,YAAY,EAAE,CAAA;IACjC,mFAAmF;IACnF,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,KAAK,CAAC,EAAE,KAAK,CAAA;IACb,KAAK,CAAC,EAAE,KAAK,CAAA;IACb,KAAK,CAAC,EAAE,KAAK,CAAA;CACd,CAAC,GACF,CAAC,SAAS,GAAG;IACX,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAA;IACjC;;;OAGG;IACH,KAAK,EAAE,SAAS,SAAS,EAAE,CAAA;IAC3B,QAAQ,CAAC,EAAE,KAAK,CAAA;IAChB,KAAK,CAAC,EAAE,KAAK,CAAA;CACd,CAAC,GACF,CAAC,MAAM,GAAG;IACR,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAA;IACjC,2CAA2C;IAC3C,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,QAAQ,CAAC,EAAE,KAAK,CAAA;IAChB,KAAK,CAAC,EAAE,KAAK,CAAA;IACb,MAAM,CAAC,EAAE,KAAK,CAAA;IACd,YAAY,CAAC,EAAE,KAAK,CAAA;IACpB,UAAU,CAAC,EAAE,KAAK,CAAA;CACnB,CAAC,CAAA;AAYN,wBAAgB,KAAK,CAAC,KAAK,EAAE,UAAU,+BA+BtC"}
@@ -0,0 +1,43 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { isReading, normalizeSegments, segmentReading, spanOf } from "./meter-model.js";
3
+ import { MeterBar, MeterEmpty, MeterLoading, MeterRing } from "./meter-parts.js";
4
+ import { asText } from "./scale.js";
5
+ let warnedTrack = false;
6
+ function warnInvalidTrack(min, max) {
7
+ if (warnedTrack || spanOf(min, max).valid || process.env.NODE_ENV === "production") return;
8
+ warnedTrack = true;
9
+ console.warn(
10
+ `[basalt] Meter: max (${max}) must be greater than min (${min}); drawing an empty track`
11
+ );
12
+ }
13
+ function Meter(props) {
14
+ const { label, min = 0, max = 100, format = asText, className, style } = props;
15
+ const shell = { className, style };
16
+ const ring = props.shape === "ring";
17
+ warnInvalidTrack(min, max);
18
+ if (props.loading === true) return /* @__PURE__ */ jsx(MeterLoading, { label, ring, shell });
19
+ const segments = props.segments === void 0 ? void 0 : normalizeSegments(props.segments);
20
+ const reading = segments === void 0 ? props.value : segmentReading(segments, min);
21
+ if (!isReading(reading) || segments?.length === 0) {
22
+ return /* @__PURE__ */ jsx(MeterEmpty, { label, text: props.emptyText ?? "No data", ring, shell });
23
+ }
24
+ if (props.shape === "ring") {
25
+ return /* @__PURE__ */ jsx(MeterRing, { ...{ label, reading, min, max, format, shell }, color: props.color });
26
+ }
27
+ return /* @__PURE__ */ jsx(
28
+ MeterBar,
29
+ {
30
+ ...{ label, reading, min, max, format, shell },
31
+ color: props.color,
32
+ segments,
33
+ zones: props.zones,
34
+ target: isReading(props.target) ? props.target : void 0,
35
+ forecastCaption: props.segments === void 0 ? void 0 : props.forecastCaption,
36
+ startCaption: props.startCaption,
37
+ endCaption: props.endCaption
38
+ }
39
+ );
40
+ }
41
+ export {
42
+ Meter
43
+ };