@slashsuite/ui-react 0.12.0 → 0.13.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 (388) hide show
  1. package/MIGRATING.md +386 -8
  2. package/README.md +101 -44
  3. package/agent-docs/components/app-shell.md +139 -0
  4. package/agent-docs/components/article-layout.md +140 -0
  5. package/agent-docs/components/audio.md +42 -0
  6. package/agent-docs/components/avatar-stack.md +64 -0
  7. package/agent-docs/components/avatar.md +76 -0
  8. package/agent-docs/components/badge.md +62 -0
  9. package/agent-docs/components/body-text.md +169 -0
  10. package/agent-docs/components/bottom-sheet.md +105 -0
  11. package/agent-docs/components/breadcrumbs.md +66 -0
  12. package/agent-docs/components/bullet-list.md +54 -0
  13. package/agent-docs/components/button.md +135 -0
  14. package/agent-docs/components/call-to-action.md +59 -0
  15. package/agent-docs/components/callout.md +87 -0
  16. package/agent-docs/components/card-grid.md +116 -0
  17. package/agent-docs/components/card.md +128 -0
  18. package/agent-docs/components/cart-button.md +63 -0
  19. package/agent-docs/components/centered-layout.md +90 -0
  20. package/agent-docs/components/chat-composer.md +49 -0
  21. package/agent-docs/components/chat-message.md +61 -0
  22. package/agent-docs/components/chat-thread.md +49 -0
  23. package/agent-docs/components/checkbox.md +81 -0
  24. package/agent-docs/components/cluster.md +108 -0
  25. package/agent-docs/components/code-example.md +48 -0
  26. package/agent-docs/components/code.md +72 -0
  27. package/agent-docs/components/colour-scheme-toggle.md +98 -0
  28. package/agent-docs/components/colour-swatch.md +41 -0
  29. package/agent-docs/components/combobox.md +88 -0
  30. package/agent-docs/components/confirm-dialog.md +98 -0
  31. package/agent-docs/components/container.md +51 -0
  32. package/agent-docs/components/copy-button.md +63 -0
  33. package/agent-docs/components/copy-line.md +55 -0
  34. package/agent-docs/components/date-field.md +106 -0
  35. package/agent-docs/components/date-range-picker.md +108 -0
  36. package/agent-docs/components/date-time-field.md +73 -0
  37. package/agent-docs/components/detail-layout.md +147 -0
  38. package/agent-docs/components/dialog.md +132 -0
  39. package/agent-docs/components/disclosure.md +70 -0
  40. package/agent-docs/components/divider.md +62 -0
  41. package/agent-docs/components/docs-layout.md +164 -0
  42. package/agent-docs/components/drawer.md +137 -0
  43. package/agent-docs/components/embed-frame.md +48 -0
  44. package/agent-docs/components/empty-state.md +70 -0
  45. package/agent-docs/components/field-dialog.md +98 -0
  46. package/agent-docs/components/field.md +71 -0
  47. package/agent-docs/components/fieldset.md +82 -0
  48. package/agent-docs/components/file-drop.md +52 -0
  49. package/agent-docs/components/flow-diagram.md +87 -0
  50. package/agent-docs/components/form-layout.md +144 -0
  51. package/agent-docs/components/form-row.md +93 -0
  52. package/agent-docs/components/full-bleed-layout.md +114 -0
  53. package/agent-docs/components/headings.md +107 -0
  54. package/agent-docs/components/hero.md +68 -0
  55. package/agent-docs/components/icon-button.md +90 -0
  56. package/agent-docs/components/icon.md +59 -0
  57. package/agent-docs/components/image.md +74 -0
  58. package/agent-docs/components/input.md +84 -0
  59. package/agent-docs/components/kbd.md +38 -0
  60. package/agent-docs/components/key-value-list.md +84 -0
  61. package/agent-docs/components/lightbox.md +97 -0
  62. package/agent-docs/components/list-layout.md +152 -0
  63. package/agent-docs/components/list-row.md +119 -0
  64. package/agent-docs/components/loading.md +69 -0
  65. package/agent-docs/components/markdown.md +51 -0
  66. package/agent-docs/components/media-tile.md +101 -0
  67. package/agent-docs/components/menu.md +110 -0
  68. package/agent-docs/components/meta-list.md +69 -0
  69. package/agent-docs/components/morph.md +134 -0
  70. package/agent-docs/components/navigation-progress.md +56 -0
  71. package/agent-docs/components/number-field.md +75 -0
  72. package/agent-docs/components/outline-region.md +74 -0
  73. package/agent-docs/components/page-fade.md +117 -0
  74. package/agent-docs/components/page-header.md +93 -0
  75. package/agent-docs/components/pagination.md +64 -0
  76. package/agent-docs/components/pill.md +105 -0
  77. package/agent-docs/components/popover.md +63 -0
  78. package/agent-docs/components/price.md +49 -0
  79. package/agent-docs/components/product-tile.md +78 -0
  80. package/agent-docs/components/progress-bar.md +66 -0
  81. package/agent-docs/components/promo-banner.md +46 -0
  82. package/agent-docs/components/prose-layout.md +87 -0
  83. package/agent-docs/components/prose.md +41 -0
  84. package/agent-docs/components/radio-group.md +77 -0
  85. package/agent-docs/components/scroll-strip.md +48 -0
  86. package/agent-docs/components/segmented-control.md +135 -0
  87. package/agent-docs/components/select.md +70 -0
  88. package/agent-docs/components/show.md +120 -0
  89. package/agent-docs/components/side-column.md +74 -0
  90. package/agent-docs/components/sidebar-layout.md +134 -0
  91. package/agent-docs/components/site-footer.md +63 -0
  92. package/agent-docs/components/site-search.md +79 -0
  93. package/agent-docs/components/slider.md +59 -0
  94. package/agent-docs/components/sortable-list.md +112 -0
  95. package/agent-docs/components/split-bar.md +54 -0
  96. package/agent-docs/components/stack.md +197 -0
  97. package/agent-docs/components/stacked-bar.md +91 -0
  98. package/agent-docs/components/stat-tile.md +69 -0
  99. package/agent-docs/components/state-machine.md +95 -0
  100. package/agent-docs/components/status-pages.md +112 -0
  101. package/agent-docs/components/stepper.md +54 -0
  102. package/agent-docs/components/steps.md +74 -0
  103. package/agent-docs/components/sticky-bar.md +51 -0
  104. package/agent-docs/components/switch.md +79 -0
  105. package/agent-docs/components/table-of-contents.md +78 -0
  106. package/agent-docs/components/table.md +384 -0
  107. package/agent-docs/components/tabs.md +178 -0
  108. package/agent-docs/components/text-link.md +110 -0
  109. package/agent-docs/components/textarea.md +53 -0
  110. package/agent-docs/components/timeline.md +79 -0
  111. package/agent-docs/components/toast.md +91 -0
  112. package/agent-docs/components/trend-chart.md +61 -0
  113. package/agent-docs/components/video.md +49 -0
  114. package/agent-docs/llms.txt +174 -0
  115. package/dist/AppShell.d.ts +25 -9
  116. package/dist/AppShell.js +67 -33
  117. package/dist/AppShellMenu.d.ts +31 -18
  118. package/dist/AppShellMenu.js +72 -45
  119. package/dist/ArticleLayout.d.ts +36 -0
  120. package/dist/ArticleLayout.js +27 -0
  121. package/dist/Audio.d.ts +16 -0
  122. package/dist/Audio.js +11 -0
  123. package/dist/Badge.d.ts +2 -1
  124. package/dist/Badge.js +3 -2
  125. package/dist/BottomSheet.d.ts +17 -6
  126. package/dist/BottomSheet.js +62 -11
  127. package/dist/Breadcrumbs.d.ts +8 -6
  128. package/dist/Breadcrumbs.js +17 -7
  129. package/dist/Button.d.ts +1 -0
  130. package/dist/Button.js +4 -3
  131. package/dist/CallToAction.d.ts +25 -0
  132. package/dist/CallToAction.js +17 -0
  133. package/dist/Callout.d.ts +2 -2
  134. package/dist/Callout.js +2 -2
  135. package/dist/Card.d.ts +88 -31
  136. package/dist/Card.js +55 -92
  137. package/dist/CardBody.d.ts +2 -0
  138. package/dist/CardBody.js +33 -3
  139. package/dist/CardGrid.d.ts +32 -4
  140. package/dist/CardGrid.js +42 -8
  141. package/dist/CardParts.d.ts +7 -1
  142. package/dist/CardParts.js +7 -2
  143. package/dist/CartButton.d.ts +33 -0
  144. package/dist/CartButton.js +18 -0
  145. package/dist/ChatComposer.d.ts +10 -4
  146. package/dist/ChatComposer.js +35 -13
  147. package/dist/Checkbox.d.ts +21 -3
  148. package/dist/Checkbox.js +66 -20
  149. package/dist/Chevron.js +1 -1
  150. package/dist/Cluster.d.ts +28 -15
  151. package/dist/Cluster.js +21 -4
  152. package/dist/Code.d.ts +15 -3
  153. package/dist/Code.js +23 -3
  154. package/dist/CodeBlock.d.ts +4 -4
  155. package/dist/CodeBlock.js +2 -2
  156. package/dist/CodeBody.d.ts +1 -1
  157. package/dist/CodeBody.js +4 -10
  158. package/dist/CodeExample.d.ts +1 -1
  159. package/dist/CodeExample.js +3 -2
  160. package/dist/ColourSchemeToggle.d.ts +21 -5
  161. package/dist/ColourSchemeToggle.js +15 -9
  162. package/dist/ColourSwatch.d.ts +15 -0
  163. package/dist/ColourSwatch.js +14 -0
  164. package/dist/Combobox.d.ts +42 -0
  165. package/dist/Combobox.js +43 -0
  166. package/dist/ConfirmDialog.d.ts +40 -0
  167. package/dist/ConfirmDialog.js +36 -0
  168. package/dist/Container.d.ts +3 -3
  169. package/dist/Container.js +1 -1
  170. package/dist/CopyButton.d.ts +8 -2
  171. package/dist/CopyButton.js +38 -28
  172. package/dist/CopyLine.d.ts +4 -2
  173. package/dist/CopyLine.js +4 -4
  174. package/dist/DateCalendar.d.ts +2 -0
  175. package/dist/DateCalendar.js +11 -9
  176. package/dist/DateField.d.ts +52 -21
  177. package/dist/DateField.js +73 -37
  178. package/dist/DateFieldCalendar.d.ts +12 -8
  179. package/dist/DateFieldCalendar.js +37 -18
  180. package/dist/DateRangePicker.d.ts +23 -3
  181. package/dist/DateRangePicker.js +10 -8
  182. package/dist/DateTimeField.d.ts +31 -0
  183. package/dist/DateTimeField.js +19 -0
  184. package/dist/Dialog.d.ts +42 -6
  185. package/dist/Dialog.js +50 -12
  186. package/dist/Disclosure.js +9 -1
  187. package/dist/DocsLayout.d.ts +13 -5
  188. package/dist/DocsLayout.js +11 -9
  189. package/dist/Drawer.d.ts +22 -7
  190. package/dist/Drawer.js +89 -8
  191. package/dist/EmbedFrame.d.ts +36 -0
  192. package/dist/EmbedFrame.js +18 -0
  193. package/dist/Field.d.ts +41 -4
  194. package/dist/Field.js +61 -25
  195. package/dist/FieldDialog.d.ts +8 -3
  196. package/dist/FieldDialog.js +19 -9
  197. package/dist/Fieldset.d.ts +3 -3
  198. package/dist/Fieldset.js +7 -9
  199. package/dist/FileDrop.js +2 -1
  200. package/dist/FlowDiagram.d.ts +92 -0
  201. package/dist/FlowDiagram.js +100 -0
  202. package/dist/FormRow.d.ts +6 -4
  203. package/dist/FormRow.js +11 -9
  204. package/dist/Hero.d.ts +30 -7
  205. package/dist/Hero.js +23 -9
  206. package/dist/Icon.d.ts +1 -1
  207. package/dist/Icon.js +1 -1
  208. package/dist/IconButton.js +1 -1
  209. package/dist/Image.d.ts +33 -9
  210. package/dist/Image.js +61 -16
  211. package/dist/Input.d.ts +1 -1
  212. package/dist/Input.js +4 -4
  213. package/dist/InputShell.d.ts +7 -0
  214. package/dist/InputShell.js +18 -3
  215. package/dist/KeyValueList.d.ts +2 -2
  216. package/dist/Lightbox.js +5 -3
  217. package/dist/ListRow.d.ts +4 -5
  218. package/dist/ListRow.js +36 -26
  219. package/dist/Mark.d.ts +10 -0
  220. package/dist/Mark.js +9 -0
  221. package/dist/Markdown.d.ts +18 -4
  222. package/dist/Markdown.js +176 -37
  223. package/dist/MediaTile.d.ts +9 -3
  224. package/dist/MediaTile.js +8 -4
  225. package/dist/Menu.d.ts +19 -8
  226. package/dist/Menu.js +13 -11
  227. package/dist/MetaList.d.ts +4 -3
  228. package/dist/MetaList.js +12 -4
  229. package/dist/Morph.d.ts +15 -1
  230. package/dist/Morph.js +70 -22
  231. package/dist/NavigationProgress.d.ts +2 -2
  232. package/dist/NavigationProgress.js +7 -5
  233. package/dist/NumberField.d.ts +66 -0
  234. package/dist/NumberField.js +68 -0
  235. package/dist/OutlineRegion.d.ts +41 -10
  236. package/dist/OutlineRegion.js +31 -6
  237. package/dist/PageFade.d.ts +9 -5
  238. package/dist/PageFade.js +39 -8
  239. package/dist/PageLayouts.d.ts +15 -5
  240. package/dist/PageLayouts.js +3 -3
  241. package/dist/Pill.d.ts +9 -4
  242. package/dist/Pill.js +15 -6
  243. package/dist/Popover.d.ts +31 -0
  244. package/dist/Popover.js +43 -0
  245. package/dist/Price.d.ts +21 -0
  246. package/dist/Price.js +34 -0
  247. package/dist/ProductTile.d.ts +36 -0
  248. package/dist/ProductTile.js +31 -0
  249. package/dist/ProgressBar.js +4 -2
  250. package/dist/PromoBanner.d.ts +25 -0
  251. package/dist/PromoBanner.js +16 -0
  252. package/dist/RadioGroup.d.ts +18 -8
  253. package/dist/RadioGroup.js +42 -18
  254. package/dist/ScrollStrip.d.ts +1 -1
  255. package/dist/ScrollStrip.js +1 -1
  256. package/dist/SearchInput.d.ts +17 -2
  257. package/dist/SearchInput.js +72 -13
  258. package/dist/SegmentedField.d.ts +15 -0
  259. package/dist/SegmentedField.js +15 -0
  260. package/dist/Select.js +5 -4
  261. package/dist/Show.d.ts +1 -1
  262. package/dist/Show.js +1 -1
  263. package/dist/SideColumn.d.ts +42 -15
  264. package/dist/SideColumn.js +45 -19
  265. package/dist/SiteFooter.d.ts +3 -3
  266. package/dist/SiteFooter.js +4 -3
  267. package/dist/SiteSearch.d.ts +57 -27
  268. package/dist/SiteSearch.js +13 -93
  269. package/dist/Slider.d.ts +27 -0
  270. package/dist/Slider.js +58 -0
  271. package/dist/SortableList.d.ts +19 -35
  272. package/dist/SortableList.js +36 -88
  273. package/dist/Stack.d.ts +4 -4
  274. package/dist/StackedBar.d.ts +13 -4
  275. package/dist/StackedBar.js +12 -7
  276. package/dist/StateMachine.d.ts +65 -0
  277. package/dist/StateMachine.js +113 -0
  278. package/dist/StatusPages.d.ts +28 -10
  279. package/dist/StatusPages.js +10 -10
  280. package/dist/Stepper.d.ts +21 -0
  281. package/dist/Stepper.js +33 -0
  282. package/dist/Steps.js +4 -3
  283. package/dist/Switch.d.ts +3 -3
  284. package/dist/Switch.js +18 -14
  285. package/dist/Table.d.ts +32 -9
  286. package/dist/Table.js +50 -20
  287. package/dist/TableCells.d.ts +24 -21
  288. package/dist/TableCells.js +68 -27
  289. package/dist/TableEditCell.d.ts +1 -1
  290. package/dist/TableOfContents.d.ts +34 -0
  291. package/dist/TableOfContents.js +23 -0
  292. package/dist/Tabs.d.ts +31 -16
  293. package/dist/Tabs.js +97 -22
  294. package/dist/TextLink.d.ts +18 -5
  295. package/dist/TextLink.js +19 -6
  296. package/dist/Textarea.d.ts +12 -1
  297. package/dist/Textarea.js +15 -2
  298. package/dist/ToastRegion.d.ts +17 -9
  299. package/dist/ToastRegion.js +70 -13
  300. package/dist/Tooltip.d.ts +10 -2
  301. package/dist/Tooltip.js +32 -11
  302. package/dist/Video.d.ts +19 -4
  303. package/dist/Video.js +15 -5
  304. package/dist/cardContext.d.ts +7 -0
  305. package/dist/cardContext.js +14 -0
  306. package/dist/cardControl.d.ts +15 -0
  307. package/dist/cardControl.js +32 -0
  308. package/dist/cardForm.d.ts +39 -0
  309. package/dist/cardForm.js +81 -0
  310. package/dist/cardWait.js +2 -1
  311. package/dist/colourScheme.d.ts +12 -2
  312. package/dist/colourScheme.js +32 -6
  313. package/dist/control.d.ts +30 -8
  314. package/dist/control.js +74 -7
  315. package/dist/copyScript.d.ts +7 -8
  316. package/dist/copyScript.js +8 -9
  317. package/dist/cx.d.ts +22 -3
  318. package/dist/cx.js +22 -3
  319. package/dist/dateLocale.d.ts +17 -0
  320. package/dist/dateLocale.js +30 -0
  321. package/dist/density.d.ts +15 -1
  322. package/dist/density.js +27 -8
  323. package/dist/emptySlot.d.ts +1 -0
  324. package/dist/fieldAnnounce.d.ts +11 -0
  325. package/dist/fieldAnnounce.js +36 -0
  326. package/dist/fieldControl.d.ts +7 -2
  327. package/dist/fieldControl.js +6 -2
  328. package/dist/fieldWait.d.ts +3 -3
  329. package/dist/fieldWait.js +3 -4
  330. package/dist/flowLayout.d.ts +68 -0
  331. package/dist/flowLayout.js +105 -0
  332. package/dist/fromXState.d.ts +73 -0
  333. package/dist/fromXState.js +110 -0
  334. package/dist/icons.d.ts +1 -1
  335. package/dist/icons.js +15 -0
  336. package/dist/index.d.ts +37 -11
  337. package/dist/index.js +24 -2
  338. package/dist/isoDate.d.ts +8 -1
  339. package/dist/isoDate.js +20 -1
  340. package/dist/labelWords.d.ts +16 -7
  341. package/dist/labelWords.js +14 -12
  342. package/dist/listRowProps.d.ts +17 -15
  343. package/dist/modal.d.ts +5 -0
  344. package/dist/modal.js +21 -1
  345. package/dist/navFold.js +6 -3
  346. package/dist/optionCard.d.ts +18 -0
  347. package/dist/optionCard.js +16 -0
  348. package/dist/scrollBody.d.ts +16 -0
  349. package/dist/scrollBody.js +15 -0
  350. package/dist/scrollEdges.d.ts +7 -0
  351. package/dist/scrollEdges.js +39 -5
  352. package/dist/scrollStop.d.ts +6 -2
  353. package/dist/scrollStop.js +24 -8
  354. package/dist/shownDate.d.ts +28 -10
  355. package/dist/shownDate.js +41 -22
  356. package/dist/siteSearchBody.d.ts +34 -0
  357. package/dist/siteSearchBody.js +117 -0
  358. package/dist/size.d.ts +7 -1
  359. package/dist/sortableDrop.d.ts +44 -0
  360. package/dist/sortableDrop.js +78 -0
  361. package/dist/sortableSlide.d.ts +9 -0
  362. package/dist/sortableSlide.js +70 -0
  363. package/dist/sortableTitle.d.ts +10 -0
  364. package/dist/sortableTitle.js +48 -0
  365. package/dist/stateMachineDots.d.ts +45 -0
  366. package/dist/stateMachineDots.js +162 -0
  367. package/dist/stickyColumn.d.ts +2 -2
  368. package/dist/stickyColumn.js +2 -2
  369. package/dist/switcher.d.ts +10 -5
  370. package/dist/switcher.js +7 -5
  371. package/dist/tableColumns.d.ts +17 -0
  372. package/dist/tableColumns.js +30 -2
  373. package/dist/tableEmpty.js +5 -5
  374. package/dist/tableRow.d.ts +26 -2
  375. package/dist/tableRow.js +23 -1
  376. package/dist/tableSort.d.ts +10 -5
  377. package/dist/tableSort.js +15 -4
  378. package/dist/target.d.ts +12 -0
  379. package/dist/target.js +12 -0
  380. package/dist/textBox.js +1 -1
  381. package/dist/truncated.d.ts +31 -0
  382. package/dist/truncated.js +51 -0
  383. package/dist/typography.d.ts +19 -11
  384. package/dist/typography.js +11 -13
  385. package/dist/useFlowLayout.d.ts +27 -0
  386. package/dist/useFlowLayout.js +119 -0
  387. package/package.json +7 -3
  388. package/skills/uislash/SKILL.md +20 -0
