@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
@@ -0,0 +1,65 @@
1
+ import { type ReactElement } from "react";
2
+ import type { Passthrough } from "./props.js";
3
+ import { type LoadingProps } from "./skeleton.js";
4
+ /**
5
+ * What a state is: `initial` (where things start), `normal`, `human` (waiting on a person),
6
+ * `terminal` (done, nothing leaves it) or `failed` (stopped on an error).
7
+ */
8
+ export type StateMachineKind = "initial" | "normal" | "human" | "terminal" | "failed";
9
+ /** One state: its `id` (what a transition's `from` and `to` and an item's `state` name), its `label`, its `kind`, and the role that `owner`s it. */
10
+ export type StateMachineState = {
11
+ id: string;
12
+ label: string;
13
+ /** @default normal */
14
+ kind?: StateMachineKind | undefined;
15
+ /** The role or lane that acts in this state (`reviewer`, `billing`), shown as a tag on it. */
16
+ owner?: string | undefined;
17
+ };
18
+ /** One move between states, with the `event` that makes it, shown on the arrow. */
19
+ export type StateMachineTransition = {
20
+ from: string;
21
+ to: string;
22
+ event?: string | undefined;
23
+ };
24
+ /** The machine: its states and the transitions between them. `fromXState` makes one from an xstate machine. */
25
+ export type StateMachineDefinition = {
26
+ states: readonly StateMachineState[];
27
+ transitions: readonly StateMachineTransition[];
28
+ };
29
+ /**
30
+ * A thing in the machine: its short `id` (a ref, shown by its dot), its full `label` (the dot's
31
+ * name and tooltip), the `state` it is in, and an optional `href` its dot links to.
32
+ */
33
+ export type StateMachineItem = {
34
+ id: string;
35
+ label: string;
36
+ state: string;
37
+ href?: string | undefined;
38
+ };
39
+ /**
40
+ * A state machine, drawn, with the things moving through it: each state a box, each transition an
41
+ * arrow named by its event, laid out like a `FlowDiagram`. A state's `kind` sets its look and a tag
42
+ * that says it: `human` takes the warn tone, `failed` the danger tone, `terminal` is muted, and
43
+ * `initial` is tagged start. Its `owner` is a tag beside it.
44
+ *
45
+ * Each of the `items` is a coloured dot with its short `id`, in the box of its `state`, which
46
+ * counts them; a box shows up to nine and a `+N` for the rest. The dot's name and tooltip is its
47
+ * full `label`, and with an `href` it is a link. An item whose state is not in the machine goes in
48
+ * a box of its own, "Not in any state", so nothing is dropped. When an item's state changes, its
49
+ * dot runs along the arrow between the two (straight across when there is none); with reduced
50
+ * motion it moves at once. `active` rings the one state that is current.
51
+ *
52
+ * `fromXState` makes `states` and `transitions` from an xstate machine.
53
+ */
54
+ export declare function StateMachine({ label, states, transitions, items, active, loading, loadingLabel, ...rest }: {
55
+ /** What the machine is: its accessible name. */
56
+ label: string;
57
+ /** The states, each with a unique `id`. */
58
+ states: readonly StateMachineState[];
59
+ /** The moves between them. One whose `from` or `to` is not a state is not drawn. */
60
+ transitions: readonly StateMachineTransition[];
61
+ /** The things in the machine, each in the state its `state` names. */
62
+ items?: readonly StateMachineItem[] | undefined;
63
+ /** The `id` of the one state to ring as current. */
64
+ active?: string | undefined;
65
+ } & LoadingProps & Passthrough): ReactElement;
@@ -0,0 +1,113 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useState } from "react";
3
+ import { FlowView } from "./FlowDiagram.js";
4
+ import { Pill } from "./Pill.js";
5
+ import { Bone, BusyLabel, busy, useLoading } from "./skeleton.js";
6
+ import { COLS, dotLayer, placeOf, SLOT_H, SLOT_W, slotsFor, UNPLACED, useMoves, } from "./stateMachineDots.js";
7
+ import { useFlowLayout } from "./useFlowLayout.js";
8
+ /** Each kind's box tone, and the tag that says it in words. */
9
+ const KIND_TONE = {
10
+ initial: "neutral",
11
+ normal: "neutral",
12
+ human: "warn",
13
+ terminal: "muted",
14
+ failed: "danger",
15
+ };
16
+ const KIND_TAG = {
17
+ initial: { text: "start", tone: "neutral" },
18
+ normal: null,
19
+ human: { text: "human", tone: "warn" },
20
+ terminal: { text: "end", tone: "neutral" },
21
+ failed: { text: "failed", tone: "danger" },
22
+ };
23
+ /** A box's tags: what kind of state it is, who owns it, and how many items it holds. */
24
+ function boxTags(tag, owner, count) {
25
+ if (!tag && !owner && count === 0)
26
+ return null;
27
+ return (_jsxs("span", { className: "flex flex-wrap items-center justify-center gap-1", children: [tag && (_jsx(Pill, { size: "sm", tone: tag.tone, children: tag.text })), owner && _jsx(Pill, { size: "sm", children: owner }), count > 0 && (_jsx(Pill, { size: "sm", tone: "accent", dot: true, children: count === 1 ? "1 item" : `${count} items` }))] }));
28
+ }
29
+ /** What a box holds under its label: its tags and the room its dots take. */
30
+ function boxContent(state, count, slots) {
31
+ const tags = boxTags(state ? KIND_TAG[state.kind ?? "normal"] : null, state?.owner, count);
32
+ if (tags === null)
33
+ return undefined;
34
+ const cols = Math.min(COLS, slots);
35
+ const rows = Math.ceil(slots / COLS);
36
+ return (_jsxs(_Fragment, { children: [tags, slots > 0 && (_jsx("span", { "aria-hidden": "true", className: "mx-auto mt-1 block", style: { width: cols * SLOT_W, height: rows * SLOT_H } }))] }));
37
+ }
38
+ /** The items each box holds: its state's, and the unplaced box's for an unknown state. */
39
+ function itemsByBox(items, known) {
40
+ const placed = placeOf(items, known);
41
+ const inBox = new Map();
42
+ for (const item of items) {
43
+ const box = placed.get(item.id) ?? UNPLACED;
44
+ inBox.set(box, [...(inBox.get(box) ?? []), item]);
45
+ }
46
+ return inBox;
47
+ }
48
+ /** The boxes to draw: one per state, and the unplaced box when an item is in no state. */
49
+ function boxesFor(states, inBox, open) {
50
+ const slots = (id) => slotsFor(inBox.get(id)?.length ?? 0, open.has(id));
51
+ const boxes = states.map((s) => ({
52
+ id: s.id,
53
+ label: s.label,
54
+ tone: KIND_TONE[s.kind ?? "normal"],
55
+ content: boxContent(s, inBox.get(s.id)?.length ?? 0, slots(s.id)),
56
+ }));
57
+ const unplaced = inBox.get(UNPLACED)?.length ?? 0;
58
+ if (unplaced === 0)
59
+ return boxes;
60
+ return [
61
+ ...boxes,
62
+ {
63
+ id: UNPLACED,
64
+ label: "Not in any state",
65
+ tone: "warn",
66
+ content: boxContent(null, unplaced, slots(UNPLACED)),
67
+ },
68
+ ];
69
+ }
70
+ /** Which boxes show all their dots, and the switch that opens or closes one. */
71
+ function useOpenBoxes(opened) {
72
+ const [open, setOpen] = useState(new Set());
73
+ const toggle = (id) => {
74
+ opened();
75
+ setOpen((current) => {
76
+ const next = new Set(current);
77
+ if (!next.delete(id))
78
+ next.add(id);
79
+ return next;
80
+ });
81
+ };
82
+ return [open, toggle];
83
+ }
84
+ /**
85
+ * A state machine, drawn, with the things moving through it: each state a box, each transition an
86
+ * arrow named by its event, laid out like a `FlowDiagram`. A state's `kind` sets its look and a tag
87
+ * that says it: `human` takes the warn tone, `failed` the danger tone, `terminal` is muted, and
88
+ * `initial` is tagged start. Its `owner` is a tag beside it.
89
+ *
90
+ * Each of the `items` is a coloured dot with its short `id`, in the box of its `state`, which
91
+ * counts them; a box shows up to nine and a `+N` for the rest. The dot's name and tooltip is its
92
+ * full `label`, and with an `href` it is a link. An item whose state is not in the machine goes in
93
+ * a box of its own, "Not in any state", so nothing is dropped. When an item's state changes, its
94
+ * dot runs along the arrow between the two (straight across when there is none); with reduced
95
+ * motion it moves at once. `active` rings the one state that is current.
96
+ *
97
+ * `fromXState` makes `states` and `transitions` from an xstate machine.
98
+ */
99
+ export function StateMachine({ label, states, transitions, items = [], active, loading, loadingLabel, ...rest }) {
100
+ const { loading: waiting, owner } = useLoading(loading);
101
+ const known = new Set(states.map((s) => s.id));
102
+ const { moves, done, clear } = useMoves(items, known);
103
+ const [open, toggle] = useOpenBoxes(clear);
104
+ const inBox = itemsByBox(items, known);
105
+ const nodes = boxesFor(states, inBox, open);
106
+ const edges = transitions.map((t) => ({ from: t.from, to: t.to, label: t.event }));
107
+ const { canvas, drawn } = useFlowLayout(nodes, edges, "down");
108
+ if (waiting && states.length === 0) {
109
+ return (_jsxs("figure", { ...rest, ...busy(owner, waiting), "aria-label": label, className: "flex flex-col", children: [_jsx(Bone, { shape: "block h-48 rounded-lg" }), _jsx(BusyLabel, { owner: owner, loading: waiting, label: loadingLabel })] }));
110
+ }
111
+ const names = new Map(nodes.map((n) => [n.id, n.label]));
112
+ return (_jsx(FlowView, { ...rest, label: label, nodes: nodes, edges: edges, active: active, layer: (layout) => dotLayer(layout, { inBox, names, open, toggle, moves, done }), canvas: canvas, drawn: drawn, fit: true }));
113
+ }
@@ -7,15 +7,33 @@ type StatusPageProps = {
7
7
  children?: ReactNode;
8
8
  /**
9
9
  * The page's own buttons, before "Back to home", which turns outline beside them. This is the one
10
- * way to a button worded differently; there is no label prop.
10
+ * way to add a button; `homeLabel` and `retryLabel` only reword the built-in ones.
11
11
  */
12
12
  actions?: ReactNode;
13
13
  } & Passthrough;
