basalt-ui 2.27.1 → 2.28.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 (243) hide show
  1. package/CHANGELOG.md +111 -0
  2. package/MIGRATING.md +172 -12
  3. package/agent/rules/basalt-batteries.md +1 -1
  4. package/agent/rules/basalt-mantine.md +1 -1
  5. package/agent/rules/basalt-tokens.md +2 -2
  6. package/agent/skills/basalt-design/SKILL.md +1 -1
  7. package/agent/skills/basalt-design/references/catalogue.md +40 -36
  8. package/agent/skills/basalt-design/references/recipes.md +47 -0
  9. package/configs/oxlint-basalt.json +2 -1
  10. package/configs/oxlint-plugin.js +110 -2
  11. package/configs/oxlint-plugin.test.ts +99 -4
  12. package/dist/agent/chat/thread-message.d.ts +1 -160
  13. package/dist/agent/chat/thread-message.d.ts.map +1 -1
  14. package/dist/agent/chat/thread-message.js +7 -162
  15. package/dist/agent/chat/virtualize.d.ts +5 -5
  16. package/dist/charts/ChartCard.d.ts +5 -2
  17. package/dist/charts/ChartCard.d.ts.map +1 -1
  18. package/dist/charts/ChartCard.js +46 -13
  19. package/dist/charts/Lines.d.ts.map +1 -1
  20. package/dist/charts/Lines.js +11 -4
  21. package/dist/charts/Sparkline.d.ts +9 -2
  22. package/dist/charts/Sparkline.d.ts.map +1 -1
  23. package/dist/charts/Sparkline.js +104 -41
  24. package/dist/charts/chart-box.module.css +69 -3
  25. package/dist/charts/chart-box.module.css.d.ts +5 -0
  26. package/dist/charts/chart-card.module.css +12 -4
  27. package/dist/charts/chart-card.module.css.d.ts +1 -0
  28. package/dist/charts/compile.d.ts.map +1 -1
  29. package/dist/charts/compile.js +21 -19
  30. package/dist/charts/labels.d.ts +13 -3
  31. package/dist/charts/labels.d.ts.map +1 -1
  32. package/dist/charts/labels.js +131 -20
  33. package/dist/charts/legend.d.ts.map +1 -1
  34. package/dist/charts/legend.js +1 -1
  35. package/dist/charts/ref-label.d.ts +31 -8
  36. package/dist/charts/ref-label.d.ts.map +1 -1
  37. package/dist/charts/ref-label.js +40 -9
  38. package/dist/charts/sparkline.module.css +6 -0
  39. package/dist/charts/state.d.ts +3 -3
  40. package/dist/charts/state.d.ts.map +1 -1
  41. package/dist/charts/state.js +20 -2
  42. package/dist/cli/shot/capture.d.ts +6 -1
  43. package/dist/cli/shot/capture.d.ts.map +1 -1
  44. package/dist/cli/shot/capture.js +18 -5
  45. package/dist/common/empty-copy.d.ts +16 -0
  46. package/dist/common/empty-copy.d.ts.map +1 -0
  47. package/dist/common/empty-copy.js +9 -0
  48. package/dist/common/virtual-rows.d.ts +196 -0
  49. package/dist/common/virtual-rows.d.ts.map +1 -0
  50. package/dist/common/virtual-rows.js +290 -0
  51. package/dist/controls/controls.module.css +33 -1
  52. package/dist/controls/controls.module.css.d.ts +2 -0
  53. package/dist/controls/enum-filter.d.ts.map +1 -1
  54. package/dist/controls/enum-filter.js +8 -2
  55. package/dist/controls/filter-pill.d.ts +27 -3
  56. package/dist/controls/filter-pill.d.ts.map +1 -1
  57. package/dist/controls/filter-pill.js +15 -4
  58. package/dist/controls/form-layout.d.ts +9 -3
  59. package/dist/controls/form-layout.d.ts.map +1 -1
  60. package/dist/controls/form-layout.js +74 -12
  61. package/dist/controls/form-layout.module.css +112 -7
  62. package/dist/controls/form-layout.module.css.d.ts +1 -0
  63. package/dist/controls/multi-select-filter.d.ts +2 -2
  64. package/dist/controls/multi-select-filter.d.ts.map +1 -1
  65. package/dist/controls/multi-select-filter.js +12 -6
  66. package/dist/controls/range-filter.d.ts +1 -1
  67. package/dist/controls/range-filter.d.ts.map +1 -1
  68. package/dist/controls/range-filter.js +8 -2
  69. package/dist/dashboard/bar-list.d.ts +1 -1
  70. package/dist/dashboard/bar-list.d.ts.map +1 -1
  71. package/dist/dashboard/bar-list.js +6 -2
  72. package/dist/dashboard/bar-list.module.css +0 -2
  73. package/dist/dashboard/board-nav.d.ts +22 -0
  74. package/dist/dashboard/board-nav.d.ts.map +1 -0
  75. package/dist/dashboard/board-nav.js +49 -0
  76. package/dist/dashboard/board.d.ts +52 -0
  77. package/dist/dashboard/board.d.ts.map +1 -0
  78. package/dist/dashboard/board.js +228 -0
  79. package/dist/dashboard/board.module.css +160 -0
  80. package/dist/dashboard/board.module.css.d.ts +26 -0
  81. package/dist/dashboard/empty-state.d.ts +3 -3
  82. package/dist/dashboard/empty-state.d.ts.map +1 -1
  83. package/dist/dashboard/empty-state.js +13 -6
  84. package/dist/dashboard/event-list-model.d.ts +51 -0
  85. package/dist/dashboard/event-list-model.d.ts.map +1 -0
  86. package/dist/dashboard/event-list-model.js +72 -0
  87. package/dist/dashboard/event-list-rows.d.ts +23 -0
  88. package/dist/dashboard/event-list-rows.d.ts.map +1 -0
  89. package/dist/dashboard/event-list-rows.js +93 -0
  90. package/dist/dashboard/event-list-scroll.d.ts +27 -0
  91. package/dist/dashboard/event-list-scroll.d.ts.map +1 -0
  92. package/dist/dashboard/event-list-scroll.js +103 -0
  93. package/dist/dashboard/event-list-skeleton.d.ts +10 -0
  94. package/dist/dashboard/event-list-skeleton.d.ts.map +1 -0
  95. package/dist/dashboard/event-list-skeleton.js +36 -0
  96. package/dist/dashboard/event-list.d.ts +65 -0
  97. package/dist/dashboard/event-list.d.ts.map +1 -0
  98. package/dist/dashboard/event-list.js +178 -0
  99. package/dist/dashboard/event-list.module.css +283 -0
  100. package/dist/dashboard/event-list.module.css.d.ts +33 -0
  101. package/dist/dashboard/index.d.ts +2 -0
  102. package/dist/dashboard/index.d.ts.map +1 -1
  103. package/dist/dashboard/index.js +4 -0
  104. package/dist/dashboard/meter-parts.d.ts.map +1 -1
  105. package/dist/dashboard/meter-parts.js +5 -3
  106. package/dist/dashboard/meter.module.css +2 -1
  107. package/dist/dashboard/query-state.js +1 -1
  108. package/dist/dashboard/settings-section.d.ts +4 -1
  109. package/dist/dashboard/settings-section.d.ts.map +1 -1
  110. package/dist/dashboard/settings-section.js +1 -1
  111. package/dist/dashboard/settings-section.module.css +19 -4
  112. package/dist/dashboard/stat-card-parts.d.ts +5 -1
  113. package/dist/dashboard/stat-card-parts.d.ts.map +1 -1
  114. package/dist/dashboard/stat-card-parts.js +8 -3
  115. package/dist/dashboard/stat-card.d.ts.map +1 -1
  116. package/dist/dashboard/stat-card.js +26 -7
  117. package/dist/dashboard/stat-card.module.css +31 -7
  118. package/dist/dashboard/stat-card.module.css.d.ts +3 -0
  119. package/dist/dashboard/stat-strip.js +1 -1
  120. package/dist/dashboard/stat-strip.module.css +4 -1
  121. package/dist/dashboard/widget-header.d.ts.map +1 -1
  122. package/dist/dashboard/widget-header.js +15 -2
  123. package/dist/dashboard/widget-header.module.css +17 -1
  124. package/dist/guard/index.d.ts.map +1 -1
  125. package/dist/guard/index.js +2 -0
  126. package/dist/index.d.ts +1 -1
  127. package/dist/index.d.ts.map +1 -1
  128. package/dist/index.js +4 -0
  129. package/dist/shell/app-main.module.css +18 -0
  130. package/dist/styles.css +46 -8
  131. package/dist/surfaces.d.ts +2 -2
  132. package/dist/surfaces.d.ts.map +1 -1
  133. package/dist/surfaces.js +8 -2
  134. package/dist/table/cell-kinds.d.ts +44 -0
  135. package/dist/table/cell-kinds.d.ts.map +1 -0
  136. package/dist/table/cell-kinds.js +169 -0
  137. package/dist/table/cell-kinds.module.css +55 -0
  138. package/dist/table/cell-kinds.module.css.d.ts +15 -0
  139. package/dist/table/data-table-fold.d.ts +147 -0
  140. package/dist/table/data-table-fold.d.ts.map +1 -0
  141. package/dist/table/data-table-fold.js +288 -0
  142. package/dist/table/data-table-state.d.ts +10 -3
  143. package/dist/table/data-table-state.d.ts.map +1 -1
  144. package/dist/table/data-table-state.js +11 -6
  145. package/dist/table/data-table.d.ts +11 -26
  146. package/dist/table/data-table.d.ts.map +1 -1
  147. package/dist/table/data-table.js +354 -254
  148. package/dist/table/data-table.module.css +210 -3
  149. package/dist/table/data-table.module.css.d.ts +12 -0
  150. package/dist/table/table-features.d.ts +34 -4
  151. package/dist/table/table-features.d.ts.map +1 -1
  152. package/dist/table/table-features.js +10 -0
  153. package/dist/theme/card-inset.module.css +35 -0
  154. package/dist/theme/controls.module.css +32 -0
  155. package/dist/theme/ctl-theme.d.ts.map +1 -1
  156. package/dist/theme/ctl-theme.js +5 -0
  157. package/dist/theme/index.d.ts.map +1 -1
  158. package/dist/theme/index.js +14 -10
  159. package/dist/tokens/core.d.ts +1 -0
  160. package/dist/tokens/core.d.ts.map +1 -1
  161. package/dist/tokens/core.js +1 -0
  162. package/dist/tokens/derive.js +1 -1
  163. package/dist/tokens/palette.d.ts +2 -1
  164. package/dist/tokens/palette.d.ts.map +1 -1
  165. package/llms.txt +34 -5
  166. package/package.json +1 -1
  167. package/src/agent/chat/thread-message.tsx +10 -403
  168. package/src/agent/chat/virtualize.ts +5 -5
  169. package/src/charts/ChartCard.tsx +79 -17
  170. package/src/charts/Lines.tsx +13 -4
  171. package/src/charts/Sparkline.tsx +131 -45
  172. package/src/charts/chart-box.module.css +69 -3
  173. package/src/charts/chart-box.module.css.d.ts +5 -0
  174. package/src/charts/chart-card.module.css +12 -4
  175. package/src/charts/chart-card.module.css.d.ts +1 -0
  176. package/src/charts/compile.ts +24 -20
  177. package/src/charts/labels.ts +175 -24
  178. package/src/charts/legend.tsx +3 -2
  179. package/src/charts/ref-label.ts +86 -17
  180. package/src/charts/sparkline.module.css +6 -0
  181. package/src/charts/state.tsx +36 -7
  182. package/src/cli/shot/capture.ts +29 -6
  183. package/src/common/empty-copy.ts +17 -0
  184. package/src/common/virtual-rows.tsx +682 -0
  185. package/src/controls/controls.module.css +33 -1
  186. package/src/controls/controls.module.css.d.ts +2 -0
  187. package/src/controls/enum-filter.tsx +8 -2
  188. package/src/controls/filter-pill.tsx +80 -27
  189. package/src/controls/form-layout.module.css +112 -7
  190. package/src/controls/form-layout.module.css.d.ts +1 -0
  191. package/src/controls/form-layout.tsx +115 -22
  192. package/src/controls/multi-select-filter.tsx +22 -11
  193. package/src/controls/range-filter.tsx +9 -3
  194. package/src/dashboard/bar-list.module.css +0 -2
  195. package/src/dashboard/bar-list.tsx +8 -5
  196. package/src/dashboard/board-nav.ts +67 -0
  197. package/src/dashboard/board.module.css +160 -0
  198. package/src/dashboard/board.module.css.d.ts +26 -0
  199. package/src/dashboard/board.tsx +394 -0
  200. package/src/dashboard/empty-state.tsx +16 -9
  201. package/src/dashboard/event-list-model.ts +113 -0
  202. package/src/dashboard/event-list-rows.tsx +120 -0
  203. package/src/dashboard/event-list-scroll.ts +145 -0
  204. package/src/dashboard/event-list-skeleton.tsx +58 -0
  205. package/src/dashboard/event-list.module.css +283 -0
  206. package/src/dashboard/event-list.module.css.d.ts +33 -0
  207. package/src/dashboard/event-list.tsx +309 -0
  208. package/src/dashboard/index.ts +2 -0
  209. package/src/dashboard/meter-parts.tsx +9 -2
  210. package/src/dashboard/meter.module.css +2 -1
  211. package/src/dashboard/query-state.tsx +1 -1
  212. package/src/dashboard/settings-section.module.css +19 -4
  213. package/src/dashboard/settings-section.tsx +7 -2
  214. package/src/dashboard/stat-card-parts.tsx +20 -3
  215. package/src/dashboard/stat-card.module.css +31 -7
  216. package/src/dashboard/stat-card.module.css.d.ts +3 -0
  217. package/src/dashboard/stat-card.tsx +25 -6
  218. package/src/dashboard/stat-strip.module.css +4 -1
  219. package/src/dashboard/stat-strip.tsx +1 -1
  220. package/src/dashboard/widget-header.module.css +17 -1
  221. package/src/dashboard/widget-header.tsx +29 -5
  222. package/src/guard/index.ts +2 -0
  223. package/src/index.ts +4 -0
  224. package/src/shell/app-main.module.css +18 -0
  225. package/src/styles.css +46 -8
  226. package/src/surfaces.ts +7 -1
  227. package/src/table/cell-kinds.module.css +55 -0
  228. package/src/table/cell-kinds.module.css.d.ts +15 -0
  229. package/src/table/cell-kinds.tsx +234 -0
  230. package/src/table/data-table-fold.tsx +514 -0
  231. package/src/table/data-table-state.ts +24 -13
  232. package/src/table/data-table.module.css +210 -3
  233. package/src/table/data-table.module.css.d.ts +12 -0
  234. package/src/table/data-table.tsx +406 -359
  235. package/src/table/table-features.ts +44 -4
  236. package/src/theme/__snapshots__/plain-theme.test.ts.snap +2 -66
  237. package/src/theme/card-inset.module.css +35 -0
  238. package/src/theme/controls.module.css +32 -0
  239. package/src/theme/ctl-theme.tsx +8 -0
  240. package/src/theme/index.ts +12 -8
  241. package/src/tokens/core.ts +1 -0
  242. package/src/tokens/derive.ts +1 -1
  243. package/src/tokens/palette.ts +4 -1