package/dist/Table.js CHANGED
@@ -1,37 +1,64 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useContext } from "react";
2
+ import { useCallback, useContext, useState } from "react";
3
3
  import { useInCard } from "./cardContext.js";
4
4
  import { cx } from "./cx.js";
5
5
  import { DensityProvider } from "./density.js";
6
6
  import { hasNoChildren } from "./emptySlot.js";
7
- import { columnCount, numericColumns, TableContext, withColumns } from "./tableColumns.js";
8
- import { rowClass, SectionContext, SELECTED, BODY_LINE, PAD, } from "./tableRow.js";
7
+ import { scrollStopProps, useScrollStop } from "./scrollStop.js";
8
+ import { columnCount, columnTitles, numericColumns, TableContext, withColumns, } from "./tableColumns.js";
9
+ import { rowClass, SectionContext, SELECTED, BODY_LINE, PAD, STACK, stackRole, } from "./tableRow.js";
9
10
  export { TableCell, TableHeaderCell } from "./TableCells.js";
10
11
  export { TableExpandCell } from "./TableExpandCell.js";
11
12
  import { BoneRows, EmptyRow } from "./tableEmpty.js";
12
13
  import { BusyLabel, busy, LoadingScope, useLoading } from "./skeleton.js";
13
14
  /**
14
- * A list of records in a rounded, bordered card that scrolls sideways on a narrow screen. Compose it
15
+ * A list of records in a rounded, bordered card. Compose it
15
16
  * from `TableHead`, `TableBody`, `TableFoot`, `TableRow`, `TableHeaderCell` and `TableCell`. `label`
16
17
  * names the table for assistive tech and is not drawn. Inside a `Card` it is plain: no card of its
17
18
  * own (border, fill and shadow), no tinted head strip and no row hover, only the row dividers. A
18
19
  * column of figures says so once, with `numeric` on its `TableHeaderCell`: its cells then take end
19
- * alignment and tabular figures. `size` is the row padding, and the controls in the rows follow it
20
- * (`sm` by default). Other props (`id`, `data-*`, `aria-*`) go on the `<table>`. While `loading`, a
20
+ * alignment and tabular figures. `size` is the row padding, and the buttons and pills in the rows follow it
21
+ * (`sm` by default); a field keeps its own `size`. Other props (`id`, `data-*`, `aria-*`) go on the `<table>`. While `loading`, a
21
22
  * body with no rows draws five rows of bones, one per column, and an empty cell draws a bone; the
22
- * table keeps its role and its name.
23
+ * table keeps its role and its name. A table that fits its box keeps its head row in view (under
24
+ * the `AppShell` header) while the page scrolls past its rows; one wider than its box scrolls
25
+ * sideways instead, and takes a tab stop when nothing in it can take focus. `narrow="stack"` draws
26
+ * each row as a card on a screen narrower than `sm` (a phone), the cells as lines labelled by their column's
27
+ * title. A click on a sortable title has the table say the new sort aloud, in `sortedLabel`'s words.
23
28
  */
