basalt-ui 2.21.0 → 2.22.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 (226) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/MIGRATING.md +277 -12
  3. package/agent/agents/basalt-design-reviewer.md +1 -1
  4. package/agent/rules/basalt-tokens.md +1 -1
  5. package/agent/skills/basalt-design/SKILL.md +1 -1
  6. package/agent/skills/basalt-design/references/anti-defaults.md +1 -1
  7. package/agent/skills/basalt-design/references/catalogue.md +1 -0
  8. package/dist/charts/BandStrip.d.ts.map +1 -1
  9. package/dist/charts/BandStrip.js +27 -3
  10. package/dist/charts/Bars.d.ts.map +1 -1
  11. package/dist/charts/Bars.js +5 -0
  12. package/dist/charts/CartesianChart.d.ts +8 -0
  13. package/dist/charts/CartesianChart.d.ts.map +1 -1
  14. package/dist/charts/CartesianChart.js +8 -5
  15. package/dist/charts/ChartCard.d.ts +12 -3
  16. package/dist/charts/ChartCard.d.ts.map +1 -1
  17. package/dist/charts/ChartCard.js +29 -8
  18. package/dist/charts/DualPanel.d.ts.map +1 -1
  19. package/dist/charts/DualPanel.js +5 -8
  20. package/dist/charts/Heatmap.d.ts +12 -1
  21. package/dist/charts/Heatmap.d.ts.map +1 -1
  22. package/dist/charts/Heatmap.js +34 -5
  23. package/dist/charts/Lines.d.ts +3 -0
  24. package/dist/charts/Lines.d.ts.map +1 -1
  25. package/dist/charts/Lines.js +29 -6
  26. package/dist/charts/MirroredBars.d.ts.map +1 -1
  27. package/dist/charts/MirroredBars.js +4 -6
  28. package/dist/charts/Sparkline.d.ts +7 -1
  29. package/dist/charts/Sparkline.d.ts.map +1 -1
  30. package/dist/charts/Sparkline.js +39 -14
  31. package/dist/charts/StackedArea.d.ts +4 -1
  32. package/dist/charts/StackedArea.d.ts.map +1 -1
  33. package/dist/charts/StackedArea.js +9 -3
  34. package/dist/charts/band-fold.d.ts +20 -1
  35. package/dist/charts/band-fold.d.ts.map +1 -1
  36. package/dist/charts/band-fold.js +9 -0
  37. package/dist/charts/chart-box.module.css +19 -0
  38. package/dist/charts/chart-card.module.css +25 -0
  39. package/dist/charts/chart-legend.module.css +7 -0
  40. package/dist/charts/compile.d.ts +17 -6
  41. package/dist/charts/compile.d.ts.map +1 -1
  42. package/dist/charts/compile.js +145 -74
  43. package/dist/charts/labels.d.ts +15 -4
  44. package/dist/charts/labels.d.ts.map +1 -1
  45. package/dist/charts/labels.js +34 -10
  46. package/dist/charts/legend.d.ts +2 -0
  47. package/dist/charts/legend.d.ts.map +1 -1
  48. package/dist/charts/legend.js +7 -21
  49. package/dist/charts/marks.js +1 -1
  50. package/dist/charts/panel.d.ts +0 -6
  51. package/dist/charts/panel.d.ts.map +1 -1
  52. package/dist/charts/panel.js +1 -10
  53. package/dist/charts/ref-label.d.ts +26 -0
  54. package/dist/charts/ref-label.d.ts.map +1 -0
  55. package/dist/charts/ref-label.js +63 -0
  56. package/dist/charts/scales.d.ts +4 -1
  57. package/dist/charts/scales.d.ts.map +1 -1
  58. package/dist/charts/scales.js +14 -3
  59. package/dist/charts/sparkline.module.css +10 -11
  60. package/dist/charts/sparkline.module.css.d.ts +1 -2
  61. package/dist/charts/state.d.ts +2 -0
  62. package/dist/charts/state.d.ts.map +1 -1
  63. package/dist/charts/state.js +2 -1
  64. package/dist/charts/types.d.ts +14 -5
  65. package/dist/charts/types.d.ts.map +1 -1
  66. package/dist/cli/doctor-upgrade.d.ts +1 -0
  67. package/dist/cli/doctor-upgrade.d.ts.map +1 -1
  68. package/dist/cli/doctor-upgrade.js +1 -0
  69. package/dist/cli/init.d.ts +2 -0
  70. package/dist/cli/init.d.ts.map +1 -1
  71. package/dist/cli/init.js +68 -4
  72. package/dist/cli/shot/capture.d.ts +21 -2
  73. package/dist/cli/shot/capture.d.ts.map +1 -1
  74. package/dist/cli/shot/capture.js +194 -32
  75. package/dist/cli/shot/detect.d.ts.map +1 -1
  76. package/dist/cli/shot/detect.js +14 -1
  77. package/dist/cli/shot/playwright.d.ts +5 -2
  78. package/dist/cli/shot/playwright.d.ts.map +1 -1
  79. package/dist/cli/shot/types.d.ts +2 -0
  80. package/dist/cli/shot/types.d.ts.map +1 -1
  81. package/dist/cli/shot/types.js +2 -0
  82. package/dist/controls/controls.module.css +11 -1
  83. package/dist/controls/filter-pill.d.ts.map +1 -1
  84. package/dist/controls/filter-pill.js +1 -0
  85. package/dist/controls/sync-button.d.ts.map +1 -1
  86. package/dist/controls/sync-button.js +22 -3
  87. package/dist/controls/sync-button.module.css +34 -2
  88. package/dist/controls/sync-button.module.css.d.ts +1 -0
  89. package/dist/dashboard/bar-list.d.ts.map +1 -1
  90. package/dist/dashboard/bar-list.js +7 -8
  91. package/dist/dashboard/bar-list.module.css +53 -0
  92. package/dist/dashboard/bar-list.module.css.d.ts +1 -0
  93. package/dist/dashboard/index.d.ts +1 -0
  94. package/dist/dashboard/index.d.ts.map +1 -1
  95. package/dist/dashboard/index.js +2 -0
  96. package/dist/dashboard/meter-model.d.ts +77 -3
  97. package/dist/dashboard/meter-model.d.ts.map +1 -1
  98. package/dist/dashboard/meter-model.js +88 -15
  99. package/dist/dashboard/meter-parts.d.ts +8 -0
  100. package/dist/dashboard/meter-parts.d.ts.map +1 -1
  101. package/dist/dashboard/meter-parts.js +238 -71
  102. package/dist/dashboard/meter.d.ts +43 -60
  103. package/dist/dashboard/meter.d.ts.map +1 -1
  104. package/dist/dashboard/meter.js +20 -3
  105. package/dist/dashboard/meter.module.css +61 -0
  106. package/dist/dashboard/meter.module.css.d.ts +5 -0
  107. package/dist/dashboard/page-summary.d.ts +20 -0
  108. package/dist/dashboard/page-summary.d.ts.map +1 -0
  109. package/dist/dashboard/page-summary.js +28 -0
  110. package/dist/dashboard/page-summary.module.css +89 -0
  111. package/dist/dashboard/page-summary.module.css.d.ts +15 -0
  112. package/dist/dashboard/section.d.ts +25 -2
  113. package/dist/dashboard/section.d.ts.map +1 -1
  114. package/dist/dashboard/section.js +10 -5
  115. package/dist/dashboard/section.module.css +23 -0
  116. package/dist/dashboard/section.module.css.d.ts +1 -0
  117. package/dist/dashboard/stat-card-parts.d.ts.map +1 -1
  118. package/dist/dashboard/stat-card-parts.js +1 -1
  119. package/dist/dashboard/stat-card.d.ts +4 -2
  120. package/dist/dashboard/stat-card.d.ts.map +1 -1
  121. package/dist/dashboard/stat-card.js +7 -5
  122. package/dist/dashboard/stat-card.module.css +17 -0
  123. package/dist/dashboard/stat-strip.d.ts +7 -1
  124. package/dist/dashboard/stat-strip.d.ts.map +1 -1
  125. package/dist/dashboard/stat-strip.js +74 -46
  126. package/dist/dashboard/stat-strip.module.css +67 -20
  127. package/dist/dashboard/stat-strip.module.css.d.ts +4 -0
  128. package/dist/dashboard/visual-slot.d.ts +7 -1
  129. package/dist/dashboard/visual-slot.d.ts.map +1 -1
  130. package/dist/dashboard/visual-slot.js +3 -1
  131. package/dist/guard/vx-names.d.ts.map +1 -1
  132. package/dist/guard/vx-names.js +2 -0
  133. package/dist/index.d.ts +1 -1
  134. package/dist/index.d.ts.map +1 -1
  135. package/dist/index.js +3 -1
  136. package/dist/styles.css +34 -2
  137. package/dist/theme/chrome-vars.d.ts +20 -5
  138. package/dist/theme/chrome-vars.d.ts.map +1 -1
  139. package/dist/theme/chrome-vars.js +46 -3
  140. package/dist/theme/controls.module.css +23 -0
  141. package/dist/theme/controls.module.css.d.ts +1 -0
  142. package/dist/theme/index.d.ts.map +1 -1
  143. package/dist/theme/index.js +8 -20
  144. package/dist/tokens/core.d.ts +2 -1
  145. package/dist/tokens/core.d.ts.map +1 -1
  146. package/dist/tokens/core.js +6 -1
  147. package/dist/tokens/derive.d.ts +3 -1
  148. package/dist/tokens/derive.d.ts.map +1 -1
  149. package/dist/tokens/derive.js +16 -1
  150. package/dist/tokens/palette.d.ts +4 -0
  151. package/dist/tokens/palette.d.ts.map +1 -1
  152. package/dist/tokens/palette.js +4 -0
  153. package/dist/tokens/status-text.d.ts.map +1 -1
  154. package/dist/tokens/status-text.js +3 -1
  155. package/llms.txt +38 -20
  156. package/package.json +1 -1
  157. package/src/charts/BandStrip.tsx +33 -3
  158. package/src/charts/Bars.tsx +6 -0
  159. package/src/charts/CartesianChart.tsx +16 -3
  160. package/src/charts/ChartCard.tsx +34 -6
  161. package/src/charts/DualPanel.tsx +3 -6
  162. package/src/charts/Heatmap.tsx +54 -5
  163. package/src/charts/Lines.tsx +56 -10
  164. package/src/charts/MirroredBars.tsx +3 -5
  165. package/src/charts/Sparkline.tsx +50 -13
  166. package/src/charts/StackedArea.tsx +14 -4
  167. package/src/charts/band-fold.ts +31 -1
  168. package/src/charts/chart-box.module.css +19 -0
  169. package/src/charts/chart-card.module.css +25 -0
  170. package/src/charts/chart-legend.module.css +7 -0
  171. package/src/charts/compile.ts +210 -85
  172. package/src/charts/labels.ts +48 -14
  173. package/src/charts/legend.tsx +10 -20
  174. package/src/charts/marks.ts +1 -1
  175. package/src/charts/panel.tsx +1 -16
  176. package/src/charts/ref-label.ts +104 -0
  177. package/src/charts/scales.ts +22 -2
  178. package/src/charts/sparkline.module.css +10 -11
  179. package/src/charts/sparkline.module.css.d.ts +1 -2
  180. package/src/charts/state.tsx +3 -1
  181. package/src/charts/types.ts +14 -5
  182. package/src/cli/doctor-upgrade.ts +1 -1
  183. package/src/cli/init.ts +100 -3
  184. package/src/cli/shot/capture.ts +251 -32
  185. package/src/cli/shot/detect.ts +18 -1
  186. package/src/cli/shot/playwright.ts +2 -2
  187. package/src/cli/shot/types.ts +3 -0
  188. package/src/controls/controls.module.css +11 -1
  189. package/src/controls/filter-pill.tsx +2 -0
  190. package/src/controls/sync-button.module.css +34 -2
  191. package/src/controls/sync-button.module.css.d.ts +1 -0
  192. package/src/controls/sync-button.tsx +40 -4
  193. package/src/dashboard/bar-list.module.css +53 -0
  194. package/src/dashboard/bar-list.module.css.d.ts +1 -0
  195. package/src/dashboard/bar-list.tsx +78 -69
  196. package/src/dashboard/index.ts +1 -0
  197. package/src/dashboard/meter-model.ts +186 -20
  198. package/src/dashboard/meter-parts.tsx +285 -64
  199. package/src/dashboard/meter.module.css +61 -0
  200. package/src/dashboard/meter.module.css.d.ts +5 -0
  201. package/src/dashboard/meter.tsx +60 -10
  202. package/src/dashboard/page-summary.module.css +89 -0
  203. package/src/dashboard/page-summary.module.css.d.ts +15 -0
  204. package/src/dashboard/page-summary.tsx +95 -0
  205. package/src/dashboard/section.module.css +23 -0
  206. package/src/dashboard/section.module.css.d.ts +1 -0
  207. package/src/dashboard/section.tsx +59 -11
  208. package/src/dashboard/stat-card-parts.tsx +5 -1
  209. package/src/dashboard/stat-card.module.css +17 -0
  210. package/src/dashboard/stat-card.tsx +12 -6
  211. package/src/dashboard/stat-strip.module.css +67 -20
  212. package/src/dashboard/stat-strip.module.css.d.ts +4 -0
  213. package/src/dashboard/stat-strip.tsx +118 -72
  214. package/src/dashboard/visual-slot.ts +12 -3
  215. package/src/guard/vx-names.ts +2 -0
  216. package/src/index.ts +2 -0
  217. package/src/styles.css +34 -2
  218. package/src/theme/__snapshots__/plain-theme.test.ts.snap +186 -60
  219. package/src/theme/chrome-vars.ts +77 -8
  220. package/src/theme/controls.module.css +23 -0
  221. package/src/theme/controls.module.css.d.ts +1 -0
  222. package/src/theme/index.ts +12 -25
  223. package/src/tokens/core.ts +4 -1
  224. package/src/tokens/derive.ts +32 -3
  225. package/src/tokens/palette.ts +4 -0
  226. package/src/tokens/status-text.ts +2 -0
