basalt-ui 2.19.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.
Files changed (157) hide show
  1. package/CHANGELOG.md +50 -0
  2. package/MIGRATING.md +174 -12
  3. package/agent/rules/basalt-charts.md +1 -1
  4. package/agent/rules/basalt-mantine.md +1 -1
  5. package/agent/skills/basalt-app/SKILL.md +1 -1
  6. package/agent/skills/basalt-design/SKILL.md +1 -1
  7. package/agent/templates/DESIGN.md.tpl +1 -1
  8. package/configs/oxlint-plugin.js +33 -19
  9. package/configs/oxlint-plugin.test.ts +32 -2
  10. package/dist/charts/ChartCard.d.ts +28 -3
  11. package/dist/charts/ChartCard.d.ts.map +1 -1
  12. package/dist/charts/ChartCard.js +33 -11
  13. package/dist/charts/Donut.d.ts.map +1 -1
  14. package/dist/charts/Donut.js +13 -1
  15. package/dist/charts/Heatmap.js +1 -1
  16. package/dist/charts/Sparkline.d.ts +7 -1
  17. package/dist/charts/Sparkline.d.ts.map +1 -1
  18. package/dist/charts/Sparkline.js +137 -18
  19. package/dist/charts/box.d.ts +2 -0
  20. package/dist/charts/box.d.ts.map +1 -1
  21. package/dist/charts/box.js +2 -0
  22. package/dist/charts/chart-box.module.css +30 -0
  23. package/dist/charts/chart-box.module.css.d.ts +1 -0
  24. package/dist/charts/chart-card.module.css +47 -0
  25. package/dist/charts/chart-card.module.css.d.ts +7 -0
  26. package/dist/charts/compile.d.ts.map +1 -1
  27. package/dist/charts/compile.js +35 -8
  28. package/dist/charts/host.d.ts.map +1 -1
  29. package/dist/charts/host.js +2 -1
  30. package/dist/charts/index.d.ts +1 -1
  31. package/dist/charts/index.d.ts.map +1 -1
  32. package/dist/charts/sparkline.module.css +59 -0
  33. package/dist/charts/sparkline.module.css.d.ts +13 -0
  34. package/dist/charts/state.d.ts.map +1 -1
  35. package/dist/charts/state.js +32 -4
  36. package/dist/charts/types.d.ts +6 -0
  37. package/dist/charts/types.d.ts.map +1 -1
  38. package/dist/controls/sync-button.d.ts +3 -0
  39. package/dist/controls/sync-button.d.ts.map +1 -1
  40. package/dist/dashboard/bar-list.d.ts +15 -4
  41. package/dist/dashboard/bar-list.d.ts.map +1 -1
  42. package/dist/dashboard/bar-list.js +39 -15
  43. package/dist/dashboard/bar-list.module.css +77 -2
  44. package/dist/dashboard/bar-list.module.css.d.ts +1 -0
  45. package/dist/dashboard/delta-badge.d.ts +8 -3
  46. package/dist/dashboard/delta-badge.d.ts.map +1 -1
  47. package/dist/dashboard/delta-badge.js +9 -2
  48. package/dist/dashboard/index.d.ts +2 -0
  49. package/dist/dashboard/index.d.ts.map +1 -1
  50. package/dist/dashboard/meter-model.d.ts +19 -0
  51. package/dist/dashboard/meter-model.d.ts.map +1 -1
  52. package/dist/dashboard/meter-model.js +18 -1
  53. package/dist/dashboard/meter-parts.d.ts +5 -1
  54. package/dist/dashboard/meter-parts.d.ts.map +1 -1
  55. package/dist/dashboard/meter-parts.js +114 -74
  56. package/dist/dashboard/meter.d.ts +22 -1
  57. package/dist/dashboard/meter.d.ts.map +1 -1
  58. package/dist/dashboard/meter.js +4 -1
  59. package/dist/dashboard/meter.module.css +90 -12
  60. package/dist/dashboard/meter.module.css.d.ts +5 -0
  61. package/dist/dashboard/query-state.d.ts.map +1 -1
  62. package/dist/dashboard/query-state.js +14 -9
  63. package/dist/dashboard/settings-section.d.ts.map +1 -1
  64. package/dist/dashboard/settings-section.js +14 -25
  65. package/dist/dashboard/stat-card-parts.js +1 -1
  66. package/dist/dashboard/stat-card.d.ts +1 -1
  67. package/dist/dashboard/stat-card.d.ts.map +1 -1
  68. package/dist/dashboard/stat-card.js +3 -6
  69. package/dist/dashboard/stat-card.module.css +15 -7
  70. package/dist/dashboard/stat-group.d.ts +11 -2
  71. package/dist/dashboard/stat-group.d.ts.map +1 -1
  72. package/dist/dashboard/stat-group.js +9 -7
  73. package/dist/dashboard/stat-strip.d.ts +50 -0
  74. package/dist/dashboard/stat-strip.d.ts.map +1 -0
  75. package/dist/dashboard/stat-strip.js +85 -0
  76. package/dist/dashboard/stat-strip.module.css +208 -0
  77. package/dist/dashboard/stat-strip.module.css.d.ts +28 -0
  78. package/dist/dashboard/widget-header.d.ts +3 -3
  79. package/dist/dashboard/widget-header.module.css +10 -6
  80. package/dist/format/date.d.ts.map +1 -1
  81. package/dist/format/date.js +4 -3
  82. package/dist/format/shared.d.ts +6 -0
  83. package/dist/format/shared.d.ts.map +1 -1
  84. package/dist/format/shared.js +6 -2
  85. package/dist/guard/index.d.ts +1 -1
  86. package/dist/guard/index.js +1 -1
  87. package/dist/index.d.ts +3 -1
  88. package/dist/index.d.ts.map +1 -1
  89. package/dist/index.js +4 -0
  90. package/dist/styles.css +6 -0
  91. package/dist/theme/card-inset.module.css +76 -0
  92. package/dist/theme/card-inset.module.css.d.ts +9 -0
  93. package/dist/theme/controls.module.css +3 -0
  94. package/dist/theme/index.d.ts.map +1 -1
  95. package/dist/theme/index.js +23 -0
  96. package/dist/theme/nav-link.module.css +8 -10
  97. package/dist/theme/status-dot.d.ts +3 -2
  98. package/dist/theme/status-dot.d.ts.map +1 -1
  99. package/dist/theme/status-dot.js +12 -3
  100. package/dist/theme/status-verdict.d.ts +3 -2
  101. package/dist/theme/status-verdict.d.ts.map +1 -1
  102. package/dist/theme/status-verdict.js +3 -2
  103. package/dist/theme/status-verdict.module.css +4 -2
  104. package/llms.txt +30 -6
  105. package/package.json +1 -1
  106. package/src/charts/ChartCard.tsx +70 -4
  107. package/src/charts/Donut.tsx +9 -1
  108. package/src/charts/Heatmap.tsx +1 -1
  109. package/src/charts/Sparkline.tsx +180 -18
  110. package/src/charts/box.tsx +2 -0
  111. package/src/charts/chart-box.module.css +30 -0
  112. package/src/charts/chart-box.module.css.d.ts +1 -0
  113. package/src/charts/chart-card.module.css +47 -0
  114. package/src/charts/chart-card.module.css.d.ts +7 -0
  115. package/src/charts/compile.ts +42 -9
  116. package/src/charts/host.tsx +6 -3
  117. package/src/charts/index.ts +1 -1
  118. package/src/charts/sparkline.module.css +59 -0
  119. package/src/charts/sparkline.module.css.d.ts +13 -0
  120. package/src/charts/state.tsx +44 -4
  121. package/src/charts/types.ts +6 -0
  122. package/src/controls/sync-button.tsx +3 -0
  123. package/src/dashboard/bar-list.module.css +77 -2
  124. package/src/dashboard/bar-list.module.css.d.ts +1 -0
  125. package/src/dashboard/bar-list.tsx +86 -18
  126. package/src/dashboard/delta-badge.tsx +21 -5
  127. package/src/dashboard/index.ts +2 -0
  128. package/src/dashboard/meter-model.ts +35 -0
  129. package/src/dashboard/meter-parts.tsx +119 -23
  130. package/src/dashboard/meter.module.css +90 -12
  131. package/src/dashboard/meter.module.css.d.ts +5 -0
  132. package/src/dashboard/meter.tsx +26 -2
  133. package/src/dashboard/query-state.tsx +28 -19
  134. package/src/dashboard/settings-section.tsx +1 -8
  135. package/src/dashboard/stat-card-parts.tsx +1 -1
  136. package/src/dashboard/stat-card.module.css +15 -7
  137. package/src/dashboard/stat-card.tsx +5 -8
  138. package/src/dashboard/stat-group.tsx +19 -8
  139. package/src/dashboard/stat-strip.module.css +208 -0
  140. package/src/dashboard/stat-strip.module.css.d.ts +28 -0
  141. package/src/dashboard/stat-strip.tsx +183 -0
  142. package/src/dashboard/widget-header.module.css +10 -6
  143. package/src/dashboard/widget-header.tsx +3 -3
  144. package/src/format/date.ts +6 -3
  145. package/src/format/shared.ts +11 -2
  146. package/src/guard/index.ts +1 -1
  147. package/src/index.ts +7 -0
  148. package/src/styles.css +6 -0
  149. package/src/theme/__snapshots__/plain-theme.test.ts.snap +168 -24
  150. package/src/theme/card-inset.module.css +76 -0
  151. package/src/theme/card-inset.module.css.d.ts +9 -0
  152. package/src/theme/controls.module.css +3 -0
  153. package/src/theme/index.ts +30 -0
  154. package/src/theme/nav-link.module.css +8 -10
  155. package/src/theme/status-dot.tsx +17 -5
  156. package/src/theme/status-verdict.module.css +4 -2
  157. package/src/theme/status-verdict.tsx +9 -4
