basalt-ui 1.30.2 → 1.31.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 (334) hide show
  1. package/AGENTS.md +1 -1
  2. package/CHANGELOG.md +31 -0
  3. package/MIGRATING.md +172 -12
  4. package/agent/rules/basalt-controls.md +19 -19
  5. package/agent/rules/basalt-mantine.md +1 -1
  6. package/configs/oxlint-plugin.js +254 -4
  7. package/configs/oxlint-plugin.test.ts +145 -2
  8. package/configs/oxlint.json +2 -1
  9. package/dist/agent-chat/composer.d.ts.map +1 -1
  10. package/dist/agent-chat/composer.js +41 -43
  11. package/dist/agent-chat/thread-workspace.d.ts +2 -2
  12. package/dist/agent-chat/thread-workspace.d.ts.map +1 -1
  13. package/dist/agent-chat/thread-workspace.js +3 -4
  14. package/dist/agent-chat/use-keyboard-inset.d.ts +2 -0
  15. package/dist/agent-chat/use-keyboard-inset.d.ts.map +1 -0
  16. package/dist/agent-chat/use-keyboard-inset.js +34 -0
  17. package/dist/charts/cursor/touch-pin.d.ts +45 -0
  18. package/dist/charts/cursor/touch-pin.d.ts.map +1 -0
  19. package/dist/charts/cursor/touch-pin.js +79 -0
  20. package/dist/charts/hooks/use-discrete-cursor.d.ts +66 -0
  21. package/dist/charts/hooks/use-discrete-cursor.d.ts.map +1 -0
  22. package/dist/charts/hooks/use-discrete-cursor.js +198 -0
  23. package/dist/charts/hooks/use-hysteresis.d.ts +18 -0
  24. package/dist/charts/hooks/use-hysteresis.d.ts.map +1 -0
  25. package/dist/charts/hooks/use-hysteresis.js +12 -0
  26. package/dist/charts/hooks/useBandPlot.d.ts +7 -0
  27. package/dist/charts/hooks/useBandPlot.d.ts.map +1 -1
  28. package/dist/charts/hooks/useBandPlot.js +62 -18
  29. package/dist/charts/hooks/useChartCursor.d.ts +40 -11
  30. package/dist/charts/hooks/useChartCursor.d.ts.map +1 -1
  31. package/dist/charts/hooks/useChartCursor.js +102 -11
  32. package/dist/charts/index.d.ts +0 -1
  33. package/dist/charts/index.d.ts.map +1 -1
  34. package/dist/charts/index.js +0 -10
  35. package/dist/charts/kinds/BandStrip.d.ts.map +1 -1
  36. package/dist/charts/kinds/BandStrip.js +54 -41
  37. package/dist/charts/kinds/Donut.d.ts +9 -3
  38. package/dist/charts/kinds/Donut.d.ts.map +1 -1
  39. package/dist/charts/kinds/Donut.js +110 -48
  40. package/dist/charts/kinds/DualPanel.d.ts.map +1 -1
  41. package/dist/charts/kinds/DualPanel.js +145 -131
  42. package/dist/charts/kinds/Heatmap.d.ts +7 -0
  43. package/dist/charts/kinds/Heatmap.d.ts.map +1 -1
  44. package/dist/charts/kinds/Heatmap.js +37 -16
  45. package/dist/charts/kinds/MirroredBars.d.ts.map +1 -1
  46. package/dist/charts/kinds/MirroredBars.js +83 -68
  47. package/dist/charts/kinds/donut-layout.d.ts +47 -0
  48. package/dist/charts/kinds/donut-layout.d.ts.map +1 -0
  49. package/dist/charts/kinds/donut-layout.js +52 -0
  50. package/dist/charts/layout/auto-margin.d.ts +7 -2
  51. package/dist/charts/layout/auto-margin.d.ts.map +1 -1
  52. package/dist/charts/layout/auto-margin.js +12 -3
  53. package/dist/charts/layout/end-labels.d.ts +64 -0
  54. package/dist/charts/layout/end-labels.d.ts.map +1 -0
  55. package/dist/charts/layout/end-labels.js +76 -0
  56. package/dist/charts/primitives/Axes.d.ts +32 -4
  57. package/dist/charts/primitives/Axes.d.ts.map +1 -1
  58. package/dist/charts/primitives/Axes.js +62 -16
  59. package/dist/charts/primitives/CartesianChart.d.ts +7 -6
  60. package/dist/charts/primitives/CartesianChart.d.ts.map +1 -1
  61. package/dist/charts/primitives/CartesianChart.js +271 -125
  62. package/dist/charts/primitives/ChartCard.d.ts +0 -14
  63. package/dist/charts/primitives/ChartCard.d.ts.map +1 -1
  64. package/dist/charts/primitives/ChartCard.js +74 -21
  65. package/dist/charts/primitives/ChartFrame.d.ts +28 -22
  66. package/dist/charts/primitives/ChartFrame.d.ts.map +1 -1
  67. package/dist/charts/primitives/ChartFrame.js +133 -34
  68. package/dist/charts/primitives/ChartLegend.d.ts +19 -15
  69. package/dist/charts/primitives/ChartLegend.d.ts.map +1 -1
  70. package/dist/charts/primitives/ChartLegend.js +212 -71
  71. package/dist/charts/primitives/ChartTooltip.d.ts.map +1 -1
  72. package/dist/charts/primitives/ChartTooltip.js +4 -3
  73. package/dist/charts/primitives/Crosshair.js +2 -2
  74. package/dist/charts/primitives/HoverOverlay.d.ts +6 -1
  75. package/dist/charts/primitives/HoverOverlay.d.ts.map +1 -1
  76. package/dist/charts/primitives/HoverOverlay.js +37 -26
  77. package/dist/charts/primitives/HoverOverlay.module.css +13 -0
  78. package/dist/charts/primitives/HoverOverlay.module.css.d.ts +8 -0
  79. package/dist/charts/primitives/chart-card-context.d.ts +29 -0
  80. package/dist/charts/primitives/chart-card-context.d.ts.map +1 -0
  81. package/dist/charts/primitives/chart-card-context.js +13 -0
  82. package/dist/charts/primitives/chart-frame-layout.d.ts +93 -113
  83. package/dist/charts/primitives/chart-frame-layout.d.ts.map +1 -1
  84. package/dist/charts/primitives/chart-frame-layout.js +76 -29
  85. package/dist/charts/primitives/chart-layout.d.ts +112 -0
  86. package/dist/charts/primitives/chart-layout.d.ts.map +1 -0
  87. package/dist/charts/primitives/chart-layout.js +175 -0
  88. package/dist/charts/primitives/chart-tier.d.ts +13 -11
  89. package/dist/charts/primitives/chart-tier.d.ts.map +1 -1
  90. package/dist/charts/primitives/chart-tier.js +42 -13
  91. package/dist/charts/series.d.ts +4 -1
  92. package/dist/charts/series.d.ts.map +1 -1
  93. package/dist/charts/utils/ticks.d.ts +27 -8
  94. package/dist/charts/utils/ticks.d.ts.map +1 -1
  95. package/dist/charts/utils/ticks.js +35 -11
  96. package/dist/common/errors.d.ts +11 -1
  97. package/dist/common/errors.d.ts.map +1 -1
  98. package/dist/common/errors.js +16 -2
  99. package/dist/common/hit-floor.d.ts +10 -0
  100. package/dist/common/hit-floor.d.ts.map +1 -0
  101. package/dist/common/hit-floor.js +6 -0
  102. package/dist/{shell → common}/isomorphic-layout-effect.d.ts +4 -3
  103. package/dist/common/isomorphic-layout-effect.d.ts.map +1 -0
  104. package/dist/common/use-measured-widths.d.ts +37 -0
  105. package/dist/common/use-measured-widths.d.ts.map +1 -0
  106. package/dist/common/use-measured-widths.js +51 -0
  107. package/dist/common/use-media-query.d.ts +6 -0
  108. package/dist/common/use-media-query.d.ts.map +1 -0
  109. package/dist/common/use-media-query.js +40 -0
  110. package/dist/common/validate.d.ts +9 -0
  111. package/dist/common/validate.d.ts.map +1 -1
  112. package/dist/common/validate.js +9 -4
  113. package/dist/content/article-layout.d.ts +4 -2
  114. package/dist/content/article-layout.d.ts.map +1 -1
  115. package/dist/content/article-layout.js +43 -3
  116. package/dist/content/article-layout.module.css +45 -4
  117. package/dist/content/article-layout.module.css.d.ts +3 -0
  118. package/dist/content/code-block.d.ts.map +1 -1
  119. package/dist/content/code-block.js +40 -2
  120. package/dist/content/code-block.module.css +32 -2
  121. package/dist/content/prose.module.css +13 -8
  122. package/dist/controls/actions.d.ts +29 -6
  123. package/dist/controls/actions.d.ts.map +1 -1
  124. package/dist/controls/actions.js +158 -27
  125. package/dist/controls/actions.module.css +14 -1
  126. package/dist/controls/actions.module.css.d.ts +1 -0
  127. package/dist/controls/controls.module.css +8 -31
  128. package/dist/controls/enum-filter.js +2 -2
  129. package/dist/controls/filter-context.d.ts +10 -0
  130. package/dist/controls/filter-context.d.ts.map +1 -1
  131. package/dist/controls/filter-context.js +2 -0
  132. package/dist/controls/filter-pill.d.ts.map +1 -1
  133. package/dist/controls/filter-pill.js +1 -0
  134. package/dist/controls/index.d.ts +1 -1
  135. package/dist/controls/index.d.ts.map +1 -1
  136. package/dist/controls/index.js +0 -2
  137. package/dist/controls/multi-select-filter.js +2 -2
  138. package/dist/controls/sync-button.module.css +1 -1
  139. package/dist/dashboard/section.d.ts.map +1 -1
  140. package/dist/dashboard/section.js +1 -0
  141. package/dist/dashboard/section.module.css +1 -26
  142. package/dist/dashboard/stat-card.d.ts +1 -1
  143. package/dist/dashboard/stat-card.d.ts.map +1 -1
  144. package/dist/dashboard/stat-card.js +4 -1
  145. package/dist/dashboard/stat-card.module.css +6 -9
  146. package/dist/dashboard/stat-group.module.css +16 -4
  147. package/dist/dashboard/widget-grid.d.ts.map +1 -1
  148. package/dist/dashboard/widget-header.d.ts +14 -4
  149. package/dist/dashboard/widget-header.d.ts.map +1 -1
  150. package/dist/dashboard/widget-header.js +23 -6
  151. package/dist/dashboard/widget-header.module.css +145 -133
  152. package/dist/dashboard/widget-header.module.css.d.ts +2 -0
  153. package/dist/data/data-table.d.ts +23 -0
  154. package/dist/data/data-table.d.ts.map +1 -1
  155. package/dist/data/data-table.js +339 -141
  156. package/dist/data/data-table.module.css +94 -0
  157. package/dist/data/data-table.module.css.d.ts +11 -0
  158. package/dist/data/virtual-list.d.ts.map +1 -1
  159. package/dist/data/virtual-list.js +10 -0
  160. package/dist/forms/form-layout.d.ts.map +1 -1
  161. package/dist/forms/form-layout.js +3 -3
  162. package/dist/forms/form-layout.module.css +30 -5
  163. package/dist/forms/form-layout.module.css.d.ts +1 -0
  164. package/dist/guard/index.d.ts +8 -2
  165. package/dist/guard/index.d.ts.map +1 -1
  166. package/dist/guard/index.js +67 -2
  167. package/dist/guard/types.d.ts +3 -3
  168. package/dist/guard/types.d.ts.map +1 -1
  169. package/dist/index.d.ts +1 -1
  170. package/dist/index.d.ts.map +1 -1
  171. package/dist/index.js +3 -1
  172. package/dist/provider/index.d.ts +20 -1
  173. package/dist/provider/index.d.ts.map +1 -1
  174. package/dist/provider/index.js +22 -2
  175. package/dist/shell/app-brand.d.ts.map +1 -1
  176. package/dist/shell/app-brand.js +1 -0
  177. package/dist/shell/app-brand.module.css +2 -2
  178. package/dist/shell/app-header.module.css +18 -8
  179. package/dist/shell/app-main.module.css +54 -3
  180. package/dist/shell/app-main.module.css.d.ts +1 -0
  181. package/dist/shell/app-mobile-nav.module.css +16 -4
  182. package/dist/shell/app-sidebar.module.css +4 -6
  183. package/dist/shell/index.d.ts +12 -0
  184. package/dist/shell/index.d.ts.map +1 -1
  185. package/dist/shell/index.js +57 -16
  186. package/dist/shell/mobile-nav-model.d.ts +1 -1
  187. package/dist/shell/page-aside.d.ts +22 -3
  188. package/dist/shell/page-aside.d.ts.map +1 -1
  189. package/dist/shell/page-aside.js +27 -13
  190. package/dist/shell/page-bar.d.ts.map +1 -1
  191. package/dist/shell/page-bar.js +10 -5
  192. package/dist/shell/page-bar.module.css +10 -34
  193. package/dist/shell/use-breakpoint.d.ts +3 -4
  194. package/dist/shell/use-breakpoint.d.ts.map +1 -1
  195. package/dist/shell/use-breakpoint.js +3 -25
  196. package/dist/shell/use-size-class.d.ts +6 -0
  197. package/dist/shell/use-size-class.d.ts.map +1 -0
  198. package/dist/shell/use-size-class.js +19 -0
  199. package/dist/state/persisted-or-local.d.ts +4 -1
  200. package/dist/state/persisted-or-local.d.ts.map +1 -1
  201. package/dist/state/persisted-or-local.js +4 -3
  202. package/dist/state/persisted.d.ts +10 -0
  203. package/dist/state/persisted.d.ts.map +1 -1
  204. package/dist/state/persisted.js +44 -14
  205. package/dist/styles.css +41 -0
  206. package/dist/surfaces.d.ts +4 -4
  207. package/dist/surfaces.d.ts.map +1 -1
  208. package/dist/surfaces.js +11 -3
  209. package/dist/theme/controls.module.css +7 -0
  210. package/dist/theme/ctl-theme.d.ts +1 -0
  211. package/dist/theme/ctl-theme.d.ts.map +1 -1
  212. package/dist/theme/ctl-theme.js +12 -4
  213. package/dist/theme/floating.module.css +36 -0
  214. package/dist/theme/floating.module.css.d.ts +3 -0
  215. package/dist/theme/index.d.ts +2 -2
  216. package/dist/theme/index.d.ts.map +1 -1
  217. package/dist/theme/index.js +34 -5
  218. package/dist/theme/nav-link.module.css +7 -0
  219. package/dist/tokens/index.d.ts +7 -16
  220. package/dist/tokens/index.d.ts.map +1 -1
  221. package/dist/tokens/index.js +23 -28
  222. package/dist/tokens/palette.d.ts +5 -27
  223. package/dist/tokens/palette.d.ts.map +1 -1
  224. package/dist/tokens/palette.js +8 -30
  225. package/dist/tokens/size-classes.d.ts +40 -0
  226. package/dist/tokens/size-classes.d.ts.map +1 -0
  227. package/dist/tokens/size-classes.js +29 -0
  228. package/dist/tokens.css +8 -4
  229. package/llms.txt +3 -3
  230. package/package.json +17 -17
  231. package/src/agent-chat/composer.tsx +74 -47
  232. package/src/agent-chat/thread-workspace.tsx +8 -11
  233. package/src/agent-chat/use-keyboard-inset.ts +68 -0
  234. package/src/charts/cursor/touch-pin.ts +138 -0
  235. package/src/charts/hooks/use-discrete-cursor.ts +335 -0
  236. package/src/charts/hooks/use-hysteresis.ts +26 -0
  237. package/src/charts/hooks/useBandPlot.ts +90 -27
  238. package/src/charts/hooks/useChartCursor.ts +211 -26
  239. package/src/charts/index.ts +0 -8
  240. package/src/charts/kinds/BandStrip.tsx +11 -1
  241. package/src/charts/kinds/Donut.tsx +153 -62
  242. package/src/charts/kinds/DualPanel.tsx +19 -4
  243. package/src/charts/kinds/Heatmap.tsx +61 -22
  244. package/src/charts/kinds/MirroredBars.tsx +15 -3
  245. package/src/charts/kinds/donut-layout.ts +82 -0
  246. package/src/charts/layout/auto-margin.ts +24 -5
  247. package/src/charts/layout/end-labels.ts +135 -0
  248. package/src/charts/primitives/Axes.tsx +112 -21
  249. package/src/charts/primitives/CartesianChart.tsx +282 -68
  250. package/src/charts/primitives/ChartCard.tsx +141 -48
  251. package/src/charts/primitives/ChartFrame.tsx +243 -60
  252. package/src/charts/primitives/ChartLegend.tsx +257 -73
  253. package/src/charts/primitives/ChartTooltip.tsx +8 -3
  254. package/src/charts/primitives/Crosshair.tsx +2 -2
  255. package/src/charts/primitives/HoverOverlay.module.css +13 -0
  256. package/src/charts/primitives/HoverOverlay.module.css.d.ts +8 -0
  257. package/src/charts/primitives/HoverOverlay.tsx +15 -4
  258. package/src/charts/primitives/chart-card-context.ts +37 -0
  259. package/src/charts/primitives/chart-frame-layout.ts +214 -177
  260. package/src/charts/primitives/chart-layout.ts +318 -0
  261. package/src/charts/primitives/chart-tier.tsx +66 -21
  262. package/src/charts/series.ts +4 -1
  263. package/src/charts/utils/ticks.ts +95 -19
  264. package/src/common/errors.ts +25 -1
  265. package/src/common/hit-floor.ts +9 -0
  266. package/src/{shell → common}/isomorphic-layout-effect.ts +4 -3
  267. package/src/common/use-measured-widths.ts +88 -0
  268. package/src/common/use-media-query.ts +56 -0
  269. package/src/common/validate.ts +17 -4
  270. package/src/content/article-layout.module.css +45 -4
  271. package/src/content/article-layout.module.css.d.ts +3 -0
  272. package/src/content/article-layout.tsx +60 -5
  273. package/src/content/code-block.module.css +32 -2
  274. package/src/content/code-block.tsx +47 -3
  275. package/src/content/prose.module.css +13 -8
  276. package/src/controls/actions.module.css +14 -1
  277. package/src/controls/actions.module.css.d.ts +1 -0
  278. package/src/controls/actions.tsx +223 -75
  279. package/src/controls/controls.module.css +8 -31
  280. package/src/controls/enum-filter.tsx +2 -2
  281. package/src/controls/filter-context.tsx +11 -0
  282. package/src/controls/filter-pill.tsx +1 -0
  283. package/src/controls/index.ts +0 -1
  284. package/src/controls/multi-select-filter.tsx +2 -2
  285. package/src/controls/sync-button.module.css +1 -1
  286. package/src/dashboard/section.module.css +1 -26
  287. package/src/dashboard/section.tsx +1 -0
  288. package/src/dashboard/stat-card.module.css +6 -9
  289. package/src/dashboard/stat-card.tsx +6 -3
  290. package/src/dashboard/stat-group.module.css +16 -4
  291. package/src/dashboard/widget-grid.tsx +7 -6
  292. package/src/dashboard/widget-header.module.css +145 -133
  293. package/src/dashboard/widget-header.module.css.d.ts +2 -0
  294. package/src/dashboard/widget-header.tsx +45 -11
  295. package/src/data/data-table.module.css +94 -0
  296. package/src/data/data-table.module.css.d.ts +11 -0
  297. package/src/data/data-table.tsx +503 -164
  298. package/src/data/virtual-list.tsx +31 -0
  299. package/src/forms/form-layout.module.css +30 -5
  300. package/src/forms/form-layout.module.css.d.ts +1 -0
  301. package/src/forms/form-layout.tsx +12 -10
  302. package/src/guard/index.ts +183 -3
  303. package/src/guard/types.ts +3 -2
  304. package/src/index.ts +2 -0
  305. package/src/provider/index.tsx +53 -1
  306. package/src/shell/app-brand.module.css +2 -2
  307. package/src/shell/app-brand.tsx +1 -0
  308. package/src/shell/app-header.module.css +18 -8
  309. package/src/shell/app-main.module.css +54 -3
  310. package/src/shell/app-main.module.css.d.ts +1 -0
  311. package/src/shell/app-mobile-nav.module.css +16 -4
  312. package/src/shell/app-sidebar.module.css +4 -6
  313. package/src/shell/index.tsx +200 -129
  314. package/src/shell/mobile-nav-model.ts +1 -1
  315. package/src/shell/page-aside.tsx +70 -21
  316. package/src/shell/page-bar.module.css +10 -34
  317. package/src/shell/page-bar.tsx +10 -5
  318. package/src/shell/use-breakpoint.ts +9 -45
  319. package/src/shell/use-size-class.ts +31 -0
  320. package/src/state/persisted-or-local.ts +10 -4
  321. package/src/state/persisted.ts +76 -17
  322. package/src/styles.css +41 -0
  323. package/src/surfaces.ts +9 -1
  324. package/src/theme/controls.module.css +7 -0
  325. package/src/theme/ctl-theme.tsx +15 -3
  326. package/src/theme/floating.module.css +36 -0
  327. package/src/theme/floating.module.css.d.ts +3 -0
  328. package/src/theme/index.ts +46 -8
  329. package/src/theme/nav-link.module.css +7 -0
  330. package/src/tokens/index.ts +20 -30
  331. package/src/tokens/palette.ts +6 -28
  332. package/src/tokens/size-classes.ts +46 -0
  333. package/dist/shell/isomorphic-layout-effect.d.ts.map +0 -1
  334. /package/dist/{shell → common}/isomorphic-layout-effect.js +0 -0
