@slashsuite/ui-react 0.12.1 → 0.13.1

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 (385) hide show
  1. package/MIGRATING.md +386 -8
  2. package/README.md +89 -44
  3. package/agent-docs/components/app-shell.md +9 -6
  4. package/agent-docs/components/article-layout.md +140 -0
  5. package/agent-docs/components/audio.md +42 -0
  6. package/agent-docs/components/badge.md +2 -1
  7. package/agent-docs/components/body-text.md +26 -15
  8. package/agent-docs/components/bottom-sheet.md +27 -17
  9. package/agent-docs/components/breadcrumbs.md +10 -6
  10. package/agent-docs/components/button.md +2 -2
  11. package/agent-docs/components/call-to-action.md +59 -0
  12. package/agent-docs/components/callout.md +4 -3
  13. package/agent-docs/components/card-grid.md +15 -7
  14. package/agent-docs/components/card.md +33 -18
  15. package/agent-docs/components/cart-button.md +63 -0
  16. package/agent-docs/components/chat-composer.md +4 -3
  17. package/agent-docs/components/checkbox.md +11 -5
  18. package/agent-docs/components/cluster.md +10 -8
  19. package/agent-docs/components/code-example.md +2 -2
  20. package/agent-docs/components/code.md +7 -5
  21. package/agent-docs/components/colour-scheme-toggle.md +12 -6
  22. package/agent-docs/components/colour-swatch.md +41 -0
  23. package/agent-docs/components/combobox.md +88 -0
  24. package/agent-docs/components/confirm-dialog.md +98 -0
  25. package/agent-docs/components/container.md +2 -1
  26. package/agent-docs/components/copy-button.md +7 -5
  27. package/agent-docs/components/copy-line.md +6 -5
  28. package/agent-docs/components/date-field.md +14 -11
  29. package/agent-docs/components/date-range-picker.md +16 -9
  30. package/agent-docs/components/date-time-field.md +73 -0
  31. package/agent-docs/components/dialog.md +22 -68
  32. package/agent-docs/components/disclosure.md +4 -0
  33. package/agent-docs/components/docs-layout.md +10 -6
  34. package/agent-docs/components/drawer.md +13 -4
  35. package/agent-docs/components/embed-frame.md +48 -0
  36. package/agent-docs/components/empty-state.md +4 -1
  37. package/agent-docs/components/field-dialog.md +6 -5
  38. package/agent-docs/components/field.md +10 -7
  39. package/agent-docs/components/fieldset.md +4 -4
  40. package/agent-docs/components/flow-diagram.md +87 -0
  41. package/agent-docs/components/form-layout.md +4 -1
  42. package/agent-docs/components/form-row.md +7 -7
  43. package/agent-docs/components/full-bleed-layout.md +0 -2
  44. package/agent-docs/components/headings.md +13 -7
  45. package/agent-docs/components/hero.md +11 -2
  46. package/agent-docs/components/icon-button.md +1 -3
  47. package/agent-docs/components/icon.md +6 -13
  48. package/agent-docs/components/image.md +24 -14
  49. package/agent-docs/components/input.md +8 -7
  50. package/agent-docs/components/key-value-list.md +4 -1
  51. package/agent-docs/components/lightbox.md +1 -1
  52. package/agent-docs/components/list-layout.md +5 -7
  53. package/agent-docs/components/list-row.md +37 -34
  54. package/agent-docs/components/loading.md +2 -2
  55. package/agent-docs/components/markdown.md +13 -13
  56. package/agent-docs/components/media-tile.md +8 -4
  57. package/agent-docs/components/menu.md +19 -12
  58. package/agent-docs/components/meta-list.md +2 -2
  59. package/agent-docs/components/morph.md +11 -5
  60. package/agent-docs/components/navigation-progress.md +2 -2
  61. package/agent-docs/components/number-field.md +75 -0
  62. package/agent-docs/components/outline-region.md +19 -8
  63. package/agent-docs/components/page-fade.md +2 -1
  64. package/agent-docs/components/pill.md +7 -6
  65. package/agent-docs/components/popover.md +63 -0
  66. package/agent-docs/components/price.md +49 -0
  67. package/agent-docs/components/product-tile.md +78 -0
  68. package/agent-docs/components/promo-banner.md +46 -0
  69. package/agent-docs/components/prose-layout.md +1 -1
  70. package/agent-docs/components/radio-group.md +9 -6
  71. package/agent-docs/components/scroll-strip.md +3 -3
  72. package/agent-docs/components/segmented-control.md +4 -2
  73. package/agent-docs/components/select.md +8 -3
  74. package/agent-docs/components/show.md +2 -2
  75. package/agent-docs/components/side-column.md +13 -9
  76. package/agent-docs/components/sidebar-layout.md +1 -1
  77. package/agent-docs/components/site-footer.md +4 -4
  78. package/agent-docs/components/site-search.md +21 -9
  79. package/agent-docs/components/slider.md +59 -0
  80. package/agent-docs/components/sortable-list.md +15 -10
  81. package/agent-docs/components/stack.md +3 -3
  82. package/agent-docs/components/stacked-bar.md +7 -4
  83. package/agent-docs/components/state-machine.md +95 -0
  84. package/agent-docs/components/status-pages.md +13 -6
  85. package/agent-docs/components/stepper.md +54 -0
  86. package/agent-docs/components/switch.md +4 -4
  87. package/agent-docs/components/table-of-contents.md +78 -0
  88. package/agent-docs/components/table.md +35 -24
  89. package/agent-docs/components/tabs.md +24 -26
  90. package/agent-docs/components/text-link.md +12 -7
  91. package/agent-docs/components/textarea.md +4 -2
  92. package/agent-docs/components/toast.md +19 -14
  93. package/agent-docs/components/video.md +7 -2
  94. package/agent-docs/llms.txt +22 -3
  95. package/dist/AppShell.d.ts +25 -9
  96. package/dist/AppShell.js +67 -33
  97. package/dist/AppShellMenu.d.ts +31 -18
  98. package/dist/AppShellMenu.js +72 -45
  99. package/dist/ArticleLayout.d.ts +36 -0
  100. package/dist/ArticleLayout.js +27 -0
  101. package/dist/Audio.d.ts +16 -0
  102. package/dist/Audio.js +11 -0
  103. package/dist/Badge.d.ts +2 -1
  104. package/dist/Badge.js +3 -2
  105. package/dist/BottomSheet.d.ts +17 -6
  106. package/dist/BottomSheet.js +62 -11
  107. package/dist/Breadcrumbs.d.ts +8 -6
  108. package/dist/Breadcrumbs.js +17 -7
  109. package/dist/Button.d.ts +4 -2
  110. package/dist/Button.js +9 -87
  111. package/dist/CallToAction.d.ts +25 -0
  112. package/dist/CallToAction.js +17 -0
  113. package/dist/Callout.d.ts +2 -2
  114. package/dist/Callout.js +2 -2
  115. package/dist/Card.d.ts +88 -31
  116. package/dist/Card.js +55 -92
  117. package/dist/CardBody.d.ts +2 -0
  118. package/dist/CardBody.js +33 -3
  119. package/dist/CardGrid.d.ts +32 -4
  120. package/dist/CardGrid.js +42 -8
  121. package/dist/CardParts.d.ts +7 -1
  122. package/dist/CardParts.js +7 -2
  123. package/dist/CartButton.d.ts +33 -0
  124. package/dist/CartButton.js +18 -0
  125. package/dist/ChatComposer.d.ts +10 -4
  126. package/dist/ChatComposer.js +35 -13
  127. package/dist/Checkbox.d.ts +21 -3
  128. package/dist/Checkbox.js +66 -20
  129. package/dist/Chevron.js +1 -1
  130. package/dist/Cluster.d.ts +28 -15
  131. package/dist/Cluster.js +21 -4
  132. package/dist/Code.d.ts +15 -3
  133. package/dist/Code.js +23 -3
  134. package/dist/CodeBlock.d.ts +4 -4
  135. package/dist/CodeBlock.js +2 -2
  136. package/dist/CodeBody.d.ts +1 -1
  137. package/dist/CodeBody.js +4 -10
  138. package/dist/CodeExample.d.ts +1 -1
  139. package/dist/CodeExample.js +3 -2
  140. package/dist/ColourSchemeToggle.d.ts +21 -5
  141. package/dist/ColourSchemeToggle.js +15 -9
  142. package/dist/ColourSwatch.d.ts +15 -0
  143. package/dist/ColourSwatch.js +14 -0
  144. package/dist/Combobox.d.ts +42 -0
  145. package/dist/Combobox.js +43 -0
  146. package/dist/ConfirmDialog.d.ts +40 -0
  147. package/dist/ConfirmDialog.js +36 -0
  148. package/dist/Container.d.ts +3 -3
  149. package/dist/Container.js +1 -1
  150. package/dist/CopyButton.d.ts +8 -2
  151. package/dist/CopyButton.js +38 -28
  152. package/dist/CopyLine.d.ts +4 -2
  153. package/dist/CopyLine.js +4 -4
  154. package/dist/DateCalendar.d.ts +2 -0
  155. package/dist/DateCalendar.js +11 -9
  156. package/dist/DateField.d.ts +52 -21
  157. package/dist/DateField.js +73 -37
  158. package/dist/DateFieldCalendar.d.ts +12 -8
  159. package/dist/DateFieldCalendar.js +37 -18
  160. package/dist/DateRangePicker.d.ts +23 -3
  161. package/dist/DateRangePicker.js +10 -8
  162. package/dist/DateTimeField.d.ts +31 -0
  163. package/dist/DateTimeField.js +19 -0
  164. package/dist/Dialog.d.ts +42 -6
  165. package/dist/Dialog.js +50 -12
  166. package/dist/Disclosure.js +9 -1
  167. package/dist/DocsLayout.d.ts +13 -5
  168. package/dist/DocsLayout.js +11 -9
  169. package/dist/Drawer.d.ts +22 -7
  170. package/dist/Drawer.js +89 -8
  171. package/dist/EmbedFrame.d.ts +36 -0
  172. package/dist/EmbedFrame.js +18 -0
  173. package/dist/Field.d.ts +41 -4
  174. package/dist/Field.js +61 -25
  175. package/dist/FieldDialog.d.ts +8 -3
  176. package/dist/FieldDialog.js +19 -9
  177. package/dist/Fieldset.d.ts +3 -3
  178. package/dist/Fieldset.js +7 -9
  179. package/dist/FileDrop.js +2 -1
  180. package/dist/FlowDiagram.d.ts +92 -0
  181. package/dist/FlowDiagram.js +100 -0
  182. package/dist/FormRow.d.ts +6 -4
  183. package/dist/FormRow.js +11 -9
  184. package/dist/Hero.d.ts +30 -7
  185. package/dist/Hero.js +23 -9
  186. package/dist/Icon.d.ts +1 -1
  187. package/dist/Icon.js +1 -1
  188. package/dist/IconButton.js +1 -1
  189. package/dist/Image.d.ts +33 -9
  190. package/dist/Image.js +61 -16
  191. package/dist/Input.d.ts +1 -1
  192. package/dist/Input.js +4 -4
  193. package/dist/InputShell.d.ts +7 -0
  194. package/dist/InputShell.js +18 -3
  195. package/dist/KeyValueList.d.ts +2 -2
  196. package/dist/Lightbox.js +5 -3
  197. package/dist/ListRow.d.ts +4 -5
  198. package/dist/ListRow.js +36 -26
  199. package/dist/Mark.d.ts +10 -0
  200. package/dist/Mark.js +9 -0
  201. package/dist/Markdown.d.ts +18 -4
  202. package/dist/Markdown.js +176 -37
  203. package/dist/MediaTile.d.ts +9 -3
  204. package/dist/MediaTile.js +8 -4
  205. package/dist/Menu.d.ts +19 -8
  206. package/dist/Menu.js +13 -11
  207. package/dist/MetaList.d.ts +4 -3
  208. package/dist/MetaList.js +12 -4
  209. package/dist/Morph.d.ts +15 -1
  210. package/dist/Morph.js +70 -22
  211. package/dist/NavigationProgress.d.ts +2 -2
  212. package/dist/NavigationProgress.js +7 -5
  213. package/dist/NumberField.d.ts +66 -0
  214. package/dist/NumberField.js +68 -0
  215. package/dist/OutlineRegion.d.ts +41 -10
  216. package/dist/OutlineRegion.js +31 -6
  217. package/dist/PageFade.d.ts +9 -5
  218. package/dist/PageFade.js +39 -8
  219. package/dist/PageLayouts.d.ts +15 -5
  220. package/dist/PageLayouts.js +3 -3
  221. package/dist/Pill.d.ts +9 -4
  222. package/dist/Pill.js +15 -6
  223. package/dist/Popover.d.ts +31 -0
  224. package/dist/Popover.js +43 -0
  225. package/dist/Price.d.ts +21 -0
  226. package/dist/Price.js +34 -0
  227. package/dist/ProductTile.d.ts +36 -0
  228. package/dist/ProductTile.js +31 -0
  229. package/dist/ProgressBar.js +4 -2
  230. package/dist/PromoBanner.d.ts +25 -0
  231. package/dist/PromoBanner.js +16 -0
  232. package/dist/RadioGroup.d.ts +18 -8
  233. package/dist/RadioGroup.js +42 -18
  234. package/dist/ScrollStrip.d.ts +1 -1
  235. package/dist/ScrollStrip.js +1 -1
  236. package/dist/SearchInput.d.ts +17 -2
  237. package/dist/SearchInput.js +72 -13
  238. package/dist/SegmentedField.d.ts +15 -0
  239. package/dist/SegmentedField.js +15 -0
  240. package/dist/Select.js +5 -4
  241. package/dist/Show.d.ts +1 -1
  242. package/dist/Show.js +1 -1
  243. package/dist/SideColumn.d.ts +42 -15
  244. package/dist/SideColumn.js +45 -19
  245. package/dist/SiteFooter.d.ts +3 -3
  246. package/dist/SiteFooter.js +4 -3
  247. package/dist/SiteSearch.d.ts +57 -27
  248. package/dist/SiteSearch.js +13 -93
  249. package/dist/Slider.d.ts +27 -0
  250. package/dist/Slider.js +58 -0
  251. package/dist/SortableList.d.ts +19 -35
  252. package/dist/SortableList.js +36 -88
  253. package/dist/Stack.d.ts +4 -4
  254. package/dist/StackedBar.d.ts +13 -4
  255. package/dist/StackedBar.js +12 -7
  256. package/dist/StateMachine.d.ts +65 -0
  257. package/dist/StateMachine.js +116 -0
  258. package/dist/StatusPages.d.ts +28 -10
  259. package/dist/StatusPages.js +10 -10
  260. package/dist/Stepper.d.ts +21 -0
  261. package/dist/Stepper.js +33 -0
  262. package/dist/Steps.js +4 -3
  263. package/dist/Switch.d.ts +3 -3
  264. package/dist/Switch.js +18 -14
  265. package/dist/Table.d.ts +32 -9
  266. package/dist/Table.js +50 -20
  267. package/dist/TableCells.d.ts +24 -21
  268. package/dist/TableCells.js +68 -27
  269. package/dist/TableEditCell.d.ts +1 -1
  270. package/dist/TableOfContents.d.ts +34 -0
  271. package/dist/TableOfContents.js +23 -0
  272. package/dist/Tabs.d.ts +31 -16
  273. package/dist/Tabs.js +97 -22
  274. package/dist/TextLink.d.ts +18 -5
  275. package/dist/TextLink.js +19 -6
  276. package/dist/Textarea.d.ts +12 -1
  277. package/dist/Textarea.js +15 -2
  278. package/dist/ToastRegion.d.ts +17 -9
  279. package/dist/ToastRegion.js +70 -13
  280. package/dist/Tooltip.d.ts +10 -2
  281. package/dist/Tooltip.js +32 -11
  282. package/dist/Video.d.ts +19 -4
  283. package/dist/Video.js +15 -5
  284. package/dist/cardContext.d.ts +7 -0
  285. package/dist/cardContext.js +14 -0
  286. package/dist/cardControl.d.ts +15 -0
  287. package/dist/cardControl.js +32 -0
  288. package/dist/cardForm.d.ts +39 -0
  289. package/dist/cardForm.js +81 -0
  290. package/dist/cardWait.js +2 -1
  291. package/dist/colourScheme.d.ts +12 -2
  292. package/dist/colourScheme.js +32 -6
  293. package/dist/control.d.ts +30 -8
  294. package/dist/control.js +74 -7
  295. package/dist/copyScript.d.ts +7 -8
  296. package/dist/copyScript.js +8 -9
  297. package/dist/core/button.d.ts +33 -0
  298. package/dist/core/button.js +89 -0
  299. package/dist/core/control.d.ts +15 -0
  300. package/dist/core/control.js +14 -0
  301. package/dist/core/fixtures/button.d.ts +26 -0
  302. package/dist/core/fixtures/button.js +52 -0
  303. package/dist/core/fixtures/types.d.ts +13 -0
  304. package/dist/core/fixtures/types.js +10 -0
  305. package/dist/core/focus.d.ts +7 -0
  306. package/dist/core/focus.js +7 -0
  307. package/dist/core/index.d.ts +12 -0
  308. package/dist/core/index.js +12 -0
  309. package/dist/core/parity.d.ts +22 -0
  310. package/dist/core/parity.js +53 -0
  311. package/dist/core/themeNative.d.ts +62 -0
  312. package/dist/core/themeNative.js +290 -0
  313. package/dist/cx.d.ts +17 -5
  314. package/dist/cx.js +18 -5
  315. package/dist/dateLocale.d.ts +17 -0
  316. package/dist/dateLocale.js +30 -0
  317. package/dist/density.d.ts +17 -3
  318. package/dist/density.js +30 -19
  319. package/dist/emptySlot.d.ts +1 -0
  320. package/dist/fieldAnnounce.d.ts +11 -0
  321. package/dist/fieldAnnounce.js +36 -0
  322. package/dist/fieldControl.d.ts +7 -2
  323. package/dist/fieldControl.js +6 -2
  324. package/dist/fieldWait.d.ts +3 -3
  325. package/dist/fieldWait.js +3 -4
  326. package/dist/flowLayout.d.ts +68 -0
  327. package/dist/flowLayout.js +105 -0
  328. package/dist/focus.d.ts +2 -0
  329. package/dist/focus.js +9 -0
  330. package/dist/fromXState.d.ts +73 -0
  331. package/dist/fromXState.js +110 -0
  332. package/dist/icons.d.ts +1 -1
  333. package/dist/icons.js +15 -0
  334. package/dist/index.d.ts +37 -11
  335. package/dist/index.js +24 -2
  336. package/dist/isoDate.d.ts +8 -1
  337. package/dist/isoDate.js +20 -1
  338. package/dist/labelWords.d.ts +16 -7
  339. package/dist/labelWords.js +14 -12
  340. package/dist/listRowProps.d.ts +17 -15
  341. package/dist/modal.d.ts +5 -0
  342. package/dist/modal.js +21 -1
  343. package/dist/navFold.js +6 -3
  344. package/dist/optionCard.d.ts +18 -0
  345. package/dist/optionCard.js +16 -0
  346. package/dist/scrollBody.d.ts +16 -0
  347. package/dist/scrollBody.js +15 -0
  348. package/dist/scrollEdges.d.ts +7 -0
  349. package/dist/scrollEdges.js +39 -5
  350. package/dist/scrollStop.d.ts +6 -2
  351. package/dist/scrollStop.js +24 -8
  352. package/dist/shownDate.d.ts +28 -10
  353. package/dist/shownDate.js +41 -22
  354. package/dist/siteSearchBody.d.ts +34 -0
  355. package/dist/siteSearchBody.js +117 -0
  356. package/dist/size.d.ts +7 -1
  357. package/dist/sortableDrop.d.ts +44 -0
  358. package/dist/sortableDrop.js +78 -0
  359. package/dist/sortableSlide.d.ts +9 -0
  360. package/dist/sortableSlide.js +70 -0
  361. package/dist/sortableTitle.d.ts +10 -0
  362. package/dist/sortableTitle.js +48 -0
  363. package/dist/stateMachineDots.d.ts +77 -0
  364. package/dist/stateMachineDots.js +188 -0
  365. package/dist/stickyColumn.d.ts +2 -2
  366. package/dist/stickyColumn.js +2 -2
  367. package/dist/switcher.d.ts +10 -5
  368. package/dist/switcher.js +7 -5
  369. package/dist/tableColumns.d.ts +17 -0
  370. package/dist/tableColumns.js +30 -2
  371. package/dist/tableEmpty.js +5 -5
  372. package/dist/tableRow.d.ts +26 -2
  373. package/dist/tableRow.js +23 -1
  374. package/dist/tableSort.d.ts +10 -5
  375. package/dist/tableSort.js +15 -4
  376. package/dist/target.d.ts +12 -0
  377. package/dist/target.js +12 -0
  378. package/dist/textBox.js +1 -1
  379. package/dist/truncated.d.ts +31 -0
  380. package/dist/truncated.js +51 -0
  381. package/dist/typography.d.ts +19 -11
  382. package/dist/typography.js +11 -13
  383. package/dist/useFlowLayout.d.ts +38 -0
  384. package/dist/useFlowLayout.js +122 -0
  385. package/package.json +5 -3
