basalt-ui 2.18.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 (76) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/MIGRATING.md +76 -12
  3. package/agent/agents/basalt-design-reviewer.md +2 -2
  4. package/dist/commands/notifications/center.d.ts.map +1 -1
  5. package/dist/commands/notifications/center.js +18 -26
  6. package/dist/content/callout.d.ts +1 -1
  7. package/dist/content/callout.d.ts.map +1 -1
  8. package/dist/content/callout.js +10 -1
  9. package/dist/content/callout.module.css +15 -3
  10. package/dist/content/callout.module.css.d.ts +1 -0
  11. package/dist/dashboard/bar-list.d.ts.map +1 -1
  12. package/dist/dashboard/bar-list.js +31 -18
  13. package/dist/dashboard/bar-list.module.css +33 -15
  14. package/dist/dashboard/bar-list.module.css.d.ts +1 -0
  15. package/dist/dashboard/meter-model.d.ts +49 -1
  16. package/dist/dashboard/meter-model.d.ts.map +1 -1
  17. package/dist/dashboard/meter-model.js +47 -3
  18. package/dist/dashboard/meter-parts.d.ts.map +1 -1
  19. package/dist/dashboard/meter-parts.js +143 -9
  20. package/dist/dashboard/meter.d.ts +16 -5
  21. package/dist/dashboard/meter.d.ts.map +1 -1
  22. package/dist/dashboard/meter.module.css +127 -9
  23. package/dist/dashboard/meter.module.css.d.ts +11 -0
  24. package/dist/dashboard/stat-card-parts.d.ts +3 -1
  25. package/dist/dashboard/stat-card-parts.d.ts.map +1 -1
  26. package/dist/dashboard/stat-card-parts.js +18 -3
  27. package/dist/dashboard/stat-card.d.ts +6 -5
  28. package/dist/dashboard/stat-card.d.ts.map +1 -1
  29. package/dist/dashboard/stat-card.js +48 -77
  30. package/dist/dashboard/stat-card.module.css +27 -7
  31. package/dist/dashboard/widget-header.d.ts.map +1 -1
  32. package/dist/dashboard/widget-header.js +2 -1
  33. package/dist/dashboard/widget-header.module.css +28 -1
  34. package/dist/theme/chrome-vars.d.ts +29 -17
  35. package/dist/theme/chrome-vars.d.ts.map +1 -1
  36. package/dist/theme/chrome-vars.js +18 -8
  37. package/dist/theme/index.d.ts.map +1 -1
  38. package/dist/theme/index.js +9 -5
  39. package/dist/theme/status-dot.d.ts +6 -0
  40. package/dist/theme/status-dot.d.ts.map +1 -0
  41. package/dist/theme/status-dot.js +9 -0
  42. package/dist/theme/status-dot.module.css +9 -0
  43. package/dist/theme/status-dot.module.css.d.ts +8 -0
  44. package/dist/theme/status-verdict.d.ts +9 -0
  45. package/dist/theme/status-verdict.d.ts.map +1 -0
  46. package/dist/theme/status-verdict.js +13 -0
  47. package/dist/theme/status-verdict.module.css +23 -0
  48. package/dist/theme/status-verdict.module.css.d.ts +9 -0
  49. package/llms.txt +2 -2
  50. package/package.json +1 -1
  51. package/src/commands/notifications/center.tsx +29 -32
  52. package/src/content/callout.module.css +15 -3
  53. package/src/content/callout.module.css.d.ts +1 -0
  54. package/src/content/callout.tsx +15 -2
  55. package/src/dashboard/bar-list.module.css +33 -15
  56. package/src/dashboard/bar-list.module.css.d.ts +1 -0
  57. package/src/dashboard/bar-list.tsx +29 -16
  58. package/src/dashboard/meter-model.ts +97 -4
  59. package/src/dashboard/meter-parts.tsx +195 -11
  60. package/src/dashboard/meter.module.css +127 -9
  61. package/src/dashboard/meter.module.css.d.ts +11 -0
  62. package/src/dashboard/meter.tsx +16 -5
  63. package/src/dashboard/stat-card-parts.tsx +22 -2
  64. package/src/dashboard/stat-card.module.css +27 -7
  65. package/src/dashboard/stat-card.tsx +18 -52
  66. package/src/dashboard/widget-header.module.css +28 -1
  67. package/src/dashboard/widget-header.tsx +4 -1
  68. package/src/theme/__snapshots__/plain-theme.test.ts.snap +88 -16
  69. package/src/theme/chrome-vars.ts +48 -23
  70. package/src/theme/index.ts +10 -6
  71. package/src/theme/status-dot.module.css +9 -0
  72. package/src/theme/status-dot.module.css.d.ts +8 -0
  73. package/src/theme/status-dot.tsx +19 -0
  74. package/src/theme/status-verdict.module.css +23 -0
  75. package/src/theme/status-verdict.module.css.d.ts +9 -0
  76. package/src/theme/status-verdict.tsx +27 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"status-dot.d.ts","sourceRoot":"","sources":["../../src/theme/status-dot.tsx"],"names":[],"mappings":"AAQA,MAAM,MAAM,cAAc,GAAG;IAC3B,uFAAuF;IACvF,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AAID,wBAAgB,SAAS,CAAC,EAAE,KAAK,EAAE,EAAE,cAAc,+BAGlD"}