@@ -93,10 +93,16 @@ export type ChartFact = {
93
93
  unit?: string | undefined
94
94
  /** Usually a `DeltaBadge`. */
95
95
  comparison?: ReactNode
96
- /** Plain text the figure covers, e.g. `last 30 d`. */
97
- period?: string | undefined
96
+ /** Plain text the figure covers, e.g. `last 30 d`. A list is joined by ` · ` (`['last entry 3 d
97
+ * ago', '12 entries']`). */
98
+ period?: string | readonly string[] | undefined
99
+ /** Ink for the whole fact (text only, never a fill): a stale or off-target figure reads `warn`. */
100
+ tone?: ChartFactTone | undefined
98
101
  }
99
102
 
103
+ /** The status inks a fact can take, plus the muted one. */
104
+ export type ChartFactTone = 'good' | 'warn' | 'bad' | 'muted'
105
+
100
106
  /** The three boxes a `ChartCard` paints. */
101
107
  export type ChartCardSlot = 'root' | 'header' | 'body'
102
108
 
@@ -124,6 +130,10 @@ type ChartCardBaseProps = BasaltProps &
124
130
  * unsized chart takes — pass the chart's own `height` when it states one, so a `<Suspense
125
131
  * fallback={<ChartCard state={{ pending: true }} …/>}>` reserves the final size. */
126
132
  placeholderHeight?: number | ResponsiveChartHeight | undefined
133
+ /** Placeholder data is showing: the facts row dims with the plot (a strip cell's `stale`). */
134
+ stale?: boolean | undefined
135
+ /** What an errored `state` names: "Could not load {stateNoun}". Default: no noun. */
136
+ stateNoun?: string | undefined
127
137
  /** An errored `state` shows the shared Retry button (the one `ErrorState` renders). */
128
138
  onRetry?: (() => void) | undefined
129
139
  /** A refetch is in flight: Retry is inert and marked busy. */
@@ -162,22 +172,37 @@ const HEADER_TRIGGERS = ['title', 'info', 'value', 'icon', 'count'] as const
162
172
  function Facts({
163
173
  facts,
164
174
  basis,
175
+ stale,
165
176
  }: {
166
177
  facts: ChartFact | readonly ChartFact[]
167
178
  basis?: string | undefined
179
+ stale?: boolean | undefined
168
180
  }): ReactElement {
169
181
  const list: readonly ChartFact[] = Array.isArray(facts) ? facts : [facts as ChartFact]
170
182
  return (
171
183
  <div data-basalt-facts="" className={classes.facts}>
172
- <div className={classes.factsRow}>
184
+ <div
185
+ data-basalt-facts-row=""
186
+ {...(stale && { 'data-stale': 'true' })}
187
+ className={classes.factsRow}
188
+ >
173
189
  {list.map((f, i) => (
174
- <span key={i} data-basalt-fact="" className={classes.fact}>
190
+ <span
191
+ key={i}
192
+ data-basalt-fact=""
193
+ {...(f.tone !== undefined && { 'data-tone': f.tone })}
194
+ className={classes.fact}
195
+ >
175
196
  <span data-basalt-fact-value="" className={classes.factValue}>
176
197
  {f.value}
177
198
  </span>
178
199
  {f.unit !== undefined && <span className={classes.factUnit}>{f.unit}</span>}
179
200
  {f.comparison}
180
- {f.period !== undefined && <span className={classes.factPeriod}>{f.period}</span>}
201
+ {f.period !== undefined && (
202
+ <span className={classes.factPeriod}>
203
+ {typeof f.period === 'string' ? f.period : f.period.join(' · ')}
204
+ </span>
205
+ )}
181
206
  </span>
182
207
  ))}
183
208
  </div>
@@ -195,6 +220,8 @@ export function ChartCard({
195
220
  state,
196
221
  placeholderHeight,
197
222
  stateAction,
223
+ stale,
224
+ stateNoun,
198
225
  onRetry,
199
226
  retrying,
200
227
  className,
@@ -233,7 +260,7 @@ export function ChartCard({
233
260
  actions: <span data-basalt-tier="widget">{actions}</span>,
234
261
  })}
235
262
  />
236
- {showFacts && <Facts facts={facts} basis={subtitle} />}
263
+ {showFacts && <Facts facts={facts} basis={subtitle} stale={stale} />}
237
264
  </div>
238
265
  )}
239
266
  <div
@@ -246,6 +273,7 @@ export function ChartCard({
246
273
  <ChartPlaceholder
247
274
  state={state}
248
275
  {...(placeholderHeight !== undefined && { height: placeholderHeight })}
276
+ {...(stateNoun !== undefined && { noun: stateNoun })}
249
277
  {...(onRetry !== undefined && { onRetry })}
250
278
  {...(retrying !== undefined && { retrying })}
251
279
  action={stateAction}
@@ -16,7 +16,7 @@ import { VX, alpha } from '../tokens'
16
16
  import { resolveContainerClass } from '../tokens/size-classes'
17
17
  import { defaultNumberFormat, engineRow, seriesRow, visibleSeries } from './compile'
18
18
  import { barMark, emphasis, lineMark, markersOf, thinFill } from './marks'
19
- import { PanelRung, chartHeightOf, paneX, paneY, rowsOf } from './panel'
19
+ import { PanelRung, paneX, paneY, rowsOf } from './panel'
20
20
  import type { PaneBuilder, PanelInput, PanelPlan } from './panel'
21
21
  import { plotContext } from './plot-context'
22
22
  import type { SignedSeries } from './legend'
@@ -283,15 +283,13 @@ export function DualPanel<T, X extends Date | number = Date | number>(
283
283
  format: topFormat,
284
284
  ticks: TOP_TICKS,
285
285
  cls,
286
- height: chartHeightOf(h, topFraction, PANE_GAP),
287
286
  }),
288
287
  },
289
288
  }
290
289
  }
291
290
 
292
- const barPane: PaneBuilder = ({ width, height: h }) => {
291
+ const barPane: PaneBuilder = ({ width }) => {
293
292
  const cls = resolveContainerClass(width)
294
- const whole = chartHeightOf(h, 1 - topFraction, PANE_GAP)
295
293
  const barRows = barOn ? rowsOf(data, x, barSeries) : []
296
294
  const dim = emphasis(highlighted, { key: BAR_KEY })
297
295
  return {
@@ -306,14 +304,13 @@ export function DualPanel<T, X extends Date | number = Date | number>(
306
304
  }),
307
305
  ],
308
306
  scales: {
309
- x: paneX({ scale: xScale(), model, format, cls, height: whole }),
307
+ x: paneX({ scale: xScale(), model, format, cls }),
310
308
  y: paneY({
311
309
  scale: barScale,
312
310
  domain: barDomain,
313
311
  format: bar.format,
314
312
  ticks: BAR_TICKS,
315
313
  cls,
316
- height: whole,
317
314
  }),
318
315
  },
319
316
  }
@@ -8,7 +8,9 @@
8
8
  * There is no cursor and no crosshair — the tooltip is per cell, its rows are `tooltip.rows(d)` data.
9
9
  */
10
10
  import { colorGradientLegend } from '@tanstack/charts/legend'
11
+ import { decorative } from '@tanstack/charts/mark/decorative'
11
12
  import { cell } from '@tanstack/charts/rect'
13
+ import { text } from '@tanstack/charts/text'
12
14
  import { scaleBand } from '@tanstack/charts/scales/band'
13
15
  import { portal } from '@tanstack/charts/tooltip/portal'
14
16
  import type { ChartBuildContext, ChartPoint, StoredChartSpec } from '@tanstack/charts/types/core'
@@ -20,7 +22,7 @@ import { alpha, VX } from '../tokens'
20
22
  import { resolveContainerClass } from '../tokens/size-classes'
21
23
  import { engineRow, strideTicks } from './compile'
22
24
  import type { CartesianDefinition } from './compile'
23
- import { resolveNamedState } from './band-fold'
25
+ import { GLYPH_MIN_PX, glyphOf, resolveNamedState } from './band-fold'
24
26
  import type { NamedChartState } from './band-fold'
25
27
  import { ABSENT_OPACITY, RAMP_LEVELS, RAMP_OPACITIES } from './heatmap-fill'
26
28
  import { engineTooltip } from './cursor'
@@ -37,11 +39,29 @@ import type { ChartSeries, ChartState, ChartTooltipRow, ResponsiveChartHeight }
37
39
  * `fillOpacity` (default 1) are its flat fill, `label` its legend entry and tooltip reading, `note`
38
40
  * a muted qualifier after the label in the legend, `legend: false` keeps it out of the legend.
39
41
  * `tooltip` is omitted: a cell's tooltip always names its state, so there is no row to hide.
42
+ *
43
+ * A categorical STATUS grid (up / degraded / down) names a `tone` instead of a `color`:
44
+ *
45
+ * ```tsx
46
+ * <Heatmap getState={(d) => d.status} getValue={() => null} …
47
+ * states={[{ key: 'up', label: 'Up', tone: 'good' }, { key: 'down', label: 'Down', tone: 'bad' }]} />
48
+ * ```
49
+ *
50
+ * `warn` and `bad` draw `!` and `×` in the cell; `glyph` overrides them, `glyph: ''` opts out.
40
51
  */
41
- export type HeatmapState<K extends string = string> = Omit<NamedChartState, 'key' | 'tooltip'> & {
52
+ export type HeatmapState<K extends string = string> = Omit<
53
+ NamedChartState,
54
+ 'key' | 'tooltip' | 'color'
55
+ > & {
42
56
  key: K
57
+ /** The flat fill, a `VX.*` ref. Needed unless `tone` is set; `color` wins over `tone`. */
58
+ color?: string | undefined
43
59
  }
44
60
 
61
+ /** The fill a state resolves to: its `color`, else its tone's status colour, else neutral. */
62
+ const fillOf = (s: HeatmapState | undefined): string =>
63
+ s?.color ?? (s?.tone === undefined ? VX.neutral : VX.status[s.tone])
64
+
45
65
  export type HeatmapProps<T, K extends string = string> = BasaltProps & {
46
66
  /** The accessible name. Required. */
47
67
  ariaLabel: string
@@ -137,7 +157,7 @@ function valueRows<K extends string>(
137
157
  formatValue: (v: number) => string,
138
158
  pointColor: string | undefined,
139
159
  ): ChartTooltipRow[] {
140
- if (named) return [{ label, value: named.label, color: named.color }]
160
+ if (named) return [{ label, value: named.label, color: fillOf(named) }]
141
161
  if (c.value === null) return [{ label, value: 'No data' }]
142
162
  return [{ label, value: formatValue(c.value), ...(pointColor && { color: pointColor }) }]
143
163
  }
@@ -241,6 +261,9 @@ export function Heatmap<T, K extends string = string>(props: HeatmapProps<T, K>)
241
261
  ? {
242
262
  use: engineTooltip,
243
263
  portal,
264
+ // Below the hovered cell (flipping above only when there is no room): the default sits
265
+ // above it and covers the caption row over the grid.
266
+ placement: ['bottom', 'top'] as const,
244
267
  content: (points: readonly ChartPoint[]) => {
245
268
  const point = points[0]
246
269
  const c = point?.datum as Cell<T, K> | undefined
@@ -265,6 +288,31 @@ export function Heatmap<T, K extends string = string>(props: HeatmapProps<T, K>)
265
288
  opacity: 1,
266
289
  thin: true,
267
290
  }
291
+ // A stated cell's glyph, centred in the cell; skipped when the cell is too narrow to hold it.
292
+ const glyphMarks = (plotWidth: number) => {
293
+ const drawn = [...stated].flatMap(([key, group]) => {
294
+ const named = stateByKey.get(key)
295
+ const glyph = named && glyphOf({ ...named, color: fillOf(named) })
296
+ return glyph ? group.map((c) => ({ ...c, glyph })) : []
297
+ })
298
+ return drawn.length > 0 && plotWidth / Math.max(cols.length, 1) >= GLYPH_MIN_PX
299
+ ? [
300
+ decorative(
301
+ text(drawn, {
302
+ id: 'state-glyphs',
303
+ x: 'col',
304
+ y: 'row',
305
+ key: 'id',
306
+ text: 'glyph',
307
+ fill: VX.surface.panel,
308
+ fontSize: VX.text.xs,
309
+ fontWeight: 600,
310
+ anchor: 'middle',
311
+ }),
312
+ ),
313
+ ]
314
+ : []
315
+ }
268
316
  const marks = [
269
317
  // Inert, not decorative: it must still win the hit test, so a pointer over an empty
270
318
  // position lands on THIS cell (whose tooltip is empty) instead of snapping to a neighbour.
@@ -273,11 +321,12 @@ export function Heatmap<T, K extends string = string>(props: HeatmapProps<T, K>)
273
321
  ...[...stated].map(([key, group]) => {
274
322
  const named = stateByKey.get(key)
275
323
  return cellMark(`state:${key}`, group, {
276
- fill: named?.color ?? VX.neutral,
324
+ fill: fillOf(named),
277
325
  ...(named?.fillOpacity !== undefined && { fillOpacity: named.fillOpacity }),
278
326
  })
279
327
  }),
280
328
  cellMark('cells', present, { color: 'value' }),
329
+ ...glyphMarks(width),
281
330
  ]
282
331
  return {
283
332
  marks,
@@ -351,7 +400,7 @@ export function Heatmap<T, K extends string = string>(props: HeatmapProps<T, K>)
351
400
  : states.map((s) => ({
352
401
  key: s.key,
353
402
  label: s.label,
354
- color: s.color,
403
+ color: fillOf(s),
355
404
  mark: 'bar' as const,
356
405
  ...(s.fillOpacity !== undefined && { fillOpacity: s.fillOpacity }),
357
406
  ...(s.legend !== undefined && { legend: s.legend }),
@@ -4,11 +4,14 @@
4
4
  * `thresholds` (fills between the first series and a value, Date/number x only). Zones, x-zones,
5
5
  * reference lines, `y2`, legend, cursor and tooltip are the rung's.
6
6
  *
7
- * At the wide class with ≤ 3 plotted lines and no `y2`, each line also carries an end label; the
8
- * legend still names every series (and still toggles them). A label that would not fit between its
9
- * last point and the plot's right edge ends at the point instead, above it. Before the engine has
10
- * measured the plot (the server HTML, the first client frame) the room is read off the frame, which
11
- * is wider by the axis gutters; the measured render corrects it.
7
+ * `naming` is the one switch for who names the series. `auto` (default): from the wide class up, a
8
+ * chart of ≤ 3 lines and no `y2` names them with end labels and its legend goes; below it the
9
+ * legend names them. `legend`: the legend at every width, no end labels. `endLabels`: end labels at
10
+ * every width, no legend (a chart with a `y2` keeps its legend). A label that would not fit between
11
+ * its last point and the plot's right edge ends at the point instead, above it; labels that would
12
+ * collide are spread apart. Before the engine has measured the plot (the server HTML, the first
13
+ * client frame) the room is read off the frame, which is wider by the axis gutters; the measured
14
+ * render corrects it.
12
15
  */
13
16
  import { areaY } from '@tanstack/charts/area'
14
17
  import { differenceY } from '@tanstack/charts/difference'
@@ -19,11 +22,13 @@ import { CartesianRung } from './CartesianChart'
19
22
  import { areaGradientId } from './compile'
20
23
  import { chartCurve } from './curves'
21
24
  import { endLabelMarks, endLabelPlan } from './labels'
25
+ import type { LinesNaming } from './labels'
22
26
  import { drawnRows, lineMark, loneDots, markersOf, yScaleOf } from './marks'
23
27
  import { rowX } from './types'
24
28
  import type {
25
29
  CartesianChartProps,
26
30
  ChartMarks,
31
+ ChartSeries,
27
32
  ChartX,
28
33
  PlotContext,
29
34
  PlotRow,
@@ -36,13 +41,47 @@ export type LinesProps<T, X extends ChartX = ChartX> = Omit<CartesianChartProps<
36
41
  * x: the engine's `differenceY` takes a Date or number x only.
37
42
  */
38
43
  thresholds?: [X] extends [string] ? never : readonly Threshold[]
44
+ /** Who names the series: `'auto'` (default; end labels from the wide class, the legend below it),
45
+ * `'legend'` or `'endLabels'`. */
46
+ naming?: 'auto' | 'legend' | 'endLabels' | undefined
39
47
  }
40
48
 
41
49
  const hasValue = <T, X extends ChartX>(r: PlotRow<T, X>): boolean => r.y !== null
42
50
 
51
+ /** Whether a series' last non-null point exists and sits inside the chart's x domain. */
52
+ function lastIsPlaceable<T, X extends ChartX>(
53
+ props: Pick<LinesProps<T, X>, 'data' | 'x' | 'xDomain'>,
54
+ s: ChartSeries<T>,
55
+ ): boolean {
56
+ const last = props.data.findLast((d) => s.getValue(d) !== null)
57
+ if (last === undefined) return false
58
+ const { xDomain } = props
59
+ if (xDomain === undefined) return true
60
+ const at = +props.x(last) // a Date's timestamp, or the number itself
61
+ return Number.isNaN(at) || (at >= +xDomain[0] && at <= +xDomain[1])
62
+ }
63
+
64
+ /** The most lines `auto` names with end labels (and so the most a legend gives way for). */
65
+ const AUTO_END_LABELS = 3
66
+
43
67
  export function Lines<T, X extends ChartX = ChartX>(props: LinesProps<T, X>): ReactElement {
44
- const { thresholds, ...rest } = props
68
+ const { thresholds, naming = 'auto', ...rest } = props
45
69
  const { series } = props
70
+ // Whether end labels can name every legend entry: only then may the legend give way to them.
71
+ const labelled = series.filter((s) => s.role !== 'reference')
72
+ const namedByLabels =
73
+ props.y2 === undefined &&
74
+ series.every((s) => s.legend === false || s.role !== 'reference') &&
75
+ !(props.refLines ?? []).some((r) => r.legend !== undefined)
76
+ // When the legend must name something the labels cannot (a right axis, a named reference line),
77
+ // it stays and the labels are not drawn: one naming, never two.
78
+ const effective: LinesNaming = namedByLabels ? naming : 'legend'
79
+ // The legend gives way only to labels that WILL draw for every line: each labelled series needs a
80
+ // last value the plot can place (a narrower `xDomain` can clip it away).
81
+ const placeable = labelled.every((s) => lastIsPlaceable(props, s))
82
+ const labelsOnly = effective === 'endLabels'
83
+ const hideAtWide =
84
+ effective === 'auto' && placeable && labelled.length > 0 && labelled.length <= AUTO_END_LABELS
46
85
  const marks = useCallback(
47
86
  (plot: PlotContext<T, X>): ChartMarks => {
48
87
  const indexOf = new Map(series.map((s, i) => [s.key, i]))
@@ -83,7 +122,7 @@ export function Lines<T, X extends ChartX = ChartX>(props: LinesProps<T, X>): Re
83
122
  y1: () => 0,
84
123
  fill: `url(#${areaGradientId(indexOf.get(s.key) ?? 0)})`,
85
124
  fillOpacity: 1,
86
- curve: chartCurve(s.curve ?? 'monotone'),
125
+ curve: chartCurve(s.curve ?? 'linear'),
87
126
  ...(yScaleOf(plot, s) !== undefined && { yScale: 'y2' }),
88
127
  }),
