basalt-ui 2.27.2 → 2.29.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 (343) hide show
  1. package/CHANGELOG.md +466 -307
  2. package/MIGRATING.md +358 -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-app/SKILL.md +3 -3
  7. package/agent/skills/basalt-charts/SKILL.md +1 -1
  8. package/agent/skills/basalt-design/SKILL.md +12 -6
  9. package/agent/skills/basalt-design/references/catalogue.md +42 -36
  10. package/agent/skills/basalt-design/references/recipes.md +47 -0
  11. package/agent/skills/basalt-design/references/states.md +1 -1
  12. package/configs/oxlint-basalt.json +2 -1
  13. package/configs/oxlint-plugin.js +112 -3
  14. package/configs/oxlint-plugin.test.ts +99 -4
  15. package/configs/oxlint.json +1 -0
  16. package/dist/agent/chat/thread-message.d.ts +1 -160
  17. package/dist/agent/chat/thread-message.d.ts.map +1 -1
  18. package/dist/agent/chat/thread-message.js +7 -162
  19. package/dist/agent/chat/virtualize.d.ts +5 -5
  20. package/dist/charts/ChartCard.d.ts +14 -7
  21. package/dist/charts/ChartCard.d.ts.map +1 -1
  22. package/dist/charts/ChartCard.js +112 -23
  23. package/dist/charts/Lines.d.ts.map +1 -1
  24. package/dist/charts/Lines.js +11 -4
  25. package/dist/charts/Sparkline.d.ts +14 -2
  26. package/dist/charts/Sparkline.d.ts.map +1 -1
  27. package/dist/charts/Sparkline.js +155 -44
  28. package/dist/charts/chart-box.module.css +59 -2
  29. package/dist/charts/chart-box.module.css.d.ts +5 -0
  30. package/dist/charts/chart-card.module.css +28 -17
  31. package/dist/charts/chart-card.module.css.d.ts +3 -0
  32. package/dist/charts/compile.d.ts +1 -1
  33. package/dist/charts/compile.d.ts.map +1 -1
  34. package/dist/charts/compile.js +38 -27
  35. package/dist/charts/labels.d.ts +13 -3
  36. package/dist/charts/labels.d.ts.map +1 -1
  37. package/dist/charts/labels.js +131 -20
  38. package/dist/charts/legend.d.ts.map +1 -1
  39. package/dist/charts/legend.js +1 -1
  40. package/dist/charts/ref-label.d.ts +37 -8
  41. package/dist/charts/ref-label.d.ts.map +1 -1
  42. package/dist/charts/ref-label.js +55 -10
  43. package/dist/charts/sparkline.module.css +50 -0
  44. package/dist/charts/sparkline.module.css.d.ts +3 -0
  45. package/dist/charts/state.d.ts +4 -4
  46. package/dist/charts/state.d.ts.map +1 -1
  47. package/dist/charts/state.js +23 -5
  48. package/dist/cli/doctor-upgrade.d.ts +11 -0
  49. package/dist/cli/doctor-upgrade.d.ts.map +1 -1
  50. package/dist/cli/doctor-upgrade.js +54 -0
  51. package/dist/cli/doctor.d.ts.map +1 -1
  52. package/dist/cli/doctor.js +32 -0
  53. package/dist/cli/help.d.ts.map +1 -1
  54. package/dist/cli/help.js +8 -3
  55. package/dist/cli/index.d.ts +13 -13
  56. package/dist/cli/index.d.ts.map +1 -1
  57. package/dist/cli/index.js +36 -2
  58. package/dist/cli/init.d.ts +6 -0
  59. package/dist/cli/init.d.ts.map +1 -1
  60. package/dist/cli/init.js +118 -27
  61. package/dist/cli/router-wiring.d.ts +3 -0
  62. package/dist/cli/router-wiring.d.ts.map +1 -1
  63. package/dist/cli/router-wiring.js +2 -0
  64. package/dist/cli/shot/capture.d.ts +34 -2
  65. package/dist/cli/shot/capture.d.ts.map +1 -1
  66. package/dist/cli/shot/capture.js +95 -12
  67. package/dist/cli/shot/detect.d.ts +4 -1
  68. package/dist/cli/shot/detect.d.ts.map +1 -1
  69. package/dist/cli/shot/detect.js +38 -16
  70. package/dist/cli/shot/index.d.ts.map +1 -1
  71. package/dist/cli/shot/index.js +9 -2
  72. package/dist/cli/shot/measure.d.ts.map +1 -1
  73. package/dist/cli/shot/measure.js +11 -2
  74. package/dist/cli/shot/types.d.ts +4 -1
  75. package/dist/cli/shot/types.d.ts.map +1 -1
  76. package/dist/cli/sync.d.ts.map +1 -1
  77. package/dist/cli/sync.js +10 -2
  78. package/dist/common/could-not-load.d.ts +13 -0
  79. package/dist/common/could-not-load.d.ts.map +1 -0
  80. package/dist/common/could-not-load.js +14 -0
  81. package/dist/common/empty-copy.d.ts +16 -0
  82. package/dist/common/empty-copy.d.ts.map +1 -0
  83. package/dist/common/empty-copy.js +9 -0
  84. package/dist/common/index.d.ts +1 -0
  85. package/dist/common/index.d.ts.map +1 -1
  86. package/dist/common/index.js +3 -0
  87. package/dist/common/props.d.ts +20 -0
  88. package/dist/common/props.d.ts.map +1 -1
  89. package/dist/common/props.js +13 -1
  90. package/dist/common/retry-button.module.css +7 -3
  91. package/dist/common/virtual-rows.d.ts +196 -0
  92. package/dist/common/virtual-rows.d.ts.map +1 -0
  93. package/dist/common/virtual-rows.js +290 -0
  94. package/dist/controls/controls.module.css +33 -1
  95. package/dist/controls/controls.module.css.d.ts +2 -0
  96. package/dist/controls/enum-filter.d.ts.map +1 -1
  97. package/dist/controls/enum-filter.js +8 -2
  98. package/dist/controls/filter-pill.d.ts +27 -3
  99. package/dist/controls/filter-pill.d.ts.map +1 -1
  100. package/dist/controls/filter-pill.js +15 -4
  101. package/dist/controls/form-layout.d.ts +9 -3
  102. package/dist/controls/form-layout.d.ts.map +1 -1
  103. package/dist/controls/form-layout.js +74 -12
  104. package/dist/controls/form-layout.module.css +112 -7
  105. package/dist/controls/form-layout.module.css.d.ts +1 -0
  106. package/dist/controls/multi-select-filter.d.ts +2 -2
  107. package/dist/controls/multi-select-filter.d.ts.map +1 -1
  108. package/dist/controls/multi-select-filter.js +12 -6
  109. package/dist/controls/range-filter.d.ts +1 -1
  110. package/dist/controls/range-filter.d.ts.map +1 -1
  111. package/dist/controls/range-filter.js +8 -2
  112. package/dist/dashboard/bar-list.d.ts +5 -5
  113. package/dist/dashboard/bar-list.d.ts.map +1 -1
  114. package/dist/dashboard/bar-list.js +15 -8
  115. package/dist/dashboard/bar-list.module.css +21 -5
  116. package/dist/dashboard/board-nav.d.ts +22 -0
  117. package/dist/dashboard/board-nav.d.ts.map +1 -0
  118. package/dist/dashboard/board-nav.js +49 -0
  119. package/dist/dashboard/board.d.ts +52 -0
  120. package/dist/dashboard/board.d.ts.map +1 -0
  121. package/dist/dashboard/board.js +247 -0
  122. package/dist/dashboard/board.module.css +179 -0
  123. package/dist/dashboard/board.module.css.d.ts +28 -0
  124. package/dist/dashboard/empty-state.d.ts +6 -6
  125. package/dist/dashboard/empty-state.d.ts.map +1 -1
  126. package/dist/dashboard/empty-state.js +17 -8
  127. package/dist/dashboard/event-list-model.d.ts +54 -0
  128. package/dist/dashboard/event-list-model.d.ts.map +1 -0
  129. package/dist/dashboard/event-list-model.js +76 -0
  130. package/dist/dashboard/event-list-rows.d.ts +23 -0
  131. package/dist/dashboard/event-list-rows.d.ts.map +1 -0
  132. package/dist/dashboard/event-list-rows.js +89 -0
  133. package/dist/dashboard/event-list-scroll.d.ts +55 -0
  134. package/dist/dashboard/event-list-scroll.d.ts.map +1 -0
  135. package/dist/dashboard/event-list-scroll.js +216 -0
  136. package/dist/dashboard/event-list-skeleton.d.ts +10 -0
  137. package/dist/dashboard/event-list-skeleton.d.ts.map +1 -0
  138. package/dist/dashboard/event-list-skeleton.js +34 -0
  139. package/dist/dashboard/event-list.d.ts +65 -0
  140. package/dist/dashboard/event-list.d.ts.map +1 -0
  141. package/dist/dashboard/event-list.js +208 -0
  142. package/dist/dashboard/event-list.module.css +336 -0
  143. package/dist/dashboard/event-list.module.css.d.ts +34 -0
  144. package/dist/dashboard/index.d.ts +2 -0
  145. package/dist/dashboard/index.d.ts.map +1 -1
  146. package/dist/dashboard/index.js +4 -0
  147. package/dist/dashboard/meter-model.d.ts +6 -3
  148. package/dist/dashboard/meter-model.d.ts.map +1 -1
  149. package/dist/dashboard/meter-model.js +9 -4
  150. package/dist/dashboard/meter-parts.d.ts +3 -0
  151. package/dist/dashboard/meter-parts.d.ts.map +1 -1
  152. package/dist/dashboard/meter-parts.js +36 -6
  153. package/dist/dashboard/meter.d.ts +3 -3
  154. package/dist/dashboard/meter.d.ts.map +1 -1
  155. package/dist/dashboard/meter.js +10 -2
  156. package/dist/dashboard/meter.module.css +20 -12
  157. package/dist/dashboard/meter.module.css.d.ts +0 -1
  158. package/dist/dashboard/page-summary.d.ts +3 -3
  159. package/dist/dashboard/page-summary.d.ts.map +1 -1
  160. package/dist/dashboard/page-summary.js +7 -2
  161. package/dist/dashboard/page-summary.module.css +5 -2
  162. package/dist/dashboard/query-state.d.ts +9 -8
  163. package/dist/dashboard/query-state.d.ts.map +1 -1
  164. package/dist/dashboard/query-state.js +29 -11
  165. package/dist/dashboard/section.d.ts +11 -3
  166. package/dist/dashboard/section.d.ts.map +1 -1
  167. package/dist/dashboard/section.js +34 -7
  168. package/dist/dashboard/settings-section.d.ts +8 -5
  169. package/dist/dashboard/settings-section.d.ts.map +1 -1
  170. package/dist/dashboard/settings-section.js +12 -8
  171. package/dist/dashboard/settings-section.module.css +25 -4
  172. package/dist/dashboard/settings-section.module.css.d.ts +1 -0
  173. package/dist/dashboard/stat-card-parts.d.ts +5 -1
  174. package/dist/dashboard/stat-card-parts.d.ts.map +1 -1
  175. package/dist/dashboard/stat-card-parts.js +8 -3
  176. package/dist/dashboard/stat-card.d.ts +3 -3
  177. package/dist/dashboard/stat-card.d.ts.map +1 -1
  178. package/dist/dashboard/stat-card.js +47 -12
  179. package/dist/dashboard/stat-card.module.css +42 -7
  180. package/dist/dashboard/stat-card.module.css.d.ts +3 -0
  181. package/dist/dashboard/stat-group.d.ts +2 -2
  182. package/dist/dashboard/stat-group.d.ts.map +1 -1
  183. package/dist/dashboard/stat-group.js +10 -3
  184. package/dist/dashboard/stat-strip.d.ts +5 -4
  185. package/dist/dashboard/stat-strip.d.ts.map +1 -1
  186. package/dist/dashboard/stat-strip.js +41 -31
  187. package/dist/dashboard/stat-strip.module.css +8 -6
  188. package/dist/dashboard/visual-slot.d.ts +4 -0
  189. package/dist/dashboard/visual-slot.d.ts.map +1 -1
  190. package/dist/dashboard/visual-slot.js +2 -0
  191. package/dist/dashboard/widget-header.d.ts +6 -6
  192. package/dist/dashboard/widget-header.d.ts.map +1 -1
  193. package/dist/dashboard/widget-header.js +4 -2
  194. package/dist/dashboard/widget-header.module.css +12 -15
  195. package/dist/format/shared.d.ts.map +1 -1
  196. package/dist/format/shared.js +24 -1
  197. package/dist/guard/index.d.ts +1 -1
  198. package/dist/guard/index.d.ts.map +1 -1
  199. package/dist/guard/index.js +4 -1
  200. package/dist/index.d.ts +1 -1
  201. package/dist/index.d.ts.map +1 -1
  202. package/dist/index.js +4 -0
  203. package/dist/shell/app-main.module.css +18 -0
  204. package/dist/styles.css +69 -0
  205. package/dist/surfaces.d.ts +2 -2
  206. package/dist/surfaces.d.ts.map +1 -1
  207. package/dist/surfaces.js +8 -2
  208. package/dist/table/cell-kinds.d.ts +47 -0
  209. package/dist/table/cell-kinds.d.ts.map +1 -0
  210. package/dist/table/cell-kinds.js +180 -0
  211. package/dist/table/cell-kinds.module.css +55 -0
  212. package/dist/table/cell-kinds.module.css.d.ts +15 -0
  213. package/dist/table/data-table-fold.d.ts +155 -0
  214. package/dist/table/data-table-fold.d.ts.map +1 -0
  215. package/dist/table/data-table-fold.js +320 -0
  216. package/dist/table/data-table-state.d.ts +10 -3
  217. package/dist/table/data-table-state.d.ts.map +1 -1
  218. package/dist/table/data-table-state.js +11 -6
  219. package/dist/table/data-table.d.ts +13 -28
  220. package/dist/table/data-table.d.ts.map +1 -1
  221. package/dist/table/data-table.js +362 -255
  222. package/dist/table/data-table.module.css +282 -3
  223. package/dist/table/data-table.module.css.d.ts +16 -0
  224. package/dist/table/table-features.d.ts +34 -4
  225. package/dist/table/table-features.d.ts.map +1 -1
  226. package/dist/table/table-features.js +10 -0
  227. package/dist/theme/card-inset.module.css +35 -0
  228. package/dist/theme/controls.module.css +55 -2
  229. package/dist/theme/ctl-theme.d.ts.map +1 -1
  230. package/dist/theme/ctl-theme.js +5 -0
  231. package/dist/theme/index.d.ts.map +1 -1
  232. package/dist/theme/index.js +14 -10
  233. package/dist/tokens/core.d.ts +1 -0
  234. package/dist/tokens/core.d.ts.map +1 -1
  235. package/dist/tokens/core.js +1 -0
  236. package/dist/tokens/derive.js +1 -1
  237. package/dist/tokens/palette.d.ts +2 -1
  238. package/dist/tokens/palette.d.ts.map +1 -1
  239. package/llms.txt +295 -5
  240. package/package.json +1 -1
  241. package/src/agent/chat/thread-message.tsx +10 -403
  242. package/src/agent/chat/virtualize.ts +5 -5
  243. package/src/charts/ChartCard.tsx +175 -31
  244. package/src/charts/Lines.tsx +13 -4
  245. package/src/charts/Sparkline.tsx +213 -48
  246. package/src/charts/chart-box.module.css +59 -2
  247. package/src/charts/chart-box.module.css.d.ts +5 -0
  248. package/src/charts/chart-card.module.css +28 -17
  249. package/src/charts/chart-card.module.css.d.ts +3 -0
  250. package/src/charts/compile.ts +59 -33
  251. package/src/charts/labels.ts +175 -24
  252. package/src/charts/legend.tsx +3 -2
  253. package/src/charts/ref-label.ts +114 -18
  254. package/src/charts/sparkline.module.css +50 -0
  255. package/src/charts/sparkline.module.css.d.ts +3 -0
  256. package/src/charts/state.tsx +40 -10
  257. package/src/cli/doctor-upgrade.ts +75 -0
  258. package/src/cli/doctor.ts +36 -0
  259. package/src/cli/help.ts +16 -6
  260. package/src/cli/index.ts +73 -67
  261. package/src/cli/init.ts +157 -36
  262. package/src/cli/router-wiring.ts +2 -2
  263. package/src/cli/shot/capture.ts +138 -16
  264. package/src/cli/shot/detect.ts +46 -22
  265. package/src/cli/shot/index.ts +8 -2
  266. package/src/cli/shot/measure.ts +11 -2
  267. package/src/cli/shot/types.ts +4 -1
  268. package/src/cli/sync.ts +12 -2
  269. package/src/common/could-not-load.ts +22 -0
  270. package/src/common/empty-copy.ts +17 -0
  271. package/src/common/index.ts +1 -0
  272. package/src/common/props.ts +30 -0
  273. package/src/common/retry-button.module.css +7 -3
  274. package/src/common/virtual-rows.tsx +682 -0
  275. package/src/controls/controls.module.css +33 -1
  276. package/src/controls/controls.module.css.d.ts +2 -0
  277. package/src/controls/enum-filter.tsx +8 -2
  278. package/src/controls/filter-pill.tsx +80 -27
  279. package/src/controls/form-layout.module.css +112 -7
  280. package/src/controls/form-layout.module.css.d.ts +1 -0
  281. package/src/controls/form-layout.tsx +115 -22
  282. package/src/controls/multi-select-filter.tsx +22 -11
  283. package/src/controls/range-filter.tsx +9 -3
  284. package/src/dashboard/bar-list.module.css +21 -5
  285. package/src/dashboard/bar-list.tsx +53 -45
  286. package/src/dashboard/board-nav.ts +67 -0
  287. package/src/dashboard/board.module.css +179 -0
  288. package/src/dashboard/board.module.css.d.ts +28 -0
  289. package/src/dashboard/board.tsx +415 -0
  290. package/src/dashboard/empty-state.tsx +21 -11
  291. package/src/dashboard/event-list-model.ts +125 -0
  292. package/src/dashboard/event-list-rows.tsx +117 -0
  293. package/src/dashboard/event-list-scroll.ts +291 -0
  294. package/src/dashboard/event-list-skeleton.tsx +62 -0
  295. package/src/dashboard/event-list.module.css +336 -0
  296. package/src/dashboard/event-list.module.css.d.ts +34 -0
  297. package/src/dashboard/event-list.tsx +336 -0
  298. package/src/dashboard/index.ts +2 -0
  299. package/src/dashboard/meter-model.ts +16 -7
  300. package/src/dashboard/meter-parts.tsx +53 -14
  301. package/src/dashboard/meter.module.css +20 -12
  302. package/src/dashboard/meter.module.css.d.ts +0 -1
  303. package/src/dashboard/meter.tsx +36 -18
  304. package/src/dashboard/page-summary.module.css +5 -2
  305. package/src/dashboard/page-summary.tsx +13 -6
  306. package/src/dashboard/query-state.tsx +55 -30
  307. package/src/dashboard/section.tsx +83 -41
  308. package/src/dashboard/settings-section.module.css +25 -4
  309. package/src/dashboard/settings-section.module.css.d.ts +1 -0
  310. package/src/dashboard/settings-section.tsx +18 -8
  311. package/src/dashboard/stat-card-parts.tsx +20 -3
  312. package/src/dashboard/stat-card.module.css +42 -7
  313. package/src/dashboard/stat-card.module.css.d.ts +3 -0
  314. package/src/dashboard/stat-card.tsx +55 -13
  315. package/src/dashboard/stat-group.tsx +22 -14
  316. package/src/dashboard/stat-strip.module.css +8 -6
  317. package/src/dashboard/stat-strip.tsx +29 -20
  318. package/src/dashboard/visual-slot.ts +5 -0
  319. package/src/dashboard/widget-header.module.css +12 -15
  320. package/src/dashboard/widget-header.tsx +8 -5
  321. package/src/format/shared.ts +30 -1
  322. package/src/guard/index.ts +7 -1
  323. package/src/index.ts +4 -0
  324. package/src/shell/app-main.module.css +18 -0
  325. package/src/styles.css +69 -0
  326. package/src/surfaces.ts +7 -1
  327. package/src/table/cell-kinds.module.css +55 -0
  328. package/src/table/cell-kinds.module.css.d.ts +15 -0
  329. package/src/table/cell-kinds.tsx +263 -0
  330. package/src/table/data-table-fold.tsx +567 -0
  331. package/src/table/data-table-state.ts +24 -13
  332. package/src/table/data-table.module.css +282 -3
  333. package/src/table/data-table.module.css.d.ts +16 -0
  334. package/src/table/data-table.tsx +430 -362
  335. package/src/table/table-features.ts +44 -4
  336. package/src/theme/__snapshots__/plain-theme.test.ts.snap +2 -66
  337. package/src/theme/card-inset.module.css +35 -0
  338. package/src/theme/controls.module.css +55 -2
  339. package/src/theme/ctl-theme.tsx +8 -0
  340. package/src/theme/index.ts +12 -8
  341. package/src/tokens/core.ts +1 -0
  342. package/src/tokens/derive.ts +1 -1
  343. package/src/tokens/palette.ts +4 -1