@@ -0,0 +1,188 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useState } from "react";
3
+ import { cx, focusRing } from "./cx.js";
4
+ import { renderLink } from "./link.js";
5
+ import { VIZ_TONE } from "./StackedBar.js";
6
+ import { useTooltip } from "./Tooltip.js";
7
+ /**
8
+ * The box items whose `state` is no state of the machine go in. Printable, since it reaches the DOM
9
+ * (a box's `data-measure`), where a server render would turn a control character into U+FFFD.
10
+ */
11
+ export const UNPLACED = "hc-sm:unplaced";
12
+ /** A dot's slot in its box: three to a row, each wide enough for a short ref. */
13
+ export const SLOT_W = 76;
14
+ export const SLOT_H = 22;
15
+ export const COLS = 3;
16
+ /** Up to this many dots show in a box; past it, one fewer and a `+N` that shows the rest. */
17
+ const LIMIT = 9;
18
+ /** From a box's bottom edge to its dots' bottom: its border and its bottom padding. */
19
+ const BOX_INSET = 9;
20
+ /** From a slot's left edge to its dot's centre: the chip's inset, its padding and half the dot. */
21
+ const DOT_X = 2 + 4 + 5;
22
+ const CATEGORIES = [
23
+ "cat1",
24
+ "cat2",
25
+ "cat3",
26
+ "cat4",
27
+ "cat5",
28
+ "cat6",
29
+ "cat7",
30
+ "cat8",
31
+ ];
32
+ /** An item's colour, the same for its id wherever it is drawn. */
33
+ function colourOf(id) {
34
+ let sum = 0;
35
+ for (const ch of id)
36
+ sum = (sum * 31 + (ch.codePointAt(0) ?? 0)) % 997;
37
+ return VIZ_TONE[CATEGORIES[sum % CATEGORIES.length] ?? "cat1"];
38
+ }
39
+ // The move is CSS: a dot runs along the arrow's path (`offset-path`) in 600ms while the dot at
40
+ // its new place waits hidden for the same time. Nothing is timed in script: the run ends on its
41
+ // own `animationend`. With reduced motion the run is hidden and over at once (so it still ends),
42
+ // and the dot is in its new place at once.
43
+ const css = `[data-hc-sm-travel]{offset-anchor:center;offset-rotate:0deg;animation:hc-sm-travel .6s ease-in-out forwards}[data-hc-sm-arrive]{animation:hc-sm-arrive .6s linear}@keyframes hc-sm-travel{from{offset-distance:0%}to{offset-distance:100%}}@keyframes hc-sm-arrive{from,to{visibility:hidden}}@media (prefers-reduced-motion:reduce){[data-hc-sm-travel]{visibility:hidden;animation-duration:1ms}[data-hc-sm-arrive]{animation:none}}`;
44
+ /** Which box each item sits in: its state's, else the unplaced box. */
45
+ export function placeOf(items, known) {
46
+ return new Map(items.map((i) => [i.id, known.has(i.state) ? i.state : UNPLACED]));
47
+ }
48
+ /**
49
+ * Remembers where every item was, and when one's place changes records the move, during render
50
+ * (React's "adjust state when a prop changes"), so the re-render that measures the boxes does not
51
+ * lose it. A move ends on its run's `animationend` (`done`), at the next change of places (which
52
+ * records only its own moves), or on `clear` (a box opened, which would start a run long over).
53
+ */
54
+ export function useMoves(items, known) {
55
+ const now = placeOf(items, known);
56
+ const key = JSON.stringify([...now]);
57
+ const [seen, setSeen] = useState({ key, places: now });
58
+ const [moves, setMoves] = useState(new Map());
59
+ // Compared by value: a caller's `items` is often a new array on every render.
60
+ if (seen.key !== key) {
61
+ const next = new Map();
62
+ for (const [id, to] of now) {
63
+ const from = seen.places.get(id);
64
+ if (from !== undefined && from !== to) {
65
+ next.set(id, { from, to, seq: (moves.get(id)?.seq ?? 0) + 1 });
66
+ }
67
+ }
68
+ setSeen({ key, places: now });
69
+ setMoves(next);
70
+ }
71
+ const done = (id, seq) => setMoves((current) => {
72
+ if (current.get(id)?.seq !== seq)
73
+ return current;
74
+ const next = new Map(current);
75
+ next.delete(id);
76
+ return next;
77
+ });
78
+ return { moves, done, clear: () => setMoves(new Map()) };
79
+ }
80
+ /** How many slots a box with `count` items draws: all of them, or the first few and a `+N`; one more for "fewer" when open. */
81
+ export function slotsFor(count, open) {
82
+ if (count <= LIMIT)
83
+ return count;
84
+ return open ? count + 1 : LIMIT;
85
+ }
86
+ /**
87
+ * The rows a box reserves for its dots, whatever its count: the nine it shows (the `+N` included),
88
+ * or the rows of an open box's full list. A box with few or no items reserves the same rows, so
89
+ * its size does not depend on how many items it holds.
90
+ */
91
+ export function rowsFor(slots) {
92
+ return Math.ceil(Math.max(LIMIT, slots) / COLS);
93
+ }
94
+ /**
95
+ * The room a box reserves under its tags for `slots` dots: the full grid's width and `rowsFor`'s
96
+ * height, so it is the same at 0, 1, 9 or 12 items (closed) and grows only when a box is opened.
97
+ */
98
+ export function dotArea(slots) {
99
+ return { width: COLS * SLOT_W, height: rowsFor(slots) * SLOT_H };
100
+ }
101
+ /** A box's tag row: one small pill's height. */
102
+ export const TAG_ROW = 20;
103
+ /** The gap between the tag row and the dot area (`mt-1`). */
104
+ export const TAG_GAP = 4;
105
+ /**
106
+ * The size of what a box holds under its label: its tag row, then its dot area. The layout takes
107
+ * it before the box can be measured (a server render), so the dots, placed up from the box's
108
+ * bottom, already sit under the tags and never on them.
109
+ */
110
+ export function boxContentSize(slots) {
111
+ const area = dotArea(slots);
112
+ return { width: area.width, height: TAG_ROW + TAG_GAP + area.height };
113
+ }
114
+ /** Where slot `i` of `slots` sits in `box`: its left edge and its vertical centre, on the box's fixed grid. */
115
+ export function slotAt(box, i, slots) {
116
+ const top = box.y + box.height - BOX_INSET - rowsFor(slots) * SLOT_H;
117
+ return {
118
+ left: box.x + box.width / 2 - (COLS * SLOT_W) / 2 + (i % COLS) * SLOT_W,
119
+ y: top + Math.floor(i / COLS) * SLOT_H + SLOT_H / 2,
120
+ };
121
+ }
122
+ /** One dot: its colour, its short ref, its full label as name and tooltip, a link when it has `href`. */
123
+ function Dot({ item, where, left, y, arriving, }) {
124
+ const { props, tooltip } = useTooltip(item.label, { describes: false, tap: item.href === undefined }, {});
125
+ const className = cx("pointer-events-auto absolute flex h-5 items-center gap-1 rounded px-1 text-xs text-slate-700", focusRing);
126
+ const position = { ...props.style, left: left + 2, top: y - 10, width: SLOT_W - 4 };
127
+ const body = (_jsxs(_Fragment, { children: [_jsx("span", { "aria-hidden": "true", className: cx("size-2.5 shrink-0 rounded-full bg-current", colourOf(item.id)) }), _jsx("span", { "aria-hidden": "true", className: "truncate", children: item.id })] }));
128
+ const own = {
129
+ ...props,
130
+ style: position,
131
+ "aria-label": `${item.label}, in ${where}`,
132
+ ...(arriving ? { "data-hc-sm-arrive": "" } : {}),
133
+ };
134
+ return (_jsxs(_Fragment, { children: [item.href === undefined ? (_jsx("span", { ...own, role: "img", tabIndex: 0, className: className, children: body })) : (renderLink({
135
+ ...own,
136
+ href: item.href,
137
+ className: cx(className, "hover:underline"),
138
+ children: body,
139
+ })), tooltip] }));
140
+ }
141
+ /** The dot that runs from an item's old box to its new one: along the arrow between them, else straight. */
142
+ function Travel({ item, move, drawn, to, done, }) {
143
+ const from = drawn.nodes.find((n) => n.id === move.from);
144
+ if (!from)
145
+ return null;
146
+ const start = slotAt(from, 0, 1);
147
+ const x0 = start.left + DOT_X;
148
+ const edge = drawn.edges.find((e) => e.from === move.from && e.to === move.to);
149
+ const via = edge ? ` L${edge.path.slice(1)}` : "";
150
+ const d = `M${x0},${start.y}${via} L${to.x},${to.y}`;
151
+ return (_jsx("span", { "aria-hidden": "true", "data-hc-sm-travel": "", onAnimationEnd: done, className: cx("absolute left-0 top-0 size-2.5 rounded-full bg-current", colourOf(item.id)), style: { offsetPath: `path("${d}")` } }));
152
+ }
153
+ /** The `+N` (or "fewer") switch in a full box's last slot. */
154
+ function MoreToggle({ hidden, open, where, left, y, toggle, }) {
155
+ return (_jsx("button", { type: "button", "aria-expanded": open, "aria-label": open ? `Show fewer in ${where}` : `Show ${hidden} more in ${where}`, onClick: toggle, className: cx("pointer-events-auto absolute flex h-5 cursor-pointer items-center rounded px-1 text-xs font-medium text-violet-600 hover:text-violet-700", focusRing), style: { left: left + 2, top: y - 10 }, children: open ? "fewer" : `+${hidden}` }));
156
+ }
157
+ /** One item's dot in `box`, and its run there when it has just moved in. */
158
+ function placeDot(item, at, box, places) {
159
+ const move = places.moves.get(item.id);
160
+ // A run needs the box it leaves; with that box gone (the last unplaced item placed) it just lands.
161
+ const arriving = move?.to === box.id && places.layout.nodes.some((n) => n.id === move.from);
162
+ const dot = (_jsx(Dot, { item: item, where: places.names.get(box.id) ?? box.id, left: at.left, y: at.y, arriving: arriving }, `${item.id}:${box.id}`));
163
+ if (!move || !arriving)
164
+ return [dot];
165
+ return [
166
+ dot,
167
+ _jsx(Travel, { item: item, move: move, drawn: places.layout, to: { x: at.left + DOT_X, y: at.y }, done: () => places.done(item.id, move.seq) }, `${item.id}:${move.seq}`),
168
+ ];
169
+ }
170
+ /** A box's dots: every item, or the first few and the `+N` that shows the rest. */
171
+ function boxDots(box, places) {
172
+ const here = places.inBox.get(box.id) ?? [];
173
+ const open = places.open.has(box.id);
174
+ const count = slotsFor(here.length, open);
175
+ const shown = here.length <= LIMIT || open ? here : here.slice(0, LIMIT - 1);
176
+ const dots = shown.flatMap((item, i) => placeDot(item, slotAt(box, i, count), box, places));
177
+ if (here.length <= LIMIT)
178
+ return dots;
179
+ const at = slotAt(box, count - 1, count);
180
+ return [
181
+ ...dots,
182
+ _jsx(MoreToggle, { hidden: here.length - shown.length, open: open, where: places.names.get(box.id) ?? box.id, left: at.left, y: at.y, toggle: () => places.toggle(box.id) }, `more:${box.id}`),
183
+ ];
184
+ }
185
+ /** Every box's dots, over the drawn diagram. */
186
+ export function dotLayer(layout, places) {
187
+ return (_jsxs(_Fragment, { children: [_jsx("style", { children: css }), layout.nodes.flatMap((box) => boxDots(box, { ...places, layout }))] }));
188
+ }
@@ -14,12 +14,12 @@
14
14
  export declare const STICKY_ASIDE_MD = "md:sticky md:top-[var(--app-header,0px)] md:self-start";