89
128
  ),
@@ -96,10 +135,17 @@ export function Lines<T, X extends ChartX = ChartX>(props: LinesProps<T, X>): Re
96
135
  out.push(...markersOf(s, plot.rows(s.key), yScale))
97
136
  }
98
137
  const labelled = plotted.filter((s) => s.role !== 'reference')
99
- out.push(...endLabelMarks(endLabelPlan(plot, labelled)))
138
+ out.push(...endLabelMarks(endLabelPlan(plot, labelled, effective)))
100
139
  return out
101
140
  },
102
- [series, thresholds],
141
+ [series, thresholds, effective],
142
+ )
143
+ return (
144
+ <CartesianRung
145
+ {...rest}
146
+ marks={marks}
147
+ {...(labelsOnly && { legend: false as const })}
148
+ {...(hideAtWide && { hideLegendAtWide: true })}
149
+ />
103
150
  )
104
- return <CartesianRung {...rest} marks={marks} />
105
151
  }
@@ -23,7 +23,7 @@ import { VX, alpha } from '../tokens'
23
23
  import { resolveContainerClass } from '../tokens/size-classes'
24
24
  import { defaultNumberFormat, seriesRow, visibleSeries } from './compile'
25
25
  import { barMark, emphasis } from './marks'
26
- import { PanelRung, chartHeightOf, paneX, paneY, rowsOf } from './panel'
26
+ import { PanelRung, paneX, paneY, rowsOf } from './panel'
27
27
  import type { PaneBuilder, PanelInput, PanelPlan } from './panel'