14
+ /** The pages that link home. */
15
+ type HomewardProps = StatusPageProps & {
16
+ /**
17
+ * The button to the `LinkProvider`'s `home`, for an app in another language.
18
+ * @default Back to home
19
+ */
20
+ homeLabel?: string | undefined;
21
+ };
22
+ /** The pages that can try again. */
23
+ type RetryProps = HomewardProps & {
24
+ /** Adds a "Try again" button that calls it, unless `actions` replaces the button. */
25
+ onRetry?: () => void;
26
+ /**
27
+ * The button `onRetry` adds, for an app in another language.
28
+ * @default Try again
29
+ */
30
+ retryLabel?: string | undefined;
31
+ };
14
32
  /**
15
33
  * 404: the page is not there. `numeral` draws a large "404" above the title, for a site whose 404
16
34
  * is a designed page; the digits are fixed. Off, the page is the title and copy alone.
17
35
  */
18
- export declare function NotFound({ numeral, ...props }: StatusPageProps & {
36
+ export declare function NotFound({ numeral, ...props }: HomewardProps & {
19
37
  /** Draws a large "404" above the title. Off by default. The digits are fixed: there is no text prop. */
20
38
  numeral?: boolean | undefined;
21
39
  }): ReactElement;
@@ -24,17 +42,17 @@ export declare function NotFound({ numeral, ...props }: StatusPageProps & {
24
42
  * only where a reader may see it (a request id, a message), never a stack trace. `onRetry` adds a
25
43
  * "Try again" button, unless `actions` replaces it.
26
44
  */
27
- export declare function ErrorPage({ detail, onRetry, actions, ...props }: StatusPageProps & {
45
+ export declare function ErrorPage({ detail, detailLabel, onRetry, retryLabel, actions, ...props }: RetryProps & {
28
46
  /** The error text, in a `CodeBlock` under the copy: a request id or a message a reader may see, never a stack trace. */
29
47
  detail?: string;
30
- /** Adds a "Try again" button that calls it, unless `actions` replaces the button. */
31
- onRetry?: () => void;
48
+ /**
49
+ * The name of the `detail` block, for an app in another language.
50
+ * @default Error
51
+ */
52
+ detailLabel?: string | undefined;
32
53
  }): ReactElement;
33
54
  /** The device has no connection. `onRetry` adds a "Try again" button, unless `actions` replaces it. */
34
- export declare function Offline({ onRetry, actions, ...props }: StatusPageProps & {
35
- /** Adds a "Try again" button that calls it, unless `actions` replaces the button. */
36
- onRetry?: () => void;
37
- }): ReactElement;
55
+ export declare function Offline({ onRetry, retryLabel, actions, ...props }: RetryProps): ReactElement;
38
56
  /**
39
57
  * The site is down on purpose and will be back: the page for planned downtime, such as an upgrade.
40
58
  * A failure is an `ErrorPage`, and no connection is `Offline`. It has no "Back to home": home is
@@ -45,5 +63,5 @@ export declare function Maintenance(props: StatusPageProps): ReactElement;
45
63
  * 403: signed in, or not, but not allowed here. The page for a route that exists and the reader may
46
64
  * not see; a route that is not there is a `NotFound`.
47
65
  */
48
- export declare function Forbidden(props: StatusPageProps): ReactElement;
66
+ export declare function Forbidden(props: HomewardProps): ReactElement;
49
67
  export {};
@@ -3,15 +3,15 @@ import { Button } from "./Button.js";
3
3
  import { CodeBlock } from "./CodeBlock.js";
4
4
  import { useHome } from "./link.js";
5
5
  import { CenteredLayout } from "./PageLayouts.js";
6
- /** "Back to home", to the `LinkProvider`'s `home`: the primary button alone, outline after the page's actions. */
7
- function HomeLink({ outline }) {
8
- return (_jsx(Button, { href: useHome(), variant: outline ? "outline" : "primary", children: "Back to home" }));
6
+ /** `label` ("Back to home"), to the `LinkProvider`'s `home`: the primary button alone, outline after the page's actions. */
7
+ function HomeLink({ outline, label }) {
8
+ return (_jsx(Button, { href: useHome(), variant: outline ? "outline" : "primary", children: label }));
9
9
  }
10
- function StatusPage({ copy, title, children, actions, extra, mark, homeward = true, ...rest }) {
11
- const home = homeward && _jsx(HomeLink, { outline: Boolean(actions) });
10
+ function StatusPage({ copy, title, children, actions, extra, mark, homeward = true, homeLabel = "Back to home", ...rest }) {
11
+ const home = homeward && _jsx(HomeLink, { outline: Boolean(actions), label: homeLabel });
12
12
  return (_jsxs(CenteredLayout, { ...rest, mark: mark, title: title ?? copy.title, description: children ?? copy.body, children: [extra, (actions || home) && (_jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [actions, home] }))] }));
13
13
  }
14
- const retry = (onRetry) => onRetry && _jsx(Button, { onClick: onRetry, children: "Try again" });
14
+ const retry = (onRetry, label = "Try again") => onRetry && _jsx(Button, { onClick: onRetry, children: label });
15
15
  /**
16
16
  * 404: the page is not there. `numeral` draws a large "404" above the title, for a site whose 404
17
17
  * is a designed page; the digits are fixed. Off, the page is the title and copy alone.
@@ -27,18 +27,18 @@ export function NotFound({ numeral = false, ...props }) {
27
27
  * only where a reader may see it (a request id, a message), never a stack trace. `onRetry` adds a
28
28
  * "Try again" button, unless `actions` replaces it.
29
29
  */
30
- export function ErrorPage({ detail, onRetry, actions, ...props }) {
30
+ export function ErrorPage({ detail, detailLabel = "Error", onRetry, retryLabel, actions, ...props }) {
31
31
  return (_jsx(StatusPage, { copy: {
32
32
  title: "Something went wrong",
33
33
  body: "An error stopped this page from loading. You can try again.",
34
- }, actions: actions ?? retry(onRetry), extra: detail && _jsx(CodeBlock, { label: "Error", children: detail }), ...props }));
34
+ }, actions: actions ?? retry(onRetry, retryLabel), extra: detail && _jsx(CodeBlock, { label: detailLabel, children: detail }), ...props }));
35
35
  }
36
36
  /** The device has no connection. `onRetry` adds a "Try again" button, unless `actions` replaces it. */
37
- export function Offline({ onRetry, actions, ...props }) {
37
+ export function Offline({ onRetry, retryLabel, actions, ...props }) {
38
38
  return (_jsx(StatusPage, { copy: {
39
39
  title: "You are offline",
40
40
  body: "Check your connection and try again.",
41
- }, actions: actions ?? retry(onRetry), ...props }));
41
+ }, actions: actions ?? retry(onRetry, retryLabel), ...props }));
42
42
  }