15
15
  export declare const STICKY_SCROLL_MD = "md:-m-1 md:max-h-[calc(100dvh-var(--app-header,0px)-2rem)] md:overflow-y-auto md:p-1";
16
16
  /**
17
- * The thin themed scrollbar (`themedScrollbar` in `cx.ts`) on a rail's scroller from `md`, where it
17
+ * The themed scrollbar (`themedScrollbar` in `cx.ts`) on a rail's scroller from `md`, where it
18
18
  * scrolls, instead of the heavy native one with arrow buttons. Its thumb is the scroller's own text
19
19
  * colour, so the rail's real ink goes back on an inner box (`STICKY_INK_MD`), the colour the shell
20
20
  * gives every page.
21
21
  */
22
- export declare const STICKY_BAR_MD = "md:text-slate-400 md:[scrollbar-width:thin] md:[scrollbar-color:currentColor_transparent]";
22
+ export declare const STICKY_BAR_MD = "md:text-slate-400 md:[scrollbar-color:currentColor_transparent]";
23
23
  export declare const STICKY_INK_MD = "md:text-slate-900";
24
24
  export declare const STICKY_ASIDE_LG = "lg:sticky lg:top-[var(--app-header,0px)] lg:self-start";
25
25
  export declare const STICKY_SCROLL_LG = "lg:-m-1 lg:max-h-[calc(100dvh-var(--app-header,0px)-2rem)] lg:overflow-y-auto lg:p-1";