24
- export function Table({ label, size = "sm", loading, loadingLabel, children, ...rest }) {
29
+ export function Table({ label, size = "sm", narrow = "scroll", sortedLabel = englishSorted, loading, loadingLabel, children, ...rest }) {
25
30
  const plain = useInCard();
26
31
  const { loading: waiting, owner } = useLoading(loading);
27
32
  const numeric = numericColumns(children, TableHead, TableRow);
28
33
  const columns = columnCount(children, TableHead, TableRow);
29
- return (_jsx(TableContext.Provider, { value: { plain, size, numeric, columns }, children: _jsx(DensityProvider, { size: size, children: _jsxs("div", { className: cx("overflow-x-auto", !plain && "rounded-xl border border-slate-200/70 bg-white shadow-sm"), children: [_jsxs("table", { ...rest, ...busy(owner, waiting), className: "w-full text-left text-sm", children: [_jsx("caption", { className: "sr-only", children: label }), _jsx(LoadingScope, { loading: waiting, children: children })] }), _jsx(BusyLabel, { owner: owner, loading: waiting, label: loadingLabel })] }) }) }));
34
+ const stack = narrow === "stack";
35
+ const titles = stack ? columnTitles(children, TableHead, TableRow) : [];
36
+ const [said, setSaid] = useState("");
37
+ const announce = useCallback((column, sort) => setSaid(sortedLabel(column, sort)), [sortedLabel]);
38
+ const { attach, stop, measured, overflows } = useScrollStop("x", tableWider);
39
+ const { props: stopProps, ring } = scrollStopProps(stop, { label });
40
+ // Until measured (a page rendered on the server) and while too wide, the box scrolls sideways.
41
+ // Once it fits, it clips instead: a clipping box is no scroll container, so the head can stick.
42
+ const fits = measured && !overflows;
43
+ return (_jsx(TableContext.Provider, { value: { plain, size, numeric, columns, announce, stack, titles }, children: _jsx(DensityProvider, { size: size, children: _jsxs("div", { ref: attach, ...stopProps, className: cx(fits ? "overflow-clip" : "overflow-x-auto", ring, !plain && "rounded-xl border border-slate-200/70 bg-white shadow-sm"), children: [_jsxs("table", { ...rest, ...stackRole(stack, "table"), ...busy(owner, waiting), className: cx("w-full text-left text-sm", stack && STACK.table), children: [_jsx("caption", { className: "sr-only", children: label }), _jsx(LoadingScope, { loading: waiting, children: children })] }), _jsx(BusyLabel, { owner: owner, loading: waiting, label: loadingLabel }), _jsx("div", { role: "status", className: "sr-only", children: said })] }) }) }));
30
44
  }
31
- /** The `<thead>`: small uppercase column titles, on a tinted strip unless the table is in a card. Holds one `TableRow` of `TableHeaderCell`s. */
45
+ /** The default `sortedLabel`. */
46
+ function englishSorted(column, sort) {
47
+ return `Sorted by ${column}, ${sort}`;
48
+ }
49
+ /** Whether the table is wider than its box: measured from the table, since a clipping box does not scroll. */
50
+ function tableWider(box) {
51
+ const table = box.querySelector(":scope > table");
52
+ return table instanceof HTMLElement && table.offsetWidth > box.clientWidth;
53
+ }
54
+ /**
55
+ * The `<thead>`: small uppercase column titles, on a tinted strip unless the table is in a card.
56
+ * Holds one `TableRow` of `TableHeaderCell`s. Unless the table is in a card, it stays in view under
57
+ * the `AppShell` header while the page scrolls past the rows, as long as the table fits its box.
58
+ */
32
59
  export function TableHead({ children, ...rest }) {
33
- const { plain } = useContext(TableContext);
34
- return (_jsx("thead", { ...rest, className: cx("text-xs uppercase tracking-wide text-slate-500", !plain && "bg-slate-50"), children: _jsx(SectionContext.Provider, { value: "head", children: children }) }));
60
+ const { plain, stack } = useContext(TableContext);
61
+ return (_jsx("thead", { ...rest, ...stackRole(stack, "rowgroup"), className: cx("text-xs uppercase tracking-wide text-slate-500", !plain && "sticky top-[var(--app-header,0px)] z-1 bg-slate-50", stack && STACK.head), children: _jsx(SectionContext.Provider, { value: "head", children: children }) }));
35
62
  }
36
63
  /**
37
64
  * The `<tbody>`: the rows, each with a line above it and, unless the table is in a card, a fill on
@@ -41,7 +68,8 @@ export function TableHead({ children, ...rest }) {
41
68
  */
42
69
  export function TableBody({ empty, children, ...rest }) {
43
70
  const waiting = useLoading(undefined).loading;
44
- return (_jsx("tbody", { ...rest, children: _jsx(SectionContext.Provider, { value: "body", children: _jsx(BodyRows, { waiting: waiting, empty: empty, children: children }) }) }));
71
+ const { stack } = useContext(TableContext);
72
+ return (_jsx("tbody", { ...rest, ...stackRole(stack, "rowgroup"), className: stack ? STACK.section : undefined, children: _jsx(SectionContext.Provider, { value: "body", children: _jsx(BodyRows, { waiting: waiting, empty: empty, children: children }) }) }));
45
73
  }
46
74
  /** What a body holds: its rows; with none, bones while loading (loading beats empty), else `empty`. */
47
75
  function BodyRows({ waiting, empty, children, }) {
@@ -57,7 +85,8 @@ function BodyRows({ waiting, empty, children, }) {
57
85
  * no `tone`.
58
86
  */
59
87
  export function TableFoot({ children, ...rest }) {
60
- return (_jsx("tfoot", { ...rest, children: _jsx(SectionContext.Provider, { value: "foot", children: children }) }));
88
+ const { stack } = useContext(TableContext);
89
+ return (_jsx("tfoot", { ...rest, ...stackRole(stack, "rowgroup"), className: stack ? STACK.section : undefined, children: _jsx(SectionContext.Provider, { value: "foot", children: children }) }));
61
90
  }
62
91
  /**
63
92
  * A `<tr>`, `relative`: the anchor a `TextLink stretch` (with `href`) stretches to. Any other link, button or
@@ -75,18 +104,19 @@ export function TableFoot({ children, ...rest }) {
75
104
  */
76
105
  export function TableRow({ tone, stripe, emphasis = false, selected = false, children, ...rest }) {
77
106
  const outer = useContext(SectionContext);
78
- const { plain } = useContext(TableContext);
107
+ const { plain, stack } = useContext(TableContext);
79
108
  const section = emphasis && outer === "body" ? "foot" : outer;
80
109
  const current = selected && section === "body";
81
- return (_jsx(SectionContext.Provider, { value: section, children: _jsx("tr", { ...rest, ...(current ? { "aria-current": true } : {}), className: current ? cx(BODY_LINE, SELECTED) : rowClass(section, plain, tone, stripe), children: withColumns(children) }) }));
110
+ return (_jsx(SectionContext.Provider, { value: section, children: _jsx("tr", { ...rest, ...stackRole(stack, "row"), ...(current ? { "aria-current": true } : {}), className: cx(current ? cx(BODY_LINE, SELECTED) : rowClass(section, plain, tone, stripe), stack && STACK.row), children: withColumns(children) }) }));
82
111
  }
83
112
  /**
84
113
  * A full-width group header in the body: a tinted row with a `label` that spans every column the
85
- * head declares (or `colSpan` columns), and optional `trailing` content at the far end (a count, a
86
- * subtotal, a small button). The group's rows follow it. For a panel of other content across the
114
+ * head declares (or `colSpan` columns), and optional `trailing` text at the far end: the group's
115
+ * count or subtotal, muted. The group's rows follow it. The row is a `<th>`, a heading for the
116
+ * group, so an action on the group goes in its rows or above the table, not here. For a panel of other content across the
87
117
  * whole row, use a `TableCell span="full"` instead.
88
118
  */
89
119
  export function TableGroupRow({ label, trailing, colSpan, ...rest }) {
90
- const { size, columns } = useContext(TableContext);
91
- return (_jsx("tr", { ...rest, className: "relative border-t border-slate-200/70 bg-slate-50", children: _jsx("th", { scope: "rowgroup", colSpan: colSpan ?? columns, className: cx(PAD[size].group, "text-left text-sm"), children: _jsxs("div", { className: "flex items-center justify-between gap-3", children: [_jsx("span", { className: "font-medium text-slate-900", children: label }), trailing != null && trailing !== false && (_jsx("span", { className: "shrink-0 font-normal text-slate-500", children: trailing }))] }) }) }));
120
+ const { size, columns, stack } = useContext(TableContext);
121
+ return (_jsx("tr", { ...rest, ...stackRole(stack, "row"), className: cx("relative border-t border-slate-200/70 bg-slate-50", stack && STACK.section), children: _jsx("th", { scope: "rowgroup", ...stackRole(stack, "rowheader"), colSpan: colSpan ?? columns, className: cx(PAD[size].group, "text-left text-sm", stack && STACK.section), children: _jsxs("div", { className: "flex items-center justify-between gap-3", children: [_jsx("span", { className: "font-medium text-slate-900", children: label }), trailing != null && trailing !== false && (_jsx("span", { className: "shrink-0 font-normal text-slate-500", children: trailing }))] }) }) }));
92
122
  }
@@ -1,5 +1,5 @@
1
1
  import { type ReactElement, type ReactNode } from "react";
2
- import { type Align, type Rest } from "./tableRow.js";
2
+ import { type CellAlign, type Rest } from "./tableRow.js";
3
3
  import { type SortProps } from "./tableSort.js";
4
4
  import { type LoadingProps } from "./skeleton.js";
5
5
  import type { Tone } from "./tone.js";
@@ -10,12 +10,15 @@ import type { Tone } from "./tone.js";
10
10
  */
11
11
  export type CellTone = "strong" | "muted" | Tone;
12
12
  /**
13
- * A column title, `<th scope="col">`. `numeric` declares a column of figures, once: the title and
14
- * every cell under it take end alignment and tabular figures. A column with nothing to show in its
15
- * head (a row's actions) takes `label` instead of `children`: the name a screen reader hears
16
- * ("Actions"), visually hidden so the head keeps its column. `sort` and `onSort` make the column
17
- * sortable: the title becomes a button that asks for the next direction, and the column says where
18
- * it stands with `aria-sort`. The app sorts its rows; the table never does.
13
+ * A header cell. In the `TableHead` it is a column title, `<th scope="col">`. `numeric` declares a
14
+ * column of figures, once: the title and every cell under it take end alignment and tabular figures.
15
+ * A column with nothing to show in its head (a row's actions) takes `label` instead of `children`:
16
+ * the name a screen reader hears ("Actions"), visually hidden so the head keeps its column. `sort`
17
+ * and `onSort` make the column sortable: the title becomes a button that fills the cell and asks for
18
+ * the next direction, the column says where it stands with `aria-sort`, and the table says the new
19
+ * sort aloud. The app sorts its rows; the table never does. In a body or foot row it is the row's
20
+ * header, `<th scope="row">`: the cell that names the row (a name, a date), drawn like a `strong`
21
+ * cell, so a screen reader reads it before each of the row's values.
19
22
  */
20
23
  export declare function TableHeaderCell({ numeric, align, children, label, sort, onSort, ...rest }: {
21
24
  /** A column of figures: this title and the cells under it are end aligned, the cells in tabular figures. */
@@ -24,7 +27,7 @@ export declare function TableHeaderCell({ numeric, align, children, label, sort,
24
27
  * The title's horizontal alignment; `end` over a column of buttons, `center` over a centred column.
25
28
  * @default end for a numeric column, else start
26
29
  */
27
- align?: Align | undefined;
30
+ align?: CellAlign | undefined;
28
31
  } & ({
29
32
  children?: ReactNode;
30
33
  label?: undefined;
@@ -46,22 +49,22 @@ type Indent = 1 | 2 | 3;
46
49
  * `strong`); `numeric` sets end alignment and tabular figures (a cell under a `numeric` head cell is
47
50
  * numeric already), `mono` a small mono face. `secondary` is a second,
48
51
  * muted line under the content. One rule for wrapping: prose (a cell of plain text) wraps onto more
49
- * lines (never narrower than `min-w-48`, so it scrolls the table before it becomes a sliver), a cell
50
- * that holds a control or a link takes that content's width, and a `numeric` or `mono` cell (a
51
- * figure, a code, a type) never breaks. `truncate` caps a long value's width, cuts it with
52
- * an ellipsis on one line and puts the full text in a `title`; the content is then plain text (strings and
53
- * numbers), since that is what the title shows. `colSpan` passes through: a cell that
52
+ * lines (never narrower than `min-w-48`, so it scrolls the table before it becomes a sliver); any
53
+ * other cell stays on one line at its content's width: one that holds a control or a link, and a
54
+ * `numeric` or `mono` cell (a figure, a code, a type). `lines={1}` caps a long value's width, cuts it with
55
+ * an ellipsis on one line and, while it is cut, shows the full text in a tooltip on hover, focus and a
56
+ * tap; the content is then plain text (strings and numbers), since that is what the tooltip shows. `colSpan` passes through: a cell that
54
57
  * spans the row is a full-width panel (a note under a group), and `align="center"` centres it. A
55
58
  * table with no rows takes `TableBody empty`, not a cell built by hand. `span="full"` spans every
56
59
  * column the head declares, so a panel under a row needs no count. `indent` sets a start-aligned cell in by 1 to 3 levels, for a line under a parent row.
57
60
  * While `loading` an empty cell draws one bone, the width of a short value.
58
61
  */
59
- export declare function TableCell({ span, colSpan, align, tone, numeric, mono, truncate, indent, secondary, loading, loadingLabel, children, ...rest }: {
62
+ export declare function TableCell({ span, colSpan, align, tone, numeric, mono, lines, indent, secondary, loading, loadingLabel, children, ...rest }: {
60
63
  /**
61
64
  * The cell's horizontal alignment; `center` for a full-width note.
62
65
  * @default end for a numeric cell, else start
63
66
  */
64
- align?: Align | undefined;
67
+ align?: CellAlign | undefined;
65
68
  /** Sets the cell in by this many levels (1 to 3), for a line under a parent row. Start-aligned cells only. */
66
69
  indent?: Indent | undefined;
67
70
  /** The text weight and colour (see `CellTone`). In a `TableFoot` it defaults to `strong`. */
@@ -74,14 +77,14 @@ export declare function TableCell({ span, colSpan, align, tone, numeric, mono, t
74
77
  /** A small monospace face for a code or a type, and the cell never wraps. */
75
78
  mono?: boolean | undefined;
76
79
  /**
77
- * Caps the width and cuts a long value with an ellipsis on one line, the full text in a `title`.
78
- * Plain text content only.
80
+ * `1` caps the width and cuts a long value with an ellipsis on one line; while it is cut, the full
81
+ * text shows in a tooltip on hover, keyboard focus and a tap. Plain text content only.
79
82
  *
80
- * Without it, a prose cell wraps down to a floor so it never becomes a sliver, a cell that holds
81
- * a control or a link (a `Pill`, a `Switch`, a `Button`, a `TextLink`) takes its content's width,
82
- * and a `numeric` or `mono` cell never breaks.
83
+ * Without it, a prose cell wraps down to a floor so it never becomes a sliver, and any other cell
84
+ * (a `Pill`, a `Switch`, a `Button`, a `TextLink`, a `numeric` or `mono` value) stays on one line
85
+ * at its content's width.
83
86
  */
84
- truncate?: boolean | undefined;
87
+ lines?: 1 | undefined;
85
88
  /** A second, muted line under the content. */
86
89
  secondary?: ReactNode;
87
90
  children?: ReactNode;
@@ -1,11 +1,12 @@
1
1
  import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Children, useContext } from "react";
3
3
  import { cx } from "./cx.js";
4
- import { TableContext, useNumericColumn } from "./tableColumns.js";
5
- import { ALIGN, PAD, SectionContext } from "./tableRow.js";
4
+ import { TableContext, useNumericColumn, useStackLabel } from "./tableColumns.js";
5
+ import { ALIGN, PAD, SectionContext, STACK, stackRole, } from "./tableRow.js";
6
6
  import { SortButton } from "./tableSort.js";
7
7
  import { Bone, BusyLabel, busy, isEmptySlot, useLoading } from "./skeleton.js";
8
8
  import { CELL_BONE } from "./tableEmpty.js";
9
+ import { Truncated } from "./truncated.js";
9
10
  import { TEXT_TONE } from "./typography.js";
10
11
  const TONE = {
11
12
  strong: "font-medium text-slate-900",
@@ -17,30 +18,59 @@ function HeadTitle({ label, children }) {
17
18
  return label === undefined ? children : _jsx("span", { className: "sr-only", children: label });
18
19
  }
19
20
  /**
20
- * A column title, `<th scope="col">`. `numeric` declares a column of figures, once: the title and
21
- * every cell under it take end alignment and tabular figures. A column with nothing to show in its
22
- * head (a row's actions) takes `label` instead of `children`: the name a screen reader hears
23
- * ("Actions"), visually hidden so the head keeps its column. `sort` and `onSort` make the column
24
- * sortable: the title becomes a button that asks for the next direction, and the column says where
25
- * it stands with `aria-sort`. The app sorts its rows; the table never does.
21
+ * A header cell. In the `TableHead` it is a column title, `<th scope="col">`. `numeric` declares a
22
+ * column of figures, once: the title and every cell under it take end alignment and tabular figures.
23
+ * A column with nothing to show in its head (a row's actions) takes `label` instead of `children`:
24
+ * the name a screen reader hears ("Actions"), visually hidden so the head keeps its column. `sort`
25
+ * and `onSort` make the column sortable: the title becomes a button that fills the cell and asks for
26
+ * the next direction, the column says where it stands with `aria-sort`, and the table says the new
27
+ * sort aloud. The app sorts its rows; the table never does. In a body or foot row it is the row's
28
+ * header, `<th scope="row">`: the cell that names the row (a name, a date), drawn like a `strong`
29
+ * cell, so a screen reader reads it before each of the row's values.
26
30
  */
27
31
  export function TableHeaderCell({ numeric = false, align = numeric ? "end" : "start", children, label, sort, onSort, ...rest }) {
28
- const { size } = useContext(TableContext);
29
- const sorted = sort === "ascending" || sort === "descending";
30
- return (_jsx("th", { ...rest, scope: "col", ...(sorted ? { "aria-sort": sort } : {}), className: cx("whitespace-nowrap font-medium", PAD[size].head, ALIGN[align]), children: sort !== undefined && onSort !== undefined ? (_jsx(SortButton, { sort: sort, onSort: onSort, align: align, children: children })) : (_jsx(HeadTitle, { label: label, children: children })) }));
32
+ const { size, stack } = useContext(TableContext);
33
+ const section = useContext(SectionContext);
34
+ const inHead = section !== "body" && section !== "foot";
35
+ const sortable = inHead && sort !== undefined && onSort !== undefined;
36
+ if (!inHead) {
37
+ return (_jsx(RowHeader, { ...rest, align: align, label: label, children: children }));
38
+ }
39
+ return (_jsx("th", { ...rest, scope: "col", ...stackRole(stack, "columnheader"), ...ariaSort(sort), className: cx("whitespace-nowrap font-medium", !sortable && PAD[size].head, ALIGN[align]), children: sortable ? (_jsx(SortButton, { sort: sort, onSort: onSort, align: align, pad: PAD[size].head, children: children })) : (_jsx(HeadTitle, { label: label, children: children })) }));
40
+ }
41
+ /** A sorted column's `aria-sort`; a column sorted by another one says nothing. */
42
+ function ariaSort(sort) {
43
+ return sort === "ascending" || sort === "descending" ? { "aria-sort": sort } : {};
44
+ }
45
+ /** A body or foot row's header cell, `<th scope="row">`, drawn like a `strong` cell. */
46
+ function RowHeader({ align, label, children, ...rest }) {
47
+ const { size, stack } = useContext(TableContext);
48
+ const stackLabel = useStackLabel(false);
49
+ return (_jsx("th", { ...rest, scope: "row", ...stackRole(stack, "rowheader"), className: cx(PAD[size].cell, ALIGN[align], TONE.strong, figureClass(false, false, isProse(children)), stackClass(stack, stackLabel)), children: _jsx(Stacked, { label: stackLabel, children: _jsx(HeadTitle, { label: label, children: children }) }) }));
50
+ }
51
+ /** A stacking table's cell: a labelled line, or a block when it has no column title. */
52
+ function stackClass(stack, label) {
53
+ return stack && (label === undefined ? STACK.block : STACK.cell);
54
+ }
55
+ /** Whether a cell spans more than one column (it then takes no column title when stacked). */
56
+ function spansColumns(span, colSpan) {
57
+ return span === "full" || (colSpan !== undefined && colSpan > 1);
31
58
  }
32
59
  /**
33
- * The wrapping rule: a figure or code never breaks; prose wraps, down to `min-w-48`. A cell that
34
- * holds an element (a link, a `Pill`, a `Switch`, a `Button`) takes its content's width.
60
+ * The wrapping rule, one for every cell: prose (plain text and nothing else) wraps, down to
61
+ * `min-w-48`; everything else stays on one line at its content's width: a figure, a code, and a cell
62
+ * that holds an element (a link, a `Pill`, a `Switch`, a `Button`). So a column of short controls is
63
+ * only as wide as they are, and a link's words never break one per line on a phone: the table
64
+ * scrolls instead.
35
65
  */
36
66
  function figureClass(numeric, mono, prose) {
37
67
  if (!numeric && !mono)
38
- return prose ? "min-w-48" : "";
68
+ return prose ? "min-w-48" : "whitespace-nowrap";
39
69
  return cx("whitespace-nowrap", numeric && "tabular-nums", mono && "font-mono text-xs");
40
70
  }
41
- /** The widest a `truncate` cell grows. */
71
+ /** The widest a `lines={1}` cell grows. */
42
72
  const TRUNCATE_WIDTH = "max-w-xs";
43
- /** Where a `truncate` cell's capped box sits, so it follows the cell's alignment. */
73
+ /** Where a `lines={1}` cell's capped box sits, so it follows the cell's alignment. */
44
74
  const TRUNCATE_ALIGN = {
45
75
  start: undefined,
46
76
  center: "mx-auto",
@@ -56,25 +86,26 @@ const INDENT = {
56
86
  * `strong`); `numeric` sets end alignment and tabular figures (a cell under a `numeric` head cell is
57
87
  * numeric already), `mono` a small mono face. `secondary` is a second,
58
88
  * muted line under the content. One rule for wrapping: prose (a cell of plain text) wraps onto more
59
- * lines (never narrower than `min-w-48`, so it scrolls the table before it becomes a sliver), a cell
60
- * that holds a control or a link takes that content's width, and a `numeric` or `mono` cell (a
61
- * figure, a code, a type) never breaks. `truncate` caps a long value's width, cuts it with
62
- * an ellipsis on one line and puts the full text in a `title`; the content is then plain text (strings and
63
- * numbers), since that is what the title shows. `colSpan` passes through: a cell that
89
+ * lines (never narrower than `min-w-48`, so it scrolls the table before it becomes a sliver); any
90
+ * other cell stays on one line at its content's width: one that holds a control or a link, and a
91
+ * `numeric` or `mono` cell (a figure, a code, a type). `lines={1}` caps a long value's width, cuts it with
92
+ * an ellipsis on one line and, while it is cut, shows the full text in a tooltip on hover, focus and a
93
+ * tap; the content is then plain text (strings and numbers), since that is what the tooltip shows. `colSpan` passes through: a cell that
64
94
  * spans the row is a full-width panel (a note under a group), and `align="center"` centres it. A
65
95
  * table with no rows takes `TableBody empty`, not a cell built by hand. `span="full"` spans every
66
96
  * column the head declares, so a panel under a row needs no count. `indent` sets a start-aligned cell in by 1 to 3 levels, for a line under a parent row.
67
97
  * While `loading` an empty cell draws one bone, the width of a short value.
68
98
  */
69
- export function TableCell({ span, colSpan, align, tone, numeric, mono = false, truncate = false, indent, secondary, loading, loadingLabel, children, ...rest }) {
99
+ export function TableCell({ span, colSpan, align, tone, numeric, mono = false, lines, indent, secondary, loading, loadingLabel, children, ...rest }) {
70
100
  const { loading: waiting, owner } = useLoading(loading);
71
101
  const bone = waiting && isEmptySlot(children);
72
102
  const foot = useContext(SectionContext) === "foot";
73
- const { size, columns } = useContext(TableContext);
103
+ const { size, columns, stack } = useContext(TableContext);
104
+ const stackLabel = useStackLabel(spansColumns(span, colSpan));
74
105
  const column = useNumericColumn();
75
106
  const figure = numeric ?? column;
76
107
  const side = align ?? (figure ? "end" : "start");
77
- return (_jsxs("td", { ...rest, ...busy(owner, waiting), colSpan: span === "full" ? columns : colSpan, className: cellClass({
108
+ return (_jsxs("td", { ...rest, ...stackRole(stack, "cell"), ...busy(owner, waiting), colSpan: span === "full" ? columns : colSpan, className: cx(cellClass({
78
109
  align: side,
79
110
  size,
80
111
  indent,
@@ -83,22 +114,32 @@ export function TableCell({ span, colSpan, align, tone, numeric, mono = false, t
83
114
  numeric: figure,
84
115
  mono,
85
116
  prose: isProse(children),
86
- }), children: [_jsx(CellBody, { align: side, truncate: truncate, secondary: secondary, children: bone ? _jsx(Bone, { shape: CELL_BONE }) : children }), _jsx(BusyLabel, { owner: owner, loading: waiting, label: loadingLabel })] }));
117
+ }), stackClass(stack, stackLabel)), children: [_jsx(Stacked, { label: stackLabel, children: _jsx(CellBody, { align: side, truncate: lines === 1, secondary: secondary, children: bone ? _jsx(Bone, { shape: CELL_BONE }) : children }) }), _jsx(BusyLabel, { owner: owner, loading: waiting, label: loadingLabel })] }));
87
118
  }
88
119
  /** The classes of a cell: the tone (`strong` by default in a foot, and a foot's cells are medium whatever the tone), then the wrapping rule. */
89
120
  function cellClass({ align, size, indent, tone, foot, numeric, mono, prose, }) {
90
121
  const resolved = tone ?? (foot ? "strong" : "neutral");
91
122
  return cx(PAD[size].cell, align === "start" && indent !== undefined && INDENT[size][indent], ALIGN[align], TONE[resolved], foot && resolved !== "strong" && "font-medium", figureClass(numeric, mono, prose));
92
123
  }
124
+ /**
125
+ * A cell's content in a stacking table: its column's title (hidden from assistive tech, which has
126
+ * the head) at the start of the line, shown only while stacked, and the value at the end. Outside
127
+ * a stacking table, or with no title, the content as it is.
128
+ */
129
+ function Stacked({ label, children }) {
130
+ if (label === undefined || label === null)
131
+ return children;
132
+ return (_jsxs(_Fragment, { children: [_jsx("span", { "aria-hidden": "true", className: STACK.label, children: label }), _jsx("div", { className: STACK.value, children: children })] }));
133
+ }
93
134
  const isText = (node) => typeof node === "string" || typeof node === "number";
94
135
  /** Prose: at least one part, every one text. An empty cell (a bone) is not prose and keeps no width. */
95
136
  function isProse(children) {
96
137
  const parts = Children.toArray(children);
97
138
  return parts.length > 0 && parts.every(isText);
98
139
  }
99
- /** What a cell holds: the content, cut to one line with its full text in a `title` when `truncate`, then the `secondary` line. */
140
+ /** What a cell holds: the content, cut to one line when `truncate` (its full text in a tooltip while cut), then the `secondary` line. */
100
141
  function CellBody({ align, truncate, secondary, children, }) {
101
142
  const parts = Children.toArray(children);
102
143
  const text = parts.every(isText) ? parts.join("") : undefined;
103
- return (_jsxs(_Fragment, { children: [truncate ? (_jsx("div", { className: cx(TRUNCATE_WIDTH, "truncate", TRUNCATE_ALIGN[align]), title: text, children: children })) : (children), secondary != null && secondary !== false && (_jsx("div", { className: "text-xs font-normal text-slate-500", children: secondary }))] }));
144
+ return (_jsxs(_Fragment, { children: [truncate ? (_jsx(Truncated, { text: text, className: cx(TRUNCATE_WIDTH, TRUNCATE_ALIGN[align]), children: children })) : (children), secondary != null && secondary !== false && (_jsx("div", { className: "text-xs font-normal text-slate-500", children: secondary }))] }));
104
145
  }
@@ -1,7 +1,7 @@
1
1
  import type { ComponentProps, ReactElement, ReactNode } from "react";
2
2
  import { TableCell } from "./Table.js";
3
3
  /** `TableCell`'s props without its content, kept a union so `span` and `colSpan` stay apart. */
4
- type CellProps = ComponentProps<typeof TableCell> extends infer Props ? Props extends unknown ? Omit<Props, "children" | "truncate"> : never : never;
4
+ type CellProps = ComponentProps<typeof TableCell> extends infer Props ? Props extends unknown ? Omit<Props, "children" | "lines"> : never : never;
5
5
  /**
6
6
  * A `TableCell` whose value opens an editor in place: a cell that holds one `InlineEdit` and
7
7
  * nothing else. It shows `children` as a button with a dotted underline; a click, Enter or Space
@@ -0,0 +1,34 @@
1
+ import type { ReactElement } from "react";
2
+ import type { Passthrough } from "./props.js";
3
+ /** One entry of a `TableOfContents`: the heading's `id` (its anchor), its words, and its level. */
4
+ export type TableOfContentsItem = {
5
+ id: string;
6
+ label: string;
7
+ level: 2 | 3;
8
+ };
9
+ /** The list of entries, each linking to its heading, the current one marked. Shared with `DocsLayout`'s own. Internal. */
10
+ export declare function ContentsList({ items, current, }: {
11
+ items: TableOfContentsItem[];
12
+ current: string | undefined;
13
+ }): ReactElement;
14
+ /**
15
+ * The headings of a long page, as links to their anchors: "On this page". `items` are the page's
16
+ * `h2`s and `h3`s in order, each `{ id, label, level }`; a level 3 entry is indented under the one
17
+ * before it. `current` is the id of the section being read, which the app tracks (from the scroll
18
+ * position or the URL hash): its link is marked in the accent and has `aria-current="location"`.
19
+ * The rest are small and quiet. `label` names the list and the `<nav>` landmark.
20
+ *
21
+ * It sets no width or position: put it in a `SideColumn`'s aside, sticky, beside the page.
22
+ * `DocsLayout` draws its own.
23
+ */
24
+ export declare function TableOfContents({ items, current, label, ...rest }: {
25
+ /** The page's headings in order: `{ id, label, level }`, `level` 2 or 3. */
26
+ items: TableOfContentsItem[];
27
+ /** The id of the section being read; its link is marked as the current one. */
28
+ current?: string | undefined;
29
+ /**
30
+ * The words over the list, and the name of the `<nav>` landmark.
31
+ * @default "On this page"
32
+ */
33
+ label?: string | undefined;
34
+ } & Passthrough): ReactElement;
@@ -0,0 +1,23 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { cx, focusRing } from "./cx.js";
3
+ import { Overline } from "./typography.js";
4
+ const ENTRY = `rounded text-sm/6 transition ${focusRing}`;
5
+ const ENTRY_ON = "font-medium text-violet-700";
6
+ const ENTRY_OFF = "text-slate-600 hover:text-violet-700";
7
+ /** The list of entries, each linking to its heading, the current one marked. Shared with `DocsLayout`'s own. Internal. */
8
+ export function ContentsList({ items, current, }) {
9
+ return (_jsx("ul", { role: "list", className: "flex list-none flex-col gap-1", children: items.map((item) => (_jsx("li", { className: item.level === 3 ? "ps-3" : undefined, children: _jsx("a", { href: `#${item.id}`, "aria-current": item.id === current ? "location" : undefined, className: cx(ENTRY, item.id === current ? ENTRY_ON : ENTRY_OFF), children: item.label }) }, item.id))) }));
10
+ }
11
+ /**
12
+ * The headings of a long page, as links to their anchors: "On this page". `items` are the page's
13
+ * `h2`s and `h3`s in order, each `{ id, label, level }`; a level 3 entry is indented under the one
14
+ * before it. `current` is the id of the section being read, which the app tracks (from the scroll
15
+ * position or the URL hash): its link is marked in the accent and has `aria-current="location"`.
16
+ * The rest are small and quiet. `label` names the list and the `<nav>` landmark.
17
+ *
18
+ * It sets no width or position: put it in a `SideColumn`'s aside, sticky, beside the page.
19
+ * `DocsLayout` draws its own.
20
+ */
21
+ export function TableOfContents({ items, current, label = "On this page", ...rest }) {
22
+ return (_jsxs("nav", { ...rest, "aria-label": label, children: [_jsx("div", { className: "pb-2", children: _jsx(Overline, { children: label }) }), _jsx(ContentsList, { items: items, current: current })] }));
23
+ }
package/dist/Tabs.d.ts CHANGED
@@ -1,16 +1,29 @@
1
- import type { ReactElement } from "react";
1
+ import { type ReactElement, type ReactNode } from "react";
2
2
  import { type TypeStep } from "./density.js";
3
3
  import type { Size } from "./size.js";
4
- import { type SwitchItem, type SwitchProps } from "./switcher.js";
4
+ import { type SwitchButton, type SwitchLink, type SwitchProps } from "./switcher.js";
5
+ /** A button tab; its `panel` is the view it shows, rendered by Tabs under (or beside) the row. */
6
+ export type TabButton = SwitchButton & {
7
+ /**
8
+ * The view this tab shows. Tabs renders it as the tab's `tabpanel`, labelled by the tab, and
9
+ * hides it while another tab is current; the browser's find in page still reaches a hidden one
10
+ * and switches to its tab.
11
+ */
12
+ panel?: ReactNode;
13
+ };
5
14
  /** One tab of a Tabs row: a button with a `value`, or a link with an `href`; never both kinds in one row. */
6
- export type Tab = SwitchItem;
7
- /** The classes of one pill tab at the type `step` in force. A `disabled` one drops the hover fill. */
15
+ export type Tab = TabButton | SwitchLink;
16
+ /**
17
+ * The classes of one pill tab at the type `step` in force. Every pill is `font-medium`, so the
18
+ * current one is no wider than it was; it has a fill and an outline. A `disabled` one drops the
19
+ * hover fill.
20
+ */
8
21
  export declare function pillTabClass(active: boolean, disabled?: boolean, size?: Size, step?: TypeStep): string;
9
- export type TabsProps = SwitchProps & ({
22
+ export type TabsProps = SwitchProps<TabButton> & ({
10
23
  /**
11
- * `horizontal` is a row of underline tabs over a bottom rule; `vertical` is the pill rail, a
12
- * column at the rail's width for a `SidebarLayout` aside, where the up and down arrows move
13
- * between button tabs.
24
+ * `horizontal` is a row of underline tabs over a bottom rule, one line that scrolls
25
+ * sideways when it is too wide; `vertical` is the pill rail, a column at the rail's width
26
+ * for a `SidebarLayout` aside, where the up and down arrows move between button tabs.
14
27
  * @default horizontal
15
28
  */
16
29
  orientation?: "horizontal";
@@ -26,13 +39,15 @@ export type TabsProps = SwitchProps & ({
26
39
  });
27
40
  /**
28
41
  * Tabs for switching a view in place or between pages. Across (the default) they are underline
29
- * tabs: a row over a bottom rule, the current tab underlined in the accent. `orientation="vertical"`
30
- * is the pill rail instead, the current tab filled, for a `SidebarLayout` aside, and takes a
31
- * `size`. `items` are `{ value, label }` buttons (`value` and `onChange` are the caller's state;
32
- * the arrow keys, Home and End move between tabs) or links (`href`, an in-app one through
33
- * `LinkProvider`; `selected` on an item, or `value`, marks the current one, which gets
34
- * `aria-current`). An item may carry a `count`, and a button one `disabledReason` (it stays
35
- * reachable by the arrows and its reason is a tooltip) or a bare `disabled`; `disabled` on the row disables every tab. `label` names the tab list. The panel is
36
- * the caller's: give it `role="tabpanel"`, and a tab `controls` to point at it.
42
+ * tabs: one line over a bottom rule, the current tab underlined in the accent, scrolling sideways
43
+ * with a fade when the row is too wide. `orientation="vertical"` is the pill rail instead, the
44
+ * current tab filled and outlined, for a `SidebarLayout` aside, and takes a `size`. `items` are
45
+ * `{ value, label, panel }` buttons (`value` and `onChange` are the caller's state; the arrow
46
+ * keys, Home and End move between tabs) or links (`href`, an in-app one through `LinkProvider`;
47
+ * `selected` on an item, or `value`, marks the current one, which gets `aria-current`). A button's
48
+ * `panel` is rendered as its `tabpanel`, wired to the tab and hidden while another is current. An
49
+ * item may carry a `count`, and a button one `disabledReason` (it stays reachable by the arrows and
50
+ * its reason is a tooltip) or a bare `disabled`; `disabled` on the row disables every tab. `label`
51
+ * names the tab list.
37
52
  */
38
53
  export declare function Tabs({ size, orientation, ...props }: TabsProps): ReactElement;