@@ -8,7 +8,7 @@
8
8
  * `legend={{ placement: 'header' }}` legend is drawn by the chart, at the top of the body under the
9
9
  * header, so it is in the server HTML and the header never grows on hydration.
10
10
  */
11
- import { useRef, useState } from 'react'
11
+ import { Children, isValidElement, useRef, useState } from 'react'
12
12
  import type { CSSProperties, ReactElement, ReactNode } from 'react'
13
13
  import { useIsomorphicLayoutEffect } from '../common/isomorphic-layout-effect'
14
14
  import { cx } from '../common/props'
@@ -17,6 +17,9 @@ import type { DeltaPolarity } from '../dashboard/delta-badge'
17
17
  import { WidgetHeader } from '../dashboard/widget-header'
18
18
  import { VX } from '../tokens'
19
19
  import { ChartCardContext } from './card-context'
20
+ import { BandStrip } from './BandStrip'
21
+ import { Lines } from './Lines'
22
+ import { StackedArea } from './StackedArea'
20
23
  import classes from './chart-card.module.css'
21
24
  import { ChartPlaceholder, resolveChartState } from './state'
22
25
  import type { ChartState, ResponsiveChartHeight } from './types'
@@ -153,8 +156,11 @@ type ChartCardBaseProps = BasaltProps &
153
156
  * fallback>` should pass a numeric height instead. */
154
157
  placeholderHeight?: number | ResponsiveChartHeight | 'content' | undefined
155
158
  /** The pending plot's ghost: `'bars'` (default), `'line'` for a line or area chart, or the bar
156
- * count when the loaded chart's data length is known. */
157
- ghost?: 'bars' | 'line' | number | undefined
159
+ * count when the loaded chart's data length is known, `'band'` for a `BandStrip`. Omitted, a
160
+ * `Lines` or `StackedArea` body (bare, or inside plain elements) loads as a line, a `BandStrip`
161
+ * as one band row at its own `height`; a body wrapped in your own component hides
162
+ * its kind from the card, so pass `ghost="line"` there. */
163
+ ghost?: 'bars' | 'line' | 'band' | number | undefined
158
164
  /** Placeholder data is showing: the facts row dims with the plot (a strip cell's `stale`). */
159
165
  stale?: boolean | undefined
160
166
  /** What an errored `state` names: "Could not load {stateNoun}". Default: no noun. */
@@ -252,6 +258,57 @@ function FactsSkeleton({ basis }: { basis: boolean }): ReactElement {
252
258
  )
253
259
  }
254
260
 
261
+ /** A stated `BandStrip` height the placeholder can take: a px number or the per-class object. */
262
+ function isChartHeight(value: unknown): value is number | ResponsiveChartHeight {
263
+ return (
264
+ typeof value === 'number' ||
265
+ (typeof value === 'object' &&
266
+ value !== null &&
267
+ typeof (value as { base?: unknown }).base === 'number')
268
+ )
269
+ }
270
+
271
+ type BodyKind = { ghost: 'line' | 'band'; height?: number | ResponsiveChartHeight; legend?: true }
272
+
273
+ /**
274
+ * What a pending body draws when `ghost` is not passed: a line for a `Lines` or `StackedArea` body,
275
+ * one band row at the strip's own `height` for a `BandStrip` (found through plain elements such as a
276
+ * `Box`), the default bars otherwise, so a loading chart is drawn as its kind, at its loaded height.
277
+ */
278
+ function bodyKindOf(node: ReactNode): BodyKind | undefined {
279
+ for (const child of Children.toArray(node)) {
280
+ if (!isValidElement<{ children?: ReactNode; height?: unknown }>(child)) continue
281
+ if (child.type === Lines || child.type === StackedArea) return { ghost: 'line' }
282
+ if (child.type === BandStrip) {
283
+ const { height, states, legend } = child.props as {
284
+ height?: unknown
285
+ states?: readonly unknown[]
286
+ legend?: unknown
287
+ }
288
+ return {
289
+ ghost: 'band',
290
+ ...(isChartHeight(height) && { height }),
291
+ // The loaded strip's legend row sits under the box: the ghost keeps its room.
292
+ ...(legend !== false && (states?.length ?? 0) > 1 && { legend: true as const }),
293
+ }
294
+ }
295
+ const inner = bodyKindOf(child.props.children)
296
+ if (inner !== undefined) return inner
297
+ }
298
+ return undefined
299
+ }
300
+
301
+ /** The loaded strip's legend row keeps its room under a pending box; other placeholders get no wrapper. */
302
+ function reserveLegend(reserve: boolean, placeholder: ReactElement): ReactElement {
303
+ return reserve ? (
304
+ <div className={classes.legendReserve} data-basalt-legend-reserve="">
305
+ {placeholder}
306
+ </div>
307
+ ) : (
308
+ placeholder
309
+ )
310
+ }
311
+
255
312
  export function ChartCard({
256
313
  actions,
257
314
  state,
@@ -271,6 +328,10 @@ export function ChartCard({
271
328
  }: ChartCardProps): ReactElement {
272
329
  const { ref, short } = useShortCard()
273
330
  const resolved = resolveChartState(state)
331
+ const kind = resolved === 'pending' ? bodyKindOf(children) : undefined
332
+ const plotGhost = ghost ?? kind?.ghost
333
+ // `ghost` changes the shape only: the wrapped strip's height still sizes the pending box.
334
+ const pendingHeight = placeholderHeight ?? kind?.height
274
335
  const showFacts = facts !== undefined && resolved === null
275
336
  const skeletonFacts = facts !== undefined && resolved === 'pending'
276
337
  const hasHeader =
@@ -293,7 +354,7 @@ export function ChartCard({
293
354
  {...(short && { 'data-basalt-card-short': '' })}
294
355
  >
295
356
  {hasHeader && (
296
- <div className={cx(classes.header, classNames?.header)}>
357
+ <div data-basalt-chart-header="" className={cx(classes.header, classNames?.header)}>
297
358
  <WidgetHeader
298
359
  tier="widget"
299
360
  {...definedOnly(headerProps)}
@@ -310,19 +371,20 @@ export function ChartCard({
310
371
  {...(classNames?.body !== undefined && { className: classNames.body })}
311
372
  style={bodyClipStyle}
312
373
  >
313
- {resolved === null || (resolved === 'pending' && placeholderHeight === 'content') ? (
314
- children
315
- ) : (
316
- <ChartPlaceholder
317
- state={state}
318
- {...(placeholderHeight !== undefined && { height: placeholderHeight })}
319
- {...(stateNoun !== undefined && { noun: stateNoun })}
320
- {...(ghost !== undefined && { ghost })}
321
- {...(onRetry !== undefined && { onRetry })}
322
- {...(retrying !== undefined && { retrying })}
323
- action={stateAction}
324
- />
325
- )}
374
+ {resolved === null || (resolved === 'pending' && placeholderHeight === 'content')
375
+ ? children
376
+ : reserveLegend(
377
+ kind?.legend === true,
378
+ <ChartPlaceholder
379
+ state={state}
380
+ {...(pendingHeight !== undefined && { height: pendingHeight })}
381
+ {...(stateNoun !== undefined && { noun: stateNoun })}
382
+ {...(plotGhost !== undefined && { ghost: plotGhost })}
383
+ {...(onRetry !== undefined && { onRetry })}
384
+ {...(retrying !== undefined && { retrying })}
385
+ action={stateAction}
386
+ />,
387
+ )}
326
388
  </div>
327
389
  </div>
328
390
  </ChartCardContext.Provider>
@@ -21,7 +21,7 @@ import type { ReactElement } from 'react'
21
21
  import { CartesianRung } from './CartesianChart'
22
22
  import { areaGradientId } from './compile'
23
23
  import { chartCurve } from './curves'
24
- import { endLabelMarks, endLabelPlan } from './labels'
24
+ import { claimLabelBoxes, endLabelMarks, endLabelPlan } from './labels'
25
25
  import type { LinesNaming } from './labels'
26
26
  import { drawnRows, lineMark, loneDots, markersOf, yScaleOf } from './marks'
27
27
  import { rowX } from './types'
@@ -65,7 +65,7 @@ function lastIsPlaceable<T, X extends ChartX>(
65
65
  const AUTO_END_LABELS = 3
66
66
 
67
67
  export function Lines<T, X extends ChartX = ChartX>(props: LinesProps<T, X>): ReactElement {
68
- const { thresholds, naming = 'auto', ...rest } = props
68
+ const { thresholds, naming = 'auto', refLines, ...rest } = props
69
69
  const { series } = props
70
70
  // Whether end labels can name every legend entry: only then may the legend give way to them.
71
71
  const labelled = series.filter((s) => s.role !== 'reference')
@@ -135,14 +135,23 @@ export function Lines<T, X extends ChartX = ChartX>(props: LinesProps<T, X>): Re
135
135
  out.push(...markersOf(s, plot.rows(s.key), yScale))
136
136
  }
137
137
  const labelled = plotted.filter((s) => s.role !== 'reference')
138
- out.push(...endLabelMarks(endLabelPlan(plot, labelled, effective)))
138
+ // The reference rules on the left axis are lines a label must not sit on; the captions in turn
139
+ // keep clear of the labels placed here.
140
+ const rules = (refLines ?? []).flatMap((r) => (r.axis === 'right' ? [] : [r.value]))
141
+ const plan = endLabelPlan(plot, labelled, effective, rules)
142
+ claimLabelBoxes(
143
+ plot,
144
+ plan.map((p) => p.box),
145
+ )
146
+ out.push(...endLabelMarks(plan))
139
147
  return out
140
148
  },
141
- [series, thresholds, effective],
149
+ [series, thresholds, effective, refLines],
142
150
  )
143
151
  return (
144
152
  <CartesianRung
145
153
  {...rest}
154
+ {...(refLines !== undefined && { refLines })}
146
155
  marks={marks}
147
156
  {...(labelsOnly && { legend: false as const })}
148
157
  {...(hideAtWide && { hideLegendAtWide: true })}
@@ -8,6 +8,7 @@
8
8
  import { dot } from '@tanstack/charts/dot'
9
9
  import { decorative } from '@tanstack/charts/mark/decorative'
10
10
  import { lineY } from '@tanstack/charts/line'
11
+ import { rect } from '@tanstack/charts/rect'
11
12
  import { ruleY } from '@tanstack/charts/rule'
12
13
  import { scaleBand } from '@tanstack/charts/scales/band'
13
14
  import { scaleLinear } from '@tanstack/charts/scales/linear'
@@ -59,9 +60,13 @@ export type SparklineProps = BasaltProps & {
59
60
  /** A quiet dashed hairline at a value, or at the mean of the plotted values (`'mean'`). The y
60
61
  * domain widens to include it. Not a legend item, never a status colour. */
61
62
  reference?: number | 'mean' | undefined
62
- /** A short caption for the `reference` line (`PR`, `30 d mean`), drawn at the plot start just
63
- * above the line. */
63
+ /** A short caption for the `reference` line (`PR`, `30 d mean`), drawn at the plot end the line
64
+ * is not near, just above the reference (below when there is no room above). */
64
65
  referenceLabel?: string | undefined
66
+ /** A productive range (`{ from: 0.6, to: 1 }`) drawn as a quiet band behind the line. The y
67
+ * domain widens to include it. Not a series: no legend item, no tooltip row. A non-finite bound or
68
+ * an empty range (`from === to`) draws nothing and leaves the domain alone. */
69
+ band?: { from: number; to: number } | undefined
65
70
  /** Formats the readout's value. Default: the compact number format. */
66
71
  format?: ((value: number) => string) | undefined
67
72
  /** The readout's x label per point, index-aligned with `data`: pass the point's day ("12 Oct"),
@@ -85,6 +90,12 @@ const LINE_INSET = 3
85
90
  const SHORT_BOX = 36
86
91
  /** The muted tone's line: the same alpha the consumers hand-built (`alpha(VX.muted, .35)`). */
87
92
  const MUTED_LINE = alpha(VX.muted, 0.35)
93
+ /** The productive band: the chart layer's neutral wash (`BandStrip`'s), under the line in the paint order. */
94
+ /** The unit x scale (`zx`) a band is drawn on, whatever the series' own x is. */
95
+ const ZONE_X = {
96
+ zx: { channel: 'x' as const, scale: scaleLinear().domain([0, 1]), axis: false as const },
97
+ }
98
+ const BAND_FILL = alpha(VX.neutral, 0.2)
88
99
  /** Air between the plot's start and the reference label, so the focus outline never covers it. */
89
100
  const REFERENCE_LABEL_DX = 3
90
101
  // Pixel policy of the self-pooling (`poolSparkline`): the densest a series may draw.
@@ -242,10 +253,12 @@ function frameOf(
242
253
  mark: 'line' | 'bar',
243
254
  count: number,
244
255
  hasEnd: boolean,
256
+ banded = false,
245
257
  ): Frame {
246
258
  if (mark === 'bar') return { x: [0, count], y: [Math.min(lo, 0), Math.max(hi, 0) || 1] }
247
259
  // A flat or single-point series needs an extent; 10% air keeps the stroke inside the box.
248
- const pad = (hi - lo) * 0.1 || 1
260
+ // A band edge that sets the domain needs air to read as an edge: a quarter of the span, not a tenth.
261
+ const pad = (hi - lo) * (banded ? 0.25 : 0.1) || 1
249
262
  // Half a dot of air at each end, in index units, so the last-point dot is not clipped.
250
263
  const xPad = hasEnd ? (count - 1) * 0.04 || 0.5 : 0
251
264
  return { x: [-xPad, Math.max(count - 1, 1) + xPad], y: [lo - pad, hi + pad] }
@@ -259,43 +272,76 @@ function compileSparkline(
259
272
  emphasisColor: string | null,
260
273
  reference: number | null,
261
274
  referenceLabel: string | undefined,
275
+ band: { from: number; to: number } | null,
276
+ bandEdges: boolean,
262
277
  ): CartesianDefinition {
263
- const frame = frameOf(extentOf, mark, source.length, emphasisColor !== null)
264
- const referenceMark = (height: number): ChartMarks =>
265
- reference === null
278
+ const frame = frameOf(extentOf, mark, source.length, emphasisColor !== null, bandEdges)
279
+ const bandMark = (): ChartMarks =>
280
+ band === null
266
281
  ? []
267
282
  : [
268
- ruleY([reference], {
269
- id: 'reference',
270
- stroke: VX.line,
271
- strokeOpacity: 1,
272
- strokeWidth: 1,
273
- strokeDasharray: DASH,
274
- }),
275
- ...(referenceLabel === undefined
276
- ? []
277
- : [
278
- decorative(
279
- text([reference], {
280
- id: 'reference-label',
281
- x: () => (mark === 'bar' ? 0 : frame.x[0]),
282
- y: (v: number) => v,
283
- text: () => referenceLabel,
284
- fill: VX.ink2,
285
- fontSize: VX.text.micro,
286
- anchor: 'start',
287
- dx: REFERENCE_LABEL_DX,
288
- dy: referenceLabelPlacement({
289
- value: reference,
290
- domain: frame.y,
291
- height,
292
- inset: mark === 'bar' ? 0 : LINE_INSET,
293
- fontSize: VX.text.micro,
294
- }).dy,
295
- }),
296
- ),
297
- ]),
283
+ decorative(
284
+ rect([band], {
285
+ id: 'band',
286
+ x1: () => 0,
287
+ x2: () => 1,
288
+ xScale: 'zx',
289
+ y1: 'from',
290
+ y2: 'to',
291
+ fill: BAND_FILL,
292
+ inset: 0,
293
+ }),
294
+ ),
298
295
  ]
296
+ const referenceMark = (height: number, width: number, rows: readonly Point[]): ChartMarks => {
297
+ if (reference === null) return []
298
+ const place =
299
+ referenceLabel === undefined
300
+ ? null
301
+ : referenceLabelPlacement({
302
+ value: reference,
303
+ domain: frame.y,
304
+ height,
305
+ width,
306
+ inset: mark === 'bar' ? 0 : LINE_INSET,
307
+ fontSize: VX.text.micro,
308
+ label: referenceLabel,
309
+ line:
310
+ mark === 'bar'
311
+ ? undefined
312
+ : rows.flatMap((r) =>
313
+ r.v === null
314
+ ? []
315
+ : [{ fx: (r.i - frame.x[0]) / (frame.x[1] - frame.x[0]), y: r.v }],
316
+ ),
317
+ })
318
+ return [
319
+ ruleY([reference], {
320
+ id: 'reference',
321
+ stroke: VX.line,
322
+ strokeOpacity: 1,
323
+ strokeWidth: 1,
324
+ strokeDasharray: DASH,
325
+ }),
326
+ ...(referenceLabel === undefined || place === null
327
+ ? []
328
+ : [
329
+ decorative(
330
+ text([reference], {
331
+ id: 'reference-label',
332
+ x: () => (place.end === 'end' ? frame.x[1] : mark === 'bar' ? 0 : frame.x[0]),
333
+ y: (v: number) => v,
334
+ text: () => referenceLabel,
335
+ fill: VX.ink2,
336
+ fontSize: VX.text.micro,
337
+ anchor: place.end,
338
+ dx: place.end === 'end' ? -REFERENCE_LABEL_DX : REFERENCE_LABEL_DX,
339
+ dy: place.dy,
340
+ }),
341
+ ),
342
+ ]),
343
+ ]
344
+ }
299
345
  return {
300
346
  // A bar's hover is the bar and the readout chip: no engine point marker (bar chrome only, as
301
347
  // `Bars`).
@@ -306,7 +352,8 @@ function compileSparkline(
306
352
  if (mark === 'bar') {
307
353
  return {
308
354
  marks: [
309
- ...referenceMark(height),
355
+ ...bandMark(),
356
+ ...referenceMark(height, width, rows),
310
357
  barMark(rows, {
311
358
  id: 'bars',
312
359
  x: 'i',
@@ -322,6 +369,8 @@ function compileSparkline(
322
369
  .padding(BAR_GAP),
323
370
  axis: false as const,
324
371
  },
372
+ // The band spans the whole plot, outer half-bars included: a unit scale, not the band x.
373
+ ...ZONE_X,
325
374
  y: {
326
375
  scale: scaleLinear().domain(frame.y),
327
376
  axis: false as const,
@@ -334,7 +383,8 @@ function compileSparkline(
334
383
  }
335
384
  return {
336
385
  marks: [
337
- ...referenceMark(height),
386
+ ...bandMark(),
387
+ ...referenceMark(height, width, rows),
338
388
  lineY(rows, {
339
389
  id: 'line',
340
390
  x: 'i',
@@ -356,6 +406,7 @@ function compileSparkline(
356
406
  scale: scaleLinear().domain(frame.x),
357
407
  axis: false as const,
358
408
  },
409
+ ...ZONE_X,
359
410
  y: { scale: scaleLinear().domain(frame.y), axis: false as const },
360
411
  },
361
412
  theme: CHART_THEME,
@@ -581,6 +632,7 @@ export function Sparkline(props: SparklineProps): ReactElement {
581
632
  state,
582
633
  reference,
583
634
  referenceLabel,
635
+ band,
584
636
  format = defaultNumberFormat,
585
637
  labels,
586
638
  className,
@@ -593,6 +645,8 @@ export function Sparkline(props: SparklineProps): ReactElement {
593
645
  const [keyed, setKeyed] = useState<number | null>(null)
594
646
  const active = hover ?? keyed
595
647
  const readoutRef = useRef<HTMLOutputElement>(null)
648
+ const bandFrom = band?.from
649
+ const bandTo = band?.to
596
650
  const model = useMemo(() => {
597
651
  const rows: Point[] = data.map((d, i) => ({
598
652
  i,
@@ -604,16 +658,40 @@ export function Sparkline(props: SparklineProps): ReactElement {
604
658
  const at = reference === 'mean' ? meanOf(rows) : (reference ?? null)
605
659
  const ref = at !== null && Number.isFinite(at) ? at : null
606
660
  // The reference is part of the extent, so it is never clipped.
607
- const full: readonly [number, number] =
608
- ref === null ? range : [Math.min(range[0], ref), Math.max(range[1], ref)]
661
+ const bandSpan =
662
+ bandFrom !== undefined &&
663
+ bandTo !== undefined &&
664
+ Number.isFinite(bandFrom + bandTo) &&
665
+ bandFrom !== bandTo
666
+ ? { from: Math.min(bandFrom, bandTo), to: Math.max(bandFrom, bandTo) }
667
+ : null
668
+ const edges = [ref, bandSpan?.from, bandSpan?.to].filter(
669
+ (v): v is number => typeof v === 'number',
670
+ )
671
+ const full: readonly [number, number] = [
672
+ Math.min(range[0], ...edges),
673
+ Math.max(range[1], ...edges),
674
+ ]
609
675
  const end = emphasizeLast ? emphasisColor : null
676
+ // A band that sets the domain's edge gets the wider air; one inside the data leaves it alone.
677
+ const bandEdges = full[0] < range[0] || full[1] > range[1]
610
678
  return {
611
679
  rows,
612
680
  moments: momentsOf(data),
613
- frame: frameOf(full, mark, rows.length, end !== null),
614
- definition: compileSparkline(rows, full, mark, color, end, ref, referenceLabel),
681
+ frame: frameOf(full, mark, rows.length, end !== null, bandSpan !== null && bandEdges),
682
+ definition: compileSparkline(
683
+ rows,
684
+ full,
685
+ mark,
686
+ color,
687
+ end,
688
+ ref,
689
+ referenceLabel,
690
+ bandSpan,
691
+ bandSpan !== null && bandEdges,
692
+ ),
615
693
  }
616
- }, [data, mark, color, emphasizeLast, emphasisColor, reference, referenceLabel])
694
+ }, [data, mark, color, emphasizeLast, emphasisColor, reference, referenceLabel, bandFrom, bandTo])
617
695
  const resolved = resolveChartState(state)
618
696
  const rows = model?.rows
619
697
  const interactive = resolved === null && model !== null
@@ -736,6 +814,7 @@ export function Sparkline(props: SparklineProps): ReactElement {
736
814
  <div
737
815
  data-basalt-sparkline=""
738
816
  {...(hosted && { 'data-basalt-hosted': '' })}
817
+ {...(shown && { 'data-basalt-readout': '' })}
739
818
  role="presentation"
740
819
  className={cx(classes.root, className)}
741
820
  style={{ width: width ?? '100%', height, minWidth: 0, ...style }}
@@ -748,7 +827,14 @@ export function Sparkline(props: SparklineProps): ReactElement {
748
827
  setKeyed(null)
749
828
  }}
750
829
  >
751
- {resolved !== null && <ChartPlaceholder state={state} height={height} compact />}
830
+ {resolved !== null && (
831
+ <ChartPlaceholder
832
+ state={state}
833
+ height={height}
834
+ compact
835
+ ghost={mark === 'bar' ? 'bars' : 'line'}
836
+ />
837
+ )}
752
838
  {resolved === null && model !== null && (
753
839
  <ChartEngine
754
840
  definition={model.definition}
@@ -758,7 +844,7 @@ export function Sparkline(props: SparklineProps): ReactElement {
758
844
  coarse={false}
759
845
  />
760
846
  )}
761
- {at !== null && (
847
+ {shown && at !== null && (
762
848
  // One layer on the plot rect (inside a line's margin): the dot and the readout take their
763
849
  // fractions of the same box, so both land where the mark did. A bar has no dot: the bar
764
850
  // is the marker.
@@ -125,6 +125,16 @@
125
125
  stroke-linejoin: round;
126
126
  }
127
127
 
128
+ .ghostBand {
129
+ flex: 1 1 0;
130
+ min-width: 0;
131
+ align-self: stretch;
132
+ /* The loaded strip is one row above its axis labels: the row keeps their room. */
133
+ margin-bottom: var(--basalt-ghost-band-axis, 1.5rem);
134
+ border-radius: 3px;
135
+ background: color-mix(in srgb, var(--vx-ink) 18%, var(--vx-surface-panel));
136
+ }
137
+
128
138
  .ghostBar {
129
139
  flex: 1 1 0;
130
140
  min-width: 0;
@@ -132,6 +142,46 @@
132
142
  background: color-mix(in srgb, var(--vx-ink) 18%, var(--vx-surface-panel));
133
143
  }
134
144
 
145
+ /*
146
+ * The empty body (SPEC § 6.11): a ring-edged tile (one inset ring, set inline in `state.tsx` so the divider ledger does not read it as a rule; card radius) filling the chart's
147
+ * own box, so the D37 height holds, with its copy centred: the title at `sm` 500, the size of the
148
+ * host's own title in every chart host, and one muted line. `EmptyState`'s section anatomy, in plain CSS
149
+ * because `src/charts/**` is Mantine-free.
150
+ */
151
+ .emptyTile {
152
+ box-sizing: border-box;
153
+ display: flex;
154
+ flex-direction: column;
155
+ align-items: center;
156
+ justify-content: center;
157
+ gap: var(--vx-space-stack-xs, 0.25rem);
158
+ width: 100%;
159
+ height: 100%;
160
+ padding: var(--vx-space-stack-md) var(--vx-space-stack-lg);
161
+ overflow: hidden;
162
+ text-align: center;
163
+ border-radius: var(--vx-radius-card);
164
+ }
165
+
166
+ .emptyCopy {
167
+ display: flex;
168
+ flex-direction: column;
169
+ align-items: center;
170
+ gap: var(--vx-space-stack-xs, 0.25rem);
171
+ }
172
+
173
+ .emptyTitle {
174
+ font-size: var(--vx-text-sm);
175
+ font-weight: 500;
176
+ color: var(--vx-ink);
177
+ }
178
+
179
+ .emptyText {
180
+ max-width: 22.5rem;
181
+ font-size: var(--vx-text-sm);
182
+ color: var(--vx-muted);
183
+ }
184
+
135
185
  /*
136
186
  * The engine paints its tooltip rows as a grid of `.55rem | minmax(0, 1fr) | auto` with inline
137
187
  * styles and `overflow-wrap: anywhere` on the card, so a narrow tooltip (a 390 viewport, a pointer
@@ -167,6 +217,14 @@
167
217
  var(--vx-surface-elevated) !important;
168
218
  }
169
219
 
220
+ /* The engine focuses the plot's `svg.ts-chart` (tabindex 0), not the `.basalt-chart` wrapper
221
+ * `styles.css` rings, so the UA's `auto` ring paints (a 5px white double ring in dark): the same
222
+ * 2px accent ring at the same offset, which the slotted chip clears (`SLOT_RING_CLEARANCE`). */
223
+ :global(.basalt-chart .ts-chart:focus-visible) {
224
+ outline: 2px solid var(--vx-accent);
225
+ outline-offset: calc(0.125rem * var(--mantine-scale));
226
+ }
227
+
170
228
  /*
171
229
  * A slotted `Bars` (`data-basalt-slot`, set by `compile.ts`) is a micro-visual: its tooltip is the
172
230
  * Sparkline's one-line chip, `<value> · <x label>` in the line the host reserves above the plot. The
@@ -179,15 +237,15 @@
179
237
  align-items: center;
180
238
  box-sizing: border-box;
181
239
  width: max-content;
182
- /* The line the cell reserves (1.125rem) less the focus ring's clearance (2px outline + 0.125rem offset), so
240
+ /* The line the cell reserves (1.125rem) less the focus ring's clearance (2px outline + 0.125rem offset) and 1px of air, so
183
241
  * the chip sits clear of the ring and still inside the reserve. */