28
28
  import { xScaleFor } from './scales'
29
29
  import { foldBands, resolveNamedState } from './band-fold'
@@ -206,9 +206,8 @@ export function MirroredBars<T, X extends ChartX = ChartX, K extends string = st
206
206
  on: boolean,
207
207
  max: number,
208
208
  ): PaneBuilder =>
209
- ({ width: w, height: h }) => {
209
+ ({ width: w }) => {
210
210
  const cls = resolveContainerClass(w)
211
- const whole = chartHeightOf(h, side === 'up' ? upFraction : 1 - upFraction, 0)
212
211
  // The down pane's zero is at its top.
213
212
  const domain: [number, number] = side === 'up' ? [0, max] : [max, 0]
214
213
  const rows: PlotRow<T, X>[] = on ? rowsOf(drawn, x, s) : []
@@ -282,7 +281,7 @@ export function MirroredBars<T, X extends ChartX = ChartX, K extends string = st
282
281
  scales: {
283
282
  x:
284
283
  side === 'down'
285
- ? paneX({ scale: bandScale(), model, format, cls, height: whole })
284
+ ? paneX({ scale: bandScale(), model, format, cls })
286
285
  : { scale: bandScale(), axis: false },
287
286
  y: paneY({
288
287
  scale: scaleLinear().domain(domain),
@@ -290,7 +289,6 @@ export function MirroredBars<T, X extends ChartX = ChartX, K extends string = st
290
289
  format: cfg.format,
291
290
  ticks: cfg.ticks ?? DEFAULT_PANE_TICKS,
292
291
  cls,
293
- height: whole,
294
292
  }),
295
293
  zx: { channel: 'x', scale: scaleLinear().domain([0, 1]), axis: false },
296
294
  },
@@ -11,11 +11,12 @@ import { lineY } from '@tanstack/charts/line'
11
11
  import { ruleY } from '@tanstack/charts/rule'
12
12
  import { scaleBand } from '@tanstack/charts/scales/band'
13
13
  import { scaleLinear } from '@tanstack/charts/scales/linear'
14
+ import { text } from '@tanstack/charts/text'
14
15
  import { useId, useMemo, useState } from 'react'
15
- import type { FocusEvent, KeyboardEvent, PointerEvent, ReactElement } from 'react'
16
+ import type { CSSProperties, FocusEvent, KeyboardEvent, PointerEvent, ReactElement } from 'react'
16
17
  import { cx } from '../common/props'
17
18
  import type { BasaltProps } from '../common/props'
18
- import { VX } from '../tokens'
19
+ import { VX, alpha } from '../tokens'
19
20
  import type { CartesianDefinition } from './compile'
20
21
  import { chartCurve } from './curves'
21
22
  import { barMark } from './marks'
@@ -24,7 +25,7 @@ import { ChartEngine, idPrefixOf } from './host'
24
25
  import classes from './sparkline.module.css'
25
26
  import { ChartPlaceholder, resolveChartState } from './state'
26
27
  import { CHART_THEME, DASH } from './theme'
27
- import type { ChartState } from './types'
28
+ import type { ChartMarks, ChartState } from './types'
28
29
 
29
30
  export type SparklineProps = BasaltProps & {
30
31
  /** The accessible name. Required: a chart without one is an unlabeled image. */
@@ -38,6 +39,8 @@ export type SparklineProps = BasaltProps & {
38
39
  mark?: 'line' | 'bar' | undefined
39
40
  /** A `VX.*` ref or a series token. Default `VX.faint`. */
40
41
  color?: string | undefined
42
+ /** `'muted'`: the quiet trend line (a muted ink at low alpha). An explicit `color` wins. */
43
+ tone?: 'muted' | undefined
41
44
  /** Paints the last point in `emphasisColor` — the one reading a trend beside a KPI is for.
42
45
  * Default `true`; pass `false` for a bare line. */
43
46
  emphasizeLast?: boolean | undefined
@@ -50,9 +53,13 @@ export type SparklineProps = BasaltProps & {
50
53
  /** A quiet dashed hairline at a value, or at the mean of the plotted values (`'mean'`). The y
51
54
  * domain widens to include it. Not a legend item, never a status colour. */
52
55
  reference?: number | 'mean' | undefined
56
+ /** A short caption for the `reference` line (`PR`, `30 d mean`), drawn at the plot start just
57
+ * above the line. */
58
+ referenceLabel?: string | undefined
53
59
  /** Formats the readout's value. Default: the compact number format. */
54
60
  format?: ((value: number) => string) | undefined
55
- /** The readout's x label per point, index-aligned with `data`. Omitted: the value alone. */
61
+ /** The readout's x label per point, index-aligned with `data`: pass the point's day ("12 Oct"),
62
+ * and the readout reads `3 items · 12 Oct` beside the point. Omitted: the value alone. */
56
63
  labels?: readonly string[] | undefined
57
64
  }
58
65
 
@@ -61,6 +68,12 @@ type Point = { i: number; v: number | null }
61
68
  const LINE_WIDTH = 1.5
62
69
  const DOT_R = 2.5
63
70
  const BAR_GAP = 0.15
71
+ /** Air round a line's plot, px (the engine's plot margin): the end marker stays inside the svg box,
72
+ * so it clears the 2px focus outline round it. A bar plot is flush. */
73
+ const LINE_INSET = 3
74
+ /** The muted tone's line: the same alpha the consumers hand-built (`alpha(VX.muted, .35)`). */
75
+ const MUTED_LINE = alpha(VX.muted, 0.35)
76
+ const REFERENCE_LABEL_DY = -4
64
77
  // Pixel policy of the self-pooling (`poolSparkline`): the densest a series may draw.
65
78
  const LINE_PX_PER_POINT = 1
66
79
  const BAR_PX_PER_BAR = 2
@@ -201,9 +214,10 @@ function compileSparkline(
201
214
  color: string,
202
215
  emphasisColor: string | null,
203
216
  reference: number | null,
217
+ referenceLabel: string | undefined,
204
218
  ): CartesianDefinition {
205
219
  const frame = frameOf(extentOf, mark, source.length, emphasisColor !== null)
206
- const referenceMark = (): readonly ReturnType<typeof ruleY>[] =>
220
+ const referenceMark = (): ChartMarks =>
207
221
  reference === null
208
222
  ? []
209
223
  : [
@@ -214,6 +228,22 @@ function compileSparkline(
214
228
  strokeWidth: 1,
215
229
  strokeDasharray: DASH,
216
230
  }),
231
+ ...(referenceLabel === undefined
232
+ ? []
233
+ : [
234
+ decorative(
235
+ text([reference], {
236
+ id: 'reference-label',
237
+ x: () => (mark === 'bar' ? 0 : frame.x[0]),
238
+ y: (v: number) => v,
239
+ text: () => referenceLabel,
240
+ fill: VX.ink2,
241
+ fontSize: VX.text.micro,
242
+ anchor: 'start',
243
+ dy: REFERENCE_LABEL_DY,
244
+ }),
245
+ ),
246
+ ]),
217
247
  ]
218
248
  return {
219
249
  chart: ({ width }) => {
@@ -276,7 +306,7 @@ function compileSparkline(
276
306
  },
277
307
  theme: CHART_THEME,
278
308
  guides: false,
279
- margin: 0,
309
+ margin: LINE_INSET,
280
310
  }
281
311
  },
282
312
  }
@@ -315,11 +345,13 @@ export function Sparkline(props: SparklineProps): ReactElement {
315
345
  height,
316
346
  width,
317
347
  mark = 'line',
318
- color = VX.faint,
348
+ tone,
349
+ color = tone === 'muted' ? MUTED_LINE : VX.faint,
319
350
  emphasizeLast = true,
320
351
  emphasisColor = VX.line,
321
352
  state,
322
353
  reference,
354
+ referenceLabel,
323
355
  format = defaultNumberFormat,
324
356
  labels,
325
357
  className,
@@ -344,9 +376,9 @@ export function Sparkline(props: SparklineProps): ReactElement {
344
376
  return {
345
377
  rows,
346
378
  frame: frameOf(full, mark, rows.length, end !== null),
347
- definition: compileSparkline(rows, full, mark, color, end, ref),
379
+ definition: compileSparkline(rows, full, mark, color, end, ref, referenceLabel),
348
380
  }
349
- }, [data, mark, color, emphasizeLast, emphasisColor, reference])
381
+ }, [data, mark, color, emphasizeLast, emphasisColor, reference, referenceLabel])
350
382
  const resolved = resolveChartState(state)
351
383
  const rows = model?.rows
352
384
  const interactive = resolved === null && model !== null
@@ -389,6 +421,8 @@ export function Sparkline(props: SparklineProps): ReactElement {
389
421
  setKeyed(lastFinite(rows))
390
422
  }
391
423
 
424
+ const inset = mark === 'line' ? LINE_INSET : 0
425
+ const layerStyle = { inset, '--basalt-spark-lift': `${inset}px` } as CSSProperties
392
426
  const value = active === null ? null : (rows?.[active]?.v ?? null)
393
427
  const at =
394
428
  interactive && active !== null && value !== null
@@ -428,7 +462,9 @@ export function Sparkline(props: SparklineProps): ReactElement {
428
462
  />
429
463
  )}