@@ -0,0 +1,9 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import classes from "./status-dot.module.css";
3
+ function StatusDot({ color }) {
4
+ const style = { "--basalt-status-dot": color };
5
+ return /* @__PURE__ */ jsx("span", { className: classes.dot, "data-basalt-status-dot": "", "aria-hidden": "true", style });
6
+ }
7
+ export {
8
+ StatusDot
9
+ };
@@ -0,0 +1,9 @@
1
+ /* The one status mark: a 6px round dot (a § 5 step). The colour arrives as `--basalt-status-dot`. */
2
+ .dot {
3
+ display: inline-block;
4
+ flex: none;
5
+ width: 6px;
6
+ height: 6px;
7
+ border-radius: 50%;
8
+ background: var(--basalt-status-dot);
9
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Typed CSS-module declaration (the S4 CSS-modules path). Named string props — not an index
3
+ * signature — so dot access stays verbatim under the package's strict flags.
4
+ */
5
+ declare const classes: {
6
+ readonly dot: string
7
+ }
8
+ export default classes
@@ -0,0 +1,9 @@
1
+ export type StatusVerdictProps = {
2
+ color: string;
3
+ /** The short visible word ("Over", "Error"). */
4
+ word: string;
5
+ /** A longer phrase for assistive tech, read in place of the word. */
6
+ phrase?: string;
7
+ };
8
+ export declare function StatusVerdict({ color, word, phrase }: StatusVerdictProps): import("react").JSX.Element;
9
+ //# sourceMappingURL=status-verdict.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"status-verdict.d.ts","sourceRoot":"","sources":["../../src/theme/status-verdict.tsx"],"names":[],"mappings":"AAQA,MAAM,MAAM,kBAAkB,GAAG;IAC/B,KAAK,EAAE,MAAM,CAAA;IACb,gDAAgD;IAChD,IAAI,EAAE,MAAM,CAAA;IACZ,qEAAqE;IACrE,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,wBAAgB,aAAa,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,kBAAkB,+BAUxE"}
@@ -0,0 +1,13 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { StatusDot } from "./status-dot.js";
3
+ import classes from "./status-verdict.module.css";
4
+ function StatusVerdict({ color, word, phrase }) {
5
+ return /* @__PURE__ */ jsxs("span", { className: classes.verdict, children: [
6
+ /* @__PURE__ */ jsx(StatusDot, { color }),
7
+ /* @__PURE__ */ jsx("span", { "data-verdict-word": "", ...phrase !== void 0 && { "aria-hidden": true }, children: word }),
8
+ phrase !== void 0 && /* @__PURE__ */ jsx("span", { className: classes.hidden, children: phrase })
9
+ ] });
10
+ }
11
+ export {
12
+ StatusVerdict
13
+ };
@@ -0,0 +1,23 @@
1
+ /* A status dot plus its word: the dot carries the colour, the word is muted ink. `flex: none` keeps
2
+ * it whole when a neighbouring caption or title truncates. */
3
+ .verdict {
4
+ display: inline-flex;
5
+ flex: none;
6
+ align-items: center;
7
+ gap: 5px;
8
+ font-family: var(--basalt-font-mono);
9
+ font-size: var(--vx-text-micro);
10
+ color: var(--vx-muted);
11
+ }
12
+
13
+ /* Visually hidden, still read by assistive tech. */
14
+ .hidden {
15
+ position: absolute;
16
+ width: 1px;
17
+ height: 1px;
18
+ margin: -1px;
19
+ padding: 0;
20
+ overflow: hidden;
21
+ clip-path: inset(50%);
22
+ white-space: nowrap;
23
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Typed CSS-module declaration (the S4 CSS-modules path). Named string props — not an index
3
+ * signature — so dot access stays verbatim under the package's strict flags.
4
+ */
5
+ declare const classes: {
6
+ readonly verdict: string
7
+ readonly hidden: string
8
+ }
9
+ export default classes
package/llms.txt CHANGED
@@ -1,4 +1,4 @@
1
- # basalt-ui v2.18.0
1
+ # basalt-ui v2.19.0
2
2
  # Opinionated framework for Mantine-based React apps — theme, app shell, TanStack Charts, toolchain presets
3
3
  #
4
4
  # Entry points: use the exact import specifier below; do not guess.
@@ -13,7 +13,7 @@
13
13
  # A subpath's `Install:` line is its required peers; `OptionalPeers:` are import()-only, install on use.
14
14
 
15
15
  Package: basalt-ui
16
- Version: 2.18.0
16
+ Version: 2.19.0
17
17
 
18
18
  ## basalt-ui
19
19
  Import: import { ... } from 'basalt-ui'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "basalt-ui",
3
- "version": "2.18.0",
3
+ "version": "2.19.0",
4
4
  "description": "Opinionated framework for Mantine-based React apps — theme, app shell, TanStack Charts, toolchain presets",
5
5
  "keywords": [
6
6
  "charts",
@@ -30,28 +30,20 @@ import {
30
30
  import type { BasaltProps } from '../../common/props'
31
31
  import { cx } from '../../common/props'
32
32
  import { relativeTime } from '../../format'
33
+ import { StatusVerdict } from '../../theme/status-verdict'
33
34
  import { VX } from '../../tokens'
34
35
  import { resolveAction } from './define-notifications'
35
36
  import { useNotificationHistory } from './store'
36
37
  import type { NotificationHistoryItem, NotificationIntent } from './store'
37
38
 
38
- // ── Intent → Mantine color (drives the action Button's own `light`-variant tint) ──────────────
39
-
40
- const INTENT_COLOR: Record<NotificationIntent, string> = {
41
- success: 'green',
42
- error: 'red',
43
- warning: 'yellow',
44
- info: 'blue',
45
- }
46
-
47
- // ── Intent → status token (docs/DESIGN-SPEC.md §5: "severity accents via status tokens") — the
48
- // exact spec success/warning/danger hex, used for the item's left-border accent. `info` has no
49
- // status tone, so it reads the neutral accent instead.
50
- const INTENT_STATUS: Record<NotificationIntent, string> = {
51
- success: VX.status.good,
52
- error: VX.status.bad,
53
- warning: VX.status.warn,
54
- info: VX.accent,
39
+ // ── Intent → the action Button's Mantine tint, the status dot colour and the visible word beside
40
+ // it (docs/DESIGN-SPEC.md §5: severity via status tokens). `info` has no status tone, so its dot is
41
+ // the neutral muted ink, not the accent.
42
+ const INTENT_META: Record<NotificationIntent, { color: string; dot: string; word: string }> = {
43
+ success: { color: 'green', dot: VX.status.good, word: 'Success' },
44
+ error: { color: 'red', dot: VX.status.bad, word: 'Error' },
45
+ warning: { color: 'yellow', dot: VX.status.warn, word: 'Warning' },
46
+ info: { color: 'blue', dot: VX.muted, word: 'Info' },
55
47
  }
56
48
 
57
49
  type CenterView = 'inbox' | 'all'
@@ -78,8 +70,7 @@ function NotificationItem({
78
70
  }) {
79
71
  const isUnread = item.readAt === undefined
80
72
  const isDismissed = item.dismissedAt !== undefined
81
- const color = INTENT_COLOR[item.intent]
82
- const statusAccent = INTENT_STATUS[item.intent]
73
+ const { color, dot, word } = INTENT_META[item.intent]
83
74
  const resolved = item.action !== undefined ? resolveAction(item.action) : undefined
84
75
 
85
76
  function handleAction(e: MouseEvent): void {
@@ -101,7 +92,6 @@ function NotificationItem({
101
92
  onClick={isUnread ? () => onMarkRead(item.id) : undefined}
102
93
  style={{
103
94
  cursor: isUnread ? 'pointer' : 'default',
104
- borderInlineStart: `3px solid ${statusAccent}`,
105
95
  borderRadius: 'var(--mantine-radius-sm)',
106
96
  background: isUnread ? 'var(--mantine-color-default-hover)' : 'transparent',
107
97
  opacity: isDismissed ? 0.55 : 1,
@@ -109,19 +99,26 @@ function NotificationItem({
109
99
  >
110
100
  <Group gap="xs" align="flex-start" wrap="nowrap">
111
101
  <Stack gap={2} style={{ minWidth: 0, flex: 1 }}>
112
- {item.title !== undefined && (
113
- <Text size="sm" fw={isUnread ? 600 : 500} lh={1.2} truncate="end">
114
- {item.title}
115
- </Text>
102
+ {item.title !== undefined ? (
103
+ <>
104
+ <Group gap="xs" align="center" wrap="nowrap">
105
+ <StatusVerdict color={dot} word={word} />
106
+ <Text size="sm" fw={isUnread ? 600 : 500} lh={1.2} miw={0} truncate="end">
107
+ {item.title}
108
+ </Text>
109
+ </Group>
110
+ <Text size="sm" lh={1.3} c="dimmed" style={{ wordBreak: 'break-word' }}>
111
+ {item.message}
112
+ </Text>
113
+ </>
114
+ ) : (
115
+ <Group gap="xs" align="flex-start" wrap="nowrap">
116
+ <StatusVerdict color={dot} word={word} />
117
+ <Text size="sm" lh={1.3} miw={0} style={{ wordBreak: 'break-word' }}>
118
+ {item.message}
119
+ </Text>
120
+ </Group>
116
121
  )}
117
- <Text
118
- size="sm"
119
- lh={1.3}
120
- {...(item.title !== undefined && { c: 'dimmed' })}
121
- style={{ wordBreak: 'break-word' }}
122
- >
123
- {item.message}
124
- </Text>
125
122
  <Group gap="xs" align="center" mt={2} wrap="nowrap">
126
123
  <Text ff="monospace" c="var(--vx-faint)" style={{ fontSize: VX.text.micro }}>
127
124
  {relativeTime(item.createdAt, { style: 'short' })}
@@ -1,13 +1,12 @@
1
1
  /*
2
- * Callout — a soft tinted panel with a left rail, keyed to one of the four semantic tokens.
3
- * `--callout-ink` is set per kind below and consumed by both the rail/bg tint and the title/icon
2
+ * Callout — a soft tinted panel, keyed to one of the four semantic tokens.
3
+ * `--callout-ink` is set per kind below and consumed by both the bg tint and the title/icon
4
4
  * color — one custom property, no per-kind duplication.
5
5
  */
6
6
 
7
7
  .root {
8
8
  border-radius: var(--vx-radius-card);
9
9
  padding: var(--vx-space-callout-inset-y) var(--vx-space-callout-inset-x);
10
- border-left: 2px solid var(--callout-ink);
11
10
  background: color-mix(in srgb, var(--callout-ink) 8%, transparent);
12
11
  }
13
12
 
@@ -56,6 +55,7 @@
56
55
  }
57
56
 
58
57
  .body {
58
+ position: relative;
59
59
  font-size: var(--vx-text-md);
60
60
  color: var(--vx-ink2);
61
61
  }
@@ -75,3 +75,15 @@
75
75
  .body p {
76
76
  margin: 0 0 var(--vx-space-stack-sm);
77
77
  }
78
+
79
+ /* The kind as a word for assistive tech; visually hidden. */
80
+ .kindWord {
81
+ position: absolute;
82
+ width: 1px;
83
+ height: 1px;
84
+ margin: -1px;
85
+ padding: 0;
86
+ overflow: hidden;
87
+ clip-path: inset(50%);
88
+ white-space: nowrap;
89
+ }
@@ -12,5 +12,6 @@ declare const classes: {
12
12
  readonly icon: string
13
13
  readonly title: string
14
14
  readonly body: string
15
+ readonly kindWord: string
15
16
  }
16
17
  export default classes
@@ -21,7 +21,7 @@ import classes from './callout.module.css'
21
21
  export type CalloutKind = 'info' | 'good' | 'warn' | 'bad'
22
22
 
23
23
  export type CalloutProps = BasaltProps & {
24
- /** Semantic kind — drives the rail/tint color and the default icon. Default `'info'`. */
24
+ /** Semantic kind — drives the tint color and the default icon. Default `'info'`. */
25
25
  readonly kind?: CalloutKind
26
26
  readonly title?: string
27
27
  /** Overrides the default per-kind icon. Only rendered alongside a `title`. */
@@ -77,6 +77,14 @@ function BadGlyph() {
77
77
  )
78
78
  }
79
79
 
80
+ // The kind as a word for assistive tech, so a title-less callout is never tint-only.
81
+ const KIND_WORD: Record<CalloutKind, string> = {
82
+ info: 'Info',
83
+ good: 'Success',
84
+ warn: 'Warning',
85
+ bad: 'Error',
86
+ }
87
+
80
88
  const DEFAULT_ICON: Record<CalloutKind, ReactNode> = {
81
89
  info: <InfoGlyph />,
82
90
  good: <GoodGlyph />,
@@ -96,7 +104,12 @@ export function Callout({ kind = 'info', title, icon, children, className, style
96
104
  <span className={classes.title}>{title}</span>
97
105
  </div>
98
106
  )}
99
- <div className={classes.body}>{children}</div>
107
+ <div className={classes.body}>
108
+ <span className={classes.kindWord} data-callout-kind-word="">
109
+ {KIND_WORD[kind]}
110
+ </span>
111
+ {children}
112
+ </div>
100
113
  </div>
101
114
  )
102
115
  }
@@ -1,30 +1,46 @@
1
1
  /*
2
- * BarList — ranked rows on one shared scale (docs/waves/design-parity/SPEC.md § 6.4). The bar sits
3
- * BEHIND the label and value; the row never wraps: the label truncates, the value is nowrap.
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: flex;
8
- flex-direction: column;
9
- gap: var(--vx-space-stack-xs, 0.25rem);
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
- position: relative;
18
- display: flex;
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,30 @@
47
62
  }
48
63
 
49
64
  .value {
50
- position: relative;
51
- flex: none;
52
65
  font-family: var(--basalt-font-mono);
53
66
  text-align: end;
54
67
  white-space: nowrap;
55
68
  }
56
69
 
70
+ .value:last-child,
71
+ .secondary:last-child {
72
+ padding-inline-end: var(--vx-space-stack-sm);
73
+ }
74
+
57
75
  .secondary {
58
- position: relative;
59
- flex: none;
60
76
  font-family: var(--basalt-font-mono);
61
- font-size: var(--vx-text-xs);
77
+ font-size: var(--vx-text-sm);
62
78
  color: var(--vx-muted);
63
79
  white-space: nowrap;
64
80
  }
65
81
 
66
82
  .empty {
83
+ grid-column: 1 / -1;
67
84
  font-size: var(--vx-text-sm);
68
85
  color: var(--vx-muted);
69
86
  }
70
87
 
71
88
  .skeletonRow {
89
+ grid-column: 1 / -1;
72
90
  height: calc(var(--vx-space-control-height-widget, 1.5rem) * var(--mantine-scale, 1));
73
91
  }
@@ -5,6 +5,7 @@
5
5
  declare const classes: {
6
6
  readonly root: string
7
7
  readonly row: string
8
+ readonly track: string
8
9
  readonly bar: string
9
10
  readonly leader: string
10
11
  readonly label: string
@@ -1,8 +1,9 @@
1
1
  /**
2
2
  * BarList — a ranked list: label, an inline bar on ONE shared scale, a mono right-aligned value and
3
3
  * an optional muted secondary value. Choose it for "top N" (the bar ranks by length before anything
4
- * is read). Intended for 5–10 rows; past 10 use a table with an inline `Meter` cell. An HTML/CSS
5
- * primitive, not a chart kind.
4
+ * is read). The bar spans the label column only — values sit outside it, so a full-scale bar ends
5
+ * before its value. Intended for 5–10 rows; past 10 use a table with an inline `Meter` cell. An
6
+ * HTML/CSS primitive, not a chart kind.
6
7
  *
7
8
  * Colour law: bars are neutral. `accentLeader` (opt-in) lets the top row take the accent — the
8
9
  * leader bar, and nothing else. Each value is rendered as text, never only a bar length.
@@ -48,6 +49,10 @@ export type BarListProps = BasaltProps & {
48
49
  emptyText?: string
49
50
  }
50
51
 
52
+ /** `null`, `undefined`, `false` and `true` render nothing, so they are not a secondary value. */
53
+ const hasContent = (node: ReactNode): boolean =>
54
+ node !== undefined && node !== null && typeof node !== 'boolean'
55
+
51
56
  export function BarList({
52
57
  label,
53
58
  items,
@@ -80,30 +85,38 @@ export function BarList({
80
85
 
81
86
  const scale =
82
87
  max ?? items.reduce((top, i) => (Number.isFinite(i.value) ? Math.max(top, i.value) : top), 0)
88
+ const hasSecondary = items.some((i) => hasContent(i.secondary))
83
89
  return (
84
90
  // The explicit role is deliberate: `list-style: none` makes Safari/VoiceOver drop the implicit one.
85
- // oxlint-disable-next-line jsx-a11y/no-redundant-roles
86
- <ul className={cx(classes.root, className)} style={style} role="list" aria-label={label}>
91
+ <ul
92
+ className={cx(classes.root, className)}
93
+ style={style}
94
+ // oxlint-disable-next-line jsx-a11y/no-redundant-roles
95
+ role="list"
96
+ aria-label={label}
97
+ data-secondary={hasSecondary ? '' : undefined}
98
+ >
87
99
  {items.map((item, i) => {
88
100
  const isLeader = accentLeader && i === 0
89
101
  return (
90
102
  <li key={item.key ?? `${item.label}-${i}`} className={classes.row}>
91
- {/* theme-allow hidden-inline-style — the width is the row's data (a % of the shared scale), not styling */}
92
- <span
93
- className={cx(classes.bar, isLeader && classes.leader)}
94
- style={{ width: `${barPercent(item.value, scale)}%` }}
95
- data-bar-leader={isLeader ? '' : undefined}
96
- aria-hidden
97
- />
98
- <span className={classes.label} title={item.label}>
99
- {item.label}
103
+ <span className={classes.track} data-bar-track>
104
+ {/* theme-allow hidden-inline-style — the width is the row's data (a % of the shared scale), not styling */}
105
+ <span
106
+ className={cx(classes.bar, isLeader && classes.leader)}
107
+ style={{ width: `${barPercent(item.value, scale)}%` }}
108
+ data-bar-leader={isLeader ? '' : undefined}
109
+ aria-hidden
110
+ />
111
+ <span className={classes.label} title={item.label}>
112
+ {item.label}
113
+ </span>
100
114
  </span>
101
115
  <span className={classes.value}>
102
116
  {Number.isFinite(item.value) ? format(item.value) : '—'}
103
117
  </span>
104
- {item.secondary !== undefined && (
105
- <span className={classes.secondary}>{item.secondary}</span>
106
- )}
118
+ {/* Kept empty on a row without one: the secondary column is shared, so every row has the cell. */}
119
+ {hasSecondary && <span className={classes.secondary}>{item.secondary}</span>}
107
120
  </li>
108
121
  )
109
122
  })}
@@ -1,20 +1,36 @@
1
1
  /**
2
- * Meter's pure model: everything the component shows, computed from numbers (no DOM, no React).
2
+ * Meter's pure model: everything the component shows, computed from numbers (no DOM, no React runtime).
3
3
  * Internal — `meter.tsx` and `meter-parts.tsx` render what this returns.
4
4
  */
5
+ import type { ReactNode } from 'react'
5
6
  import { clamp01, toPct } from './scale'
6
7
 
7
8
  export type MeterSegment = { value: number; label: string; color?: string; forecast?: boolean }
8
9
  export type MeterZone = { from: number; to: number; label: string; color?: string }
9
10
 
10
- /** A fill on the track, as fractions (0–1) of the span. */
11
+ /** A fill on the track, as fractions (0–1) of the span, with the segment it was laid out from. */
11
12
  export type Part = {
12
13
  readonly start: number
13
14
  readonly size: number
14
15
  readonly color: string | undefined
15
16
  readonly forecast: boolean
17
+ readonly label: string
18
+ /** The segment's own (normalised) amount, in the reading's units — what its caption states. */
19
+ readonly amount: number
16
20
  }
17
21
 
22
+ /** One categorical part's caption: its position key, name, formatted amount and fill colour (`undefined` = neutral). */
23
+ export type PartCaption = { key: string; label: string; text: string; color: string | undefined }
24
+
25
+ /** One zone's name on the band: where its band starts (percent) and whether it holds the reading. */
26
+ export type ZoneLabel = { key: string; label: string; startPct: number; holding: boolean }
27
+
28
+ /**
29
+ * What the caption row says. `reading`: the formatted reading; `parts`: categorical segments name
30
+ * every part instead; `forecast`: committed/forecast keeps the reading plus the forecast caption.
31
+ */
32
+ export type CaptionMode = 'reading' | 'parts' | 'forecast'
33
+
18
34
  type Format = (value: number) => string
19
35
 
20
36
  export const isReading = (n: number | null | undefined): n is number =>
@@ -50,7 +66,14 @@ export function layoutSegments(segments: readonly MeterSegment[], span: number):
50
66
  const size = Math.max(0, Math.min(clamp01(s.value / span), 1 - cursor))
51
67
  const forecast = s.forecast === true
52
68
  // A forecast stays the lighter neutral: a colour would turn the committed/forecast pair into hue.
53
- const part = { start: cursor, size, color: forecast ? undefined : s.color, forecast }
69
+ const part = {
70
+ start: cursor,
71
+ size,
72
+ color: forecast ? undefined : s.color,
73
+ forecast,
74
+ label: s.label,
75
+ amount: s.value,
76
+ }
54
77
  cursor += size
55
78
  return part
56
79
  })
@@ -62,6 +85,27 @@ export function findHoldingZone(zones: readonly MeterZone[], value: number): Met
62
85
  return zones.find((z) => value >= z.from && (value < z.to || (value === z.to && z.to === end)))
63
86
  }
64
87
 
88
+ /** Sub-pixel rounding in measured boxes: two labels touching within this do not collide. */
89
+ export const LABEL_SUBPIXEL = 0.5
90
+
91
+ /** A measured label box on one axis (any shared origin), in CSS pixels. */
92
+ export type LabelBox = { left: number; 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 function zoneLabelsFit(boxes: readonly LabelBox[], rowWidth: number): boolean {
100
+ const sorted = boxes.toSorted((a, b) => a.left - b.left)
101
+ return sorted.every(
102
+ (a, i) =>
103
+ a.left >= -LABEL_SUBPIXEL &&
104
+ a.right <= rowWidth + LABEL_SUBPIXEL &&
105
+ sorted.slice(i + 1).every((b) => a.right <= b.left + LABEL_SUBPIXEL),
106
+ )
107
+ }
108
+
65
109
  /** A zone band as left edge + width in percent, clipped to the track. */
66
110
  export function zoneBand(zone: MeterZone, min: number, span: number) {
67
111
  const lo = clamp01((zone.from - min) / span)
@@ -91,8 +135,14 @@ export type BarModel = {
91
135
  /** Percent where the first forecast part starts; absent when the forecast opens the track. */
92
136
  boundaryPct: number | undefined
93
137
  forecastText: string | null
138
+ captionMode: CaptionMode
139
+ /** Only in `parts` mode: one caption per part, in order. Empty otherwise. */
140
+ partCaptions: readonly PartCaption[]
141
+ /** Only on a zoned track: every zone's name, in zone order. Empty otherwise. */
142
+ zoneLabels: readonly ZoneLabel[]
94
143
  markerPct: number | undefined
95
144
  targetPct: number | undefined
145
+ /** The default start caption (the zone is named on the band, so it is the bare reading); `startCaption` decides whether it shows. */
96
146
  startText: string
97
147
  endText: string | null
98
148
  describedByText: string | null
@@ -115,6 +165,36 @@ function fillParts(input: BarInput, span: number, zoned: boolean): Part[] {
115
165
  export const segmentReading = (segments: readonly MeterSegment[], min: number): number =>
116
166
  segments.reduce((sum, s) => sum + s.value, min)
117
167
 
168
+ /** Keyed by index: segments are an ordered list, and labels are the consumer's, so they may repeat. */
169
+ function partCaptionsOf(parts: readonly Part[], format: Format): PartCaption[] {
170
+ return parts.map((p, i) => ({
171
+ key: String(i),
172
+ label: p.label,
173
+ text: format(p.amount),
174
+ color: p.color,
175
+ }))
176
+ }
177
+
178
+ /**
179
+ * Zones win over segments (the union forbids both, a JS caller can still pass them): a zoned track
180
+ * has no fills to caption. Empty segments are the empty state, never categorical.
181
+ */
182
+ function captionModeOf(
183
+ segments: readonly MeterSegment[] | undefined,
184
+ zoned: boolean,
185
+ firstForecast: number,
186
+ ): CaptionMode {
187
+ if (zoned) return 'reading'
188
+ if (segments === undefined || segments.length === 0) return 'reading'
189
+ return firstForecast < 0 ? 'parts' : 'forecast'
190
+ }
191
+
192
+ /** The start caption: the consumer's override, else the model's default — absent in `parts` mode. */
193
+ export function startCaptionText(model: BarModel, override: ReactNode | undefined): ReactNode {
194
+ if (override !== undefined) return override
195
+ return model.captionMode === 'parts' ? null : model.startText
196
+ }
197
+
118
198
  export function modelBar(input: BarInput): BarModel {
119
199
  const { reading, min, max, format, segments, zones, target } = input
120
200
  const { span } = spanOf(min, max)
@@ -126,6 +206,9 @@ export function modelBar(input: BarInput): BarModel {
126
206
  const forecastLabels =
127
207
  segments?.filter((s) => s.forecast === true).map((s) => `${s.label} ${format(s.value)}`) ?? []
128
208
 
209
+ const captionMode = captionModeOf(segments, zoned, firstForecast)
210
+ const partCaptions = captionMode === 'parts' ? partCaptionsOf(parts, format) : []
211
+
129
212
  const zoneText = !zoned
130
213
  ? []
131
214
  : [
@@ -148,9 +231,19 @@ export function modelBar(input: BarInput): BarModel {
148
231
  forecastLabels.length === 0
149
232
  ? null
150
233
  : (input.forecastCaption ?? `Forecast: ${forecastLabels.join(', ')}`),
234
+ captionMode,
235
+ partCaptions,
236
+ zoneLabels: !zoned
237
+ ? []
238
+ : zones.map((z, i) => ({
239
+ key: String(i),
240
+ label: z.label,
241
+ startPct: zoneBand(z, min, span).start,
242
+ holding: z === holding,
243
+ })),
151
244
  markerPct: zoned ? toPct((reading - min) / span) : undefined,
152
245
  targetPct: target === undefined ? undefined : toPct((target - min) / span),
153
- startText: holding === undefined ? format(reading) : `${holding.label} · ${format(reading)}`,
246
+ startText: format(reading),
154
247
  endText: endCaptionText(reading, target, format),
155
248
  describedByText: describedBy.length > 0 ? describedBy.join('; ') : null,
156
249
  }