@@ -0,0 +1,335 @@
1
+ import { useCallback, useEffect, useId, useMemo, useRef, useState } from 'react'
2
+ import type {
3
+ KeyboardEventHandler,
4
+ PointerEvent as ReactPointerEvent,
5
+ PointerEventHandler,
6
+ } from 'react'
7
+ import { useDismissOnOutside, useTouchPin } from '../cursor/touch-pin'
8
+
9
+ /** A discrete target plus the viewport-space point its tooltip anchors to. */
10
+ export type DiscreteCursorTip<T> = { target: T; anchor: { x: number; y: number } }
11
+
12
+ type ActiveState = { key: string; anchor: { x: number; y: number } }
13
+
14
+ export type UseDiscreteCursorResult<T> = {
15
+ /** The target whose tooltip should render, resolved from whichever mode last set it (hover, a
16
+ * touch pin, or keyboard focus). `null` when nothing is active. */
17
+ tip: DiscreteCursorTip<T> | null
18
+ /** True once a coarse-pointer tap has PINNED `tip` open (survives pointer lift). */
19
+ isPinned: boolean
20
+ /** Pointer handlers for one target's shape — spread onto its `<g>`/`<rect>`. Fine pointers
21
+ * (mouse/pen) hover; a coarse pointer (touch) pins on `pointerdown` instead. */
22
+ pointerProps: (t: T) => {
23
+ onPointerEnter: PointerEventHandler<Element>
24
+ onPointerMove: PointerEventHandler<Element>
25
+ onPointerDown: PointerEventHandler<Element>
26
+ onPointerUp: PointerEventHandler<Element>
27
+ onPointerLeave: PointerEventHandler<Element>
28
+ onPointerCancel: PointerEventHandler<Element>
29
+ }
30
+ /** DOM id for a target's `role="option"` element — also `aria-activedescendant`'s value while
31
+ * that target is active. Spread `id={optionId(t)}` on the same node that gets `pointerProps`. */
32
+ optionId: (t: T) => string
33
+ /** Dismisses a pin and clears keyboard focus. Already wired to Escape and an outside tap while
34
+ * pinned; call it directly for anything else that should close the tooltip (e.g. data changing
35
+ * out from under the focused key). */
36
+ clear: () => void
37
+ /** Spread on the ONE shared, focusable host (the chart's `<svg>`). */
38
+ hostProps: {
39
+ ref: (node: Element | null) => void
40
+ tabIndex: 0
41
+ role: 'listbox'
42
+ 'aria-label': string
43
+ 'aria-activedescendant': string | undefined
44
+ onKeyDown: KeyboardEventHandler<Element>
45
+ onBlur: () => void
46
+ }
47
+ }
48
+
49
+ /**
50
+ * Keyboard + focus + tap parity for a DISCRETE set of targets (donut slices, heatmap cells) — the
51
+ * counterpart `HoverOverlay` gives a continuous cartesian domain (`docs/CHARTS-SPEC.md` §4).
52
+ *
53
+ * **Role choice**: `listbox`/`option` (WAI-ARIA APG "Listbox"), not `slider`. A cartesian domain is
54
+ * one continuous value; a donut slice or heatmap cell is a named choice among discrete siblings.
55
+ * `aria-activedescendant` announces the focused option's id while DOM focus stays on the one host.
56
+ *
57
+ * Three input modes converge on one `tip`: hover (fine pointer, ephemeral), a provisional tap that
58
+ * `pointerup` commits into a pin (a `pointercancel` first — a scroll — clears it), and keyboard
59
+ * stepping on the one focusable host (`columns` maps Up/Down to a full-row jump for a 2D grid;
60
+ * Left/Right always step by one). Keyboard focus anchors the tooltip to the host's center — an
61
+ * accepted simplification; the value still reaches a screen reader via the option's text.
62
+ */
63
+ export function useDiscreteCursor<T>({
64
+ targets,
65
+ getKey,
66
+ columns,
67
+ ariaLabel = 'Chart data — use arrow keys to navigate, Escape to dismiss',
68
+ }: {
69
+ targets: readonly T[]
70
+ getKey: (t: T) => string
71
+ /** Row width for a 2D grid — see the Up/Down mapping above. Omit for a 1D ring. */
72
+ columns?: number
73
+ /** Accessible name for the shared listbox host. */
74
+ ariaLabel?: string
75
+ }): UseDiscreteCursorResult<T> {
76
+ const [active, setActive] = useState<ActiveState | null>(null)
77
+ const [pinned, setPinned] = useState(false)
78
+ const hostElRef = useRef<Element | null>(null)
79
+ const idPrefix = useId()
80
+
81
+ // Mirrors `active`/`pinned` so the provisional-press machine below can read the CURRENT committed
82
+ // value synchronously from an event handler, without either living in a ref of its own.
83
+ const activeRef = useRef(active)
84
+ activeRef.current = active
85
+ const pinnedRef = useRef(pinned)
86
+ pinnedRef.current = pinned
87
+
88
+ // Read through refs so a keypress or an outside tap arriving between renders (the two
89
+ // `document`-level listeners below) always sees the LATEST list/accessor, not the ones closed
90
+ // over when the effect was installed — `targets` and `columns` can both change every render (a
91
+ // filtered dataset, a resize).
92
+ const targetsRef = useRef(targets)
93
+ targetsRef.current = targets
94
+ const getKeyRef = useRef(getKey)
95
+ getKeyRef.current = getKey
96
+ const columnsRef = useRef(columns)
97
+ columnsRef.current = columns
98
+
99
+ // `pointermove`/`pointerenter` flood far faster than one `setActive` is worth on a fast scrub
100
+ // across many targets — coalesced to one commit per animation frame, the same treatment
101
+ // `useChartCursor`'s own hover path gives its (costlier) nearest-point search. Cancelled on
102
+ // unmount and in `clear()` — which `onPointerLeave`/`onPointerCancel` below also route through —
103
+ // so a frame already in flight cannot resurrect a hover the clear just dismissed.
104
+ const moveFrameRef = useRef<number | null>(null)
105
+ const pendingActiveRef = useRef<ActiveState | null>(null)
106
+ useEffect(
107
+ () => () => {
108
+ if (moveFrameRef.current !== null) cancelAnimationFrame(moveFrameRef.current)
109
+ },
110
+ [],
111
+ )
112
+ const scheduleActive = useCallback((next: ActiveState) => {
113
+ pendingActiveRef.current = next
114
+ if (moveFrameRef.current !== null) return
115
+ moveFrameRef.current = requestAnimationFrame(() => {
116
+ moveFrameRef.current = null
117
+ setActive(pendingActiveRef.current)
118
+ })
119
+ }, [])
120
+
121
+ // Cancels a hover frame already in flight and clears what it was about to commit — called by
122
+ // every SYNCHRONOUS writer of `active` (a touch press, a keyboard step, `clear()` itself) before
123
+ // it writes. Without this, a `pointermove` scheduled a tick earlier (coalesced onto
124
+ // `moveFrameRef`/`pendingActiveRef`, per `scheduleActive` above) is still in flight when one of
125
+ // those writes lands, and the frame fires a moment later and overwrites it right back with the
126
+ // stale hover target — the keyboard/touch target "reverts" to whatever was last hovered.
127
+ const cancelPendingFrame = useCallback(() => {
128
+ if (moveFrameRef.current !== null) {
129
+ cancelAnimationFrame(moveFrameRef.current)
130
+ moveFrameRef.current = null
131
+ }
132
+ pendingActiveRef.current = null
133
+ }, [])
134
+
135
+ // The provisional-press commit/revert machine (`docs/CHARTS-SPEC.md` §4) — shared with
136
+ // `useChartCursor`. The committed value IS `active` whenever `pinned` is true — there is no
137
+ // separate ref to keep in sync, `pinnedRef`/`activeRef` above already mirror both.
138
+ const touchPin = useTouchPin<ActiveState | null>({
139
+ getCommitted: () => (pinnedRef.current ? activeRef.current : null),
140
+ setCommitted: (value) => {
141
+ setActive(value)
142
+ setPinned(value !== null)
143
+ },
144
+ })
145
+
146
+ const clear = useCallback(() => {
147
+ cancelPendingFrame()
148
+ touchPin.reset()
149
+ setActive(null)
150
+ setPinned(false)
151
+ }, [touchPin, cancelPendingFrame])
152
+
153
+ // Coarse-pointer pin dismissal that can't be expressed as a per-target handler: a tap OUTSIDE
154
+ // the host, or Escape, from anywhere on the page. A tap landing back INSIDE the host is handled
155
+ // by the per-target `onPointerDown` in `pointerProps` instead (it MOVES the pin), so this
156
+ // listener only ever fires for the "elsewhere" case — same shape as `ChartLegend`'s disclosure
157
+ // dismissal. Shared with `useChartCursor` (`touch-pin.ts`).
158
+ const isInsideHost = useCallback(
159
+ (target: Node): boolean => hostElRef.current?.contains(target) === true,
160
+ [],
161
+ )
162
+ useDismissOnOutside({ enabled: pinned, isInside: isInsideHost, onDismiss: clear })
163
+
164
+ // Index in `targetsRef`, NOT the key: Heatmap's `cellKey` joins cells with `\u0000`, which would
165
+ // leak a NUL into a DOM id, and an id has to be a valid DOM token. Resolved by KEY, not reference:
166
+ // Heatmap builds a fresh `{ row, col, value }` object per cell render, so a reference lookup always
167
+ // misses. A `Map` built once per `targets` change keeps `optionId` O(1) on the render loop the
168
+ // touch-scrub path re-runs every frame.
169
+ const indexByKey = useMemo(() => {
170
+ const map = new Map<string, number>()
171
+ targets.forEach((t, i) => map.set(getKeyRef.current(t), i))
172
+ return map
173
+ }, [targets])
174
+ const optionId = useCallback(
175
+ (t: T): string => `${idPrefix}-${indexByKey.get(getKeyRef.current(t)) ?? -1}`,
176
+ [idPrefix, indexByKey],
177
+ )
178
+
179
+ // O(1) via `indexByKey` rather than a fresh scan — the same Map `optionId` already builds.
180
+ const findTarget = (key: string): T | undefined => {
181
+ const index = indexByKey.get(key)
182
+ return index === undefined ? undefined : targetsRef.current[index]
183
+ }
184
+
185
+ const pointerProps = (t: T): ReturnType<UseDiscreteCursorResult<T>['pointerProps']> => {
186
+ const key = getKeyRef.current(t)
187
+ const showAt = (event: ReactPointerEvent<Element>): void => {
188
+ scheduleActive({ key, anchor: { x: event.clientX, y: event.clientY } })
189
+ }
190
+ // Shared by `onPointerLeave` and `onPointerCancel`: a still-UNCOMMITTED press ending here is the
191
+ // browser taking the gesture (a scroll) — `touchPin.cancel` restores whatever was COMMITTED
192
+ // before this press started (or leaves it clear when nothing was), regardless of `pinned`. The
193
+ // two used to diverge (`onPointerCancel` checked this, `onPointerLeave` didn't), which left a
194
+ // stale press and a stuck readout on the leave-before-cancel ordering a scroll off a small hit
195
+ // target commonly produces.
196
+ const cancelIfUncommitted = (event: ReactPointerEvent<Element>): boolean =>
197
+ touchPin.cancel(event.pointerId)
198
+ // `pointerType !== 'mouse'` throughout (never `=== 'touch'`), matching `useChartCursor` —
199
+ // pen counts as coarse too, so a stylus tap gets the same pin-until-dismiss contract a finger
200
+ // does, not the fine-pointer hover path.
201
+ return {
202
+ onPointerEnter: (event) => {
203
+ // Guarded on `pinned`, not just pointer type: while a touch tap has pinned a DIFFERENT
204
+ // target, a stray mouse hover elsewhere (a hybrid touchscreen + mouse device) must not
205
+ // silently steal `active` out from under the pin — it would leave that new hover's
206
+ // tooltip stuck on lift, since leave/cancel below still see `pinned` and no-op.
207
+ if (event.pointerType !== 'mouse' || pinned) return
208
+ showAt(event)
209
+ },
210
+ onPointerMove: (event) => {
211
+ if (event.pointerType !== 'mouse' || pinned) return
212
+ showAt(event)
213
+ },
214
+ // Only a coarse pointer presses — a fine pointer's `down` is a no-op, it already shows via
215
+ // enter/move above. The press is PROVISIONAL: it snapshots whatever is committed now (so a
216
+ // cancel can restore it) BEFORE showing the readout, which only `onPointerUp` commits. On
217
+ // touch the readout anchors to the HOST's top edge rather than the finger, which would cover
218
+ // it; a missing host falls back to the pointer.
219
+ onPointerDown: (event) => {
220
+ if (event.pointerType === 'mouse') return
221
+ touchPin.begin(event.pointerId)
222
+ // A hover frame scheduled just before this press (e.g. a hybrid touch+mouse device) must
223
+ // not be allowed to land after this — see `cancelPendingFrame`'s own doc.
224
+ cancelPendingFrame()
225
+ const rect = hostElRef.current?.getBoundingClientRect()
226
+ setActive({
227
+ key,
228
+ anchor:
229
+ rect === undefined
230
+ ? { x: event.clientX, y: event.clientY }
231
+ : { x: rect.left + rect.width / 2, y: rect.top },
232
+ })
233
+ },
234
+ // A completed tap commits the pin. Only the tracked pointer commits — and only a coarse one:
235
+ // some browsers assign a touch's `pointerId` the same value (1) mouse pointers use, so a
236
+ // `pointerType` check keeps an unrelated mouse `pointerup` reusing that id from committing an
237
+ // abandoned touch press.
238
+ onPointerUp: (event) => {
239
+ if (event.pointerType === 'mouse') return
240
+ if (!touchPin.commit(event.pointerId)) return
241
+ setPinned(true)
242
+ },
243
+ // A still-uncommitted press ending here is the browser taking the gesture (a scroll); clear it
244
+ // regardless of `pinned`. Otherwise keep the fine-pointer/pinned guard. Routes through the
245
+ // same `clear()` the outside-tap/Escape dismissal uses (mirrors `useChartCursor`'s own
246
+ // `onPointerLeave`) rather than a bare `setActive(null)` — a `pointermove` scheduled just
247
+ // before this event fires is still in flight (coalesced onto `moveFrameRef`/
248
+ // `pendingActiveRef`), and only `clear()` cancels it. A bare `setActive(null)` left that frame
249
+ // free to land a tick later and resurrect the tooltip this leave/cancel was meant to dismiss.
250
+ onPointerLeave: (event) => {
251
+ if (cancelIfUncommitted(event)) return
252
+ if (event.pointerType !== 'mouse' || pinned) return
253
+ clear()
254
+ },
255
+ onPointerCancel: (event) => {
256
+ if (cancelIfUncommitted(event)) return
257
+ if (event.pointerType !== 'mouse' || pinned) return
258
+ clear()
259
+ },
260
+ }
261
+ }
262
+
263
+ const onKeyDown: KeyboardEventHandler<Element> = (event) => {
264
+ const list = targetsRef.current
265
+ if (list.length === 0) return
266
+ if (event.key === 'Escape') {
267
+ clear()
268
+ return
269
+ }
270
+ const cols = columnsRef.current
271
+ let delta = 0
272
+ switch (event.key) {
273
+ case 'ArrowRight':
274
+ delta = 1
275
+ break
276
+ case 'ArrowLeft':
277
+ delta = -1
278
+ break
279
+ case 'ArrowDown':
280
+ delta = cols ?? 1
281
+ break
282
+ case 'ArrowUp':
283
+ delta = -(cols ?? 1)
284
+ break
285
+ default:
286
+ return
287
+ }
288
+ event.preventDefault()
289
+
290
+ const currentIndex =
291
+ active === null ? -1 : list.findIndex((t) => getKeyRef.current(t) === active.key)
292
+ // Mirrors `useChartCursor`'s onKeyDown: no current focus starts one step before/after the
293
+ // domain edge, so the first arrow press lands on the first or last target.
294
+ const base = currentIndex === -1 ? (delta > 0 ? -1 : list.length) : currentIndex
295
+ const nextIndex = Math.min(Math.max(base + delta, 0), list.length - 1)
296
+ const next = list[nextIndex] as T
297
+
298
+ const rect = hostElRef.current?.getBoundingClientRect()
299
+ const anchor =
300
+ rect === undefined
301
+ ? { x: 0, y: 0 }
302
+ : { x: rect.left + rect.width / 2, y: rect.top + rect.height / 2 }
303
+ // A hover frame scheduled just before this keypress must not be allowed to land after this —
304
+ // see `cancelPendingFrame`'s own doc.
305
+ cancelPendingFrame()
306
+ setActive({ key: getKeyRef.current(next), anchor })
307
+ }
308
+
309
+ const tip: DiscreteCursorTip<T> | null = (() => {
310
+ if (active === null) return null
311
+ const target = findTarget(active.key)
312
+ return target === undefined ? null : { target, anchor: active.anchor }
313
+ })()
314
+
315
+ return {
316
+ tip,
317
+ isPinned: pinned,
318
+ pointerProps,
319
+ optionId,
320
+ clear,
321
+ hostProps: {
322
+ ref: (node) => {
323
+ hostElRef.current = node
324
+ },
325
+ tabIndex: 0,
326
+ role: 'listbox',
327
+ 'aria-label': ariaLabel,
328
+ 'aria-activedescendant': tip === null ? undefined : optionId(tip.target),
329
+ onKeyDown,
330
+ onBlur: () => {
331
+ if (!pinned) clear()
332
+ },
333
+ },
334
+ }
335
+ }
@@ -0,0 +1,26 @@
1
+ import { useLayoutEffect, useRef } from 'react'
2
+
3
+ /**
4
+ * A derived value that feeds back into its own next computation — hysteresis, "was X last frame" —
5
+ * without the anti-pattern of mutating a ref during render (`ChartCard`'s short-card flag, P0-1;
6
+ * `Donut`'s side/stacked layout, P2-10, both hit the SAME bug independently: a render a concurrent
7
+ * commit discards must not still poison the next real one's input).
8
+ *
9
+ * `compute` is called with the PREVIOUS committed value (never mutated here) and returns this
10
+ * render's value; the ref only updates in a `useLayoutEffect`, after the value has actually
11
+ * committed. Internal only — not on any public barrel.
12
+ *
13
+ * @example
14
+ * const short = useHysteresis(
15
+ * (wasShort) => measuredHeight > 0 && measuredHeight < (wasShort ? EXIT : ENTER),
16
+ * false,
17
+ * )
18
+ */
19
+ export function useHysteresis<T>(compute: (previous: T) => T, initial: T): T {
20
+ const ref = useRef(initial)
21
+ const value = compute(ref.current)
22
+ useLayoutEffect(() => {
23
+ ref.current = value
24
+ }, [value])
25
+ return value
26
+ }
@@ -20,7 +20,13 @@ import type { ReactNode, RefObject } from 'react'
20
20
  import type { ChartMargin } from '../../tokens'