@@ -14,12 +14,12 @@
14
14
  export const STICKY_ASIDE_MD = "md:sticky md:top-[var(--app-header,0px)] md:self-start";
15
15
  export const STICKY_SCROLL_MD = "md:-m-1 md:max-h-[calc(100dvh-var(--app-header,0px)-2rem)] md:overflow-y-auto md:p-1";
16
16
  /**
17
- * The thin themed scrollbar (`themedScrollbar` in `cx.ts`) on a rail's scroller from `md`, where it
17
+ * The themed scrollbar (`themedScrollbar` in `cx.ts`) on a rail's scroller from `md`, where it
18
18
  * scrolls, instead of the heavy native one with arrow buttons. Its thumb is the scroller's own text
19
19
  * colour, so the rail's real ink goes back on an inner box (`STICKY_INK_MD`), the colour the shell
20
20
  * gives every page.
21
21
  */
22
- export const STICKY_BAR_MD = "md:text-slate-400 md:[scrollbar-width:thin] md:[scrollbar-color:currentColor_transparent]";
22
+ export const STICKY_BAR_MD = "md:text-slate-400 md:[scrollbar-color:currentColor_transparent]";
23
23
  export const STICKY_INK_MD = "md:text-slate-900";
24
24
  export const STICKY_ASIDE_LG = "lg:sticky lg:top-[var(--app-header,0px)] lg:self-start";