43
43
  /**
44
44
  * The site is down on purpose and will be back: the page for planned downtime, such as an upgrade.
@@ -0,0 +1,21 @@
1
+ import type { ReactElement } from "react";
2
+ import type { Passthrough } from "./props.js";
3
+ /**
4
+ * Where the reader is in a fixed run of steps (checkout, a setup flow): each step done, current
5
+ * or still to come. An ordered list named by `label`, across from `sm` and down on a phone.
6
+ * `current` is the step in progress, from 1; past the last step every step is done. It shows
7
+ * progress and does not navigate: the flow's own buttons move between steps.
8
+ */
9
+ export declare function Stepper({ steps, current, label, doneLabel, ...rest }: {
10
+ /** The steps' names, in order: "Cart", "Shipping", "Payment", "Review". Short, one or two words. */
11
+ steps: readonly string[];
12
+ /** The step in progress, from 1. Past the last step, every step is done. */
13
+ current: number;
14
+ /** The list's accessible name: "Checkout progress". */
15
+ label: string;
16
+ /**
17
+ * What a screen reader hears after a done step's name, for an app in another language.
18
+ * @default done
19
+ */
20
+ doneLabel?: string | undefined;
21
+ } & Passthrough): ReactElement;
@@ -0,0 +1,33 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { cx } from "./cx.js";
3
+ import { Icon } from "./Icon.js";
4
+ // The current step is told apart by more than colour: its marker is outlined in the accent and its
5
+ // label is medium weight; a done step's marker is filled and holds a tick.
6
+ const MARKER = {
7
+ done: "border-violet-600 bg-violet-600 text-violet-50",
8
+ current: "border-violet-600 bg-white text-violet-700",
9
+ upcoming: "border-slate-300 bg-white text-slate-500",
10
+ };
11
+ const LABEL = {
12
+ done: "text-slate-600",
13
+ current: "font-medium text-slate-900",
14
+ upcoming: "text-slate-600",
15
+ };
16
+ function stateOf(index, current) {
17
+ if (index < current)
18
+ return "done";
19
+ return index === current ? "current" : "upcoming";
20
+ }
21
+ /**
22
+ * Where the reader is in a fixed run of steps (checkout, a setup flow): each step done, current
23
+ * or still to come. An ordered list named by `label`, across from `sm` and down on a phone.
24
+ * `current` is the step in progress, from 1; past the last step every step is done. It shows
25
+ * progress and does not navigate: the flow's own buttons move between steps.
26
+ */
27
+ export function Stepper({ steps, current, label, doneLabel = "done", ...rest }) {
28
+ const last = steps.length - 1;
29
+ return (_jsx("ol", { ...rest, "aria-label": label, className: "flex flex-col gap-3 text-sm sm:flex-row sm:items-center", children: steps.map((step, index) => {
30
+ const state = stateOf(index + 1, current);
31
+ return (_jsxs("li", { "aria-current": state === "current" ? "step" : undefined, className: cx("flex min-w-0 items-center gap-2", index < last && "sm:flex-1"), children: [_jsx("span", { "aria-hidden": "true", className: cx("flex size-7 shrink-0 items-center justify-center rounded-full border-2 font-medium tabular-nums", MARKER[state]), children: state === "done" ? _jsx(Icon, { name: "check", size: "sm" }) : index + 1 }), _jsxs("span", { className: LABEL[state], children: [step, state === "done" && _jsxs("span", { className: "sr-only", children: [" (", doneLabel, ")"] })] }), index < last && (_jsx("span", { "aria-hidden": "true", className: cx("hidden h-0 min-w-4 flex-1 border-t-2 sm:block", state === "done" ? "border-violet-600" : "border-slate-300") }))] }, index));
32
+ }) }));
33
+ }
package/dist/Steps.js CHANGED
@@ -11,9 +11,10 @@ const ITEM = {
11
11
  md: {
12
12
  item: "grid grid-cols-[1.625rem_1fr] gap-3 [counter-increment:step]",
13
13
  number: "flex size-[1.625rem] items-center justify-center rounded-full bg-violet-50 text-xs font-semibold tabular-nums text-violet-600 before:content-[counter(step)]",
14
- body: "min-w-0 pt-0.5",
15
- title: "text-sm/5 font-medium text-slate-900",
16
- detail: "mt-1 text-sm/5 text-slate-600",
14
+ // The 1.5rem first line sits centred on the 1.625rem number.
15
+ body: "min-w-0 pt-px",
16
+ title: "text-base/6 font-medium text-slate-900",
17
+ detail: "mt-1 text-base/6 text-slate-600",
17
18
  },
18
19
  lg: {
19
20
  item: "flex flex-col gap-4 [counter-increment:step]",
package/dist/Switch.d.ts CHANGED
@@ -20,7 +20,7 @@ type SwitchProps = Naming & {
20
20
  onChange?: ((checked: boolean) => void) | undefined;
21
21
  /** A muted line under the label that says more. It is the switch's `aria-describedby`. */
22
22
  hint?: ReactNode;
23
- /** Replaces the hint with a red line (`role="alert"`) and makes the switch `aria-invalid`. */
23
+ /** A red line under the hint, with an alert icon, announced politely; makes the switch `aria-invalid`. */
24
24
  error?: ReactNode;
25
25
  /**
26
26
  * The label's text size and the switch with it.
@@ -45,8 +45,8 @@ type SwitchProps = Naming & {
45
45
  * `onChange`, or gives `defaultChecked` and the switch keeps its own state. A value sent with a
46
46
  * form is a `Checkbox`, not a Switch. Give it a `label`
47
47
  * (the whole label is the click target), or in a table cell leave the label out and name it with
48
- * `aria-label`. `hint` is a muted line under the label; `error` replaces it with a red line
49
- * (`role="alert"`) and makes the switch `aria-invalid`. The note is the switch's
48
+ * `aria-label`. `hint` is a muted line under the label; `error` adds a red line under it, with an alert
49
+ * icon, and makes the switch `aria-invalid` and red-edged. The note is the switch's
50
50
  * `aria-describedby`. `size` is `sm`, `md` (the default) or `lg`. `busy` is for the save in
51
51
  * flight: clicks and keys do nothing, and the switch keeps its colour and its focus.
52
52
  * `disabledReason` blocks it, focusable, with the reason as its tooltip. `disabled` is the native
package/dist/Switch.js CHANGED
@@ -1,19 +1,22 @@
1
1
  import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useState } from "react";
3
+ import { INVALID_EDGE } from "./control.js";
3
4
  import { cx, focusRing } from "./cx.js";
5
+ import { controlText, useTypeStep } from "./density.js";
4
6
  import { useNote, Words } from "./labelWords.js";
5
7
  import { useBlocked } from "./blocked.js";
8
+ import { MIN_TARGET } from "./target.js";
6
9
  import { WaitingChoice } from "./fieldWait.js";
7
10
  import { useLoading } from "./skeleton.js";
8
11
  /**
9
- * The label's gap and text, the track, its thumb and the thumb's slide, by `size`. The track is a
12
+ * The label's gap, the track, its thumb and the thumb's slide, by `size`. The track is a
10
13
  * 2px border plus 2px of padding, so the thumb is the track's height less 8px and slides the
11
14
  * track's width less 8px less its own width.
12
15
  */
13
16
  const SIZE = {
14
- sm: { label: "gap-2 text-xs", track: "h-5 w-9", thumb: "h-3 w-3", slide: "translate-x-4" },
15
- md: { label: "gap-2.5 text-sm", track: "h-6 w-11", thumb: "h-4 w-4", slide: "translate-x-5" },
16
- lg: { label: "gap-3 text-base", track: "h-7 w-13", thumb: "h-5 w-5", slide: "translate-x-6" },
17
+ sm: { gap: "gap-2", track: "h-5 w-9", thumb: "h-3 w-3", slide: "translate-x-4" },
18
+ md: { gap: "gap-2.5", track: "h-6 w-11", thumb: "h-4 w-4", slide: "translate-x-5" },
19
+ lg: { gap: "gap-3", track: "h-7 w-13", thumb: "h-5 w-5", slide: "translate-x-6" },
17
20
  };
18
21
  // Off is an outline of the text colour with a thumb of the same colour; on is the accent filled,
19
22
  // with a thumb in its pale text colour. `border-current` and `bg-current` are no palette colour.
@@ -32,7 +35,7 @@ function washOf(disabled, busy) {
32
35
  /** The switch itself: the track, with the thumb in it. */
33
36
  function Track({ checked, onChange, size, busy, disabled, onClick, className, ...rest }) {
34
37
  const { track, thumb, slide } = SIZE[size];
35
- return (_jsx("button", { type: "button", role: "switch", "aria-checked": checked, "aria-busy": busy || undefined, "aria-disabled": busy || undefined, disabled: disabled, className: cx("inline-flex shrink-0 items-center rounded-full border-2 p-0.5", track, checked ? ON : OFF, className, focusRing), onClick: (event) => {
38
+ return (_jsx("button", { type: "button", role: "switch", "aria-checked": checked, "aria-busy": busy || undefined, "aria-disabled": busy || undefined, disabled: disabled, className: cx("inline-flex shrink-0 items-center rounded-full border-2 p-0.5", INVALID_EDGE, track, size === "sm" && MIN_TARGET, checked ? ON : OFF, className, focusRing), onClick: (event) => {
36
39
  onClick?.(event);
37
40
  if (event.defaultPrevented || busy)
38
41
  return;
@@ -52,9 +55,9 @@ function useChecked(checked, defaultChecked, onChange) {
52
55
  ];
53
56
  }
54
57
  /** The switch inside its label, the note under the words. */
55
- function Labelled({ label, hint, error, noteId, size, wash, children, }) {
56
- const start = noteId !== undefined;
57
- return (_jsxs("label", { className: cx("inline-flex text-slate-700", start ? "items-start" : "items-center", SIZE[size].label, wash), children: [children, _jsx("span", { className: cx(start && "mt-0.5"), children: _jsx(Words, { label: label, hint: hint, error: error, id: noteId }) })] }));
58
+ function Labelled({ label, hint, error, noteIds, size, wash, children, }) {
59
+ const start = noteIds !== undefined;
60
+ return (_jsxs("label", { className: cx("inline-flex text-slate-700", start ? "items-start" : "items-center", SIZE[size].gap, controlText(size, useTypeStep(), false), wash), children: [children, _jsx("span", { className: cx(start && "mt-0.5"), children: _jsx(Words, { label: label, hint: hint, error: error, ids: noteIds }) })] }));
58
61
  }
59
62
  /**
60
63
  * An on/off switch for a setting that takes effect at once, usually by saving it to a server: a
@@ -62,23 +65,24 @@ function Labelled({ label, hint, error, noteId, size, wash, children, }) {
62
65
  * `onChange`, or gives `defaultChecked` and the switch keeps its own state. A value sent with a
63
66
  * form is a `Checkbox`, not a Switch. Give it a `label`
64
67
  * (the whole label is the click target), or in a table cell leave the label out and name it with
65
- * `aria-label`. `hint` is a muted line under the label; `error` replaces it with a red line
66
- * (`role="alert"`) and makes the switch `aria-invalid`. The note is the switch's
68
+ * `aria-label`. `hint` is a muted line under the label; `error` adds a red line under it, with an alert
69
+ * icon, and makes the switch `aria-invalid` and red-edged. The note is the switch's
67
70
  * `aria-describedby`. `size` is `sm`, `md` (the default) or `lg`. `busy` is for the save in
68
71
  * flight: clicks and keys do nothing, and the switch keeps its colour and its focus.
69
72
  * `disabledReason` blocks it, focusable, with the reason as its tooltip. `disabled` is the native
70
73
  * one, washed out. While `loading` the label is drawn and the track is a bone of its size.
71
74
  */
72
75
  export function Switch({ loading, loadingLabel, ...props }) {
76
+ const step = useTypeStep();
73
77
  if (useLoading(loading).loading) {
74
78
  const size = props.size ?? "md";
75
- return (_jsx(WaitingChoice, { own: loading, loadingLabel: loadingLabel, label: props.label, look: cx("items-center", SIZE[size].label), shape: cx(SIZE[size].track, "rounded-full"), attrs: props }));
79
+ return (_jsx(WaitingChoice, { own: loading, loadingLabel: loadingLabel, label: props.label, look: cx("items-center", SIZE[size].gap, controlText(size, step, false)), shape: cx(SIZE[size].track, "rounded-full"), attrs: props }));
76
80
  }
77
81
  return _jsx(ShownSwitch, { ...props });
78
82
  }
79
83
  /** A switch with its track drawn. */
80
84
  function ShownSwitch({ label, hint, error, checked, defaultChecked = false, onChange, size = "md", busy = false, disabledReason, "aria-describedby": describedBy, ...rest }) {
81
- const { noteId, describedIds, invalid } = useNote(hint, error, describedBy);
85
+ const { ids: noteIds, describedIds, invalid } = useNote(hint, error, describedBy);
82
86
  const [on, flip] = useChecked(checked, defaultChecked, onChange);
83
87
  const { props: guard, tooltip, blocked, } = useBlocked(disabledReason, {
84
88
  ...rest,
@@ -86,6 +90,6 @@ function ShownSwitch({ label, hint, error, checked, defaultChecked = false, onCh
86
90
  });
87
91
  const off = rest.disabled === true || blocked;
88
92
  const wash = washOf(off, busy);
89
- const track = (_jsx(Track, { ...rest, checked: on, onChange: flip, size: size, busy: busy, className: label === undefined ? wash : cursorOf(off, busy), ...(invalid ? { "aria-invalid": true } : {}), ...guard }));
90
- return (_jsxs(_Fragment, { children: [label === undefined ? (track) : (_jsx(Labelled, { label: label, hint: hint, error: error, noteId: noteId, size: size, wash: wash, children: track })), tooltip] }));
93
+ const track = (_jsx(Track, { ...rest, checked: on, onChange: flip, size: size, busy: busy, className: label === undefined ? wash : cursorOf(off, busy), "aria-invalid": invalid, ...guard }));
94
+ return (_jsxs(_Fragment, { children: [label === undefined ? (track) : (_jsx(Labelled, { label: label, hint: hint, error: error, noteIds: noteIds, size: size, wash: wash, children: track })), tooltip] }));
91
95
  }
package/dist/Table.d.ts CHANGED
@@ -6,17 +6,21 @@ export { TableExpandCell } from "./TableExpandCell.js";
6
6
  export type { TableSort } from "./tableSort.js";
7
7
  import { type LoadingProps } from "./skeleton.js";
8
8
  /**
9
- * A list of records in a rounded, bordered card that scrolls sideways on a narrow screen. Compose it
9
+ * A list of records in a rounded, bordered card. Compose it
10
10
  * from `TableHead`, `TableBody`, `TableFoot`, `TableRow`, `TableHeaderCell` and `TableCell`. `label`
11
11
  * names the table for assistive tech and is not drawn. Inside a `Card` it is plain: no card of its
12
12
  * own (border, fill and shadow), no tinted head strip and no row hover, only the row dividers. A
13
13
  * column of figures says so once, with `numeric` on its `TableHeaderCell`: its cells then take end
14
- * alignment and tabular figures. `size` is the row padding, and the controls in the rows follow it
15
- * (`sm` by default). Other props (`id`, `data-*`, `aria-*`) go on the `<table>`. While `loading`, a
14
+ * alignment and tabular figures. `size` is the row padding, and the buttons and pills in the rows follow it
15
+ * (`sm` by default); a field keeps its own `size`. Other props (`id`, `data-*`, `aria-*`) go on the `<table>`. While `loading`, a
16
16
  * body with no rows draws five rows of bones, one per column, and an empty cell draws a bone; the
17
- * table keeps its role and its name.
17
+ * table keeps its role and its name. A table that fits its box keeps its head row in view (under
18
+ * the `AppShell` header) while the page scrolls past its rows; one wider than its box scrolls
19
+ * sideways instead, and takes a tab stop when nothing in it can take focus. `narrow="stack"` draws
20
+ * each row as a card on a screen narrower than `sm` (a phone), the cells as lines labelled by their column's
21
+ * title. A click on a sortable title has the table say the new sort aloud, in `sortedLabel`'s words.
18
22
  */
19
- export declare function Table({ label, size, loading, loadingLabel, children, ...rest }: {
23
+ export declare function Table({ label, size, narrow, sortedLabel, loading, loadingLabel, children, ...rest }: {
20
24
  /** Names the table for assistive tech; it is not drawn. */
21
25
  label: string;
22
26
  /**
@@ -24,9 +28,27 @@ export declare function Table({ label, size, loading, loadingLabel, children, ..
24
28
  * @default sm
25
29
  */
26
30
  size?: Size | undefined;
31
+ /**
32
+ * What the table does on a screen narrower than `sm` (a phone): `scroll` sideways, or `stack` each row into
33
+ * a card, the first cell its title and every other cell a line labelled by its column's title.
34
+ * Stack a table whose rows a person reads one at a time; keep `scroll` for one they compare
35
+ * down a column.
36
+ * @default scroll
37
+ */
38
+ narrow?: "scroll" | "stack" | undefined;
39
+ /**
40
+ * What a screen reader hears after a click on a sortable title, from the column's title and the
41
+ * new direction.
42
+ * @default `Sorted by Name, ascending`
43
+ */
44
+ sortedLabel?: ((column: string, sort: "ascending" | "descending") => string) | undefined;
27
45
  children: ReactNode;
28
46
  } & LoadingProps & Rest<"table">): ReactElement;
29
- /** The `<thead>`: small uppercase column titles, on a tinted strip unless the table is in a card. Holds one `TableRow` of `TableHeaderCell`s. */
47
+ /**
48
+ * The `<thead>`: small uppercase column titles, on a tinted strip unless the table is in a card.
49
+ * Holds one `TableRow` of `TableHeaderCell`s. Unless the table is in a card, it stays in view under
50
+ * the `AppShell` header while the page scrolls past the rows, as long as the table fits its box.
51
+ */
30
52
  export declare function TableHead({ children, ...rest }: {
31
53
  children: ReactNode;
32
54
  } & Rest<"thead">): ReactElement;
@@ -75,14 +97,15 @@ export declare function TableRow({ tone, stripe, emphasis, selected, children, .
75
97
  } & Rest<"tr">): ReactElement;
76
98
  /**
77
99
  * A full-width group header in the body: a tinted row with a `label` that spans every column the
78
- * head declares (or `colSpan` columns), and optional `trailing` content at the far end (a count, a
79
- * subtotal, a small button). The group's rows follow it. For a panel of other content across the
100
+ * head declares (or `colSpan` columns), and optional `trailing` text at the far end: the group's
101
+ * count or subtotal, muted. The group's rows follow it. The row is a `<th>`, a heading for the
102
+ * 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
80
103
  * whole row, use a `TableCell span="full"` instead.
81
104
  */
82
105
  export declare function TableGroupRow({ label, trailing, colSpan, ...rest }: {
83
106
  /** The group's name, at the start of the row. */
84
107
  label: ReactNode;
85
- /** Content at the far end of the row: a count, a subtotal, a small button. */
108
+ /** The group's count or subtotal, muted at the far end of the row. */
86
109
  trailing?: ReactNode;
87
110
  /**
88
111
  * How many columns the header spans.