21
21
  import type { CursorResolution } from '../cursor/resolve'
22
22
  import { autoMargin } from '../layout/auto-margin'
23
- import { useChartTierMetrics } from '../primitives/chart-tier'
23
+ import {
24
+ isTightClass,
25
+ planXLabels,
26
+ resolveMarginFloor,
27
+ resolveYPlacement,
28
+ } from '../primitives/chart-layout'
29
+ import { useChartContainerClass, useChartMetrics } from '../primitives/chart-tier'
24
30
  import { maxTextWidth } from '../utils/measure-text'
25
31
  import { smartTicks, xLabelPxFor } from '../utils/ticks'
26
32
  import { useChartCursor } from './useChartCursor'
@@ -150,6 +156,13 @@ export type BandPlot<T> = {
150
156
  /** Drawn width of one band — the pitch minus a 1px separator, floored at 1. */
151
157
  bandWidth: number
152
158
  tickValues: string[]
159
+ /** Where the left axis paints: inside the plot (compact), not at all (micro), else outside. An
160
+ * explicit `margin.left` keeps it outside. Same law as `CartesianChart`. */
161
+ yPlacement: 'outside' | 'inside' | 'none'
162
+ /** Terminal x labels anchor inward (compact/micro). */
163
+ xAnchorTerminals: boolean
164
+ /** Width to wrap x labels to; undefined when they do not wrap. */
165
+ xWrapWidth: number | undefined
153
166
  svgRef: RefObject<SVGSVGElement | null>
154
167
  tooltipAnchor: CursorAnchor | null
155
168
  showTooltip: boolean
@@ -181,18 +194,44 @@ export function useBandPlot<T>(input: UseBandPlotInput<T>): BandPlot<T> {
181
194
  // two things `CartesianChart` reads off it: the tick font its gutters are MEASURED at (the same
182
195
  // one `AxisBottomDate` paints — measured labels must be the painted labels, §1) and the tightened
183
196
  // margin FLOORS (`docs/CHARTS-SPEC.md` §8).
184
- const tier = useChartTierMetrics()
197
+ const tier = useChartMetrics()
198
+ const containerClass = useChartContainerClass()
199
+ const tight = isTightClass(containerClass)
185
200
 
186
201
  const hasLeftAxis = leftLabels !== undefined && leftLabels.length > 0
202
+ // Ladder step 5: inside labels reserve no gutter. An explicit `margin.left` keeps them outside.
203
+ const yPlacement = resolveYPlacement(containerClass, {
204
+ hasLeftAxis,
205
+ marginOverrideLeft: marginOverride?.left,
206
+ })
187
207
  const xLabelsAll = useMemo(() => data.map((d) => formatX(getX(d))), [data, getX, formatX])
188
208
 
209
+ // Ladder step 4 (wrap; a band axis cannot rotate, so it thins instead). Sized from the token
210
+ // floors because the real gutters depend on the wrapped line count. A band chart's x labels are
211
+ // always categorical by construction (one slot per datum) — no whitespace heuristic needed.
212
+ const xPlan = useMemo(
213
+ () =>
214
+ planXLabels({
215
+ labels: xLabelsAll,
216
+ plotWidth: width - tier.margin.left - tier.margin.right,
217
+ fontPx: tier.axisFont,
218
+ categorical: tight,
219
+ }),
220
+ [xLabelsAll, width, tier.margin, tier.axisFont, tight],
221
+ )
222
+ const xWrapWidth = xPlan.wrap ? xPlan.wrapPx : undefined
223
+
189
224
  // ── Pass 1: gutters, from the labels that will actually be painted ──────────────────────────
190
225
  const margin = useMemo<ChartMargin>(() => {
191
226
  const measured = autoMargin({
192
- ...(leftLabels !== undefined && { left: leftLabels }),
227
+ ...(leftLabels !== undefined && { left: yPlacement === 'outside' ? leftLabels : [] }),
193
228
  bottom: xLabelsAll,
194
229
  fontPx: tier.axisFont,
195
- floor: tier.margin,
230
+ // An inside-placed left axis paints IN the plot, so the outside label-width floor is dead
231
+ // space there — same law as `CartesianChart`'s `marginInput.floor`.
232
+ floor: resolveMarginFloor(yPlacement, tier.margin),
233
+ anchorTerminals: tight,
234
+ bottomLines: xPlan.lines,
196
235
  ...(marginOverride !== undefined && { override: marginOverride }),
197
236
  })
198
237
  if (marginOverride?.left !== undefined && marginOverride.right !== undefined) return measured
@@ -201,24 +240,38 @@ export function useBandPlot<T>(input: UseBandPlotInput<T>): BandPlot<T> {
201
240
  // A band axis puts its FIRST tick on the plot's left edge, so the left gutter needs the same
202
241
  // half-label law `autoMargin` already applies on the right. `autoMargin` cannot know that —
203
242
  // its left law measures a left AXIS, which a band plot may not have.
204
- const left = hasLeftAxis ? measured.left : Math.max(measured.left, halfXLabel)
243
+ const left = hasLeftAxis || tight ? measured.left : Math.max(measured.left, halfXLabel)
205
244
  return {
206
245
  ...measured,
207
246
  ...(marginOverride?.left === undefined && {
208
- left: hasLeftAxis
209
- ? left
210
- : capTerminalGutter(left, width, TERMINAL_GUTTER_MAX_FRACTION.left, tier.margin.left),
247
+ left:
248
+ hasLeftAxis || tight
249
+ ? left
250
+ : capTerminalGutter(left, width, TERMINAL_GUTTER_MAX_FRACTION.left, tier.margin.left),
211
251
  }),
212
252
  ...(marginOverride?.right === undefined && {
213
- right: capTerminalGutter(
214
- measured.right,
215
- width,
216
- TERMINAL_GUTTER_MAX_FRACTION.right,
217
- tier.margin.right,
218
- ),
253
+ right: tight
254
+ ? measured.right
255
+ : capTerminalGutter(
256
+ measured.right,
257
+ width,
258
+ TERMINAL_GUTTER_MAX_FRACTION.right,
259
+ tier.margin.right,
260
+ ),
219
261
  }),
220
262
  }
221
- }, [leftLabels, xLabelsAll, marginOverride, hasLeftAxis, width, tier.axisFont, tier.margin])
263
+ }, [
264
+ leftLabels,
265
+ xLabelsAll,
266
+ marginOverride,
267
+ hasLeftAxis,
268
+ width,
269
+ tier.axisFont,
270
+ tier.margin,
271
+ tight,
272
+ yPlacement,
273
+ xPlan.lines,
274
+ ])
222
275
 
223
276
  const plotWidth = Math.max(width - margin.left - margin.right, 0)
224
277
 
@@ -249,12 +302,17 @@ export function useBandPlot<T>(input: UseBandPlotInput<T>): BandPlot<T> {
249
302
  [scale],
250
303
  )
251
304
 
305
+ const svgRef = useRef<SVGSVGElement>(null)
252
306
  const cursor = useChartCursor<T>({
253
307
  data: bands,
254
308
  chartId,
255
309
  getKey: getX,
256
310
  xScale: bandCenter,
257
311
  marginLeft: margin.left,
312
+ // Both callers (`BandStrip`, `MirroredBars`) mount exactly one `<svg ref={band.svgRef}>`, so
313
+ // it doubles as the tap-outside boundary (`docs/CHARTS-SPEC.md` §4, Tooltip) with no separate
314
+ // passthrough option — reusing the ref this hook already returns, not a new one.
315
+ boundaryRef: svgRef,
258
316
  ...(cursorResolution !== undefined && { resolution: cursorResolution }),
259
317
  })
260
318
 
@@ -262,20 +320,19 @@ export function useBandPlot<T>(input: UseBandPlotInput<T>): BandPlot<T> {
262
320
  // same measured-spacing law `CartesianChart` applies (`docs/CHARTS-SPEC.md` §1). `keys` (not
263
321
  // `xLabelsAll`) because ticks are chosen from the post-fold key list.
264
322
  const xLabelPx = useMemo(
265
- () => xLabelPxFor(keys.map(formatX), tier.axisFont),
266
- [keys, formatX, tier.axisFont],
323
+ () =>
324
+ xWrapWidth === undefined ? xLabelPxFor(keys.map(formatX), tier.axisFont) : xPlan.labelPx,
325
+ [keys, formatX, tier.axisFont, xWrapWidth, xPlan.labelPx],
267
326
  )
268
327
 
269
- const tickValues = useMemo(
270
- () => [
271
- ...(xTickValues === undefined
272
- ? smartTicks(keys, plotWidth, xLabelPx)
273
- : xTickValues(keys, plotWidth)),
274
- ],
275
- [keys, plotWidth, xTickValues, xLabelPx],
276
- )
328
+ const tickValues = useMemo(() => {
329
+ if (xTickValues !== undefined) return [...xTickValues(keys, plotWidth)]
330
+ // Micro: the two terminals only.
331
+ if (containerClass === 'micro')
332
+ return keys.length > 1 ? [keys[0]!, keys[keys.length - 1]!] : [...keys]
333
+ return [...smartTicks(keys, plotWidth, xLabelPx, tight)]
334
+ }, [keys, plotWidth, xTickValues, xLabelPx, containerClass, tight])
277
335
 
278
- const svgRef = useRef<SVGSVGElement>(null)
279
336
  const point = cursor.point
280
337
  const crosshairX = point === null ? null : (bandCenter(getX(point)) ?? null)
281
338
 
@@ -284,7 +341,10 @@ export function useBandPlot<T>(input: UseBandPlotInput<T>): BandPlot<T> {
284
341
  // no pointer under it, so it is always positioned via the anchored (crosshair) path.
285
342
  const isFollowerRender = !cursor.isSource && cfg?.onFollow === true
286
343
  const showTooltip = tooltip !== false && point !== null && (cursor.isSource || isFollowerRender)
287
- const useAnchored = cfg?.follow === false || isFollowerRender
344
+ // An unset `follow` also anchors on touch (spec §5) — same law as `CartesianChart`'s
345
+ // `useAnchoredPosition`; an EXPLICIT `follow` always wins over that default.
346
+ const useAnchored =
347
+ cfg?.follow === false || (cfg?.follow === undefined && cursor.isTouch) || isFollowerRender
288
348
  const anchorX = useAnchored ? crosshairX : null
289
349
  const svgRect = anchorX === null ? undefined : svgRef.current?.getBoundingClientRect()
290
350
  const tooltipAnchor =
@@ -307,6 +367,9 @@ export function useBandPlot<T>(input: UseBandPlotInput<T>): BandPlot<T> {
307
367
  step,
308
368
  bandWidth,
309
369
  tickValues,
370
+ yPlacement,
371
+ xAnchorTerminals: tight,
372
+ xWrapWidth,
310
373
  svgRef,
311
374
  tooltipAnchor,
312
375
  showTooltip,