430
464
  {at !== null && (
431
- <>
465
+ // One layer on the plot rect (inside a line's margin): the dot and the readout take their
466
+ // fractions of the same box, so both land where the mark did.
467
+ <span aria-hidden="true" className={classes.layer} style={layerStyle}>
432
468
  <span
433
469
  data-basalt-sparkline-dot=""
434
470
  className={classes.dot}
@@ -437,12 +473,13 @@ export function Sparkline(props: SparklineProps): ReactElement {
437
473
  <output
438
474
  data-basalt-sparkline-readout=""
439
475
  aria-live={hover === null ? 'polite' : 'off'}
440
- className={cx(classes.readout, at.fx > 0.5 ? classes.start : classes.end)}
476
+ className={classes.readout}
477
+ style={{ left: `${at.fx * 100}%`, transform: `translateX(-${at.fx * 100}%)` }}
441
478
  >
442
- {at.label !== undefined && <span className={classes.label}>{at.label} </span>}
443
479
  {format(at.value)}
480
+ {at.label !== undefined && <span className={classes.label}> · {at.label}</span>}
444
481
  </output>
445
- </>
482
+ </span>
446
483
  )}
447
484
  </div>
448
485
  )
@@ -24,7 +24,7 @@ export type StackedAreaBand<T> = Pick<
24
24
  ChartSeries<T>,
