basalt-ui 2.18.0 → 2.20.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 +90 -0
- package/MIGRATING.md +238 -12
- package/agent/agents/basalt-design-reviewer.md +2 -2
- package/agent/rules/basalt-charts.md +1 -1
- package/agent/rules/basalt-mantine.md +1 -1
- package/agent/skills/basalt-app/SKILL.md +1 -1
- package/agent/skills/basalt-design/SKILL.md +1 -1
- package/agent/templates/DESIGN.md.tpl +1 -1
- package/configs/oxlint-plugin.js +33 -19
- package/configs/oxlint-plugin.test.ts +32 -2
- package/dist/charts/ChartCard.d.ts +28 -3
- package/dist/charts/ChartCard.d.ts.map +1 -1
- package/dist/charts/ChartCard.js +33 -11
- package/dist/charts/Donut.d.ts.map +1 -1
- package/dist/charts/Donut.js +13 -1
- package/dist/charts/Heatmap.js +1 -1
- package/dist/charts/Sparkline.d.ts +7 -1
- package/dist/charts/Sparkline.d.ts.map +1 -1
- package/dist/charts/Sparkline.js +137 -18
- package/dist/charts/box.d.ts +2 -0
- package/dist/charts/box.d.ts.map +1 -1
- package/dist/charts/box.js +2 -0
- package/dist/charts/chart-box.module.css +30 -0
- package/dist/charts/chart-box.module.css.d.ts +1 -0
- package/dist/charts/chart-card.module.css +47 -0
- package/dist/charts/chart-card.module.css.d.ts +7 -0
- package/dist/charts/compile.d.ts.map +1 -1
- package/dist/charts/compile.js +35 -8
- package/dist/charts/host.d.ts.map +1 -1
- package/dist/charts/host.js +2 -1
- package/dist/charts/index.d.ts +1 -1
- package/dist/charts/index.d.ts.map +1 -1
- package/dist/charts/sparkline.module.css +59 -0
- package/dist/charts/sparkline.module.css.d.ts +13 -0
- package/dist/charts/state.d.ts.map +1 -1
- package/dist/charts/state.js +32 -4
- package/dist/charts/types.d.ts +6 -0
- package/dist/charts/types.d.ts.map +1 -1
- package/dist/commands/notifications/center.d.ts.map +1 -1
- package/dist/commands/notifications/center.js +18 -26
- package/dist/content/callout.d.ts +1 -1
- package/dist/content/callout.d.ts.map +1 -1
- package/dist/content/callout.js +10 -1
- package/dist/content/callout.module.css +15 -3
- package/dist/content/callout.module.css.d.ts +1 -0
- package/dist/controls/sync-button.d.ts +3 -0
- package/dist/controls/sync-button.d.ts.map +1 -1
- package/dist/dashboard/bar-list.d.ts +15 -4
- package/dist/dashboard/bar-list.d.ts.map +1 -1
- package/dist/dashboard/bar-list.js +56 -19
- package/dist/dashboard/bar-list.module.css +110 -17
- package/dist/dashboard/bar-list.module.css.d.ts +2 -0
- package/dist/dashboard/delta-badge.d.ts +8 -3
- package/dist/dashboard/delta-badge.d.ts.map +1 -1
- package/dist/dashboard/delta-badge.js +9 -2
- package/dist/dashboard/index.d.ts +2 -0
- package/dist/dashboard/index.d.ts.map +1 -1
- package/dist/dashboard/meter-model.d.ts +68 -1
- package/dist/dashboard/meter-model.d.ts.map +1 -1
- package/dist/dashboard/meter-model.js +65 -4
- package/dist/dashboard/meter-parts.d.ts +5 -1
- package/dist/dashboard/meter-parts.d.ts.map +1 -1
- package/dist/dashboard/meter-parts.js +234 -60
- package/dist/dashboard/meter.d.ts +38 -6
- package/dist/dashboard/meter.d.ts.map +1 -1
- package/dist/dashboard/meter.js +4 -1
- package/dist/dashboard/meter.module.css +209 -13
- package/dist/dashboard/meter.module.css.d.ts +16 -0
- package/dist/dashboard/query-state.d.ts.map +1 -1
- package/dist/dashboard/query-state.js +14 -9
- package/dist/dashboard/settings-section.d.ts.map +1 -1
- package/dist/dashboard/settings-section.js +14 -25
- package/dist/dashboard/stat-card-parts.d.ts +3 -1
- package/dist/dashboard/stat-card-parts.d.ts.map +1 -1
- package/dist/dashboard/stat-card-parts.js +18 -3
- package/dist/dashboard/stat-card.d.ts +7 -6
- package/dist/dashboard/stat-card.d.ts.map +1 -1
- package/dist/dashboard/stat-card.js +51 -83
- package/dist/dashboard/stat-card.module.css +42 -14
- package/dist/dashboard/stat-group.d.ts +11 -2
- package/dist/dashboard/stat-group.d.ts.map +1 -1
- package/dist/dashboard/stat-group.js +9 -7
- package/dist/dashboard/stat-strip.d.ts +50 -0
- package/dist/dashboard/stat-strip.d.ts.map +1 -0
- package/dist/dashboard/stat-strip.js +85 -0
- package/dist/dashboard/stat-strip.module.css +208 -0
- package/dist/dashboard/stat-strip.module.css.d.ts +28 -0
- package/dist/dashboard/widget-header.d.ts +3 -3
- package/dist/dashboard/widget-header.d.ts.map +1 -1
- package/dist/dashboard/widget-header.js +2 -1
- package/dist/dashboard/widget-header.module.css +38 -7
- package/dist/format/date.d.ts.map +1 -1
- package/dist/format/date.js +4 -3
- package/dist/format/shared.d.ts +6 -0
- package/dist/format/shared.d.ts.map +1 -1
- package/dist/format/shared.js +6 -2
- package/dist/guard/index.d.ts +1 -1
- package/dist/guard/index.js +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/styles.css +6 -0
- package/dist/theme/card-inset.module.css +76 -0
- package/dist/theme/card-inset.module.css.d.ts +9 -0
- package/dist/theme/chrome-vars.d.ts +29 -17
- package/dist/theme/chrome-vars.d.ts.map +1 -1
- package/dist/theme/chrome-vars.js +18 -8
- package/dist/theme/controls.module.css +3 -0
- package/dist/theme/index.d.ts.map +1 -1
- package/dist/theme/index.js +32 -5
- package/dist/theme/nav-link.module.css +8 -10
- package/dist/theme/status-dot.d.ts +7 -0
- package/dist/theme/status-dot.d.ts.map +1 -0
- package/dist/theme/status-dot.js +18 -0
- package/dist/theme/status-dot.module.css +9 -0
- package/dist/theme/status-dot.module.css.d.ts +8 -0
- package/dist/theme/status-verdict.d.ts +10 -0
- package/dist/theme/status-verdict.d.ts.map +1 -0
- package/dist/theme/status-verdict.js +14 -0
- package/dist/theme/status-verdict.module.css +25 -0
- package/dist/theme/status-verdict.module.css.d.ts +9 -0
- package/llms.txt +30 -6
- package/package.json +1 -1
- package/src/charts/ChartCard.tsx +70 -4
- package/src/charts/Donut.tsx +9 -1
- package/src/charts/Heatmap.tsx +1 -1
- package/src/charts/Sparkline.tsx +180 -18
- package/src/charts/box.tsx +2 -0
- package/src/charts/chart-box.module.css +30 -0
- package/src/charts/chart-box.module.css.d.ts +1 -0
- package/src/charts/chart-card.module.css +47 -0
- package/src/charts/chart-card.module.css.d.ts +7 -0
- package/src/charts/compile.ts +42 -9
- package/src/charts/host.tsx +6 -3
- package/src/charts/index.ts +1 -1
- package/src/charts/sparkline.module.css +59 -0
- package/src/charts/sparkline.module.css.d.ts +13 -0
- package/src/charts/state.tsx +44 -4
- package/src/charts/types.ts +6 -0
- package/src/commands/notifications/center.tsx +29 -32
- package/src/content/callout.module.css +15 -3
- package/src/content/callout.module.css.d.ts +1 -0
- package/src/content/callout.tsx +15 -2
- package/src/controls/sync-button.tsx +3 -0
- package/src/dashboard/bar-list.module.css +110 -17
- package/src/dashboard/bar-list.module.css.d.ts +2 -0
- package/src/dashboard/bar-list.tsx +102 -21
- package/src/dashboard/delta-badge.tsx +21 -5
- package/src/dashboard/index.ts +2 -0
- package/src/dashboard/meter-model.ts +132 -4
- package/src/dashboard/meter-parts.tsx +305 -25
- package/src/dashboard/meter.module.css +209 -13
- package/src/dashboard/meter.module.css.d.ts +16 -0
- package/src/dashboard/meter.tsx +42 -7
- package/src/dashboard/query-state.tsx +28 -19
- package/src/dashboard/settings-section.tsx +1 -8
- package/src/dashboard/stat-card-parts.tsx +22 -2
- package/src/dashboard/stat-card.module.css +42 -14
- package/src/dashboard/stat-card.tsx +23 -60
- package/src/dashboard/stat-group.tsx +19 -8
- package/src/dashboard/stat-strip.module.css +208 -0
- package/src/dashboard/stat-strip.module.css.d.ts +28 -0
- package/src/dashboard/stat-strip.tsx +183 -0
- package/src/dashboard/widget-header.module.css +38 -7
- package/src/dashboard/widget-header.tsx +7 -4
- package/src/format/date.ts +6 -3
- package/src/format/shared.ts +11 -2
- package/src/guard/index.ts +1 -1
- package/src/index.ts +7 -0
- package/src/styles.css +6 -0
- package/src/theme/__snapshots__/plain-theme.test.ts.snap +242 -26
- package/src/theme/card-inset.module.css +76 -0
- package/src/theme/card-inset.module.css.d.ts +9 -0
- package/src/theme/chrome-vars.ts +48 -23
- package/src/theme/controls.module.css +3 -0
- package/src/theme/index.ts +40 -6
- package/src/theme/nav-link.module.css +8 -10
- package/src/theme/status-dot.module.css +9 -0
- package/src/theme/status-dot.module.css.d.ts +8 -0
- package/src/theme/status-dot.tsx +31 -0
- package/src/theme/status-verdict.module.css +25 -0
- package/src/theme/status-verdict.module.css.d.ts +9 -0
- package/src/theme/status-verdict.tsx +32 -0
|
@@ -1,10 +1,25 @@
|
|
|
1
1
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Skeleton, VisuallyHidden } from "@mantine/core";
|
|
3
|
-
import { useId } from "react";
|
|
3
|
+
import { useId, useRef, useState } from "react";
|
|
4
|
+
import { useIsomorphicLayoutEffect } from "../common/isomorphic-layout-effect.js";
|
|
4
5
|
import { cx } from "../common/props.js";
|
|
5
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
ariaValues,
|
|
8
|
+
modelBar,
|
|
9
|
+
ringFraction,
|
|
10
|
+
startCaptionText,
|
|
11
|
+
zoneBand,
|
|
12
|
+
zoneLabelsFit
|
|
13
|
+
} from "./meter-model.js";
|
|
6
14
|
import classes from "./meter.module.css";
|
|
7
15
|
import { toPct } from "./scale.js";
|
|
16
|
+
function rootProps(shell) {
|
|
17
|
+
return {
|
|
18
|
+
className: cx(classes.root, shell.row && classes.row, shell.className),
|
|
19
|
+
style: shell.style,
|
|
20
|
+
"data-basalt-meter": ""
|
|
21
|
+
};
|
|
22
|
+
}
|
|
8
23
|
const RING_VIEWBOX = 36;
|
|
9
24
|
const RING_STROKE = 4;
|
|
10
25
|
const RING_RADIUS = (RING_VIEWBOX - RING_STROKE) / 2;
|
|
@@ -36,13 +51,18 @@ function RingSvg({ fraction, color }) {
|
|
|
36
51
|
)
|
|
37
52
|
] });
|
|
38
53
|
}
|
|
54
|
+
const UNITS = "h|d|w|mo|y|s|ms|min|m|km|mi|g|kg|%|\u20AC|pts|bpm|AU|kcal|KB|MB|GB|TB";
|
|
55
|
+
const UNIT_AFTER_NUMBER = new RegExp(`(\\d) (?=(?:${UNITS})(?![\\p{L}\\d]))`, "gu");
|
|
56
|
+
const SHORT_LAST_WORD = /([^ ]) ([^ ]{1,6})$/u;
|
|
57
|
+
const glueUnits = (text) => typeof text === "string" ? text.replace(UNIT_AFTER_NUMBER, "$1\xA0") : text;
|
|
58
|
+
const glue = (text) => typeof text === "string" ? String(glueUnits(text)).replace(SHORT_LAST_WORD, "$1\xA0$2") : text;
|
|
39
59
|
function MeterLoading({
|
|
40
60
|
label,
|
|
41
61
|
ring,
|
|
42
62
|
shell
|
|
43
63
|
}) {
|
|
44
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
45
|
-
/* @__PURE__ */ jsx(VisuallyHidden, { children: `Loading ${label}` }),
|
|
64
|
+
return /* @__PURE__ */ jsxs("div", { ...rootProps(shell), "aria-busy": "true", children: [
|
|
65
|
+
/* @__PURE__ */ jsx(VisuallyHidden, { className: classes.summary, children: `Loading ${label}` }),
|
|
46
66
|
ring ? /* @__PURE__ */ jsx(Skeleton, { className: classes.skeletonRing, circle: true }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
47
67
|
/* @__PURE__ */ jsx(Skeleton, { className: classes.skeletonTrack }),
|
|
48
68
|
/* @__PURE__ */ jsx(Skeleton, { className: classes.skeletonCaption, radius: "sm" })
|
|
@@ -51,14 +71,14 @@ function MeterLoading({
|
|
|
51
71
|
}
|
|
52
72
|
function MeterEmpty(props) {
|
|
53
73
|
const { label, text, ring, shell } = props;
|
|
54
|
-
return /* @__PURE__ */ jsxs("output", {
|
|
74
|
+
return /* @__PURE__ */ jsxs("output", { ...rootProps(shell), "aria-label": label, children: [
|
|
55
75
|
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 }) }),
|
|
56
76
|
/* @__PURE__ */ jsx("span", { className: classes.empty, children: text })
|
|
57
77
|
] });
|
|
58
78
|
}
|
|
59
79
|
function MeterRing(props) {
|
|
60
80
|
const { label, reading, min, max, color, format, shell } = props;
|
|
61
|
-
return /* @__PURE__ */ jsx("div", {
|
|
81
|
+
return /* @__PURE__ */ jsx("div", { ...rootProps(shell), children: /* @__PURE__ */ jsxs(
|
|
62
82
|
"span",
|
|
63
83
|
{
|
|
64
84
|
className: classes.ringBox,
|
|
@@ -88,72 +108,226 @@ function zoneStyle(zone, index, count, min, span) {
|
|
|
88
108
|
background: zone.color ?? `color-mix(in srgb, var(--vx-line) ${strength}%, transparent)`
|
|
89
109
|
};
|
|
90
110
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
111
|
+
const labelsKey = (labels) => labels.map((l) => l.label + (l.holding ? "*" : "")).join("\0");
|
|
112
|
+
function useZoneLabelLayout(rowRef, key) {
|
|
113
|
+
const [fits, setFits] = useState(true);
|
|
114
|
+
useIsomorphicLayoutEffect(() => {
|
|
115
|
+
const row = rowRef.current;
|
|
116
|
+
if (!row) return;
|
|
117
|
+
const measure = () => {
|
|
118
|
+
const origin = row.getBoundingClientRect();
|
|
119
|
+
const boxes = [...row.children].map((c) => {
|
|
120
|
+
const r = c.getBoundingClientRect();
|
|
121
|
+
return { left: r.left - origin.left, right: r.right - origin.left };
|
|
122
|
+
});
|
|
123
|
+
setFits(zoneLabelsFit(boxes, origin.width));
|
|
124
|
+
};
|
|
125
|
+
measure();
|
|
126
|
+
const observer = typeof ResizeObserver === "undefined" ? void 0 : new ResizeObserver(measure);
|
|
127
|
+
observer?.observe(row);
|
|
128
|
+
const fonts = typeof document === "undefined" ? void 0 : document.fonts;
|
|
129
|
+
let live = true;
|
|
130
|
+
void fonts?.ready?.then(() => live && measure());
|
|
131
|
+
fonts?.addEventListener?.("loadingdone", measure);
|
|
132
|
+
return () => {
|
|
133
|
+
live = false;
|
|
134
|
+
observer?.disconnect();
|
|
135
|
+
fonts?.removeEventListener?.("loadingdone", measure);
|
|
136
|
+
};
|
|
137
|
+
}, [rowRef, key]);
|
|
138
|
+
return fits;
|
|
139
|
+
}
|
|
140
|
+
function ZoneReading({ pct, children }) {
|
|
141
|
+
const rowRef = useRef(null);
|
|
142
|
+
const textRef = useRef(null);
|
|
143
|
+
const [start, setStart] = useState();
|
|
144
|
+
useIsomorphicLayoutEffect(() => {
|
|
145
|
+
const row = rowRef.current;
|
|
146
|
+
const text = textRef.current;
|
|
147
|
+
if (!row || !text) return;
|
|
148
|
+
const measure = () => {
|
|
149
|
+
const centre = row.clientWidth * pct / 100;
|
|
150
|
+
setStart(
|
|
151
|
+
Math.max(0, Math.min(centre - text.offsetWidth / 2, row.clientWidth - text.offsetWidth))
|
|
152
|
+
);
|
|
153
|
+
};
|
|
154
|
+
measure();
|
|
155
|
+
if (typeof ResizeObserver === "undefined") return;
|
|
156
|
+
const observer = new ResizeObserver(measure);
|
|
157
|
+
observer.observe(row);
|
|
158
|
+
observer.observe(text);
|
|
159
|
+
return () => observer.disconnect();
|
|
160
|
+
}, [pct]);
|
|
161
|
+
return /* @__PURE__ */ jsx("div", { ref: rowRef, className: classes.zoneReadingRow, "data-meter-reading-row": true, children: /* @__PURE__ */ jsx(
|
|
162
|
+
"span",
|
|
163
|
+
{
|
|
164
|
+
ref: textRef,
|
|
165
|
+
className: classes.zoneReading,
|
|
166
|
+
"data-measured": start === void 0 ? void 0 : "",
|
|
167
|
+
style: { insetInlineStart: start === void 0 ? `${pct}%` : `${start}px` },
|
|
168
|
+
children
|
|
169
|
+
}
|
|
170
|
+
) });
|
|
171
|
+
}
|
|
172
|
+
function ZoneName({ label, ...rest }) {
|
|
173
|
+
return /* @__PURE__ */ jsx(
|
|
174
|
+
"span",
|
|
175
|
+
{
|
|
176
|
+
...rest,
|
|
177
|
+
className: cx(rest.className, label.holding && classes.zoneLabelHolding),
|
|
178
|
+
"data-meter-zone-label": label.label,
|
|
179
|
+
"data-holding": label.holding || void 0,
|
|
180
|
+
children: label.label
|
|
181
|
+
}
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
function ZoneLabels({ labels }) {
|
|
185
|
+
const rowRef = useRef(null);
|
|
186
|
+
const fits = useZoneLabelLayout(rowRef, labelsKey(labels));
|
|
187
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
188
|
+
/* @__PURE__ */ jsx(
|
|
101
189
|
"div",
|
|
102
190
|
{
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
)),
|
|
118
|
-
model.parts.map((p, i) => /* @__PURE__ */ jsx(
|
|
119
|
-
"div",
|
|
120
|
-
{
|
|
121
|
-
className: cx(classes.fill, p.forecast && classes.forecastFill),
|
|
122
|
-
"data-meter-fill": p.forecast ? "forecast" : "committed",
|
|
123
|
-
style: fillStyle(p)
|
|
124
|
-
},
|
|
125
|
-
i
|
|
126
|
-
))
|
|
127
|
-
] }),
|
|
128
|
-
/* @__PURE__ */ jsx(Tick, { kind: "marker", className: classes.marker, pct: model.markerPct }),
|
|
129
|
-
/* @__PURE__ */ jsx(Tick, { kind: "boundary", className: classes.boundaryTick, pct: model.boundaryPct }),
|
|
130
|
-
/* @__PURE__ */ jsx(Tick, { kind: "target", className: classes.tick, pct: model.targetPct })
|
|
131
|
-
]
|
|
191
|
+
ref: rowRef,
|
|
192
|
+
className: classes.zoneBand,
|
|
193
|
+
"data-meter-zone-band": true,
|
|
194
|
+
"data-collapsed": fits ? void 0 : "",
|
|
195
|
+
"aria-hidden": true,
|
|
196
|
+
children: labels.map((l) => /* @__PURE__ */ jsx(
|
|
197
|
+
ZoneName,
|
|
198
|
+
{
|
|
199
|
+
label: l,
|
|
200
|
+
className: classes.zoneLabel,
|
|
201
|
+
style: { insetInlineStart: `${l.startPct}%` }
|
|
202
|
+
},
|
|
203
|
+
l.key
|
|
204
|
+
))
|
|
132
205
|
}
|
|
133
206
|
),
|
|
134
|
-
|
|
135
|
-
hasCaptions && /* @__PURE__ */ jsxs("div", { className: classes.captions, "data-meter-captions": true, children: [
|
|
136
|
-
start !== null && /* @__PURE__ */ jsx("span", { className: classes.caption, children: start }),
|
|
137
|
-
model.forecastText !== null && /* @__PURE__ */ jsx("span", { className: classes.caption, children: model.forecastText }),
|
|
138
|
-
end !== null && /* @__PURE__ */ jsx("span", { className: classes.captionEnd, children: end })
|
|
139
|
-
] })
|
|
207
|
+
!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)) })
|
|
140
208
|
] });
|
|
141
209
|
}
|
|
210
|
+
const TICK_LABEL_FLIP_PCT = 50;
|
|
211
|
+
function TickLabels({ ticks }) {
|
|
212
|
+
const rowRef = useRef(null);
|
|
213
|
+
const fits = useZoneLabelLayout(rowRef, ticks.map((t) => `${t.label}@${t.pct}`).join("\0"));
|
|
214
|
+
return /* @__PURE__ */ jsxs("div", { className: classes.tickLabels, children: [
|
|
215
|
+
/* @__PURE__ */ jsx(
|
|
216
|
+
"div",
|
|
217
|
+
{
|
|
218
|
+
ref: rowRef,
|
|
219
|
+
className: classes.tickBand,
|
|
220
|
+
"data-meter-tick-band": true,
|
|
221
|
+
"data-collapsed": fits ? void 0 : "",
|
|
222
|
+
"aria-hidden": true,
|
|
223
|
+
children: ticks.map((t) => /* @__PURE__ */ jsx(
|
|
224
|
+
"span",
|
|
225
|
+
{
|
|
226
|
+
className: classes.tickLabel,
|
|
227
|
+
"data-meter-tick-label": "",
|
|
228
|
+
style: t.pct > TICK_LABEL_FLIP_PCT ? { insetInlineEnd: `${100 - t.pct}%` } : { insetInlineStart: `${t.pct}%` },
|
|
229
|
+
children: t.label
|
|
230
|
+
},
|
|
231
|
+
t.key
|
|
232
|
+
))
|
|
233
|
+
}
|
|
234
|
+
),
|
|
235
|
+
!fits && /* @__PURE__ */ jsx("div", { className: classes.zoneList, "data-meter-tick-list": true, "aria-hidden": true, children: ticks.map((t) => /* @__PURE__ */ jsx("span", { className: classes.zoneListItem, children: t.label }, t.key)) })
|
|
236
|
+
] });
|
|
237
|
+
}
|
|
238
|
+
function MeterBar(props) {
|
|
239
|
+
const { label, reading, min, max, format, zones, shell } = props;
|
|
240
|
+
const describedId = useId();
|
|
241
|
+
const model = modelBar(props);
|
|
242
|
+
const compact = shell.row;
|
|
243
|
+
const start = compact ? null : startCaptionText(model, props.startCaption);
|
|
244
|
+
const end = compact ? null : props.endCaption === void 0 ? model.endText : props.endCaption;
|
|
245
|
+
const anchored = model.markerPct !== void 0 && start !== null;
|
|
246
|
+
const hasCaptions = start !== null && !anchored || end !== null || !compact && model.forecastText !== null;
|
|
247
|
+
const hasParts = !compact && model.partCaptions.length > 0;
|
|
248
|
+
const tickLabels = compact ? [] : model.ticks.filter((t) => t.label !== void 0);
|
|
249
|
+
const describedBy = model.describedByText === null ? {} : { "aria-describedby": describedId };
|
|
250
|
+
const root = rootProps(shell);
|
|
251
|
+
return /* @__PURE__ */ jsxs(
|
|
252
|
+
"div",
|
|
253
|
+
{
|
|
254
|
+
...root,
|
|
255
|
+
className: cx(root.className, !compact && model.zoneLabels.length > 0 && classes.zoned),
|
|
256
|
+
children: [
|
|
257
|
+
tickLabels.length > 0 && /* @__PURE__ */ jsx(TickLabels, { ticks: tickLabels }),
|
|
258
|
+
/* @__PURE__ */ jsxs(
|
|
259
|
+
"div",
|
|
260
|
+
{
|
|
261
|
+
className: classes.trackBox,
|
|
262
|
+
"aria-label": label,
|
|
263
|
+
...ariaValues(reading, min, max, format),
|
|
264
|
+
...describedBy,
|
|
265
|
+
children: [
|
|
266
|
+
/* @__PURE__ */ jsxs("div", { className: classes.track, "data-meter-track": true, children: [
|
|
267
|
+
model.markerPct !== void 0 && zones?.map((z, i) => /* @__PURE__ */ jsx(
|
|
268
|
+
"div",
|
|
269
|
+
{
|
|
270
|
+
className: classes.zone,
|
|
271
|
+
"data-meter-zone": z.label,
|
|
272
|
+
style: zoneStyle(z, i, zones.length, min, model.span)
|
|
273
|
+
},
|
|
274
|
+
i
|
|
275
|
+
)),
|
|
276
|
+
model.parts.map((p, i) => /* @__PURE__ */ jsx(
|
|
277
|
+
"div",
|
|
278
|
+
{
|
|
279
|
+
className: cx(classes.fill, p.forecast && classes.forecastFill),
|
|
280
|
+
"data-meter-fill": p.forecast ? "forecast" : "committed",
|
|
281
|
+
"data-tone": props.tone === "muted" && p.color === void 0 && !p.forecast ? "muted" : void 0,
|
|
282
|
+
style: fillStyle(p)
|
|
283
|
+
},
|
|
284
|
+
i
|
|
285
|
+
))
|
|
286
|
+
] }),
|
|
287
|
+
/* @__PURE__ */ jsx(Tick, { kind: "marker", className: classes.marker, pct: model.markerPct }),
|
|
288
|
+
/* @__PURE__ */ jsx(Tick, { kind: "boundary", className: classes.boundaryTick, pct: model.boundaryPct }),
|
|
289
|
+
model.ticks.map((t) => /* @__PURE__ */ jsx(Tick, { kind: "tick", className: classes.tick, pct: t.pct }, t.key)),
|
|
290
|
+
/* @__PURE__ */ jsx(Tick, { kind: "target", className: classes.tick, pct: model.targetPct })
|
|
291
|
+
]
|
|
292
|
+
}
|
|
293
|
+
),
|
|
294
|
+
!compact && model.zoneLabels.length > 0 && /* @__PURE__ */ jsx(ZoneLabels, { labels: model.zoneLabels }),
|
|
295
|
+
anchored && /* @__PURE__ */ jsx(ZoneReading, { pct: model.markerPct ?? 0, children: start }),
|
|
296
|
+
model.describedByText !== null && /* @__PURE__ */ jsx(VisuallyHidden, { id: describedId, className: classes.summary, children: model.describedByText }),
|
|
297
|
+
hasParts && // The explicit role is deliberate: `list-style: none` makes Safari/VoiceOver drop the implicit one.
|
|
298
|
+
// oxlint-disable-next-line jsx-a11y/no-redundant-roles
|
|
299
|
+
/* @__PURE__ */ jsx("ul", { className: classes.partCaptions, role: "list", "data-meter-parts": true, children: model.partCaptions.map((c) => /* @__PURE__ */ jsxs("li", { className: classes.partCaption, children: [
|
|
300
|
+
/* @__PURE__ */ jsx(
|
|
301
|
+
"span",
|
|
302
|
+
{
|
|
303
|
+
className: classes.swatch,
|
|
304
|
+
style: { background: c.color ?? "var(--vx-line)" },
|
|
305
|
+
"aria-hidden": true
|
|
306
|
+
}
|
|
307
|
+
),
|
|
308
|
+
glueUnits(`${c.label} ${c.text}`)
|
|
309
|
+
] }, c.key)) }),
|
|
310
|
+
hasCaptions && /* @__PURE__ */ jsxs("div", { className: classes.captions, "data-meter-captions": true, children: [
|
|
311
|
+
start !== null && !anchored && /* @__PURE__ */ jsx("span", { className: classes.caption, children: glue(start) }),
|
|
312
|
+
!compact && model.forecastText !== null && /* @__PURE__ */ jsx("span", { className: classes.caption, children: glue(model.forecastText) }),
|
|
313
|
+
end !== null && /* @__PURE__ */ jsx("span", { className: classes.captionEnd, children: glue(end) })
|
|
314
|
+
] })
|
|
315
|
+
]
|
|
316
|
+
}
|
|
317
|
+
);
|
|
318
|
+
}
|
|
319
|
+
const TICK_WIDTH = "2px";
|
|
320
|
+
function tickPosition(kind, pct) {
|
|
321
|
+
if (pct < 100 || kind === "marker" || kind === "boundary") return { insetInlineStart: `${pct}%` };
|
|
322
|
+
return { insetInlineStart: `calc(100% - ${TICK_WIDTH})`, marginInlineStart: 0 };
|
|
323
|
+
}
|
|
142
324
|
function Tick({
|
|
143
325
|
kind,
|
|
144
326
|
className,
|
|
145
327
|
pct
|
|
146
328
|
}) {
|
|
147
329
|
if (pct === void 0) return null;
|
|
148
|
-
return /* @__PURE__ */ jsx(
|
|
149
|
-
"div",
|
|
150
|
-
{
|
|
151
|
-
className,
|
|
152
|
-
"data-meter-tick": kind,
|
|
153
|
-
style: { insetInlineStart: `${pct}%` },
|
|
154
|
-
"aria-hidden": true
|
|
155
|
-
}
|
|
156
|
-
);
|
|
330
|
+
return /* @__PURE__ */ jsx("div", { className, "data-meter-tick": kind, style: tickPosition(kind, pct), "aria-hidden": true });
|
|
157
331
|
}
|
|
158
332
|
export {
|
|
159
333
|
MeterBar,
|
|
@@ -11,15 +11,26 @@
|
|
|
11
11
|
* track end; the caption still states the real value.
|
|
12
12
|
*
|
|
13
13
|
* `zones` (bar only) draws the track as contiguous bands (neutral at stepped strengths unless a zone
|
|
14
|
-
* passes a status colour) and the reading becomes a MARKER on the track, not a fill
|
|
15
|
-
* the
|
|
14
|
+
* passes a status colour) and the reading becomes a MARKER on the track, not a fill. Each zone is
|
|
15
|
+
* named under the band at its start, the one holding the value (`from` inclusive) in ink and a
|
|
16
|
+
* heavier weight; names that would collide wrap as a list instead. The fit is measured in the
|
|
17
|
+
* browser, so server markup shows the band and the list may appear after mount. Use it for a
|
|
18
|
+
* reading judged against ranges.
|
|
19
|
+
*
|
|
20
|
+
* Every state (bar, ring, empty, loading) carries `data-basalt-meter` on its root. That attribute is
|
|
21
|
+
* the contract with `StatCard`: a Meter passed as its `sparkline` visual makes the slot size to content
|
|
22
|
+
* and keep the card's inline inset (both placements) instead of the sparkline's fixed height and bleed.
|
|
23
|
+
*
|
|
24
|
+
* Categorical `segments` (no `forecast` part) are captioned one per part — swatch, name, value — under
|
|
25
|
+
* the track and the default start caption is dropped (an explicit `startCaption` still shows);
|
|
26
|
+
* committed/forecast keeps the reading plus the forecast caption.
|
|
16
27
|
*
|
|
17
28
|
* @example
|
|
18
29
|
* import { Meter } from 'basalt-ui'
|
|
19
30
|
*
|
|
20
31
|
* // Spend against a budget: past the target the end caption states the overage.
|
|
21
32
|
* <Meter label="Monthly spend" value={512} max={600} target={450} color="var(--vx-status-bad)" format={usd} />
|
|
22
|
-
* // Training load as a zone band with a marker:
|
|
33
|
+
* // Training load as a zone band with a marker: the zones are named under the band, "Optimal" in ink.
|
|
23
34
|
* <Meter
|
|
24
35
|
* label="Training load"
|
|
25
36
|
* max={1000}
|
|
@@ -41,7 +52,7 @@
|
|
|
41
52
|
*/
|
|
42
53
|
import type { ReactNode } from 'react';
|
|
43
54
|
import type { BasaltProps } from '../common/props.js';
|
|
44
|
-
import type { MeterSegment, MeterZone } from './meter-model.js';
|
|
55
|
+
import type { MeterSegment, MeterTick, MeterZone } from './meter-model.js';
|
|
45
56
|
type Common = BasaltProps & {
|
|
46
57
|
/** Accessible name (`aria-label`). Required: a meter without one is announced as a bare number. */
|
|
47
58
|
label: string;
|
|
@@ -60,7 +71,25 @@ type BarCommon = Common & {
|
|
|
60
71
|
shape?: 'bar';
|
|
61
72
|
/** Target position; draws a tick and states it in the end caption (with the overage past it). */
|
|
62
73
|
target?: number;
|
|
63
|
-
/**
|
|
74
|
+
/**
|
|
75
|
+
* More marks on the track (cut-offs, a window mean). Each is drawn at `at`; a `label` is captioned
|
|
76
|
+
* above the track, wrapping to a list when two collide. A tick outside `[min, max]` is dropped, not
|
|
77
|
+
* clamped. All are listed in the accessible description. Works with `value`, `zones`, `segments`
|
|
78
|
+
* and `target`.
|
|
79
|
+
*/
|
|
80
|
+
ticks?: readonly MeterTick[];
|
|
81
|
+
/**
|
|
82
|
+
* `'muted'`: a non-verdict fill (a load, not a verdict) in `--vx-muted` at a strength that holds
|
|
83
|
+
* 3:1 against the track in both schemes — the neutral fill is near-white in dark. A `color` wins.
|
|
84
|
+
*/
|
|
85
|
+
tone?: 'muted';
|
|
86
|
+
/**
|
|
87
|
+
* `'row'`: in-line use — a track one text line tall and no caption rows (reading, target, forecast,
|
|
88
|
+
* part, zone and tick captions). The label stays as `aria-label`; the described-by text keeps the
|
|
89
|
+
* rest. Put the value beside it in your own layout.
|
|
90
|
+
*/
|
|
91
|
+
size?: 'row';
|
|
92
|
+
/** Start caption (default: the formatted reading). `null` drops it. */
|
|
64
93
|
startCaption?: ReactNode;
|
|
65
94
|
/** End caption (default: `Target <target>`). `null` drops it. */
|
|
66
95
|
endCaption?: ReactNode;
|
|
@@ -91,7 +120,7 @@ export type MeterProps = (BarCommon & {
|
|
|
91
120
|
value?: number | null | undefined;
|
|
92
121
|
/**
|
|
93
122
|
* Contiguous bands drawn as the track, positioned from each `from`. The reading becomes a marker
|
|
94
|
-
* and
|
|
123
|
+
* and each band is named under the track, the one that holds it in ink.
|
|
95
124
|
*/
|
|
96
125
|
zones: readonly MeterZone[];
|
|
97
126
|
segments?: never;
|
|
@@ -104,6 +133,9 @@ export type MeterProps = (BarCommon & {
|
|
|
104
133
|
segments?: never;
|
|
105
134
|
zones?: never;
|
|
106
135
|
target?: never;
|
|
136
|
+
ticks?: never;
|
|
137
|
+
tone?: never;
|
|
138
|
+
size?: never;
|
|
107
139
|
startCaption?: never;
|
|
108
140
|
endCaption?: never;
|
|
109
141
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"meter.d.ts","sourceRoot":"","sources":["../../src/dashboard/meter.tsx"],"names":[],"mappings":"AAAA
|
|
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,SAAS,EAAE,MAAM,eAAe,CAAA;AAIvE,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;;;;;OAKG;IACH,KAAK,CAAC,EAAE,SAAS,SAAS,EAAE,CAAA;IAC5B;;;OAGG;IACH,IAAI,CAAC,EAAE,OAAO,CAAA;IACd;;;;OAIG;IACH,IAAI,CAAC,EAAE,KAAK,CAAA;IACZ,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,KAAK,CAAC,EAAE,KAAK,CAAA;IACb,IAAI,CAAC,EAAE,KAAK,CAAA;IACZ,IAAI,CAAC,EAAE,KAAK,CAAA;IACZ,YAAY,CAAC,EAAE,KAAK,CAAA;IACpB,UAAU,CAAC,EAAE,KAAK,CAAA;CACnB,CAAC,CAAA;AAYN,wBAAgB,KAAK,CAAC,KAAK,EAAE,UAAU,+BAkCtC"}
|
package/dist/dashboard/meter.js
CHANGED
|
@@ -12,7 +12,8 @@ function warnInvalidTrack(min, max) {
|
|
|
12
12
|
}
|
|
13
13
|
function Meter(props) {
|
|
14
14
|
const { label, min = 0, max = 100, format = asText, className, style } = props;
|
|
15
|
-
const
|
|
15
|
+
const row = props.size === "row";
|
|
16
|
+
const shell = { className, style, row };
|
|
16
17
|
const ring = props.shape === "ring";
|
|
17
18
|
warnInvalidTrack(min, max);
|
|
18
19
|
if (props.loading === true) return /* @__PURE__ */ jsx(MeterLoading, { label, ring, shell });
|
|
@@ -32,6 +33,8 @@ function Meter(props) {
|
|
|
32
33
|
segments,
|
|
33
34
|
zones: props.zones,
|
|
34
35
|
target: isReading(props.target) ? props.target : void 0,
|
|
36
|
+
ticks: props.ticks,
|
|
37
|
+
tone: props.tone,
|
|
35
38
|
forecastCaption: props.segments === void 0 ? void 0 : props.forecastCaption,
|
|
36
39
|
startCaption: props.startCaption,
|
|
37
40
|
endCaption: props.endCaption
|