25
25
  export const STICKY_SCROLL_LG = "lg:-m-1 lg:max-h-[calc(100dvh-var(--app-header,0px)-2rem)] lg:overflow-y-auto lg:p-1";
@@ -26,8 +26,6 @@ export type SwitchButton = Option & {
26
26
  * keyboard focus and a tap, read out as its description.
27
27
  */
28
28
  disabledReason?: string;
29
- /** The id of the element this option controls (a tab's panel). */
30
- controls?: string;
31
29
  href?: undefined;
32
30
  external?: undefined;
33
31
  };
@@ -43,7 +41,6 @@ export type SwitchLink = Option & {
43
41
  selected?: boolean;
44
42
  disabled?: undefined;
45
43
  disabledReason?: undefined;
46
- controls?: undefined;
47
44
  external?: boolean;
48
45
  /** Where the option links. */
49
46
  href: string;
@@ -54,9 +51,10 @@ type Shared = {
54
51
  /** The accessible name of the group. */
55
52
  label: string;
56
53
  } & Passthrough;
57
- export type SwitchProps = Shared & ({
54
+ /** A group's props; `Button` is its button option (Tabs adds a `panel` to it). */
55
+ export type SwitchProps<Button extends SwitchButton = SwitchButton> = Shared & ({
58
56
  /** The options in order: `{ value, label }` buttons, or links (`href`), the current link marked by its `selected` or by a `value` equal to the group's. Either may carry a `count`; a button may be `disabled`. */
59
- items: SwitchButton[];
57
+ items: Button[];
60
58
  /** The `value` of the current option; for links, an alternative to `selected` on the item. */
61
59
  value: string;
62
60
  /** Called with the option's `value` when one is chosen, by click or arrow key. */
@@ -81,6 +79,13 @@ type Parts = {
81
79
  stacked?: boolean;
82
80
  root: string;
83
81
  option: (active: boolean, disabled: boolean) => string;
82
+ /** Handed the group's root element (the box that scrolls, for a Tabs row). */
83
+ onRoot?: (root: HTMLElement | null) => void;
84
+ /** A button option's own id and the id of the panel it controls (`aria-controls`), by index; none for an option with no panel. */
85
+ ids?: (index: number) => {
86
+ tab: string;
87
+ panel: string;
88
+ } | undefined;
84
89
  };
85
90
  /**
86
91
  * The shared body of Tabs and SegmentedControl: a row of options with one current. Buttons form a
package/dist/switcher.js CHANGED
@@ -22,6 +22,8 @@ function Label({ item }) {
22
22
  return _jsx(_Fragment, { children: item.label });
23
23
  return (_jsxs(_Fragment, { children: [item.label, " ", _jsx("span", { className: "ml-0.5 text-xs tabular-nums opacity-70", children: item.count })] }));
24
24
  }
25
+ /** A tab's own id and `aria-controls`, when it has a panel. */
26
+ const ariaIds = (ids) => ids ? { id: ids.tab, "aria-controls": ids.panel } : {};
25
27
  const isLinks = (items) => items.some((item) => item.href !== undefined);
26
28
  const isCurrent = (item, value) => item.selected === true || (item.value !== undefined && item.value === value);
27
29
  function SwitchLinkItem({ item, current, parts, }) {
@@ -60,19 +62,19 @@ function moveByArrows(event, vertical) {
60
62
  * chooses); links form a `<nav>` with `aria-current="page"` on the current one.
61
63
  */
62
64
  export function Switcher({ items, value, onChange, disabled: groupDisabled, label, parts, ...rest }) {
63
- const root = parts.root;
65
+ const { root, onRoot } = parts;
64
66
  if (isLinks(items)) {
65
- return (_jsx("nav", { ...rest, "aria-label": label, className: root, children: items.map((item, index) => (_jsx(SwitchLinkItem, { item: item, current: isCurrent(item, value), parts: parts }, item.value ?? item.href ?? index))) }));
67
+ return (_jsx("nav", { ...rest, ref: onRoot, "aria-label": label, className: root, children: items.map((item, index) => (_jsx(SwitchLinkItem, { item: item, current: isCurrent(item, value), parts: parts }, item.value ?? item.href ?? index))) }));
66
68
  }
67
69
  const off = (item) => groupDisabled === true || item.disabled === true || hasReason(item.disabledReason);
68
70
  // An option with a reason stays reachable by the arrow keys, so the keyboard finds out why.
69
71
  const reasoned = (item) => groupDisabled !== true && hasReason(item.disabledReason);
70
72
  const enabled = items.filter((item) => !off(item));
71
73
  const stop = enabled.some((item) => item.value === value) ? value : enabled[0]?.value;
72
- return (_jsx("div", { ...rest, role: parts.group, "aria-label": label, ...(parts.stacked ? { "aria-orientation": "vertical" } : {}), ...(groupDisabled ? { "aria-disabled": true } : {}), onKeyDown: (event) => moveByArrows(event, parts.vertical), className: root, children: items.map((item) => (_jsx(Tipped, { text: hasReason(item.disabledReason) ? item.disabledReason : item.title, describes: true, tap: off(item), own: {}, children: (tip) => (_jsx("button", { ...dataAttributes(item), type: "button", role: parts.item, ...(parts.item === "tab"
74
+ return (_jsx("div", { ...rest, ref: onRoot, role: parts.group, "aria-label": label, ...(parts.stacked ? { "aria-orientation": "vertical" } : {}), ...(groupDisabled ? { "aria-disabled": true } : {}), onKeyDown: (event) => moveByArrows(event, parts.vertical), className: root, children: items.map((item, index) => (_jsx(Tipped, { text: hasReason(item.disabledReason) ? item.disabledReason : item.title, describes: true, tap: off(item), own: {}, children: (tip) => (_jsx("button", { ...dataAttributes(item), type: "button", role: parts.item, ...(parts.item === "tab"
73
75
  ? { "aria-selected": item.value === value }
74
- : { "aria-checked": item.value === value }), ...(item.controls === undefined ? {} : { "aria-controls": item.controls }), tabIndex: item.value === stop ? 0 : -1, ...(off(item) ? { "aria-disabled": true } : {}), ...(reasoned(item) ? { "data-hc-reason": "" } : {}), ...tip, onClick: () => {
76
+ : { "aria-checked": item.value === value }), ...ariaIds(parts.ids?.(index)), tabIndex: item.value === stop ? 0 : -1, ...(off(item) ? { "aria-disabled": true } : {}), ...(reasoned(item) ? { "data-hc-reason": "" } : {}), ...tip, onClick: () => {
75
77
  if (!off(item))
76
78
  onChange?.(item.value);
77
- }, className: cx(parts.option(item.value === value, off(item)), off(item) && "cursor-not-allowed opacity-50"), children: _jsx(Label, { item: item }) })) }, item.value))) }));
79
+ }, className: cx(parts.option(item.value === value, off(item)), off(item) ? "cursor-not-allowed opacity-50" : "cursor-pointer"), children: _jsx(Label, { item: item }) })) }, item.value))) }));
78
80
  }
@@ -10,6 +10,12 @@ type TableSetting = {
10
10
  numeric: readonly boolean[];
11
11
  /** How many columns the head declares, or `undefined` with no `TableHead`. */
12
12
  columns: number | undefined;
13
+ /** Says a new sort aloud, through the table's status region: the column's title and its direction. */
14
+ announce: (column: string, sort: "ascending" | "descending") => void;
15
+ /** Whether the table stacks its rows into cards in a narrow box (`narrow="stack"`). */
16
+ stack: boolean;
17
+ /** Each column's visible title from the head, for a stacked cell's label; `undefined` for a column with none. */
18
+ titles: readonly ReactNode[];
13
19
  };
14
20
  export declare const TableContext: import("react").Context<TableSetting>;
15
21
  /**
@@ -18,6 +24,12 @@ export declare const TableContext: import("react").Context<TableSetting>;
18
24
  * own component is not seen; its body cells then say `numeric` themselves.
19
25
  */
20
26
  export declare function numericColumns(children: ReactNode, head: unknown, row: unknown): boolean[];
27
+ /**
28
+ * Each column's visible title, read from the first head row like `numericColumns`: the head cell's
29
+ * children, or `undefined` for a column whose title is a hidden `label` (a row's actions) and for
30
+ * the later columns a spanning title covers.
31
+ */
32
+ export declare function columnTitles(children: ReactNode, head: unknown, row: unknown): ReactNode[];
21
33
  /**
22
34
  * How many columns the table has: the largest total of `colSpan`s (one each when unset) over the
23
35
  * rows of its `TableHead`, read through arrays and fragments. `undefined` when there is no head;
@@ -28,4 +40,9 @@ export declare function columnCount(children: ReactNode, head: unknown, row: unk
28
40
  export declare function withColumns(children: ReactNode): ReactNode[];
29
41
  /** Whether the head declared this cell's column numeric. */
30
42
  export declare function useNumericColumn(): boolean;
43
+ /**
44
+ * A stacked cell's label: its column's title from the head. None for the first column (the card's
45
+ * title), for a cell that spans columns, and outside a stacking table.
46
+ */
47
+ export declare function useStackLabel(spans: boolean): ReactNode;
31
48
  export {};
@@ -4,6 +4,9 @@ export const TableContext = createContext({
4
4
  size: "sm",
5
5
  numeric: [],
6
6
  columns: undefined,
7
+ announce: () => undefined,
8
+ stack: false,
9
+ titles: [],
7
10
  });
8
11
  /** The column a cell starts at, set by its `TableRow`. */
9
12
  const ColumnContext = createContext(undefined);
@@ -27,14 +30,28 @@ function first(children, type) {
27
30
  * own component is not seen; its body cells then say `numeric` themselves.
28
31
  */
29
32
  export function numericColumns(children, head, row) {
33
+ return headCells(children, head, row).flatMap((cell) => isValidElement(cell)
34
+ ? Array.from({ length: span(cell.props) }, () => cell.props.numeric === true)
35
+ : []);
36
+ }
37
+ /** The cells of the table's first head row, read from their element props, or none. */
38
+ function headCells(children, head, row) {
30
39
  const headElement = first(children, head);
31
40
  if (!isValidElement(headElement))
32
41
  return [];
33
42
  const rowElement = first(headElement.props.children, row);
34
43
  if (!isValidElement(rowElement))
35
44
  return [];
36
- return flat(rowElement.props.children).flatMap((cell) => isValidElement(cell)
37
- ? Array.from({ length: span(cell.props) }, () => cell.props.numeric === true)
45
+ return flat(rowElement.props.children);
46
+ }
47
+ /**
48
+ * Each column's visible title, read from the first head row like `numericColumns`: the head cell's
49
+ * children, or `undefined` for a column whose title is a hidden `label` (a row's actions) and for
50
+ * the later columns a spanning title covers.
51
+ */
52
+ export function columnTitles(children, head, row) {
53
+ return headCells(children, head, row).flatMap((cell) => isValidElement(cell)
54
+ ? Array.from({ length: span(cell.props) }, (_, i) => i === 0 && cell.props.label === undefined ? cell.props.children : undefined)
38
55
  : []);
39
56
  }
40
57
  /**
@@ -70,3 +87,14 @@ export function useNumericColumn() {
70
87
  const { numeric } = useContext(TableContext);
71
88
  return at !== undefined && numeric[at] === true;
72
89
  }
90
+ /**
91
+ * A stacked cell's label: its column's title from the head. None for the first column (the card's
92
+ * title), for a cell that spans columns, and outside a stacking table.
93
+ */
94
+ export function useStackLabel(spans) {
95
+ const at = useContext(ColumnContext);
96
+ const { stack, titles } = useContext(TableContext);
97
+ if (!stack || spans || at === undefined || at === 0)
98
+ return undefined;
99
+ return titles[at];
100
+ }
@@ -3,15 +3,15 @@ import { useContext } from "react";
3
3
  import { cx } from "./cx.js";
4
4
  import { EmptySlot } from "./emptySlot.js";
5
5
  import { TableContext } from "./tableColumns.js";
6
- import { BODY_LINE, PAD } from "./tableRow.js";
6
+ import { BODY_LINE, PAD, STACK, stackRole } from "./tableRow.js";
7
7
  import { Bone } from "./skeleton.js";
8
8
  /**
9
9
  * A table body's one row when it has no rows: a cell across every column the head declares, holding
10
10
  * `empty` at the slot's small size. Internal to `TableBody`.
11
11
  */
12
12
  export function EmptyRow({ children }) {
13
- const { columns, size } = useContext(TableContext);
14
- return (_jsx("tr", { className: BODY_LINE, children: _jsx("td", { colSpan: columns ?? 1, className: cx(PAD[size].cell, "text-center"), children: _jsx(EmptySlot, { size: "sm", children: children }) }) }));
13
+ const { columns, size, stack } = useContext(TableContext);
14
+ return (_jsx("tr", { ...stackRole(stack, "row"), className: cx(BODY_LINE, stack && STACK.row), children: _jsx("td", { ...stackRole(stack, "cell"), colSpan: columns ?? 1, className: cx(PAD[size].cell, "text-center", stack && STACK.block), children: _jsx(EmptySlot, { size: "sm", children: children }) }) }));
15
15
  }
16
16
  /** The bones of a body cell: one line of text not here yet. */
17
17
  export const CELL_BONE = "block h-[0.6lh] w-3/4 rounded";
@@ -20,7 +20,7 @@ export const CELL_BONE = "block h-[0.6lh] w-3/4 rounded";
20
20
  * head declares (one across the row with no head). Internal to `TableBody`.
21
21
  */
22
22
  export function BoneRows() {
23
- const { columns, size } = useContext(TableContext);
23
+ const { columns, size, stack } = useContext(TableContext);
24
24
  const cells = Array.from({ length: columns ?? 1 }, (_, i) => i);
25
- return (_jsx(_Fragment, { children: [0, 1, 2, 3, 4].map((row) => (_jsx("tr", { className: BODY_LINE, children: cells.map((cell) => (_jsx("td", { className: PAD[size].cell, children: _jsx(Bone, { shape: CELL_BONE }) }, cell))) }, row))) }));
25
+ return (_jsx(_Fragment, { children: [0, 1, 2, 3, 4].map((row) => (_jsx("tr", { ...stackRole(stack, "row"), className: cx(BODY_LINE, stack && STACK.row), children: cells.map((cell) => (_jsx("td", { ...stackRole(stack, "cell"), className: cx(PAD[size].cell, stack && STACK.block), children: _jsx(Bone, { shape: CELL_BONE }) }, cell))) }, row))) }));
26
26
  }
@@ -9,6 +9,8 @@ export declare const SELECTED = "bg-violet-50 hover:bg-violet-50";
9
9
  * stripe takes the tone's text colour, which every theme already remaps, so no new palette entry.
10
10
  */
11
11
  export type RowTone = "neutral" | "info" | "positive" | "warn" | "danger" | "muted";
12
+ /** A stripe on the leading edge in the current text colour. Shared with `ListRow`. */
13
+ export declare const STRIPE = "shadow-[inset_4px_0_0_0_currentColor]";
12
14
  /** The row's mark: a `tone` (stripe and fill, or faded), a `stripe` alone or `emphasis`, only one of them. */
13
15
  export type RowMark = {
14
16
  /** The row's status: a stripe on the leading edge plus the tone's soft fill, or `muted` to fade the row. Give only one of `tone`, `stripe` and `emphasis`. */
@@ -56,8 +58,30 @@ export declare const PAD: Record<Size, {
56
58
  cell: string;
57
59
  group: string;
58
60
  }>;
59
- export type Align = "start" | "center" | "end";
60
- export declare const ALIGN: Record<Align, string>;
61
+ /**
62
+ * The look of a `Table` with `narrow="stack"` on a screen narrower than `sm` (a phone): the table,
63
+ * its sections and its rows become blocks, the head is hidden but still read, and each cell is a
64
+ * line of the row's card, its column's title at the start and its value at the end. The first
65
+ * column is the card's title. A viewport query, not a container query: a container has no width
66
+ * of its own, so a table in a box that sizes to its content would collapse to nothing.
67
+ */
68
+ export declare const STACK: {
69
+ readonly table: "max-sm:block";
70
+ readonly head: "max-sm:sr-only";
71
+ readonly section: "max-sm:block";
72
+ readonly row: "max-sm:block max-sm:py-2";
73
+ readonly cell: "max-sm:flex max-sm:min-w-0 max-sm:items-baseline max-sm:justify-between max-sm:gap-4 max-sm:whitespace-normal max-sm:py-1";
74
+ readonly block: "max-sm:block max-sm:min-w-0 max-sm:whitespace-normal max-sm:py-1";
75
+ readonly label: "hidden shrink-0 text-xs font-medium uppercase tracking-wide text-slate-500 max-sm:block";
76
+ readonly value: "min-w-0 max-sm:text-right";
77
+ };
78
+ /** The ARIA role a stacking table puts on a part, since a part drawn as a block can lose its table role in some browsers. */
79
+ export declare function stackRole(stack: boolean, role: string): {
80
+ role?: string;
81
+ };
82
+ /** Where a table cell's content sits across it: `start`, `center` or `end` (numbers). */
83
+ export type CellAlign = "start" | "center" | "end";
84
+ export declare const ALIGN: Record<CellAlign, string>;
61
85
  /**
62
86
  * Whether a `TableRow` sits in the body (a line above, a hover fill), the foot (a firmer line above,
63
87
  * strong cells) or the head or nowhere (neither).
package/dist/tableRow.js CHANGED
@@ -13,7 +13,8 @@ const ROW_TONE = {
13
13
  danger: "bg-red-50 text-red-700",
14
14
  muted: "opacity-60",
15
15
  };
16
- const STRIPE = "shadow-[inset_4px_0_0_0_currentColor]";
16
+ /** A stripe on the leading edge in the current text colour. Shared with `ListRow`. */
17
+ export const STRIPE = "shadow-[inset_4px_0_0_0_currentColor]";
17
18
  export const BODY_LINE = cx("relative border-t border-slate-200/70", liftInteractive);
18
19
  /** The classes of a row: a line above in the body and the foot, the hover fill and the tone's or stripe's look in the body only. */
19
20
  export function rowClass(section, plain, tone, stripe) {
@@ -37,6 +38,27 @@ export const PAD = {
37
38
  md: { head: "px-5 py-3", cell: "px-5 py-4", group: "px-5 py-2.5" },
38
39
  lg: { head: "px-6 py-3.5", cell: "px-6 py-5", group: "px-6 py-3" },
39
40
  };
41
+ /**
42
+ * The look of a `Table` with `narrow="stack"` on a screen narrower than `sm` (a phone): the table,
43
+ * its sections and its rows become blocks, the head is hidden but still read, and each cell is a
44
+ * line of the row's card, its column's title at the start and its value at the end. The first
45
+ * column is the card's title. A viewport query, not a container query: a container has no width
46
+ * of its own, so a table in a box that sizes to its content would collapse to nothing.
47
+ */
48
+ export const STACK = {
49
+ table: "max-sm:block",
50
+ head: "max-sm:sr-only",
51
+ section: "max-sm:block",
52
+ row: "max-sm:block max-sm:py-2",
53
+ cell: "max-sm:flex max-sm:min-w-0 max-sm:items-baseline max-sm:justify-between max-sm:gap-4 max-sm:whitespace-normal max-sm:py-1",
54
+ block: "max-sm:block max-sm:min-w-0 max-sm:whitespace-normal max-sm:py-1",
55
+ label: "hidden shrink-0 text-xs font-medium uppercase tracking-wide text-slate-500 max-sm:block",
56
+ value: "min-w-0 max-sm:text-right",
57
+ };
58
+ /** The ARIA role a stacking table puts on a part, since a part drawn as a block can lose its table role in some browsers. */
59
+ export function stackRole(stack, role) {
60
+ return stack ? { role } : {};
61
+ }
40
62
  export const ALIGN = {
41
63
  start: "text-left",
42
64
  center: "text-center",
@@ -1,5 +1,5 @@
1
- import type { ReactElement, ReactNode } from "react";
2
- import type { Align } from "./tableRow.js";
1
+ import { type ReactElement, type ReactNode } from "react";
2
+ import type { CellAlign } from "./tableRow.js";
3
3
  /** Where a sortable column stands: ARIA's own words. `none` is a column the table is not sorted by. */
4
4
  export type TableSort = "ascending" | "descending" | "none";
5
5
  /** The props of a sortable `TableHeaderCell`: the column's `sort` and what a click asks for. */
@@ -15,8 +15,13 @@ export type SortProps = {
15
15
  /** Called with the next direction on a click: `none` goes to `ascending`, then each click flips it. */
16
16
  onSort: (next: "ascending" | "descending") => void;
17
17
  };
18
- /** A sortable column's title: a native button that fills the cell, named by the title. */
19
- export declare function SortButton({ sort, onSort, align, children, }: SortProps & {
20
- align: Align;
18
+ /**
19
+ * A sortable column's title: a native button that fills the cell, padding and all, so the whole
20
+ * cell is its target (never under 24px tall), named by the title. A click asks for the next
21
+ * direction and has the table say the new sort aloud.
22
+ */
23
+ export declare function SortButton({ sort, onSort, align, pad, children, }: SortProps & {
24
+ align: CellAlign;
25
+ pad: string;
21
26
  children: ReactNode;
22
27
  }): ReactElement;
package/dist/tableSort.js CHANGED
@@ -1,5 +1,7 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { cx, focusRing } from "./cx.js";
2
+ import { useContext } from "react";
3
+ import { cx, insetFocusRing } from "./cx.js";
4
+ import { TableContext } from "./tableColumns.js";
3
5
  /** The direction a click asks for: `ascending` first, then it flips. */
4
6
  function nextSort(sort) {
5
7
  return sort === "ascending" ? "descending" : "ascending";
@@ -13,7 +15,16 @@ const JUSTIFY = {
13
15
  function SortArrow({ sort }) {
14
16
  return (_jsxs("svg", { "aria-hidden": "true", viewBox: "0 0 12 12", className: cx("size-3 shrink-0", sort === "none" ? "text-slate-300" : "text-slate-600"), fill: "currentColor", children: [sort !== "descending" && _jsx("path", { d: "M6 1.5 9 5H3z" }), sort !== "ascending" && _jsx("path", { d: "M6 10.5 3 7h6z" })] }));
15
17
  }
16
- /** A sortable column's title: a native button that fills the cell, named by the title. */
17
- export function SortButton({ sort, onSort, align, children, }) {
18
- return (_jsxs("button", { type: "button", onClick: () => onSort(nextSort(sort)), className: cx("inline-flex w-full cursor-pointer items-center gap-1 rounded-sm uppercase tracking-wide hover:text-violet-700", JUSTIFY[align], focusRing), children: [children, _jsx(SortArrow, { sort: sort })] }));
18
+ /**
19
+ * A sortable column's title: a native button that fills the cell, padding and all, so the whole
20
+ * cell is its target (never under 24px tall), named by the title. A click asks for the next
21
+ * direction and has the table say the new sort aloud.
22
+ */
23
+ export function SortButton({ sort, onSort, align, pad, children, }) {
24
+ const { announce } = useContext(TableContext);
25
+ return (_jsxs("button", { type: "button", onClick: (event) => {
26
+ const next = nextSort(sort);
27
+ onSort(next);
28
+ announce(event.currentTarget.textContent.trim(), next);
29
+ }, className: cx("flex min-h-6 w-full cursor-pointer items-center gap-1 uppercase tracking-wide hover:text-violet-700", pad, JUSTIFY[align], insetFocusRing), children: [children, _jsx(SortArrow, { sort: sort })] }));
19
30
  }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Hit areas bigger than what is drawn, made with an invisible `::before` centred on the element: it
3
+ * covers the element and grows to the minimum, so a click or tap on it lands on the element (a
4
+ * label's area toggles its input). Nothing moves: the pseudo-element is absolutely placed.
5
+ */
6
+ /** At least 24px square for every pointer (WCAG 2.5.8), for a control drawn smaller (a `sm` Switch). */
7
+ export declare const MIN_TARGET = "relative before:absolute before:top-1/2 before:left-1/2 before:size-full before:min-h-6 before:min-w-6 before:-translate-x-1/2 before:-translate-y-1/2";
8
+ /**
9
+ * At least 44px square under a coarse pointer (a finger), for a small choice (a `Checkbox`, a
10
+ * `Radio`). A mouse keeps the drawn size, so stacked choices do not overlap.
11
+ */
12
+ export declare const TOUCH_TARGET = "relative pointer-coarse:before:absolute pointer-coarse:before:top-1/2 pointer-coarse:before:left-1/2 pointer-coarse:before:size-full pointer-coarse:before:min-h-11 pointer-coarse:before:min-w-11 pointer-coarse:before:-translate-x-1/2 pointer-coarse:before:-translate-y-1/2";
package/dist/target.js ADDED
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Hit areas bigger than what is drawn, made with an invisible `::before` centred on the element: it
3
+ * covers the element and grows to the minimum, so a click or tap on it lands on the element (a
4
+ * label's area toggles its input). Nothing moves: the pseudo-element is absolutely placed.
5
+ */
6
+ /** At least 24px square for every pointer (WCAG 2.5.8), for a control drawn smaller (a `sm` Switch). */
7
+ export const MIN_TARGET = "relative before:absolute before:top-1/2 before:left-1/2 before:size-full before:min-h-6 before:min-w-6 before:-translate-x-1/2 before:-translate-y-1/2";
8
+ /**
9
+ * At least 44px square under a coarse pointer (a finger), for a small choice (a `Checkbox`, a
10
+ * `Radio`). A mouse keeps the drawn size, so stacked choices do not overlap.
11
+ */
12
+ export const TOUCH_TARGET = "relative pointer-coarse:before:absolute pointer-coarse:before:top-1/2 pointer-coarse:before:left-1/2 pointer-coarse:before:size-full pointer-coarse:before:min-h-11 pointer-coarse:before:min-w-11 pointer-coarse:before:-translate-x-1/2 pointer-coarse:before:-translate-y-1/2";
package/dist/textBox.js CHANGED
@@ -17,7 +17,7 @@ const CLAMP = {
17
17
  */
18
18
  export function layoutClass(align, lines) {
19
19
  const box = lines === 1
20
- ? cx("min-w-0 truncate align-bottom", align ? "block" : "inline-block")
20
+ ? cx("min-w-0 max-w-full truncate align-bottom", align ? "block" : "inline-block")
21
21
  : (lines && CLAMP[lines]) || (align && "block");
22
22
  return cx(align && ALIGN[align], box);
23
23
  }
@@ -0,0 +1,31 @@
1
+ import { type ReactElement, type ReactNode, type RefObject } from "react";
2
+ type Cut = {
3
+ cut: boolean;
4
+ inner: boolean;
5
+ };
6
+ /**
7
+ * Whether the run in `ref` is cut by its box, and whether it holds its own focusable. Measured on
8
+ * each resize and when `text` changes. jsdom (a consumer's own tests) has no ResizeObserver, so
9
+ * there it reads never cut.
10
+ */
11
+ export declare function useCut(ref: RefObject<HTMLElement | null>, text: string | undefined): Cut;
12
+ /**
13
+ * A one-line truncated run (`truncate` plus the caller's width) that shows its whole `text` in a
14
+ * tooltip while it is cut. A run that holds a link takes the link's focus; a plain one becomes a
15
+ * focus stop only while it is cut and the tooltip is the library's own, so the keyboard can reach
16
+ * it. Internal.
17
+ */
18
+ export declare function Truncated({ text, as: Tag, attrs, className, children, }: {
19
+ /** The run's element: a block `div`, or inline `code`. */
20
+ as?: "div" | "code" | undefined;
21
+ /** The caller's own attributes for the run (`id`, `data-*`, `aria-*`). */
22
+ attrs?: {
23
+ "aria-describedby"?: string | undefined;
24
+ } | undefined;
25
+ /** The run's whole text; left out (the run is not plain text), it truncates with no tooltip. */
26
+ text: string | undefined;
27
+ /** The run's width and placement, added to `truncate`. */
28
+ className?: string | undefined;
29
+ children: ReactNode;
30
+ }): ReactElement;
31
+ export {};