25
25
  'key' | 'label' | 'color' | 'getValue' | 'formatValue' | 'tooltip' | 'legend' | 'role' | 'note'
26
26
  > & {
27
- /** Default 0.85. */
27
+ /** Default: the chart's `fillOpacity` (0.85). */
28
28
  fillOpacity?: number | undefined
29
29
  }
30
30
 
@@ -34,6 +34,9 @@ export type StackedAreaProps<T, X extends ChartX = ChartX> = Omit<
34
34
  > & {
35
35
  /** The bands, bottom to top. */
36
36
  series: readonly StackedAreaBand<T>[]
37
+ /** Every band's fill opacity, 0–1 (default 0.85: full-opacity bands read saturated). A band's own
38
+ * `fillOpacity` wins. The legend swatch wears the same shade. */
39
+ fillOpacity?: number | undefined
37
40
  /** No `scale`: a log axis has no additive zero to stack from. */
38
41
  y?: Omit<NonNullable<CartesianChartProps<T, X>['y']>, 'scale'> | undefined
39
42
  }
@@ -41,11 +44,18 @@ export type StackedAreaProps<T, X extends ChartX = ChartX> = Omit<
41
44
  export function StackedArea<T, X extends ChartX = ChartX>(
42
45
  props: StackedAreaProps<T, X>,
43
46
  ): ReactElement {
44
- const { series: bands, ...rest } = props
47
+ const { series: bands, fillOpacity, ...rest } = props
45
48
  // `mark: 'bar'` is what the rung sums for the auto domain, and the legend/tooltip swatch.
46
49
  const series = useMemo<ChartSeries<T>[]>(
47
- () => bands.map((s) => ({ ...s, mark: 'bar' as const })),
48
- [bands],
50
+ () =>
51
+ bands.map((s) => ({
52
+ ...s,
53
+ mark: 'bar' as const,
54
+ ...((s.fillOpacity ?? fillOpacity) !== undefined && {
55
+ fillOpacity: s.fillOpacity ?? fillOpacity,
56
+ }),
57
+ })),
58
+ [bands, fillOpacity],
49
59
  )
50
60
 
51
61
  const marks = useCallback((plot: PlotContext<T, X>): ChartMarks => {
@@ -1,4 +1,5 @@
1
1
  import { oneOf } from '../common/errors'
2
+ import { VX } from '../tokens'
2
3
  import type { ChartSeries } from './types'
3
4
 
4
5
  /**
@@ -9,7 +10,36 @@ import type { ChartSeries } from './types'
9
10
  export type NamedChartState = Pick<
10
11
  ChartSeries<never>,
11
12
  'key' | 'label' | 'color' | 'tooltip' | 'legend' | 'note' | 'fillOpacity'
12
- >
13
+ > & {
14
+ /**
15
+ * A short mark (`!`, `×`) drawn in the middle of each cell in this state, so a state is not told
16
+ * apart by hue alone; `''` opts out of the default. Default: `!` for a `warn` state and `×` for a
17
+ * `bad` one (by `tone`, or by a `color` that is `VX.status.warn` / `VX.status.bad`); none
18
+ * otherwise. Skipped on a cell too narrow to hold it.
19
+ */
20
+ glyph?: string | undefined
21
+ /** The status this state means. `Heatmap` also fills from it; on `BandStrip` it only picks the
22
+ * default `glyph` (the fill is `color`). */
23
+ tone?: StatusTone | undefined
24
+ }
25
+
26
+ /** The status inks a state can name: `VX.status.*`. */
27
+ export type StatusTone = 'good' | 'warn' | 'bad' | 'neutral'
28
+
29
+ /** `warn` and `bad` carry a glyph by default: a status state is not told apart by hue alone. */
30
+ const TONE_GLYPH: Partial<Record<StatusTone, string>> = { warn: '!', bad: '×' }
31
+
32
+ /** The glyph a state draws: its own, else its status tone's default, else none. */
33
+ export function glyphOf(
34
+ s: Pick<NamedChartState, 'glyph' | 'tone'> & { color?: string | undefined },
35
+ ): string | undefined {
36
+ const tone =
37
+ s.tone ?? (s.color === VX.status.warn ? 'warn' : s.color === VX.status.bad ? 'bad' : undefined)
38
+ return s.glyph ?? (tone === undefined ? undefined : TONE_GLYPH[tone])
39
+ }
40
+
41
+ /** A cell narrower than this (px) draws no glyph: it would not fit inside the fill. */
42
+ export const GLYPH_MIN_PX = 12
13
43
 
14
44
  /** A run of adjacent slots drawn as one band; `items` are the source data it stands for. */
15
45
  export type Group<T> = { start: number; items: T[] }