@@ -35,13 +35,16 @@ export type ChartEngineProps = {
35
35
  /** The engine props of a basalt definition (`CartesianDefinition`'s datum and value types). */
36
36
  type EngineProps = ChartProps<unknown, ChartValue, number>
37
37
 
38
- /** `currentColor` is the axis ink. The font is pinned to mono (the 1.x tick look) and inherited by
39
- * the svg — TanStack measures guides with the host's computed font. */
38
+ /** `currentColor` is the axis ink. The font is the proportional sans with tabular figures (Wave 35
39
+ * law: tabular in axis ticks, mono only for captions, times and code); `--basalt-chart-font` retunes
40
+ * the face from outside. It is inherited by the svg —
41
+ * TanStack measures guides with the host's computed font. */
40
42
  const HOST_STYLE: CSSProperties = {
41
43
  // Overrides the host's own fallback height: the box decides, the engine measures it.
42
44
  height: '100%',
43
45
  color: 'var(--vx-axis)',
44
- fontFamily: 'var(--basalt-font-mono)',
46
+ fontFamily: 'var(--basalt-chart-font, var(--basalt-font-sans))',
47
+ fontVariantNumeric: 'tabular-nums',
45
48
  }
46
49
  const COARSE_STYLE: CSSProperties = { ...HOST_STYLE, touchAction: 'pan-y' }
47
50
 
@@ -27,7 +27,7 @@ export {
27
27
  type MirroredBarsSeries,
28
28
  type MirroredBarPane,
29
29
  } from './MirroredBars'
30
- export { ChartCard, type ChartCardProps, type ChartCardSlot } from './ChartCard'
30
+ export { ChartCard, type ChartCardProps, type ChartCardSlot, type ChartFact } from './ChartCard'
31
31
  export { chartCursor } from './cursor'
32
32
  export { chartCurve, type CurveName } from './curves'
33
33
  export type {
@@ -0,0 +1,59 @@
1
+ /*
2
+ * The sparkline's hover / focus readout: one quiet chip, never a floating tooltip, so a narrow cell
3
+ * cannot be escaped. It sits OUTSIDE the plot box, on the line just above it, so it can never cover
4
+ * a mark: the plot is the whole box, and a chip inside it would have to hide some series (a line's
5
+ * last segment, a bar, the end dot) wherever it landed. Above is always free inside a card or strip
6
+ * cell (the hero value or caption is what sits there), and the chip is opaque so it reads over it.
7
+ * It takes the side away from the hovered point.
8
+ */
9
+
10
+ .root {
11
+ position: relative;
12
+ }
13
+
14
+ .readout {
15
+ position: absolute;
16
+ bottom: 100%;
17
+ z-index: 1;
18
+ max-width: 100%;
19
+ box-sizing: border-box;
20
+ padding: 0 4px;
21
+ overflow: hidden;
22
+ font-family: var(--basalt-font-numeral, var(--basalt-font-sans));
23
+ font-variant-numeric: lining-nums;
24
+ font-size: var(--vx-text-xs);
25
+ /* The line a host slot reserves above the plot: it sets `--basalt-spark-readout-h` to the same
26
+ * value (`stat-card.module.css`, `stat-strip.module.css`), so the chip lands in reserved space. */
27
+ block-size: var(--basalt-spark-readout-h, 1.125rem);
28
+ line-height: calc(var(--basalt-spark-readout-h, 1.125rem) - 2px);
29
+ color: var(--vx-tooltip-text);
30
+ text-overflow: ellipsis;
31
+ white-space: nowrap;
32
+ pointer-events: none;
33
+ background: var(--vx-tooltip-bg);
34
+ border: 1px solid var(--vx-tooltip-border);
35
+ border-radius: var(--vx-radius-ctrl);
36
+ }
37
+
38
+ .start {
39
+ left: 0;
40
+ }
41
+
42
+ .end {
43
+ right: 0;
44
+ }
45
+
46
+ .label {
47
+ font-family: var(--basalt-font-mono);
48
+ opacity: 0.7;
49
+ }
50
+
51
+ .dot {
52
+ position: absolute;
53
+ width: 6px;
54
+ height: 6px;
55
+ pointer-events: none;
56
+ background: var(--vx-ink);
57
+ border-radius: 50%;
58
+ transform: translate(-50%, -50%);
59
+ }
@@ -0,0 +1,13 @@
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 root: string
7
+ readonly readout: string
8
+ readonly start: string
9
+ readonly end: string
10
+ readonly label: string
11
+ readonly dot: string
12
+ }
13
+ export default classes
@@ -5,7 +5,7 @@
5
5
  import type { CSSProperties, ReactElement, ReactNode } from 'react'
6
6
  import { toErrorMessage } from '../common/errors'
7
7
  import { VX } from '../tokens'
8
- import { ChartBox, stateClass } from './box'
8
+ import { ChartBox, growClass, stateClass } from './box'
9
9
  import type { ChartBoxHeight } from './box'
10
10
  import type { ChartState } from './types'
11
11
 
@@ -36,6 +36,36 @@ const pendingStyle: CSSProperties = {
36
36
  background: `linear-gradient(90deg, transparent, ${VX.surface.subtle}, transparent)`,
37
37
  }
38
38
 
39
+ // The error idiom (D28, SPEC § 6.12): a status dot + a word + the message + the action, on the
40
+ // neutral surface. The dot is drawn from `--vx-*` tokens here — `src/charts/**` stays Mantine-free and `theme/status-dot` sits in the
41
+ // Mantine-coupled theme layer.
42
+ const dotStyle: CSSProperties = {
43
+ display: 'inline-block',
44
+ flex: 'none',
45
+ width: 6,
46
+ height: 6,
47
+ // theme-allow raw-surface — a 6px status dot, not a surface
48
+ borderRadius: '50%',
49
+ background: VX.status.bad,
50
+ }
51
+ // StatCard's error anatomy (`ErrorState` at the section tier): a left-aligned stack, never centred.
52
+ const errorStyle: CSSProperties = {
53
+ ...boxStyle,
54
+ alignItems: 'flex-start',
55
+ textAlign: 'start',
56
+ fontSize: VX.text.sm,
57
+ gap: VX.space.controlGap,
58
+ }
59
+ const errorHeadStyle: CSSProperties = {
60
+ display: 'inline-flex',
61
+ alignItems: 'center',
62
+ gap: VX.space.controlGap,
63
+ color: VX.ink,
64
+ fontWeight: 500,
65
+ }
66
+
67
+ const errorMessageStyle: CSSProperties = { color: VX.muted }
68
+
39
69
  const emptyLabel = (state: ChartState | undefined): string =>
40
70
  typeof state?.empty === 'string' ? state.empty : 'No data'
41
71
 
@@ -51,9 +81,13 @@ export function ChartPlaceholder(props: {
51
81
  }): ReactElement | null {
52
82
  const kind = resolveChartState(props.state)
53
83
  if (kind === null) return null
54
- const style = kind === 'pending' ? pendingStyle : boxStyle
84
+ const style = kind === 'pending' ? pendingStyle : kind === 'error' ? errorStyle : boxStyle
85
+ // An error GROWS past the final chart's height rather than clip its action: the box's height is
86
+ // the floor, not the size.
55
87
  const fit = (node: ReactElement): ReactElement => (
56
- <ChartBox height={props.height}>{node}</ChartBox>
88
+ <ChartBox height={props.height} {...(kind === 'error' && { className: growClass })}>
89
+ {node}
90
+ </ChartBox>
57
91
  )
58
92
  if (kind === 'pending')
59
93
  return fit(
@@ -67,7 +101,13 @@ export function ChartPlaceholder(props: {
67
101
  <span aria-hidden="true">—</span>
68
102
  ) : (
69
103
  <>
70
- <span>{label}</span>
104
+ {kind === 'error' && (
105
+ <span style={errorHeadStyle}>
106
+ <span aria-hidden="true" data-basalt-status-dot="" style={dotStyle} />
107
+ Could not load this chart
108
+ </span>
109
+ )}
110
+ <span style={errorMessageStyle}>{label}</span>
71
111
  {props.action}
72
112
  </>
73
113
  )
@@ -154,6 +154,12 @@ export type RefLine = {
154
154
  color: string
155
155
  dashed?: boolean | undefined
156
156
  axis?: 'left' | 'right' | undefined
157
+ /**
158
+ * Names the line on the plot: a small muted caption at the plot's right end (left end for a
159
+ * right-axis line, clear of its tick labels), above the line, below it near the plot's top. It
160
+ * follows the legend toggle. The ink is `--vx-ink2`, never the line colour.
161
+ */
162
+ label?: string | undefined
157
163
  /**
158
164
  * Names the line in the legend (its color, dashed as `dashed`; a toggle hides the line), so a
159
165
  * threshold needs no always-`null` series. `mark` is the swatch shape. Default `'line'`. The
@@ -86,6 +86,9 @@ function subscribeAgeTick(onTick: () => void): () => void {
86
86
  }
87
87
 
88
88
  /**
89
+ * The age label follows the `BasaltProvider` / `defineFormat` locale. It is read when the label is
90
+ * formatted, so a locale switch shows on the next age tick or re-render (no new subscription).
91
+ *
89
92
  * @example
90
93
  * // page scope — the page's own data
91
94
  * <PageBar sync={{ syncing, lastCompletedAt, onSync: refetch }} />
@@ -62,7 +62,8 @@
62
62
  }
63
63
 
64
64
  .value {
65
- font-family: var(--basalt-font-mono);
65
+ font-family: var(--basalt-font-numeral, var(--basalt-font-sans));
66
+ font-variant-numeric: lining-nums;
66
67
  text-align: end;
67
68
  white-space: nowrap;
68
69
  }
@@ -73,7 +74,8 @@
73
74
  }
74
75
 
75
76
  .secondary {
76
- font-family: var(--basalt-font-mono);
77
+ font-family: var(--basalt-font-numeral, var(--basalt-font-sans));
78
+ font-variant-numeric: lining-nums;
77
79
  font-size: var(--vx-text-sm);
78
80
  color: var(--vx-muted);
79
81
  white-space: nowrap;
@@ -89,3 +91,76 @@
89
91
  grid-column: 1 / -1;
90
92
  height: calc(var(--vx-space-control-height-widget, 1.5rem) * var(--mantine-scale, 1));
91
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
+ }
@@ -8,6 +8,7 @@ declare const classes: {
8
8
  readonly track: string
9
9
  readonly bar: string
10
10
  readonly leader: string
11
+ readonly tick: string
11
12
  readonly label: string
12
13
  readonly value: string
13
14
  readonly secondary: string
@@ -1,10 +1,18 @@
1
1
  /**
2
- * BarList — a ranked list: label, an inline bar on ONE shared scale, a mono right-aligned value and
2
+ * BarList — a ranked list: label, an inline bar on ONE shared scale, a right-aligned sans value and
3
3
  * an optional muted secondary value. Choose it for "top N" (the bar ranks by length before anything
4
4
  * is read). The bar spans the label column only — values sit outside it, so a full-scale bar ends
5
5
  * before its value. Intended for 5–10 rows; past 10 use a table with an inline `Meter` cell. An
6
6
  * HTML/CSS primitive, not a chart kind.
7
7
  *
8
+ * A row may carry its own `max` (points of 40 / 35 / 25): its bar fills value / row.max and the value
9
+ * column reads "32 / 40". The shared scale — `max` prop, else the largest value — is computed over the
10
+ * rows WITHOUT their own `max` only. A row's `tick` (on that row's scale) draws a hairline across the
11
+ * bar, named for assistive tech. `variant="thin"` puts the label on its own line above a thin bar with
12
+ * the value right-aligned on the label line.
13
+ *
14
+ * Thin rows sit flush: no inline inset on the label or the rail.
15
+ *
8
16
  * Colour law: bars are neutral. `accentLeader` (opt-in) lets the top row take the accent — the
9
17
  * leader bar, and nothing else. Each value is rendered as text, never only a bar length.
10
18
  *
@@ -14,6 +22,14 @@
14
22
  * // Recovery contributors on a fixed 0–100 scale, the qualitative level as the secondary value:
15
23
  * <BarList label="Recovery contributors" max={100} items={[{ label: 'Sleep', value: 82, secondary: 'Good' }]} />
16
24
  *
25
+ * // Points of different maxima, thin rows, a threshold tick ("32 / 40 pts"; the tick is named for AT):
26
+ * <BarList
27
+ * label="Recovery contributors"
28
+ * variant="thin"
29
+ * format={(n, part) => (part === 'max' ? `${n} pts` : String(n))}
30
+ * items={[{ label: 'Sleep', value: 32, max: 40, tick: 30, tickLabel: 'Target' }, { label: 'HRV', value: 14, max: 35 }]}
31
+ * />
32
+ *
17
33
  * <BarList
18
34
  * label="Top projects by tokens"
19
35
  * items={[{ label: 'argo', value: 1840, secondary: '41%' }, { label: 'rb', value: 920 }]}
@@ -28,17 +44,33 @@ import type { BasaltProps } from '../common/props'
28
44
  import classes from './bar-list.module.css'
29
45
  import { asText, barPercent } from './scale'
30
46
 
31
- type BarListItem = { label: string; value: number; secondary?: ReactNode; key?: string }
47
+ type BarListItem = {
48
+ label: string
49
+ value: number
50
+ secondary?: ReactNode
51
+ key?: string
52
+ /** This row's own scale end: the bar fills value / max and the value reads "value / max". */
53
+ max?: number
54
+ /** A hairline mark at this position on the row's scale (a threshold). */
55
+ tick?: number
56
+ /** Names the tick for assistive tech (visually hidden text in the track). Default "Threshold". */
57
+ tickLabel?: string
58
+ }
32
59
 
33
60
  export type BarListProps = BasaltProps & {
34
61
  /** Accessible name of the list. Required. */
35
62
  label: string
36
63
  /** Rows in display order (sort them yourself; the list does not reorder). */
37
64
  items: readonly BarListItem[]
38
- /** Formats each value. Default: the number as written. */
39
- format?: (value: number) => string
40
- /** Scale end shared by every bar. Default: the largest value. */
65
+ /**
66
+ * Formats each number. `part` is `'max'` for a row's denominator, `'value'` otherwise (the value and
67
+ * the tick), so a unit can sit on one side only: `'32 / 40 pts'`. Default: the number as written.
68
+ */
69
+ format?: (value: number, part: 'value' | 'max') => string
70
+ /** Scale end shared by rows without their own `max`. Default: the largest of those rows' values. */
41
71
  max?: number
72
+ /** `thin`: label on its own line above a thin bar, value right-aligned on that line. */
73
+ variant?: 'default' | 'thin'
42
74
  /** The first row's bar takes the accent. Off by default. */
43
75
  accentLeader?: boolean
44
76
  /** Renders row-shaped skeletons. */
@@ -58,6 +90,7 @@ export function BarList({
58
90
  items,
59
91
  format = asText,
60
92
  max,
93
+ variant = 'default',
61
94
  accentLeader = false,
62
95
  loading = false,
63
96
  loadingRows = 5,
@@ -84,7 +117,12 @@ export function BarList({
84
117
  }
85
118
 
86
119
  const scale =
87
- max ?? items.reduce((top, i) => (Number.isFinite(i.value) ? Math.max(top, i.value) : top), 0)
120
+ max ??
121
+ items.reduce(
122
+ (top, i) => (i.max === undefined && Number.isFinite(i.value) ? Math.max(top, i.value) : top),
123
+ 0,
124
+ )
125
+ const thin = variant === 'thin'
88
126
  const hasSecondary = items.some((i) => hasContent(i.secondary))
89
127
  return (
90
128
  // The explicit role is deliberate: `list-style: none` makes Safari/VoiceOver drop the implicit one.
@@ -95,28 +133,58 @@ export function BarList({
95
133
  role="list"
96
134
  aria-label={label}
97
135
  data-secondary={hasSecondary ? '' : undefined}
136
+ data-variant={thin ? 'thin' : undefined}
98
137
  >
99
138
  {items.map((item, i) => {
100
139
  const isLeader = accentLeader && i === 0
101
- return (
102
- <li key={item.key ?? `${item.label}-${i}`} className={classes.row}>
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 */}
140
+ const rowScale = item.max ?? scale
141
+ const labelNode = (
142
+ <span className={classes.label} title={item.label}>
143
+ {item.label}
144
+ </span>
145
+ )
146
+ const tickName =
147
+ item.tick === undefined
148
+ ? ''
149
+ : `${item.tickLabel ?? 'Threshold'} ${format(item.tick, 'value')}`
150
+ const track = (
151
+ <span className={classes.track} data-bar-track>
152
+ {/* theme-allow hidden-inline-style — the width is the row's data (a % of its scale), not styling */}
153
+ <span
154
+ className={cx(classes.bar, isLeader && classes.leader)}
155
+ style={{ width: `${barPercent(item.value, rowScale)}%` }}
156
+ data-bar-fill=""
157
+ data-bar-leader={isLeader ? '' : undefined}
158
+ aria-hidden
159
+ />
160
+ {item.tick !== undefined && (
161
+ // theme-allow hidden-inline-style — the position is the row's data (a % of its scale)
105
162
  <span
106
- className={cx(classes.bar, isLeader && classes.leader)}
107
- style={{ width: `${barPercent(item.value, scale)}%` }}
108
- data-bar-leader={isLeader ? '' : undefined}
163
+ className={classes.tick}
164
+ style={{ insetInlineStart: `${barPercent(item.tick, rowScale)}%` }}
165
+ data-bar-tick=""
109
166
  aria-hidden
110
167
  />
111
- <span className={classes.label} title={item.label}>
112
- {item.label}
113
- </span>
114
- </span>
168
+ )}
169
+ {!thin && labelNode}
170
+ {/* Inside the track so it is never the row's last child (the value/secondary inset). */}
171
+ {item.tick !== undefined && <VisuallyHidden>{tickName}</VisuallyHidden>}
172
+ </span>
173
+ )
174
+ return (
175
+ <li key={item.key ?? `${item.label}-${i}`} className={classes.row}>
176
+ {thin && labelNode}
177
+ {!thin && track}
115
178
  <span className={classes.value}>
116
- {Number.isFinite(item.value) ? format(item.value) : '—'}
179
+ {Number.isFinite(item.value)
180
+ ? item.max === undefined
181
+ ? format(item.value, 'value')
182
+ : `${format(item.value, 'value')} / ${format(item.max, 'max')}`
183
+ : '—'}
117
184
  </span>
118
185
  {/* Kept empty on a row without one: the secondary column is shared, so every row has the cell. */}
119
186
  {hasSecondary && <span className={classes.secondary}>{item.secondary}</span>}
187
+ {thin && track}
120
188
  </li>
121
189
  )
122
190
  })}
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * DeltaBadge — the KPI trend readout (docs/DESIGN-CORE.md: "up/down deltas are text colour only,
3
- * never a fill"): a glyph and a signed figure in the trend colour, mono `sm`, with NO fill, border
4
- * or padding in either scheme. The optional ▲/▼ glyph sits on the `micro` rung and `period` is
3
+ * never a fill"): a glyph and a signed figure in the trend colour, proportional-sans `sm` with
4
+ * lining figures, with NO fill, border or padding in either scheme. The optional ▲/▼ glyph sits on the `micro` rung and `period` is
5
5
  * `micro` muted. `polarity` decides the TONE the sign maps to — `'up-good'` (default) reads a rise
6
6
  * as success and a fall as danger; `'up-bad'` inverts that for a metric where a rise is the worse
7
7
  * reading (a cycle-top index, latency, error rate); `'neutral'` renders every sign in a faint,
@@ -23,6 +23,7 @@
23
23
  * <DeltaBadge value={0} /> // 0.0%, faint, no glyph
24
24
  * <DeltaBadge value={182} format={(v) => `${Math.abs(v)}ms`} withGlyph={false} />
25
25
  * <DeltaBadge value={35.9} polarity="up-bad" /> // ▲ 35.9%, danger — a rise is bad here
26
+ * <DeltaBadge value={4.2} period="last week" /> // ▲ 4.2% vs last week
26
27
  */
27
28
  import { VX } from '../tokens'
28
29
  import classes from './widget-header.module.css'
@@ -41,13 +42,24 @@ export type DeltaBadgeProps = {
41
42
  format?: (value: number) => string
42
43
  /** Render the ▲/▼ direction glyph. Defaults to `true`; a zero value never shows a glyph. */
43
44
  withGlyph?: boolean
44
- /** Optional comparison timeframe rendered directly after the value, muted (e.g. `MoM`, `WoW`,
45
- * `YTD`) — states what the delta is measured against without a hover. */
45
+ /** Optional comparison period rendered after the value, muted, as `<periodPrefix> <period>`
46
+ * (`period="last week"` → "vs last week"). One rule: the prefix is prepended unless the period
47
+ * already starts with it (case-insensitive, optional trailing dot: "vs", "VS", "vs."), so a caller
48
+ * still writing "vs last week" renders it once. Other words ("versus") are not detected. */
46
49
  period?: string | undefined
50
+ /** The word composed before `period`. Defaults to `'vs'`; pass your locale's word, or `''` to
51
+ * render `period` raw. */
52
+ periodPrefix?: string
47
53
  }
48
54
 
49
55
  const defaultFormat = (value: number): string => `${Math.abs(value).toFixed(1)}%`
50
56
 
57
+ function composePeriod(period: string, prefix: string): string {
58
+ if (prefix === '') return period
59
+ const escaped = prefix.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
60
+ return new RegExp(`^${escaped}\\.?(\\s|$)`, 'i').test(period) ? period : `${prefix} ${period}`
61
+ }
62
+
51
63
  function resolveTone(value: number, polarity: DeltaPolarity): string {
52
64
  if (value === 0 || polarity === 'neutral') return VX.faint
53
65
  const rose = value > 0
@@ -68,6 +80,7 @@ export function DeltaBadge({
68
80
  format = defaultFormat,
69
81
  withGlyph = true,
70
82
  period,
83
+ periodPrefix = 'vs',
71
84
  }: DeltaBadgeProps) {
72
85
  const tone = resolveTone(value, polarity)
73
86
  const glyph = directionGlyph(value)
@@ -77,7 +90,10 @@ export function DeltaBadge({
77
90
  <span className={classes.deltaBadge} style={{ color: tone }}>
78
91
  {showGlyph && <span className={classes.deltaGlyph}>{glyph}</span>}
79
92
  {format(value)}
80
- {period !== undefined && <span className={classes.deltaPeriod}>{period}</span>}
93
+ {period !== undefined && ' '}
94
+ {period !== undefined && (
95
+ <span className={classes.deltaPeriod}>{composePeriod(period, periodPrefix)}</span>
96
+ )}
81
97
  </span>
82
98
  )
83
99
  }
@@ -3,7 +3,9 @@ export { DeltaBadge } from './delta-badge'
3
3
  export { Section } from './section'
4
4
  export { StatCard, type StatCardBreakdownRow, type StatCardSparklineSize } from './stat-card'
5
5
  export { StatGroup } from './stat-group'
6
+ export type { StatStripCell, StatStripRow } from './stat-strip'
6
7
  export { EmptyState } from './empty-state'
7
8
  export { SettingsSection, SettingsRow, DangerZone } from './settings-section'
8
9
  export { Meter, type MeterProps } from './meter'
10
+ export type { MeterSegment, MeterTick, MeterZone } from './meter-model'
9
11
  export { BarList, type BarListProps } from './bar-list'
@@ -7,6 +7,11 @@ import { clamp01, toPct } from './scale'
7
7
 
8
8
  export type MeterSegment = { value: number; label: string; color?: string; forecast?: boolean }
9
9
  export type MeterZone = { from: number; to: number; label: string; color?: string }
10
+ /** A mark on the track at `at` (in the reading's units). A label is captioned beside it. */
11
+ export type MeterTick = { at: number; label?: string }
12
+
13
+ /** One tick on the track: its percent position and what it says (caption `label`, aria `text`). */
14
+ export type TickMark = { key: string; pct: number; label: string | undefined; text: string }
10
15
 
11
16
  /** A fill on the track, as fractions (0–1) of the span, with the segment it was laid out from. */
12
17
  export type Part = {
@@ -33,6 +38,31 @@ export type CaptionMode = 'reading' | 'parts' | 'forecast'
33
38
 
34
39
  type Format = (value: number) => string
35
40
 
41
+ /**
42
+ * The ticks that sit on the track, in the order given. A tick outside `[min, max]` (or not a number)
43
+ * is DROPPED, never clamped: a mark pinned to the end would state a position it is not at.
44
+ */
45
+ export function tickMarks(
46
+ ticks: readonly MeterTick[] | undefined,
47
+ min: number,
48
+ max: number,
49
+ format: Format,
50
+ ): TickMark[] {
51
+ const { span } = spanOf(min, max)
52
+ return (ticks ?? []).flatMap((t, i) =>
53
+ Number.isFinite(t.at) && t.at >= min && t.at <= max
54
+ ? [
55
+ {
56
+ key: String(i),
57
+ pct: toPct((t.at - min) / span),
58
+ label: t.label,
59
+ text: `${t.label ?? 'Tick'} ${format(t.at)}`,
60
+ },
61
+ ]
62
+ : [],
63
+ )
64
+ }
65
+
36
66
  export const isReading = (n: number | null | undefined): n is number =>
37
67
  typeof n === 'number' && Number.isFinite(n)
38
68
 
@@ -124,6 +154,7 @@ export type BarInput = {
124
154
  segments?: readonly MeterSegment[] | undefined
125
155
  zones?: readonly MeterZone[] | undefined
126
156
  target?: number | undefined
157
+ ticks?: readonly MeterTick[] | undefined
127
158
  color?: string | undefined
128
159
  forecastCaption?: string | undefined
129
160
  }
@@ -140,6 +171,7 @@ export type BarModel = {
140
171
  partCaptions: readonly PartCaption[]
141
172
  /** Only on a zoned track: every zone's name, in zone order. Empty otherwise. */
142
173
  zoneLabels: readonly ZoneLabel[]
174
+ ticks: readonly TickMark[]
143
175
  markerPct: number | undefined
144
176
  targetPct: number | undefined
145
177
  /** The default start caption (the zone is named on the band, so it is the bare reading); `startCaption` decides whether it shows. */
@@ -197,6 +229,7 @@ export function startCaptionText(model: BarModel, override: ReactNode | undefine
197
229
 
198
230
  export function modelBar(input: BarInput): BarModel {
199
231
  const { reading, min, max, format, segments, zones, target } = input
232
+ const ticks = tickMarks(input.ticks, min, max, format)
200
233
  const { span } = spanOf(min, max)
201
234
  const zoned = zones !== undefined && zones.length > 0
202
235
  const holding = zoned ? findHoldingZone(zones, reading) : undefined
@@ -221,6 +254,7 @@ export function modelBar(input: BarInput): BarModel {
221
254
  ...(segments?.map((s) => segmentText(s, format)) ?? []),
222
255
  ...zoneText,
223
256
  ...(target === undefined ? [] : [`Target ${format(target)}`]),
257
+ ...ticks.map((t) => t.text),
224
258
  ]
225
259
 
226
260
  return {
@@ -241,6 +275,7 @@ export function modelBar(input: BarInput): BarModel {
241
275
  startPct: zoneBand(z, min, span).start,
242
276
  holding: z === holding,
243
277
  })),
278
+ ticks,
244
279
  markerPct: zoned ? toPct((reading - min) / span) : undefined,
245
280
  targetPct: target === undefined ? undefined : toPct((target - min) / span),
246
281
  startText: format(reading),