184
- block-size: calc(1.125rem - 0.25rem);
242
+ block-size: calc(1.125rem - 0.3125rem);
185
243
  padding: 0 4px !important;
186
244
  overflow: hidden;
187
245
  font-family: var(--basalt-font-numeral, var(--basalt-font-sans));
188
246
  font-variant-numeric: lining-nums;
189
247
  font-size: var(--vx-text-xs);
190
- line-height: calc(1.125rem - 0.25rem - 2px);
248
+ line-height: calc(1.125rem - 0.3125rem - 2px);
191
249
  white-space: nowrap !important;
192
250
  border-radius: var(--vx-radius-ctrl) !important;
193
251
  /* theme-allow css-raw-surface — the chip is flat, like the Sparkline's, not a floating panel */
@@ -213,6 +271,14 @@
213
271
  display: none;
214
272
  }
215
273
 
274
+ /* The engine's series swatch is a block above the figure: it stacks the row taller than the chip and the
275
+ * figure's lower half falls under the chip's `overflow: hidden`. `!important`: the engine sets the
276
+ * swatch's `display` with a rule this one cannot out-rank by specificity alone (measured: the swatch
277
+ * stayed `block` under a plain selector). */
278
+ :global(.ts-chart-tooltip[data-basalt-slot] .ts-chart-tooltip__swatch) {
279
+ display: none !important;
280
+ }
281
+
216
282
  :global(.ts-chart-tooltip[data-basalt-slot] .ts-chart-tooltip__title) {
217
283
  display: block !important;
218
284
  flex: 0 1 auto;
@@ -11,6 +11,11 @@ declare const classes: {
11
11
  readonly grow: string
12
12
  readonly ghost: string
13
13
  readonly ghostLine: string
14
+ readonly ghostBand: string
14
15
  readonly ghostBar: string
16
+ readonly emptyTile: string
17
+ readonly emptyCopy: string
18
+ readonly emptyTitle: string
19
+ readonly emptyText: string
15
20
  }
16
21
  export default classes
@@ -1,9 +1,8 @@
1
1
  /*
2
2
  * ChartCard's header inset, by the card's own inline size (W10 SSR contract). A card under 480px
3
- * trims the header's top inset: the subtitle has already folded into the info glyph there, and the
4
- * chart below is sized by the 160–420px law, so a narrow card is a short one. Decided in CSS, not
5
- * from a post-hydration height measurement, so the server HTML is the hydrated header. The literal
6
- * is CONTAINER_CLASSES.regular (`breakpoint-literals.test.ts`).
3
+ * trims the header's top inset: the chart below is sized by the 160–420px law, so a narrow card is
4
+ * a short one. Decided in CSS, not from a post-hydration height measurement, so the server HTML is
5
+ * the hydrated header. The literal is CONTAINER_CLASSES.regular (`breakpoint-literals.test.ts`).
7
6
  */
8
7
 
9
8
  .header {
@@ -129,3 +128,12 @@
129
128
  border-radius: 3px;
130
129
  background: color-mix(in srgb, var(--vx-ink) 18%, var(--vx-surface-panel));
131
130
  }
131
+
132
+ /* A pending `BandStrip` card keeps the room of the legend row the loaded strip carries under its box:
133
+ * the chart root's 6px gap plus one legend line (`micro` x 1.35 and the 2px entry border, `legend.tsx`).
134
+ * The legend shows from 240px, the same container class the chart picks it by. */
135
+ @container basalt-card (min-width: 240px) {
136
+ .legendReserve {
137
+ padding-bottom: calc(6px + var(--vx-text-micro) * 1.35 + 2px);
138
+ }
139
+ }
@@ -13,5 +13,6 @@ declare const classes: {
13
13
  readonly factPeriod: string
14
14
  readonly skeletonFigure: string
15
15
  readonly skeletonBasis: string
16
+ readonly legendReserve: string
16
17
  }
17
18
  export default classes