@@ -8,15 +8,20 @@
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
- import { cx } from '../common/props'
15
- import type { BasaltProps, SlotStylesProps } from '../common/props'
14
+ import { HostTitleContext } from '../common/could-not-load'
15
+ import { cx, splitDataAttributes } from '../common/props'
16
+ import type { BasaltProps, DataAttributes, SlotStylesProps } from '../common/props'
17
+ import { DeltaBadge } from '../dashboard/delta-badge'
16
18
  import type { DeltaPolarity } from '../dashboard/delta-badge'
17
19
  import { WidgetHeader } from '../dashboard/widget-header'
18
20
  import { VX } from '../tokens'
19
21
  import { ChartCardContext } from './card-context'
22
+ import { BandStrip } from './BandStrip'
23
+ import { Lines } from './Lines'
24
+ import { StackedArea } from './StackedArea'
20
25
  import classes from './chart-card.module.css'
21
26
  import { ChartPlaceholder, resolveChartState } from './state'
22
27
  import type { ChartState, ResponsiveChartHeight } from './types'
@@ -27,6 +32,9 @@ import type { ChartState, ResponsiveChartHeight } from './types'
27
32
  const cardStyle: CSSProperties = {
28
33
  display: 'flex',
29
34
  flexDirection: 'column',
35
+ // Fills its grid cell (or a `h="100%"` anchor wrapper): two cards in one row end together, with
36
+ // no wrapper background under the shorter one. In an auto-height parent it resolves to auto.
37
+ height: '100%',
30
38
  minHeight: 0,
31
39
  containerType: 'inline-size',
32
40
  containerName: 'basalt-card',
@@ -101,6 +109,28 @@ function periodText(period: string | readonly string[], afterUnit: boolean): str
101
109
  return afterUnit && !text.startsWith(PERIOD_SEPARATOR.trim()) ? PERIOD_SEPARATOR + text : text
102
110
  }
