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
|
@@ -3,11 +3,13 @@ import { Skeleton, VisuallyHidden } from "@mantine/core";
|
|
|
3
3
|
import { cx } from "../common/props.js";
|
|
4
4
|
import classes from "./bar-list.module.css";
|
|
5
5
|
import { asText, barPercent } from "./scale.js";
|
|
6
|
+
const hasContent = (node) => node !== void 0 && node !== null && typeof node !== "boolean";
|
|
6
7
|
function BarList({
|
|
7
8
|
label,
|
|
8
9
|
items,
|
|
9
10
|
format = asText,
|
|
10
11
|
max,
|
|
12
|
+
variant = "default",
|
|
11
13
|
accentLeader = false,
|
|
12
14
|
loading = false,
|
|
13
15
|
loadingRows = 5,
|
|
@@ -24,27 +26,62 @@ function BarList({
|
|
|
24
26
|
if (items.length === 0) {
|
|
25
27
|
return /* @__PURE__ */ jsx("output", { className: cx(classes.root, className), style, "aria-label": label, children: /* @__PURE__ */ jsx("span", { className: classes.empty, children: emptyText }) });
|
|
26
28
|
}
|
|
27
|
-
const scale = max ?? items.reduce(
|
|
29
|
+
const scale = max ?? items.reduce(
|
|
30
|
+
(top, i) => i.max === void 0 && Number.isFinite(i.value) ? Math.max(top, i.value) : top,
|
|
31
|
+
0
|
|
32
|
+
);
|
|
33
|
+
const thin = variant === "thin";
|
|
34
|
+
const hasSecondary = items.some((i) => hasContent(i.secondary));
|
|
28
35
|
return (
|
|
29
36
|
// The explicit role is deliberate: `list-style: none` makes Safari/VoiceOver drop the implicit one.
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
37
|
+
/* @__PURE__ */ jsx(
|
|
38
|
+
"ul",
|
|
39
|
+
{
|
|
40
|
+
className: cx(classes.root, className),
|
|
41
|
+
style,
|
|
42
|
+
role: "list",
|
|
43
|
+
"aria-label": label,
|
|
44
|
+
"data-secondary": hasSecondary ? "" : void 0,
|
|
45
|
+
"data-variant": thin ? "thin" : void 0,
|
|
46
|
+
children: items.map((item, i) => {
|
|
47
|
+
const isLeader = accentLeader && i === 0;
|
|
48
|
+
const rowScale = item.max ?? scale;
|
|
49
|
+
const labelNode = /* @__PURE__ */ jsx("span", { className: classes.label, title: item.label, children: item.label });
|
|
50
|
+
const tickName = item.tick === void 0 ? "" : `${item.tickLabel ?? "Threshold"} ${format(item.tick, "value")}`;
|
|
51
|
+
const track = /* @__PURE__ */ jsxs("span", { className: classes.track, "data-bar-track": true, children: [
|
|
52
|
+
/* @__PURE__ */ jsx(
|
|
53
|
+
"span",
|
|
54
|
+
{
|
|
55
|
+
className: cx(classes.bar, isLeader && classes.leader),
|
|
56
|
+
style: { width: `${barPercent(item.value, rowScale)}%` },
|
|
57
|
+
"data-bar-fill": "",
|
|
58
|
+
"data-bar-leader": isLeader ? "" : void 0,
|
|
59
|
+
"aria-hidden": true
|
|
60
|
+
}
|
|
61
|
+
),
|
|
62
|
+
item.tick !== void 0 && // theme-allow hidden-inline-style — the position is the row's data (a % of its scale)
|
|
63
|
+
/* @__PURE__ */ jsx(
|
|
64
|
+
"span",
|
|
65
|
+
{
|
|
66
|
+
className: classes.tick,
|
|
67
|
+
style: { insetInlineStart: `${barPercent(item.tick, rowScale)}%` },
|
|
68
|
+
"data-bar-tick": "",
|
|
69
|
+
"aria-hidden": true
|
|
70
|
+
}
|
|
71
|
+
),
|
|
72
|
+
!thin && labelNode,
|
|
73
|
+
item.tick !== void 0 && /* @__PURE__ */ jsx(VisuallyHidden, { children: tickName })
|
|
74
|
+
] });
|
|
75
|
+
return /* @__PURE__ */ jsxs("li", { className: classes.row, children: [
|
|
76
|
+
thin && labelNode,
|
|
77
|
+
!thin && track,
|
|
78
|
+
/* @__PURE__ */ jsx("span", { className: classes.value, children: Number.isFinite(item.value) ? item.max === void 0 ? format(item.value, "value") : `${format(item.value, "value")} / ${format(item.max, "max")}` : "\u2014" }),
|
|
79
|
+
hasSecondary && /* @__PURE__ */ jsx("span", { className: classes.secondary, children: item.secondary }),
|
|
80
|
+
thin && track
|
|
81
|
+
] }, item.key ?? `${item.label}-${i}`);
|
|
82
|
+
})
|
|
83
|
+
}
|
|
84
|
+
)
|
|
48
85
|
);
|
|
49
86
|
}
|
|
50
87
|
export {
|
|
@@ -1,30 +1,46 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* BarList — ranked rows on one shared scale (docs/waves/design-parity/SPEC.md § 6.4). The bar
|
|
3
|
-
*
|
|
2
|
+
* BarList — ranked rows on one shared scale (docs/waves/design-parity/SPEC.md § 6.4). The bar track
|
|
3
|
+
* is the LABEL column only; the value (and secondary) columns sit outside it, so a full-scale bar ends
|
|
4
|
+
* before the value. The columns are shared by every row (subgrid), which is what keeps one scale. The
|
|
5
|
+
* row never wraps: the label truncates, the value is nowrap.
|
|
4
6
|
*/
|
|
5
7
|
|
|
6
8
|
.root {
|
|
7
|
-
display:
|
|
8
|
-
|
|
9
|
-
gap: var(--vx-space-
|
|
9
|
+
display: grid;
|
|
10
|
+
grid-template-columns: minmax(0, 1fr) auto;
|
|
11
|
+
column-gap: var(--vx-space-control-gap, 0.375rem);
|
|
12
|
+
row-gap: var(--vx-space-stack-xs, 0.25rem);
|
|
10
13
|
margin: 0;
|
|
11
14
|
padding: 0;
|
|
12
15
|
list-style: none;
|
|
13
16
|
min-width: 0;
|
|
14
17
|
}
|
|
15
18
|
|
|
19
|
+
.root[data-secondary] {
|
|
20
|
+
grid-template-columns: minmax(0, 1fr) auto auto;
|
|
21
|
+
}
|
|
22
|
+
|
|
16
23
|
.row {
|
|
17
|
-
|
|
18
|
-
|
|
24
|
+
display: grid;
|
|
25
|
+
grid-column: 1 / -1;
|
|
26
|
+
grid-template-columns: subgrid;
|
|
19
27
|
align-items: center;
|
|
20
|
-
gap: var(--vx-space-control-gap, 0.375rem);
|
|
21
28
|
min-width: 0;
|
|
22
29
|
min-height: calc(var(--vx-space-control-height-widget, 1.5rem) * var(--mantine-scale, 1));
|
|
23
|
-
padding-inline: var(--vx-space-stack-sm);
|
|
24
30
|
font-size: var(--vx-text-sm);
|
|
25
31
|
color: var(--vx-ink);
|
|
26
32
|
}
|
|
27
33
|
|
|
34
|
+
/* The bar's scale: `.bar` is a percentage of THIS box, never of the row. */
|
|
35
|
+
.track {
|
|
36
|
+
position: relative;
|
|
37
|
+
display: flex;
|
|
38
|
+
align-items: center;
|
|
39
|
+
align-self: stretch;
|
|
40
|
+
min-width: 0;
|
|
41
|
+
padding-inline: var(--vx-space-stack-sm);
|
|
42
|
+
}
|
|
43
|
+
|
|
28
44
|
.bar {
|
|
29
45
|
position: absolute;
|
|
30
46
|
inset-block: 0;
|
|
@@ -39,7 +55,6 @@
|
|
|
39
55
|
|
|
40
56
|
.label {
|
|
41
57
|
position: relative;
|
|
42
|
-
flex: 1 1 0;
|
|
43
58
|
min-width: 0;
|
|
44
59
|
overflow: hidden;
|
|
45
60
|
text-overflow: ellipsis;
|
|
@@ -47,27 +62,105 @@
|
|
|
47
62
|
}
|
|
48
63
|
|
|
49
64
|
.value {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
font-family: var(--basalt-font-mono);
|
|
65
|
+
font-family: var(--basalt-font-numeral, var(--basalt-font-sans));
|
|
66
|
+
font-variant-numeric: lining-nums;
|
|
53
67
|
text-align: end;
|
|
54
68
|
white-space: nowrap;
|
|
55
69
|
}
|
|
56
70
|
|
|
71
|
+
.value:last-child,
|
|
72
|
+
.secondary:last-child {
|
|
73
|
+
padding-inline-end: var(--vx-space-stack-sm);
|
|
74
|
+
}
|
|
75
|
+
|
|
57
76
|
.secondary {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
font-
|
|
61
|
-
font-size: var(--vx-text-xs);
|
|
77
|
+
font-family: var(--basalt-font-numeral, var(--basalt-font-sans));
|
|
78
|
+
font-variant-numeric: lining-nums;
|
|
79
|
+
font-size: var(--vx-text-sm);
|
|
62
80
|
color: var(--vx-muted);
|
|
63
81
|
white-space: nowrap;
|
|
64
82
|
}
|
|
65
83
|
|
|
66
84
|
.empty {
|
|
85
|
+
grid-column: 1 / -1;
|
|
67
86
|
font-size: var(--vx-text-sm);
|
|
68
87
|
color: var(--vx-muted);
|
|
69
88
|
}
|
|
70
89
|
|
|
71
90
|
.skeletonRow {
|
|
91
|
+
grid-column: 1 / -1;
|
|
72
92
|
height: calc(var(--vx-space-control-height-widget, 1.5rem) * var(--mantine-scale, 1));
|
|
73
93
|
}
|
|
94
|
+
|
|
95
|
+
/* A row's threshold: a hairline across the bar at a position on the row's own scale. */
|
|
96
|
+
.tick {
|
|
97
|
+
position: absolute;
|
|
98
|
+
inset-block: 0;
|
|
99
|
+
inline-size: 0;
|
|
100
|
+
border-inline-start: 1px solid var(--vx-ink);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/*
|
|
104
|
+
* Thin: label and value share the first line, the bar is a thin rail on the second spanning every
|
|
105
|
+
* column. The label column is still shared (subgrid), so the value columns stay aligned.
|
|
106
|
+
*/
|
|
107
|
+
.root[data-variant='thin'] .row {
|
|
108
|
+
grid-template-rows: auto auto;
|
|
109
|
+
row-gap: var(--vx-space-stack-xs, 0.25rem);
|
|
110
|
+
align-items: baseline;
|
|
111
|
+
padding-block: var(--vx-space-stack-xs, 0.25rem);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
.root[data-variant='thin'] .track {
|
|
115
|
+
grid-column: 1 / -1;
|
|
116
|
+
align-self: auto;
|
|
117
|
+
block-size: 0.25rem;
|
|
118
|
+
padding-inline: 0;
|
|
119
|
+
border-radius: var(--vx-radius-fine);
|
|
120
|
+
background: color-mix(in srgb, var(--vx-line) 20%, transparent);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
.root[data-variant='thin'] .bar {
|
|
124
|
+
background: color-mix(in srgb, var(--vx-line) 80%, transparent);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
.root[data-variant='thin'] .bar.leader {
|
|
128
|
+
background: var(--vx-accent);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/* The mark outgrows the rail so a 1px line stays visible against a 4px bar. */
|
|
132
|
+
.root[data-variant='thin'] .tick {
|
|
133
|
+
inset-block: calc(var(--vx-space-stack-xs, 0.25rem) * -1);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/*
|
|
137
|
+
* Thin rows get a phone's width: the label wraps up to two lines, then truncates (its `title` carries
|
|
138
|
+
* the whole text), and the secondary column takes at most 40% of the list, clipped, so a long status
|
|
139
|
+
* never squeezes the title down to a few characters.
|
|
140
|
+
*/
|
|
141
|
+
.root[data-variant='thin'][data-secondary] {
|
|
142
|
+
grid-template-columns: minmax(0, 1fr) auto fit-content(40%);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
.root[data-variant='thin'] .label {
|
|
146
|
+
display: -webkit-box;
|
|
147
|
+
overflow: hidden;
|
|
148
|
+
white-space: normal;
|
|
149
|
+
overflow-wrap: anywhere;
|
|
150
|
+
-webkit-box-orient: vertical;
|
|
151
|
+
-webkit-line-clamp: 2;
|
|
152
|
+
line-clamp: 2;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
.root[data-variant='thin'] .secondary {
|
|
156
|
+
min-width: 0;
|
|
157
|
+
overflow: hidden;
|
|
158
|
+
text-overflow: ellipsis;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
.root[data-variant='thin'] .secondary [data-verdict-word] {
|
|
162
|
+
min-width: 0;
|
|
163
|
+
overflow: hidden;
|
|
164
|
+
text-overflow: ellipsis;
|
|
165
|
+
white-space: nowrap;
|
|
166
|
+
}
|
|
@@ -11,9 +11,14 @@ export type DeltaBadgeProps = {
|
|
|
11
11
|
format?: (value: number) => string;
|
|
12
12
|
/** Render the ▲/▼ direction glyph. Defaults to `true`; a zero value never shows a glyph. */
|
|
13
13
|
withGlyph?: boolean;
|
|
14
|
-
/** Optional comparison
|
|
15
|
-
* `
|
|
14
|
+
/** Optional comparison period rendered after the value, muted, as `<periodPrefix> <period>`
|
|
15
|
+
* (`period="last week"` → "vs last week"). One rule: the prefix is prepended unless the period
|
|
16
|
+
* already starts with it (case-insensitive, optional trailing dot: "vs", "VS", "vs."), so a caller
|
|
17
|
+
* still writing "vs last week" renders it once. Other words ("versus") are not detected. */
|
|
16
18
|
period?: string | undefined;
|
|
19
|
+
/** The word composed before `period`. Defaults to `'vs'`; pass your locale's word, or `''` to
|
|
20
|
+
* render `period` raw. */
|
|
21
|
+
periodPrefix?: string;
|
|
17
22
|
};
|
|
18
|
-
export declare function DeltaBadge({ value, polarity, format, withGlyph, period, }: DeltaBadgeProps): import("react").JSX.Element;
|
|
23
|
+
export declare function DeltaBadge({ value, polarity, format, withGlyph, period, periodPrefix, }: DeltaBadgeProps): import("react").JSX.Element;
|
|
19
24
|
//# sourceMappingURL=delta-badge.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"delta-badge.d.ts","sourceRoot":"","sources":["../../src/dashboard/delta-badge.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"delta-badge.d.ts","sourceRoot":"","sources":["../../src/dashboard/delta-badge.tsx"],"names":[],"mappings":"AA8BA,MAAM,MAAM,aAAa,GAAG,SAAS,GAAG,QAAQ,GAAG,SAAS,CAAA;AAE5D,MAAM,MAAM,eAAe,GAAG;IAC5B,+FAA+F;IAC/F,KAAK,EAAE,MAAM,CAAA;IACb;;;kCAG8B;IAC9B,QAAQ,CAAC,EAAE,aAAa,CAAA;IACxB,2FAA2F;IAC3F,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAA;IAClC,4FAA4F;IAC5F,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB;;;gGAG4F;IAC5F,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC3B;8BAC0B;IAC1B,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB,CAAA;AAwBD,wBAAgB,UAAU,CAAC,EACzB,KAAK,EACL,QAAoB,EACpB,MAAsB,EACtB,SAAgB,EAChB,MAAM,EACN,YAAmB,GACpB,EAAE,eAAe,+BAejB"}
|
|
@@ -2,6 +2,11 @@ import { jsx, jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import { VX } from "../tokens/index.js";
|
|
3
3
|
import classes from "./widget-header.module.css";
|
|
4
4
|
const defaultFormat = (value) => `${Math.abs(value).toFixed(1)}%`;
|
|
5
|
+
function composePeriod(period, prefix) {
|
|
6
|
+
if (prefix === "") return period;
|
|
7
|
+
const escaped = prefix.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
8
|
+
return new RegExp(`^${escaped}\\.?(\\s|$)`, "i").test(period) ? period : `${prefix} ${period}`;
|
|
9
|
+
}
|
|
5
10
|
function resolveTone(value, polarity) {
|
|
6
11
|
if (value === 0 || polarity === "neutral") return VX.faint;
|
|
7
12
|
const rose = value > 0;
|
|
@@ -18,7 +23,8 @@ function DeltaBadge({
|
|
|
18
23
|
polarity = "up-good",
|
|
19
24
|
format = defaultFormat,
|
|
20
25
|
withGlyph = true,
|
|
21
|
-
period
|
|
26
|
+
period,
|
|
27
|
+
periodPrefix = "vs"
|
|
22
28
|
}) {
|
|
23
29
|
const tone = resolveTone(value, polarity);
|
|
24
30
|
const glyph = directionGlyph(value);
|
|
@@ -26,7 +32,8 @@ function DeltaBadge({
|
|
|
26
32
|
return /* @__PURE__ */ jsxs("span", { className: classes.deltaBadge, style: { color: tone }, children: [
|
|
27
33
|
showGlyph && /* @__PURE__ */ jsx("span", { className: classes.deltaGlyph, children: glyph }),
|
|
28
34
|
format(value),
|
|
29
|
-
period !== void 0 &&
|
|
35
|
+
period !== void 0 && " ",
|
|
36
|
+
period !== void 0 && /* @__PURE__ */ jsx("span", { className: classes.deltaPeriod, children: composePeriod(period, periodPrefix) })
|
|
30
37
|
] });
|
|
31
38
|
}
|
|
32
39
|
export {
|
|
@@ -3,8 +3,10 @@ export { DeltaBadge } from './delta-badge.js';
|
|
|
3
3
|
export { Section } from './section.js';
|
|
4
4
|
export { StatCard, type StatCardBreakdownRow, type StatCardSparklineSize } from './stat-card.js';
|
|
5
5
|
export { StatGroup } from './stat-group.js';
|
|
6
|
+
export type { StatStripCell, StatStripRow } from './stat-strip.js';
|
|
6
7
|
export { EmptyState } from './empty-state.js';
|
|
7
8
|
export { SettingsSection, SettingsRow, DangerZone } from './settings-section.js';
|
|
8
9
|
export { Meter, type MeterProps } from './meter.js';
|
|
10
|
+
export type { MeterSegment, MeterTick, MeterZone } from './meter-model.js';
|
|
9
11
|
export { BarList, type BarListProps } from './bar-list.js';
|
|
10
12
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/dashboard/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,QAAQ,EAAE,KAAK,oBAAoB,EAAE,KAAK,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAC7F,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAC7E,OAAO,EAAE,KAAK,EAAE,KAAK,UAAU,EAAE,MAAM,SAAS,CAAA;AAChD,OAAO,EAAE,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,YAAY,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/dashboard/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,QAAQ,EAAE,KAAK,oBAAoB,EAAE,KAAK,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAC7F,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AACxC,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAC/D,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAC7E,OAAO,EAAE,KAAK,EAAE,KAAK,UAAU,EAAE,MAAM,SAAS,CAAA;AAChD,YAAY,EAAE,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AACvE,OAAO,EAAE,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,YAAY,CAAA"}
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Meter's pure model: everything the component shows, computed from numbers (no DOM, no React runtime).
|
|
3
|
+
* Internal — `meter.tsx` and `meter-parts.tsx` render what this returns.
|
|
4
|
+
*/
|
|
5
|
+
import type { ReactNode } from 'react';
|
|
1
6
|
export type MeterSegment = {
|
|
2
7
|
value: number;
|
|
3
8
|
label: string;
|
|
@@ -10,14 +15,53 @@ export type MeterZone = {
|
|
|
10
15
|
label: string;
|
|
11
16
|
color?: string;
|
|
12
17
|
};
|
|
13
|
-
/** A
|
|
18
|
+
/** A mark on the track at `at` (in the reading's units). A label is captioned beside it. */
|
|
19
|
+
export type MeterTick = {
|
|
20
|
+
at: number;
|
|
21
|
+
label?: string;
|
|
22
|
+
};
|
|
23
|
+
/** One tick on the track: its percent position and what it says (caption `label`, aria `text`). */
|
|
24
|
+
export type TickMark = {
|
|
25
|
+
key: string;
|
|
26
|
+
pct: number;
|
|
27
|
+
label: string | undefined;
|
|
28
|
+
text: string;
|
|
29
|
+
};
|
|
30
|
+
/** A fill on the track, as fractions (0–1) of the span, with the segment it was laid out from. */
|
|
14
31
|
export type Part = {
|
|
15
32
|
readonly start: number;
|
|
16
33
|
readonly size: number;
|
|
17
34
|
readonly color: string | undefined;
|
|
18
35
|
readonly forecast: boolean;
|
|
36
|
+
readonly label: string;
|
|
37
|
+
/** The segment's own (normalised) amount, in the reading's units — what its caption states. */
|
|
38
|
+
readonly amount: number;
|
|
39
|
+
};
|
|
40
|
+
/** One categorical part's caption: its position key, name, formatted amount and fill colour (`undefined` = neutral). */
|
|
41
|
+
export type PartCaption = {
|
|
42
|
+
key: string;
|
|
43
|
+
label: string;
|
|
44
|
+
text: string;
|
|
45
|
+
color: string | undefined;
|
|
46
|
+
};
|
|
47
|
+
/** One zone's name on the band: where its band starts (percent) and whether it holds the reading. */
|
|
48
|
+
export type ZoneLabel = {
|
|
49
|
+
key: string;
|
|
50
|
+
label: string;
|
|
51
|
+
startPct: number;
|
|
52
|
+
holding: boolean;
|
|
19
53
|
};
|
|
54
|
+
/**
|
|
55
|
+
* What the caption row says. `reading`: the formatted reading; `parts`: categorical segments name
|
|
56
|
+
* every part instead; `forecast`: committed/forecast keeps the reading plus the forecast caption.
|
|
57
|
+
*/
|
|
58
|
+
export type CaptionMode = 'reading' | 'parts' | 'forecast';
|
|
20
59
|
type Format = (value: number) => string;
|
|
60
|
+
/**
|
|
61
|
+
* The ticks that sit on the track, in the order given. A tick outside `[min, max]` (or not a number)
|
|
62
|
+
* is DROPPED, never clamped: a mark pinned to the end would state a position it is not at.
|
|
63
|
+
*/
|
|
64
|
+
export declare function tickMarks(ticks: readonly MeterTick[] | undefined, min: number, max: number, format: Format): TickMark[];
|
|
21
65
|
export declare const isReading: (n: number | null | undefined) => n is number;
|
|
22
66
|
/** The track's span. A track that ends at or before its start falls back to 1 and is `valid: false`. */
|
|
23
67
|
export declare function spanOf(min: number, max: number): {
|
|
@@ -40,6 +84,19 @@ export declare function normalizeSegments(segments: readonly MeterSegment[]): Me
|
|
|
40
84
|
export declare function layoutSegments(segments: readonly MeterSegment[], span: number): Part[];
|
|
41
85
|
/** `from` is inclusive; a value on the last band's `to` belongs to that band. */
|
|
42
86
|
export declare function findHoldingZone(zones: readonly MeterZone[], value: number): MeterZone | undefined;
|
|
87
|
+
/** Sub-pixel rounding in measured boxes: two labels touching within this do not collide. */
|
|
88
|
+
export declare const LABEL_SUBPIXEL = 0.5;
|
|
89
|
+
/** A measured label box on one axis (any shared origin), in CSS pixels. */
|
|
90
|
+
export type LabelBox = {
|
|
91
|
+
left: number;
|
|
92
|
+
right: number;
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* Whether every zone name fits on the band: inside `[0, rowWidth]` and clear of every other name
|
|
96
|
+
* (pairwise, so a long name cannot hide behind a short one between it and a distant neighbour).
|
|
97
|
+
* Boxes are relative to the row's own start edge.
|
|
98
|
+
*/
|
|
99
|
+
export declare function zoneLabelsFit(boxes: readonly LabelBox[], rowWidth: number): boolean;
|
|
43
100
|
/** A zone band as left edge + width in percent, clipped to the track. */
|
|
44
101
|
export declare function zoneBand(zone: MeterZone, min: number, span: number): {
|
|
45
102
|
start: number;
|
|
@@ -53,6 +110,7 @@ export type BarInput = {
|
|
|
53
110
|
segments?: readonly MeterSegment[] | undefined;
|
|
54
111
|
zones?: readonly MeterZone[] | undefined;
|
|
55
112
|
target?: number | undefined;
|
|
113
|
+
ticks?: readonly MeterTick[] | undefined;
|
|
56
114
|
color?: string | undefined;
|
|
57
115
|
forecastCaption?: string | undefined;
|
|
58
116
|
};
|
|
@@ -63,14 +121,23 @@ export type BarModel = {
|
|
|
63
121
|
/** Percent where the first forecast part starts; absent when the forecast opens the track. */
|
|
64
122
|
boundaryPct: number | undefined;
|
|
65
123
|
forecastText: string | null;
|
|
124
|
+
captionMode: CaptionMode;
|
|
125
|
+
/** Only in `parts` mode: one caption per part, in order. Empty otherwise. */
|
|
126
|
+
partCaptions: readonly PartCaption[];
|
|
127
|
+
/** Only on a zoned track: every zone's name, in zone order. Empty otherwise. */
|
|
128
|
+
zoneLabels: readonly ZoneLabel[];
|
|
129
|
+
ticks: readonly TickMark[];
|
|
66
130
|
markerPct: number | undefined;
|
|
67
131
|
targetPct: number | undefined;
|
|
132
|
+
/** The default start caption (the zone is named on the band, so it is the bare reading); `startCaption` decides whether it shows. */
|
|
68
133
|
startText: string;
|
|
69
134
|
endText: string | null;
|
|
70
135
|
describedByText: string | null;
|
|
71
136
|
};
|
|
72
137
|
/** Segments are amounts accumulated from `min`, so the reading is `min` plus their sum. */
|
|
73
138
|
export declare const segmentReading: (segments: readonly MeterSegment[], min: number) => number;
|
|
139
|
+
/** The start caption: the consumer's override, else the model's default — absent in `parts` mode. */
|
|
140
|
+
export declare function startCaptionText(model: BarModel, override: ReactNode | undefined): ReactNode;
|
|
74
141
|
export declare function modelBar(input: BarInput): BarModel;
|
|
75
142
|
/** The ring's one arc, as a fraction of the circumference. */
|
|
76
143
|
export declare const ringFraction: (reading: number, min: number, max: number) => number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"meter-model.d.ts","sourceRoot":"","sources":["../../src/dashboard/meter-model.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"meter-model.d.ts","sourceRoot":"","sources":["../../src/dashboard/meter-model.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,M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EAAE,CAAA;IAChC,KAAK,EAAE,SAAS,QAAQ,EAAE,CAAA;IAC1B,SAAS,EAAE,MAAM,GAAG,SAAS,CAAA;IAC7B,SAAS,EAAE,MAAM,GAAG,SAAS,CAAA;IAC7B,qIAAqI;IACrI,SAAS,EAAE,MAAM,CAAA;IACjB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;IACtB,eAAe,EAAE,MAAM,GAAG,IAAI,CAAA;CAC/B,CAAA;AAeD,2FAA2F;AAC3F,eAAO,MAAM,cAAc,GAAI,UAAU,SAAS,YAAY,EAAE,EAAE,KAAK,MAAM,KAAG,MAC/B,CAAA;AA0BjD,qGAAqG;AACrG,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,GAAG,SAAS,GAAG,SAAS,CAG5F;AAED,wBAAgB,QAAQ,CAAC,KAAK,EAAE,QAAQ,GAAG,QAAQ,CAuDlD;AAED,8DAA8D;AAC9D,eAAO,MAAM,YAAY,GAAI,SAAS,MAAM,EAAE,KAAK,MAAM,EAAE,KAAK,MAAM,KAAG,MACvB,CAAA"}
|
|
@@ -1,4 +1,17 @@
|
|
|
1
1
|
import { clamp01, toPct } from "./scale.js";
|
|
2
|
+
function tickMarks(ticks, min, max, format) {
|
|
3
|
+
const { span } = spanOf(min, max);
|
|
4
|
+
return (ticks ?? []).flatMap(
|
|
5
|
+
(t, i) => Number.isFinite(t.at) && t.at >= min && t.at <= max ? [
|
|
6
|
+
{
|
|
7
|
+
key: String(i),
|
|
8
|
+
pct: toPct((t.at - min) / span),
|
|
9
|
+
label: t.label,
|
|
10
|
+
text: `${t.label ?? "Tick"} ${format(t.at)}`
|
|
11
|
+
}
|
|
12
|
+
] : []
|
|
13
|
+
);
|
|
14
|
+
}
|
|
2
15
|
const isReading = (n) => typeof n === "number" && Number.isFinite(n);
|
|
3
16
|
function spanOf(min, max) {
|
|
4
17
|
return max > min ? { span: max - min, valid: true } : { span: 1, valid: false };
|
|
@@ -20,7 +33,14 @@ function layoutSegments(segments, span) {
|
|
|
20
33
|
return segments.map((s) => {
|
|
21
34
|
const size = Math.max(0, Math.min(clamp01(s.value / span), 1 - cursor));
|
|
22
35
|
const forecast = s.forecast === true;
|
|
23
|
-
const part = {
|
|
36
|
+
const part = {
|
|
37
|
+
start: cursor,
|
|
38
|
+
size,
|
|
39
|
+
color: forecast ? void 0 : s.color,
|
|
40
|
+
forecast,
|
|
41
|
+
label: s.label,
|
|
42
|
+
amount: s.value
|
|
43
|
+
};
|
|
24
44
|
cursor += size;
|
|
25
45
|
return part;
|
|
26
46
|
});
|
|
@@ -29,6 +49,13 @@ function findHoldingZone(zones, value) {
|
|
|
29
49
|
const end = Math.max(...zones.map((z) => z.to));
|
|
30
50
|
return zones.find((z) => value >= z.from && (value < z.to || value === z.to && z.to === end));
|
|
31
51
|
}
|
|
52
|
+
const LABEL_SUBPIXEL = 0.5;
|
|
53
|
+
function zoneLabelsFit(boxes, rowWidth) {
|
|
54
|
+
const sorted = boxes.toSorted((a, b) => a.left - b.left);
|
|
55
|
+
return sorted.every(
|
|
56
|
+
(a, i) => a.left >= -LABEL_SUBPIXEL && a.right <= rowWidth + LABEL_SUBPIXEL && sorted.slice(i + 1).every((b) => a.right <= b.left + LABEL_SUBPIXEL)
|
|
57
|
+
);
|
|
58
|
+
}
|
|
32
59
|
function zoneBand(zone, min, span) {
|
|
33
60
|
const lo = clamp01((zone.from - min) / span);
|
|
34
61
|
const hi = clamp01((zone.to - min) / span);
|
|
@@ -47,14 +74,34 @@ function fillParts(input, span, zoned) {
|
|
|
47
74
|
return layoutSegments([input.color === void 0 ? fill : { ...fill, color: input.color }], span);
|
|
48
75
|
}
|
|
49
76
|
const segmentReading = (segments, min) => segments.reduce((sum, s) => sum + s.value, min);
|
|
77
|
+
function partCaptionsOf(parts, format) {
|
|
78
|
+
return parts.map((p, i) => ({
|
|
79
|
+
key: String(i),
|
|
80
|
+
label: p.label,
|
|
81
|
+
text: format(p.amount),
|
|
82
|
+
color: p.color
|
|
83
|
+
}));
|
|
84
|
+
}
|
|
85
|
+
function captionModeOf(segments, zoned, firstForecast) {
|
|
86
|
+
if (zoned) return "reading";
|
|
87
|
+
if (segments === void 0 || segments.length === 0) return "reading";
|
|
88
|
+
return firstForecast < 0 ? "parts" : "forecast";
|
|
89
|
+
}
|
|
90
|
+
function startCaptionText(model, override) {
|
|
91
|
+
if (override !== void 0) return override;
|
|
92
|
+
return model.captionMode === "parts" ? null : model.startText;
|
|
93
|
+
}
|
|
50
94
|
function modelBar(input) {
|
|
51
95
|
const { reading, min, max, format, segments, zones, target } = input;
|
|
96
|
+
const ticks = tickMarks(input.ticks, min, max, format);
|
|
52
97
|
const { span } = spanOf(min, max);
|
|
53
98
|
const zoned = zones !== void 0 && zones.length > 0;
|
|
54
99
|
const holding = zoned ? findHoldingZone(zones, reading) : void 0;
|
|
55
100
|
const parts = fillParts(input, span, zoned);
|
|
56
101
|
const firstForecast = parts.findIndex((p) => p.forecast);
|
|
57
102
|
const forecastLabels = segments?.filter((s) => s.forecast === true).map((s) => `${s.label} ${format(s.value)}`) ?? [];
|
|
103
|
+
const captionMode = captionModeOf(segments, zoned, firstForecast);
|
|
104
|
+
const partCaptions = captionMode === "parts" ? partCaptionsOf(parts, format) : [];
|
|
58
105
|
const zoneText = !zoned ? [] : [
|
|
59
106
|
...zones.map((z) => `${z.label} ${format(z.from)} to ${format(z.to)}`),
|
|
60
107
|
holding === void 0 ? `${format(reading)} is outside every zone` : `${format(reading)} is in ${holding.label}`
|
|
@@ -62,22 +109,33 @@ function modelBar(input) {
|
|
|
62
109
|
const describedBy = [
|
|
63
110
|
...segments?.map((s) => segmentText(s, format)) ?? [],
|
|
64
111
|
...zoneText,
|
|
65
|
-
...target === void 0 ? [] : [`Target ${format(target)}`]
|
|
112
|
+
...target === void 0 ? [] : [`Target ${format(target)}`],
|
|
113
|
+
...ticks.map((t) => t.text)
|
|
66
114
|
];
|
|
67
115
|
return {
|
|
68
116
|
span,
|
|
69
117
|
parts,
|
|
70
118
|
boundaryPct: firstForecast > 0 ? toPct(parts[firstForecast]?.start ?? 0) : void 0,
|
|
71
119
|
forecastText: forecastLabels.length === 0 ? null : input.forecastCaption ?? `Forecast: ${forecastLabels.join(", ")}`,
|
|
120
|
+
captionMode,
|
|
121
|
+
partCaptions,
|
|
122
|
+
zoneLabels: !zoned ? [] : zones.map((z, i) => ({
|
|
123
|
+
key: String(i),
|
|
124
|
+
label: z.label,
|
|
125
|
+
startPct: zoneBand(z, min, span).start,
|
|
126
|
+
holding: z === holding
|
|
127
|
+
})),
|
|
128
|
+
ticks,
|
|
72
129
|
markerPct: zoned ? toPct((reading - min) / span) : void 0,
|
|
73
130
|
targetPct: target === void 0 ? void 0 : toPct((target - min) / span),
|
|
74
|
-
startText:
|
|
131
|
+
startText: format(reading),
|
|
75
132
|
endText: endCaptionText(reading, target, format),
|
|
76
133
|
describedByText: describedBy.length > 0 ? describedBy.join("; ") : null
|
|
77
134
|
};
|
|
78
135
|
}
|
|
79
136
|
const ringFraction = (reading, min, max) => clamp01((reading - min) / spanOf(min, max).span);
|
|
80
137
|
export {
|
|
138
|
+
LABEL_SUBPIXEL,
|
|
81
139
|
ariaValues,
|
|
82
140
|
findHoldingZone,
|
|
83
141
|
isReading,
|
|
@@ -87,5 +145,8 @@ export {
|
|
|
87
145
|
ringFraction,
|
|
88
146
|
segmentReading,
|
|
89
147
|
spanOf,
|
|
90
|
-
|
|
148
|
+
startCaptionText,
|
|
149
|
+
tickMarks,
|
|
150
|
+
zoneBand,
|
|
151
|
+
zoneLabelsFit
|
|
91
152
|
};
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { CSSProperties, ReactNode } from 'react';
|
|
2
|
-
import type { MeterSegment, MeterZone } from './meter-model.js';
|
|
2
|
+
import type { MeterSegment, MeterTick, MeterZone } from './meter-model.js';
|
|
3
3
|
export type Shell = {
|
|
4
4
|
className: string | undefined;
|
|
5
5
|
style: CSSProperties | undefined;
|
|
6
|
+
/** `size="row"`: one text line tall, no caption rows. */
|
|
7
|
+
row: boolean;
|
|
6
8
|
};
|
|
7
9
|
export declare function MeterLoading({ label, ring, shell, }: {
|
|
8
10
|
label: string;
|
|
@@ -34,6 +36,8 @@ export declare function MeterBar(props: {
|
|
|
34
36
|
segments: readonly MeterSegment[] | undefined;
|
|
35
37
|
zones: readonly MeterZone[] | undefined;
|
|
36
38
|
target: number | undefined;
|
|
39
|
+
ticks: readonly MeterTick[] | undefined;
|
|
40
|
+
tone: 'muted' | undefined;
|
|
37
41
|
forecastCaption: string | undefined;
|
|
38
42
|
startCaption: ReactNode;
|
|
39
43
|
endCaption: ReactNode;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"meter-parts.d.ts","sourceRoot":"","sources":["../../src/dashboard/meter-parts.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,
|
|
1
|
+
{"version":3,"file":"meter-parts.d.ts","sourceRoot":"","sources":["../../src/dashboard/meter-parts.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAkB,SAAS,EAAa,MAAM,OAAO,CAAA;AAWhF,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,SAAS,EAA6B,MAAM,eAAe,CAAA;AAIlG,MAAM,MAAM,KAAK,GAAG;IAClB,SAAS,EAAE,MAAM,GAAG,SAAS,CAAA;IAC7B,KAAK,EAAE,aAAa,GAAG,SAAS,CAAA;IAChC,yDAAyD;IACzD,GAAG,EAAE,OAAO,CAAA;CACb,CAAA;AA8DD,wBAAgB,YAAY,CAAC,EAC3B,KAAK,EACL,IAAI,EACJ,KAAK,GACN,EAAE;IACD,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,OAAO,CAAA;IACb,KAAK,EAAE,KAAK,CAAA;CACb,+BAcA;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAA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