103
111
 
112
+ /** A comparison that renders something: `cond && <DeltaBadge />` leaves `false`, `null` or `''`. */
113
+ const hasComparison = (node: ReactNode): boolean =>
114
+ node !== undefined && node !== null && node !== false && node !== ''
115
+
116
+ /**
117
+ * A plain-text comparison with a leading sign ("+0.3", "-4%") reads as a delta: the sign becomes
118
+ * DeltaBadge's direction glyph (▲/▼). Any other node (a `DeltaBadge`, which carries its own) is as is.
119
+ */
120
+ function Comparison({ node }: { node: ReactNode }): ReactNode {
121
+ if (typeof node !== 'string') return node
122
+ const sign = /^\s*([+\-−])\s*(.+)$/.exec(node)
123
+ if (sign === null) return node
124
+ return (
125
+ <>
126
+ <span aria-hidden="true" className={classes.factGlyph}>
127
+ {sign[1] === '+' ? '▲' : '▼'}
128
+ </span>
129
+ {sign[2]}
130
+ </>
131
+ )
132
+ }
133
+
104
134
  /** One headline figure: the value is the hero, then its unit, a comparison node and the period. */
105
135
  export type ChartFact = {
106
136
  value: ReactNode
@@ -110,7 +140,9 @@ export type ChartFact = {
110
140
  /** Plain text the figure covers, e.g. `last 30 d`. A list is joined by ` · ` (`['last entry 3 d
111
141
  * ago', '12 entries']`) and, behind a `unit`, led by one. */
112
142
  period?: string | readonly string[] | undefined
113
- /** Ink for the whole fact (text only, never a fill): a stale or off-target figure reads `warn`. */
143
+ /** Ink for the comparison, with its direction glyph (text only, never a fill): an off-target
144
+ * change reads `warn`. A fact with no comparison inks its value instead. A `DeltaBadge` comparison keeps
145
+ * its own polarity ink (it is inline), so `tone` is for plain-text comparisons. */
114
146
  tone?: ChartFactTone | undefined
115
147
  }
116
148
 
@@ -121,6 +153,7 @@ export type ChartFactTone = 'good' | 'warn' | 'bad' | 'muted'
121
153
  export type ChartCardSlot = 'root' | 'header' | 'body'
122
154
 
123
155
  type ChartCardBaseProps = BasaltProps &
156
+ DataAttributes &
124
157
  SlotStylesProps<ChartCardSlot> & {
125
158
  title?: string | undefined
126
159
  icon?: ReactNode
@@ -153,11 +186,16 @@ type ChartCardBaseProps = BasaltProps &
153
186
  * fallback>` should pass a numeric height instead. */
154
187
  placeholderHeight?: number | ResponsiveChartHeight | 'content' | undefined
155
188
  /** 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
189
+ * count when the loaded chart's data length is known, `'band'` for a `BandStrip`. Omitted, a
190
+ * `Lines` or `StackedArea` body (bare, or inside plain elements) loads as a line, a `BandStrip`
191
+ * as one band row at its own `height`; a body wrapped in your own component hides
192
+ * its kind from the card, so pass `ghost="line"` there. */
193
+ ghost?: 'bars' | 'line' | 'band' | number | undefined
158
194
  /** Placeholder data is showing: the facts row dims with the plot (a strip cell's `stale`). */
159
195
  stale?: boolean | undefined
160
- /** What an errored `state` names: "Could not load {stateNoun}". Default: no noun. */
196
+ /** What an errored `state` names: "Could not load {stateNoun}". Default: the card's `title`; with
197
+ * neither, the title is a bare "Could not load". A leading capital is lowercased unless the next
198
+ * character is a capital or a non-letter ("Revenue" → "revenue", "KPI" and "2024 sales" stay). */
161
199
  stateNoun?: string | undefined
162
200
  /** An errored `state` shows the shared Retry button (the one `ErrorState` renders). */
163
201
  onRetry?: (() => void) | undefined
@@ -186,6 +224,29 @@ export type ChartCardProps = ChartCardBaseProps &
186
224
  | { facts?: undefined }
187
225
  )
188
226
 
227
+ /** The legacy `value`/`delta` hero as the one fact the headline row draws. */
228
+ function legacyFact(header: {
229
+ value?: string | undefined
230
+ delta?: number | undefined
231
+ deltaPeriod?: string | undefined
232
+ deltaPolarity?: DeltaPolarity | undefined
233
+ }): ChartFact | undefined {
234
+ const { value, delta, deltaPeriod, deltaPolarity } = header
235
+ if (value === undefined && delta === undefined) return undefined
236
+ return {
237
+ value: value ?? null,
238
+ ...(delta !== undefined && {
239
+ comparison: (
240
+ <DeltaBadge
241
+ value={delta}
242
+ period={deltaPeriod}
243
+ {...(deltaPolarity !== undefined && { polarity: deltaPolarity })}
244
+ />
245
+ ),
246
+ }),
247
+ }
248
+ }
249
+
189
250
  /** Drops explicit `undefined`s: `WidgetHeader` is exact-optional, this props type is not. */
190
251
  const definedOnly = <T extends object>(o: T): { [K in keyof T]?: Exclude<T[K], undefined> } =>
191
252
  Object.fromEntries(Object.entries(o).filter(([, v]) => v !== undefined)) as {
@@ -221,11 +282,28 @@ function Facts({
221
282
  {...(f.tone !== undefined && { 'data-tone': f.tone })}
222
283
  className={classes.fact}
223
284
  >
224
- <span data-basalt-fact-value="" className={classes.factValue}>
225
- {f.value}
226
- </span>
285
+ {f.value !== null && f.value !== undefined && f.value !== '' && (
286
+ <span
287
+ data-basalt-fact-value=""
288
+ {...(!hasComparison(f.comparison) && { 'data-basalt-fact-tone': '' })}
289
+ className={cx(
290
+ classes.factValue,
291
+ !hasComparison(f.comparison) && classes.factTone,
292
+ )}
293
+ >
294
+ {f.value}
295
+ </span>
296
+ )}
227
297
  {f.unit !== undefined && <span className={classes.factUnit}>{f.unit}</span>}
228
- {f.comparison}
298
+ {hasComparison(f.comparison) && (
299
+ <span
300
+ data-basalt-fact-delta=""
301
+ data-basalt-fact-tone=""
302
+ className={classes.factTone}
303
+ >
304
+ <Comparison node={f.comparison} />
305
+ </span>
306
+ )}
229
307
  {period !== '' && <span className={classes.factPeriod}>{period}</span>}
230
308
  </span>
231
309
  )
@@ -252,6 +330,57 @@ function FactsSkeleton({ basis }: { basis: boolean }): ReactElement {
252
330
  )
253
331
  }
254
332
 
333
+ /** A stated `BandStrip` height the placeholder can take: a px number or the per-class object. */
334
+ function isChartHeight(value: unknown): value is number | ResponsiveChartHeight {
335
+ return (
336
+ typeof value === 'number' ||
337
+ (typeof value === 'object' &&
338
+ value !== null &&
339
+ typeof (value as { base?: unknown }).base === 'number')
340
+ )
341
+ }
342
+
343
+ type BodyKind = { ghost: 'line' | 'band'; height?: number | ResponsiveChartHeight; legend?: true }
344
+
345
+ /**
346
+ * What a pending body draws when `ghost` is not passed: a line for a `Lines` or `StackedArea` body,
347
+ * one band row at the strip's own `height` for a `BandStrip` (found through plain elements such as a
348
+ * `Box`), the default bars otherwise, so a loading chart is drawn as its kind, at its loaded height.
349
+ */
350
+ function bodyKindOf(node: ReactNode): BodyKind | undefined {
351
+ for (const child of Children.toArray(node)) {
352
+ if (!isValidElement<{ children?: ReactNode; height?: unknown }>(child)) continue
353
+ if (child.type === Lines || child.type === StackedArea) return { ghost: 'line' }
354
+ if (child.type === BandStrip) {
355
+ const { height, states, legend } = child.props as {
356
+ height?: unknown
357
+ states?: readonly unknown[]
358
+ legend?: unknown
359
+ }
360
+ return {
361
+ ghost: 'band',
362
+ ...(isChartHeight(height) && { height }),
363
+ // The loaded strip's legend row sits under the box: the ghost keeps its room.
364
+ ...(legend !== false && (states?.length ?? 0) > 1 && { legend: true as const }),
365
+ }
366
+ }
367
+ const inner = bodyKindOf(child.props.children)
368
+ if (inner !== undefined) return inner
369
+ }
370
+ return undefined
371
+ }
372
+
373
+ /** The loaded strip's legend row keeps its room under a pending box; other placeholders get no wrapper. */
374
+ function reserveLegend(reserve: boolean, placeholder: ReactElement): ReactElement {
375
+ return reserve ? (
376
+ <div className={classes.legendReserve} data-basalt-legend-reserve="">
377
+ {placeholder}
378
+ </div>
379
+ ) : (
380
+ placeholder
381
+ )
382
+ }
383
+
255
384
  export function ChartCard({
256
385
  actions,
257
386
  state,
@@ -267,25 +396,39 @@ export function ChartCard({
267
396
  style,
268
397
  children,
269
398
  facts,
270
- ...header
399
+ ...headerAndData
271
400
  }: ChartCardProps): ReactElement {
401
+ const { data, rest: header } = splitDataAttributes(headerAndData)
272
402
  const { ref, short } = useShortCard()
273
403
  const resolved = resolveChartState(state)
274
- const showFacts = facts !== undefined && resolved === null
275
- const skeletonFacts = facts !== undefined && resolved === 'pending'
404
+ // The noun an error names: `stateNoun`, else the card's own title ("Revenue" → "revenue").
405
+ const noun = stateNoun ?? header.title
406
+ const kind = resolved === 'pending' ? bodyKindOf(children) : undefined
407
+ const plotGhost = ghost ?? kind?.ghost
408
+ // `ghost` changes the shape only: the wrapped strip's height still sizes the pending box.
409
+ const pendingHeight = placeholderHeight ?? kind?.height
410
+ // One headline anatomy: the legacy `value`/`delta` hero is drawn as a fact (title, then value, delta
411
+ // and period in one baseline group), never pushed to the far edge of the title row.
412
+ const headline = facts ?? legacyFact(header)
413
+ const showFacts = headline !== undefined && resolved === null
414
+ const skeletonFacts = headline !== undefined && resolved === 'pending'
276
415
  const hasHeader =
277
416
  actions !== undefined ||
278
417
  showFacts ||
279
418
  skeletonFacts ||
280
419
  HEADER_TRIGGERS.some((k) => header[k] !== undefined)
281
420
  // With facts the subtitle is the basis line after them, not WidgetHeader's foldable row.
282
- const { subtitle, ...rest } = header
283
- const headerProps = facts === undefined ? header : rest
421
+ // The hero props are drawn by the facts row below, so `WidgetHeader` never sees them.
422
+ const { subtitle, value: _v, delta: _d, deltaPeriod: _p, deltaPolarity: _pol, ...rest } = header
423
+ const headerProps = headline === undefined ? header : rest
424
+
425
+ const hostBody = <HostTitleContext value={header.title}>{children}</HostTitleContext>
284
426
 
285
427
  return (
286
428
  <ChartCardContext.Provider value>
287
429
  <div
288
430
  ref={ref}
431
+ {...data}
289
432
  data-basalt-chart-card=""
290
433
  className={cx(classNames?.root, className)}
291
434
  style={{ ...cardStyle, ...style }}
@@ -293,7 +436,7 @@ export function ChartCard({
293
436
  {...(short && { 'data-basalt-card-short': '' })}
294
437
  >
295
438
  {hasHeader && (
296
- <div className={cx(classes.header, classNames?.header)}>
439
+ <div data-basalt-chart-header="" className={cx(classes.header, classNames?.header)}>
297
440
  <WidgetHeader
298
441
  tier="widget"
299
442
  {...definedOnly(headerProps)}
@@ -302,7 +445,7 @@ export function ChartCard({
302
445
  actions: <span data-basalt-tier="widget">{actions}</span>,
303
446
  })}
304
447
  />
305
- {showFacts && <Facts facts={facts} basis={subtitle} stale={stale} />}
448
+ {showFacts && <Facts facts={headline} basis={subtitle} stale={stale} />}
306
449
  {skeletonFacts && <FactsSkeleton basis={subtitle !== undefined} />}
307
450
  </div>
308
451
  )}
@@ -310,19 +453,20 @@ export function ChartCard({
310
453
  {...(classNames?.body !== undefined && { className: classNames.body })}
311
454
  style={bodyClipStyle}
312
455
  >
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
- )}
456
+ {resolved === null || (resolved === 'pending' && placeholderHeight === 'content')
457
+ ? hostBody
458
+ : reserveLegend(
459
+ kind?.legend === true,
460
+ <ChartPlaceholder
461
+ state={state}
462
+ {...(pendingHeight !== undefined && { height: pendingHeight })}
463
+ {...(noun !== undefined && { noun })}
464
+ {...(plotGhost !== undefined && { ghost: plotGhost })}
465
+ {...(onRetry !== undefined && { onRetry })}
466
+ {...(retrying !== undefined && { retrying })}
467
+ action={stateAction}
468
+ />,
469
+ )}
326
470
  </div>
327
471
  </div>
328
472
  </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 })}