@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/Dialog.d.ts CHANGED
@@ -13,7 +13,8 @@ export type DialogProps = {
13
13
  * Makes the dialog a form: one `<form noValidate>` holds the body, the `error` and the footer,
14
14
  * so a `Button type="submit"` in the footer or Enter in a field submits it, with no `form`
15
15
  * attribute or id. The default is prevented before this runs, and a rejection is yours to
16
- * catch and show as `error`. Put no `<form method="dialog">` in the footer of a form dialog:
16
+ * catch and show as `error`. Once the submit settles, the focus moves to the first field marked
17
+ * invalid (`aria-invalid="true"`), if any. Put no `<form method="dialog">` in the footer of a form dialog:
17
18
  * it would nest a form.
18
19
  */
19
20
  onSubmit?: ((event: FormEvent<HTMLFormElement>) => void | Promise<unknown>) | undefined;
@@ -27,14 +28,22 @@ export type DialogProps = {
27
28
  * The panel's width: `sm` (320px) is a list, `md` (440px) holds a form, `lg` (640px) a wider
28
29
  * form or a table. `full` fills the whole screen, for media or a player: the body takes the
29
30
  * height between the header and the footer and scrolls if it is taller. It has no backdrop to
30
- * click, so give it a close action in the `footer` (a `<form method="dialog">` button).
31
+ * click: its close button and Esc close it.
31
32
  *
32
33
  * A single photo or video is a `Lightbox`.
33
34
  * @default md
34
35
  */
35
36
  width?: Size | "full";
36
- /** Called when the dialog closes: Esc, a click on the backdrop, or a `<form method="dialog">` submit. */
37
+ /**
38
+ * Called when the dialog closes: its close button, Esc, a click on the backdrop, or a
39
+ * `<form method="dialog">` submit.
40
+ */
37
41
  onClose: () => void;
42
+ /**
43
+ * The name of the close button in the top corner, for an app in another language.
44
+ * @default Close
45
+ */
46
+ closeLabel?: string | undefined;
38
47
  } & Passthrough;
39
48
  /**
40
49
  * What a modal resets, since the browser's `<dialog>` renders where it is written: it is back on the
@@ -50,7 +59,34 @@ export declare function BodyContext({ children }: {
50
59
  /**
51
60
  * A modal on the browser's own `<dialog>`: it is opened with `showModal()` on mount, so render it
52
61
  * only while it is open. The page behind goes inert, Esc closes it and focus stays inside; a click
53
- * on the backdrop (the `<dialog>` element itself, not its contents) closes it too. A windowed dialog is
54
- * never taller than the screen: a tall body scrolls and the title and footer stay on screen.
62
+ * on the backdrop (the `<dialog>` element itself, not its contents) closes it too, and so does the
63
+ * close button in its top corner, which every dialog has. The close button comes last in the
64
+ * keyboard order, so the open focuses the first field, not it. A windowed dialog is never taller
65
+ * than the screen: a tall body scrolls and the title and footer stay on screen, and a scroll inside
66
+ * it never carries on to the page behind.
55
67
  */
56
- export declare function Dialog({ title, description, children, footer, onSubmit, error, width, onClose, ...rest }: DialogProps): ReactElement;
68
+ export declare function Dialog(props: DialogProps): ReactElement;
69
+ /**
70
+ * The `Dialog` itself, with the one thing the library's own dialogs set that a consumer does not:
71
+ * `role="alertdialog"`, for `ConfirmDialog`.
72
+ */
73
+ export declare function DialogFrame({ title, description, children, footer, onSubmit, error, width, onClose, closeLabel, role, ...rest }: DialogProps & {
74
+ role?: "alertdialog";
75
+ }): ReactElement;
76
+ /**
77
+ * The `error` of a form dialog or drawer: a danger `Callout`, announced as an alert, pinned between
78
+ * the body and the footer. `space` is the panel's own spacing around it.
79
+ */
80
+ export declare function FormError({ error, space, }: {
81
+ error: ReactNode;
82
+ space: string;
83
+ }): ReactElement | null;
84
+ /**
85
+ * With `onSubmit`, the body, error and footer in one `<form>` that keeps the panel's column, so the
86
+ * body still scrolls under the cap; without it they sit in the panel as they are. Shared by `Dialog`
87
+ * and `Drawer`.
88
+ */
89
+ export declare function FormColumn({ onSubmit, children, }: {
90
+ onSubmit: DialogProps["onSubmit"];
91
+ children: ReactNode;
92
+ }): ReactElement;
package/dist/Dialog.js CHANGED
@@ -1,10 +1,11 @@
1
1
  import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useId, useLayoutEffect, useRef, } from "react";
2
+ import { useEffect, useId, useLayoutEffect, useRef, useState, } from "react";
3
3
  import { Callout } from "./Callout.js";
4
4
  import { InCard } from "./cardContext.js";
5
5
  import { cx } from "./cx.js";
6
6
  import { DensityProvider } from "./density.js";
7
7
  import { HeadingLevelProvider } from "./headingLevel.js";
8
+ import { IconButton } from "./IconButton.js";
8
9
  import { useBackdropClose, useModal } from "./modal.js";
9
10
  import { scrollStopProps, TABBABLE, useScrollStop } from "./scrollStop.js";
10
11
  import { GapProvider } from "./stackGap.js";
@@ -26,9 +27,9 @@ const CAP = "max-h-[calc(100dvh-8rem-2px)]";
26
27
  * the ring whole (4px: a 2px outline at a 2px offset), and the negative margins give that room back,
27
28
  * so the body sits where an unpadded one would.
28
29
  */
29
- const SCROLL_BODY = "mt-3 -mb-1 -mx-1 min-h-0 flex-1 scroll-py-1 overflow-y-auto px-1 pt-1 pb-1";
30
+ const SCROLL_BODY = "mt-3 -mb-1 -mx-1 min-h-0 flex-1 scroll-py-1 overflow-y-auto overscroll-contain px-1 pt-1 pb-1";
30
31
  /** The whole viewport, edge to edge: no margin, radius, border or shadow, and a column so the body can fill it. */
31
- const FULL = "fixed inset-0 m-0 size-full max-h-none max-w-none flex-col overflow-hidden rounded-none border-0 open:flex";
32
+ const FULL = "fixed inset-0 m-0 size-full max-h-none max-w-none flex-col overflow-hidden overscroll-contain rounded-none border-0 open:flex";
32
33
  /**
33
34
  * The body's keyboard side. In a windowed dialog Chromium's `showModal()` focuses a scrolling box
34
35
  * ahead of the field inside it, though the other engines pick the field: when the open took the
@@ -51,7 +52,7 @@ function useScrollingBody(dialog, titleId, full) {
51
52
  return {
52
53
  attach,
53
54
  props,
54
- className: cx(full ? "mt-4 min-h-0 flex-1 overflow-auto" : SCROLL_BODY, ring),
55
+ className: cx(full ? "mt-4 min-h-0 flex-1 overflow-auto overscroll-contain" : SCROLL_BODY, ring),
55
56
  };
56
57
  }
57
58
  /**
@@ -68,27 +69,64 @@ export function BodyContext({ children }) {
68
69
  /**
69
70
  * A modal on the browser's own `<dialog>`: it is opened with `showModal()` on mount, so render it
70
71
  * only while it is open. The page behind goes inert, Esc closes it and focus stays inside; a click
71
- * on the backdrop (the `<dialog>` element itself, not its contents) closes it too. A windowed dialog is
72
- * never taller than the screen: a tall body scrolls and the title and footer stay on screen.
72
+ * on the backdrop (the `<dialog>` element itself, not its contents) closes it too, and so does the
73
+ * close button in its top corner, which every dialog has. The close button comes last in the
74
+ * keyboard order, so the open focuses the first field, not it. A windowed dialog is never taller
75
+ * than the screen: a tall body scrolls and the title and footer stay on screen, and a scroll inside
76
+ * it never carries on to the page behind.
73
77
  */
74
- export function Dialog({ title, description, children, footer, onSubmit, error, width = "md", onClose, ...rest }) {
78
+ export function Dialog(props) {
79
+ return _jsx(DialogFrame, { ...props });
80
+ }
81
+ /**
82
+ * The `Dialog` itself, with the one thing the library's own dialogs set that a consumer does not:
83
+ * `role="alertdialog"`, for `ConfirmDialog`.
84
+ */
85
+ export function DialogFrame({ title, description, children, footer, onSubmit, error, width = "md", onClose, closeLabel = "Close", role, ...rest }) {
75
86
  const dialog = useRef(null);
76
87
  const titleId = useId();
77
88
  const closed = useModal(dialog, onClose);
78
89
  const backdrop = useBackdropClose(dialog);
79
90
  const full = width === "full";
80
91
  const { attach, props: bodyProps, className: bodyClass, } = useScrollingBody(dialog, titleId, full);
81
- return (_jsx(ModalScope, { children: _jsx("dialog", { ...rest, ref: dialog, "aria-labelledby": titleId, onClose: closed, ...backdrop, className: cx(BASE, width === "full" ? FULL : `${WINDOW} ${WIDTH[width]}`), children: _jsxs("div", { className: cx("flex flex-col p-5.5", full ? "min-h-0 flex-1" : CAP), children: [_jsx(SectionHeading, { id: titleId, children: title }), description && (_jsx("div", { className: "mt-1", children: _jsx(HeaderText, { children: description }) })), _jsxs(FormColumn, { onSubmit: onSubmit, children: [children && (_jsx("div", { ref: attach, ...bodyProps, className: bodyClass, children: _jsx(BodyContext, { children: children }) })), error && (_jsx("div", { className: "mt-5 shrink-0", children: _jsx(Callout, { tone: "danger", children: error }) })), footer && _jsx("div", { className: "mt-5 flex shrink-0 justify-end gap-2", children: footer })] })] }) }) }));
92
+ return (_jsx(ModalScope, { children: _jsxs("dialog", { ...rest, ref: dialog, role: role, "aria-labelledby": titleId, onClose: closed, ...backdrop, className: cx(BASE, width === "full" ? FULL : `${WINDOW} ${WIDTH[width]}`), children: [_jsxs("div", { className: cx("flex flex-col p-5.5", full ? "min-h-0 flex-1" : CAP), children: [_jsx("div", { className: "pe-8", children: _jsx(SectionHeading, { id: titleId, children: title }) }), description && (_jsx("div", { className: "mt-1 pe-8", children: _jsx(HeaderText, { children: description }) })), _jsxs(FormColumn, { onSubmit: onSubmit, children: [children && (_jsx("div", { ref: attach, ...bodyProps, className: bodyClass, children: _jsx(BodyContext, { children: children }) })), _jsx(FormError, { error: error, space: "mt-5" }), footer && _jsx("div", { className: "mt-5 flex shrink-0 justify-end gap-2", children: footer })] })] }), _jsx("div", { className: "absolute end-4 top-4.5", children: _jsx(IconButton, { size: "sm", variant: "ghost", label: closeLabel, icon: "close", onClick: () => dialog.current?.close() }) })] }) }));
93
+ }
94
+ /**
95
+ * The `error` of a form dialog or drawer: a danger `Callout`, announced as an alert, pinned between
96
+ * the body and the footer. `space` is the panel's own spacing around it.
97
+ */
98
+ export function FormError({ error, space, }) {
99
+ if (!error)
100
+ return null;
101
+ return (_jsx("div", { className: cx("shrink-0", space), children: _jsx(Callout, { tone: "danger", children: error }) }));
82
102
  }
83
103
  /**
84
104
  * With `onSubmit`, the body, error and footer in one `<form>` that keeps the panel's column, so the
85
- * body still scrolls under the cap; without it they sit in the panel as they are.
105
+ * body still scrolls under the cap; without it they sit in the panel as they are. Shared by `Dialog`
106
+ * and `Drawer`.
86
107
  */
87
- function FormColumn({ onSubmit, children, }) {
108
+ export function FormColumn({ onSubmit, children, }) {
109
+ const form = useRef(null);
110
+ const settled = useFocusFirstInvalid(form);
88
111
  if (!onSubmit)
89
112
  return _jsx(_Fragment, { children: children });
90
- return (_jsx("form", { noValidate: true, className: "flex min-h-0 flex-1 flex-col", onSubmit: (event) => {
113
+ return (_jsx("form", { ref: form, noValidate: true, className: "flex min-h-0 flex-1 flex-col", onSubmit: (event) => {
91
114
  event.preventDefault();
92
- void onSubmit(event);
115
+ // A rejection stays the caller's to catch, as before; `finally` passes it on.
116
+ void Promise.resolve(onSubmit(event)).finally(settled);
93
117
  }, children: children }));
94
118
  }
119
+ /**
120
+ * After each submit settles, moves the focus to the form's first field marked `aria-invalid="true"`,
121
+ * so a failed submit lands the reader on what to fix. It runs once per submit, after the render
122
+ * that shows the submit's errors, and never while the reader types.
123
+ */
124
+ function useFocusFirstInvalid(form) {
125
+ const [submits, setSubmits] = useState(0);
126
+ useEffect(() => {
127
+ if (submits === 0)
128
+ return;
129
+ form.current?.querySelector('[aria-invalid="true"]')?.focus();
130
+ }, [form, submits]);
131
+ return () => setSubmits((n) => n + 1);
132
+ }
@@ -6,6 +6,14 @@ import { cx, focusRing } from "./cx.js";
6
6
  const FRAME = "overflow-hidden rounded-xl border border-slate-200/70 bg-white shadow-sm";
7
7
  /** The body's own box, not the panel's: a collapsed panel still draws its border and padding. */
8
8
  const PANEL = "border-t border-slate-200/70 p-4";
9
+ /** The plain body's indent, inside the panel too, so a closed fold takes no room. */
10
+ const PLAIN_BODY = "pt-1 pb-2 pl-6";
11
+ /**
12
+ * The panel's height follows react-aria's measured `--disclosure-panel-height`, which runs from 0
13
+ * to the body's height and back as the fold opens and closes; react-aria hides the body once the
14
+ * transition ends. With reduced motion there is no transition and it opens at once.
15
+ */
16
+ const SLIDE = "h-(--disclosure-panel-height) overflow-clip motion-safe:transition-[height] motion-safe:duration-200 motion-safe:ease-out";
9
17
  /**
10
18
  * A summary line with a chevron over a body that opens and closes under it. The summary is a
11
19
  * button with `aria-expanded`, and Enter and Space toggle it; the body is hidden while closed.
@@ -19,5 +27,5 @@ const PANEL = "border-t border-slate-200/70 p-4";
19
27
  export function Disclosure({ summary, defaultOpen = false, open, onOpenChange, bordered = false, children, ...rest }) {
20
28
  return (_jsx("div", { ...rest, className: bordered ? FRAME : undefined, children: _jsx(AriaDisclosure, { defaultExpanded: defaultOpen, ...(open === undefined ? {} : { isExpanded: open }), ...(onOpenChange ? { onExpandedChange: onOpenChange } : {}), children: ({ isExpanded }) => (_jsxs(_Fragment, { children: [_jsxs(Button, { slot: "trigger", className: cx("flex w-full cursor-pointer items-center gap-2 text-left text-sm font-medium text-slate-900", focusRing, bordered
21
29
  ? "px-4 py-3 hover:bg-slate-50 focus-visible:-outline-offset-2"
22
- : "rounded-md py-1.5 hover:text-violet-700"), children: [_jsx(Chevron, { open: isExpanded }), summary] }), _jsx(DisclosurePanel, { className: cx("text-sm text-slate-700", !bordered && "pt-1 pb-2 pl-6"), children: bordered ? _jsx("div", { className: PANEL, children: children }) : children })] })) }) }));
30
+ : "rounded-md py-1.5 hover:text-violet-700"), children: [_jsx(Chevron, { open: isExpanded }), summary] }), _jsx(DisclosurePanel, { className: cx("text-sm text-slate-700", SLIDE), children: _jsx("div", { className: bordered ? PANEL : PLAIN_BODY, children: children }) })] })) }) }));
23
31
  }
@@ -1,5 +1,6 @@
1
1
  import { type ReactElement, type ReactNode } from "react";
2
2
  import type { Passthrough } from "./props.js";
3
+ import type { LoadingProps } from "./skeleton.js";
3
4
  import type { SwitchLink } from "./switcher.js";
4
5
  /** One group of the docs nav: a title over its links (`Tab`s with an `href`). A group with no title is the nav's top. */
5
6
  export type DocsNavGroup = {
@@ -20,8 +21,11 @@ export type DocsNeighbour = {
20
21
  type DocsLayoutProps = {
21
22
  /** The docs nav, in reading order: each group's title over a vertical pill list of its pages. */
22
23
  nav: DocsNavGroup[];
23
- /** Names the nav's landmark, and the disclosure it folds behind below `md` ("Docs", "All components"). */
24
- navLabel: string;
24
+ /**
25
+ * Names the rail's landmark, and the disclosure it folds behind below `md` ("Docs", "All
26
+ * components"), as `SidebarLayout`'s `asideLabel` does.
27
+ */
28
+ asideLabel: string;
25
29
  /** The page's title, its `h1`. */
26
30
  title: ReactNode;
27
31
  /** The line under the title (a `Lead`). */
@@ -53,10 +57,10 @@ type DocsLayoutProps = {
53
57
  nextLabel?: string | undefined;
54
58
  /** The article. Wrap long text in a `Prose`. */
55
59
  children: ReactNode;
56
- } & Passthrough;
60
+ } & LoadingProps & Passthrough;
57
61
  /**
58
62
  * A docs page: a `SidebarLayout` whose rail is the docs `nav` (each group's title over its links,
59
- * folded behind a disclosure named `navLabel` below `md`), and a canvas of the page's title, an
63
+ * folded behind a disclosure named `asideLabel` below `md`), and a canvas of the page's title, an
60
64
  * "On this page" list of its `contents`, the article and the previous and next links.
61
65
  *
62
66
  * The contents list is rendered once: from `xl` a 12rem column right of the article that sticks
@@ -64,6 +68,10 @@ type DocsLayoutProps = {
64
68
  * being read; it is a value the page passes (a site that follows the reader computes it), with no
65
69
  * scroll spy inside. The previous and next links are links, not cards, so they add no heading to
66
70
  * the page's outline.
71
+ *
72
+ * While `loading` the canvas waits, as in `SidebarLayout`: an empty title is a bone and what the
73
+ * article holds draws its own bones; the nav, the contents list and the previous and next links are
74
+ * navigation, drawn as themselves. The layout owns the wait.
67
75
  */
68
- export declare function DocsLayout({ nav, navLabel, title, description, breadcrumbs, contents, current, contentsLabel, previous, next, previousLabel, nextLabel, children, ...rest }: DocsLayoutProps): ReactElement;
76
+ export declare function DocsLayout({ nav, asideLabel, title, description, breadcrumbs, contents, current, contentsLabel, previous, next, previousLabel, nextLabel, children, ...rest }: DocsLayoutProps): ReactElement;
69
77
  export {};
@@ -7,16 +7,14 @@ import { PageHeaderContent } from "./PageHeader.js";
7
7
  import { useScrollEdges } from "./scrollEdges.js";
8
8
  import { SidebarLayout } from "./SidebarLayout.js";
9
9
  import { Stack } from "./Stack.js";
10
+ import { ContentsList } from "./TableOfContents.js";
10
11
  import { STICKY_ASIDE_XL, STICKY_FADE_XL, STICKY_SCROLL_XL } from "./stickyColumn.js";
11
12
  import { Tabs } from "./Tabs.js";
12
13
  import { Overline } from "./typography.js";
13
14
  /** The rail: each group's title over a vertical list of its pages, the groups `md` apart. */
14
- function DocsNav({ nav, navLabel }) {
15
- return (_jsx(Stack, { gap: "md", children: nav.map((group, index) => (_jsxs(Stack, { gap: "xs", children: [group.title !== undefined && _jsx(Overline, { children: group.title }), _jsx(Tabs, { orientation: "vertical", size: "sm", label: group.title ?? navLabel, items: group.items })] }, group.title ?? `group-${index}`))) }));
15
+ function DocsNav({ nav, label }) {
16
+ return (_jsx(Stack, { gap: "md", children: nav.map((group, index) => (_jsxs(Stack, { gap: "xs", children: [group.title !== undefined && _jsx(Overline, { children: group.title }), _jsx(Tabs, { orientation: "vertical", size: "sm", label: group.title ?? label, items: group.items })] }, group.title ?? `group-${index}`))) }));
16
17
  }
17
- const ENTRY = `rounded text-sm/6 transition ${focusRing}`;
18
- const ENTRY_ON = "font-medium text-violet-700";
19
- const ENTRY_OFF = "text-slate-600 hover:text-violet-700";
20
18
  /**
21
19
  * "On this page": one `<nav>` at every width. From `xl` a 12rem column right of the article that
22
20
  * sticks under the header and scrolls itself when it is taller than the screen; below `xl` the same
@@ -25,7 +23,7 @@ const ENTRY_OFF = "text-slate-600 hover:text-violet-700";
25
23
  function DocsContents({ contents, current, label, }) {
26
24
  const [scroller, setScroller] = useState(null);
27
25
  useScrollEdges(scroller, "y");
28
- return (_jsx("nav", { "aria-label": label, className: cx("xl:col-start-2 xl:row-span-2 xl:row-start-1", STICKY_ASIDE_XL), children: _jsx("div", { ref: setScroller, className: cx(STICKY_SCROLL_XL, STICKY_FADE_XL), children: _jsxs(FoldedColumn, { from: "xl", label: label, children: [_jsx("div", { className: "hidden pb-2 xl:block", children: _jsx(Overline, { children: label }) }), _jsx("ul", { className: "flex flex-col gap-1", children: contents.map((entry) => (_jsx("li", { className: entry.level === 3 ? "pl-3" : undefined, children: _jsx("a", { href: `#${entry.id}`, "aria-current": entry.id === current ? "location" : undefined, className: cx(ENTRY, entry.id === current ? ENTRY_ON : ENTRY_OFF), children: entry.label }) }, entry.id))) })] }) }) }));
26
+ return (_jsx("nav", { "aria-label": label, className: cx("xl:col-start-2 xl:row-span-2 xl:row-start-1", STICKY_ASIDE_XL), children: _jsx("div", { ref: setScroller, className: cx(STICKY_SCROLL_XL, STICKY_FADE_XL), children: _jsxs(FoldedColumn, { from: "xl", label: label, children: [_jsx("div", { className: "hidden pb-2 xl:block", children: _jsx(Overline, { children: label }) }), _jsx(ContentsList, { items: contents, current: current })] }) }) }));
29
27
  }
30
28
  /**
31
29
  * One way onwards: the small `word` line over the page's label, in a bordered box. Its name is its
@@ -47,7 +45,7 @@ function DocsPager({ previous, next, previousLabel, nextLabel, }) {
47
45
  }
48
46
  /**
49
47
  * A docs page: a `SidebarLayout` whose rail is the docs `nav` (each group's title over its links,
50
- * folded behind a disclosure named `navLabel` below `md`), and a canvas of the page's title, an
48
+ * folded behind a disclosure named `asideLabel` below `md`), and a canvas of the page's title, an
51
49
  * "On this page" list of its `contents`, the article and the previous and next links.
52
50
  *
53
51
  * The contents list is rendered once: from `xl` a 12rem column right of the article that sticks
@@ -55,10 +53,14 @@ function DocsPager({ previous, next, previousLabel, nextLabel, }) {
55
53
  * being read; it is a value the page passes (a site that follows the reader computes it), with no
56
54
  * scroll spy inside. The previous and next links are links, not cards, so they add no heading to
57
55
  * the page's outline.
56
+ *
57
+ * While `loading` the canvas waits, as in `SidebarLayout`: an empty title is a bone and what the
58
+ * article holds draws its own bones; the nav, the contents list and the previous and next links are
59
+ * navigation, drawn as themselves. The layout owns the wait.
58
60
  */
59
- export function DocsLayout({ nav, navLabel, title, description, breadcrumbs, contents = [], current, contentsLabel = "On this page", previous, next, previousLabel = "Previous", nextLabel = "Next", children, ...rest }) {
61
+ export function DocsLayout({ nav, asideLabel, title, description, breadcrumbs, contents = [], current, contentsLabel = "On this page", previous, next, previousLabel = "Previous", nextLabel = "Next", children, ...rest }) {
60
62
  const listed = contents.length >= 2;
61
- return (_jsx(SidebarLayout, { ...rest, asideLabel: navLabel, aside: _jsx(DocsNav, { nav: nav, navLabel: navLabel }), children: _jsxs("div", { className: cx("flex flex-col gap-12 sm:gap-16",
63
+ return (_jsx(SidebarLayout, { ...rest, asideLabel: asideLabel, aside: _jsx(DocsNav, { nav: nav, label: asideLabel }), children: _jsxs("div", { className: cx("flex flex-col gap-12 sm:gap-16",
62
64
  // The contents column only when there is a list, so a page without one keeps the width.
63
65
  listed && "xl:grid xl:grid-cols-[minmax(0,1fr)_12rem] xl:gap-x-10"), children: [_jsx(PageHeaderContent, { breadcrumbs: breadcrumbs, title: title, description: description, className: "xl:col-start-1" }), listed && _jsx(DocsContents, { contents: contents, current: current, label: contentsLabel }), _jsx("div", { className: "min-w-0 xl:col-start-1", children: _jsxs(Stack, { gap: "xl", children: [children, _jsx(DocsPager, { previous: previous, next: next, previousLabel: previousLabel, nextLabel: nextLabel })] }) })] }) }));
64
66
  }
package/dist/Drawer.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { type ReactElement, type ReactNode } from "react";
1
+ import { type FormEvent, type ReactElement, type ReactNode } from "react";
2
2
  import type { Passthrough } from "./props.js";
3
3
  import type { Size } from "./size.js";
4
4
  export type DrawerProps = {
@@ -7,14 +7,27 @@ export type DrawerProps = {
7
7
  /** A muted line under the title, as on a `Dialog`. */
8
8
  description?: ReactNode;
9
9
  children?: ReactNode;
10
- /** Actions pinned under the scrolling body, right-aligned. */
10
+ /** Actions pinned under the scrolling body, right-aligned: Cancel (`variant="ghost"`), then the one main action. */
11
11
  footer?: ReactNode;
12
+ /**
13
+ * Makes the drawer a form, as on a `Dialog`: one `<form noValidate>` holds the body, the `error`
14
+ * and the footer, so a `Button type="submit"` in the footer or Enter in a field submits it. The
15
+ * default is prevented before this runs, and a rejection is yours to catch and show as `error`.
16
+ * Once the submit settles, the focus moves to the first field marked invalid
17
+ * (`aria-invalid="true"`), if any.
18
+ */
19
+ onSubmit?: ((event: FormEvent<HTMLFormElement>) => void | Promise<unknown>) | undefined;
20
+ /**
21
+ * What went wrong with the whole submit, as on a `Dialog`: a danger `Callout`, announced as an
22
+ * alert, pinned between the body and the footer. An error about one field is that `Field`'s `error`.
23
+ */
24
+ error?: ReactNode;
12
25
  /**
13
26
  * The panel's width: `md` holds a form or a record; `sm` (320px) is narrower and `lg` (640px) wider.
14
27
  * @default md
15
28
  */
16
29
  width?: Size | undefined;
17
- /** Called when the drawer closes: Esc, a click on the scrim or the close button. */
30
+ /** Called when the drawer closes: Esc, a click on the scrim, the close button or a swipe to the right on touch. */
18
31
  onClose: () => void;
19
32
  /** The accessible name of the close button. */
20
33
  closeLabel?: string;
@@ -23,8 +36,10 @@ export type DrawerProps = {
23
36
  * A modal slide-over anchored to the right edge, on the browser's own `<dialog>`: it is opened
24
37
  * with `showModal()` on mount, so render it only while it is open. The page behind goes inert, Esc
25
38
  * closes it and focus stays inside; a click on the scrim (the `<dialog>` element itself, not its
26
- * contents) closes it too. The header holds the title, an optional `description` under it and a
27
- * close button; the body scrolls between
28
- * it and an optional pinned `footer`.
39
+ * contents) closes it too, and on touch a swipe to the right drags it off (a short one springs
40
+ * back). The header holds the title, an optional `description` under it and a close button; the
41
+ * body scrolls between it and an optional pinned `footer`, and a scroll in it never carries on to
42
+ * the page behind. `onSubmit` makes it a form and `error` shows what went wrong with the submit, as
43
+ * on a `Dialog`.
29
44
  */
30
- export declare function Drawer({ title, description, children, footer, width, onClose, closeLabel, ...rest }: DrawerProps): ReactElement;
45
+ export declare function Drawer({ title, description, children, footer, onSubmit, error, width, onClose, closeLabel, ...rest }: DrawerProps): ReactElement;
package/dist/Drawer.js CHANGED
@@ -1,24 +1,105 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useId, useRef } from "react";
2
+ import { useId, useRef, useState, } from "react";
3
3
  import { cx } from "./cx.js";
4
- import { BodyContext, ModalScope } from "./Dialog.js";
4
+ import { BodyContext, FormColumn, FormError, ModalScope } from "./Dialog.js";
5
5
  import { IconButton } from "./IconButton.js";
6
6
  import { useBackdropClose, useModal } from "./modal.js";
7
+ import { ScrollBody } from "./scrollBody.js";
8
+ import { FLING, releaseVelocity } from "./sheetSnap.js";
7
9
  import { HeaderText, SectionHeading } from "./typography.js";
8
- const PANEL = "fixed inset-y-0 right-0 left-auto m-0 h-dvh max-h-none max-w-full flex-col overflow-hidden border-l border-slate-200 bg-white p-0 text-slate-900 shadow-2xl translate-x-full transition-[translate,overlay,display] transition-discrete duration-200 open:flex open:translate-x-0 starting:open:translate-x-full backdrop:bg-slate-900/35 backdrop:opacity-0 backdrop:transition-[opacity,overlay,display] backdrop:transition-discrete backdrop:duration-200 open:backdrop:opacity-100 starting:open:backdrop:opacity-0 motion-reduce:transition-none motion-reduce:backdrop:transition-none";
10
+ const PANEL = "fixed inset-y-0 right-0 left-auto m-0 h-dvh max-h-none max-w-full flex-col overflow-hidden overscroll-contain border-l border-slate-200 bg-white p-0 text-slate-900 shadow-2xl translate-x-full transition-[translate,overlay,display] transition-discrete duration-200 touch-pan-y data-swiping:transition-none open:flex open:translate-x-0 starting:open:translate-x-full backdrop:bg-slate-900/35 backdrop:opacity-0 backdrop:transition-[opacity,overlay,display] backdrop:transition-discrete backdrop:duration-200 open:backdrop:opacity-100 starting:open:backdrop:opacity-0 motion-reduce:transition-none motion-reduce:backdrop:transition-none";
9
11
  const WIDTH = { sm: "w-80", md: "w-110", lg: "w-160" };
12
+ /** Where a horizontal drag is the control's own, not the drawer's. */
13
+ const OWN_DRAG = "input, textarea, select, [contenteditable], [role=slider], .overflow-x-auto";
14
+ /** Finger travel (px) before a touch is read as a swipe or a scroll. */
15
+ const SLOP = 8;
16
+ /** Whether a released swipe closes: a flick to the right, or a travel past a third of the width. */
17
+ const swipedOff = (s, at) => releaseVelocity(s.samples, at) >= FLING || (s.samples.at(-1)?.height ?? 0) > s.width / 3;
18
+ /**
19
+ * Swipe to dismiss on touch: a finger that moves right more than it moves down drags the panel
20
+ * with it, and a release past a third of its width, or a quick flick to the right, closes it. A
21
+ * shorter, slower swipe springs back. A vertical move is the body's scroll and is left alone
22
+ * (`touch-action: pan-y`). A mouse or a pen does nothing here. The offset while dragging is
23
+ * `null` at rest.
24
+ */
25
+ function useSwipeClose(dialog) {
26
+ const swipe = useRef(null);
27
+ const [offset, setOffset] = useState(null);
28
+ const onPointerDown = (event) => {
29
+ if (event.pointerType !== "touch" || swipe.current || event.target === dialog.current)
30
+ return;
31
+ // A field, a slider or a horizontally scrolling area keeps its own horizontal drag, and a dialog
32
+ // opened from inside the drawer (React portals its events up through it) is not the drawer.
33
+ const target = event.target instanceof Element ? event.target : null;
34
+ if (target?.closest(OWN_DRAG) || target?.closest("dialog") !== dialog.current)
35
+ return;
36
+ swipe.current = {
37
+ pointer: event.pointerId,
38
+ x: event.clientX,
39
+ y: event.clientY,
40
+ width: event.currentTarget.getBoundingClientRect().width,
41
+ across: null,
42
+ samples: [{ height: 0, t: event.timeStamp }],
43
+ };
44
+ };
45
+ const onPointerMove = (event) => {
46
+ const s = swipe.current;
47
+ if (!s || s.pointer !== event.pointerId)
48
+ return;
49
+ const dx = event.clientX - s.x;
50
+ const dy = event.clientY - s.y;
51
+ if (s.across === null) {
52
+ if (Math.abs(dx) < SLOP && Math.abs(dy) < SLOP)
53
+ return;
54
+ s.across = dx > Math.abs(dy);
55
+ }
56
+ if (!s.across)
57
+ return;
58
+ const travel = Math.max(0, dx);
59
+ s.samples = [...s.samples.slice(-1), { height: travel, t: event.timeStamp }];
60
+ setOffset(travel);
61
+ };
62
+ const release = (event, cancelled) => {
63
+ const s = swipe.current;
64
+ if (!s || s.pointer !== event.pointerId)
65
+ return;
66
+ swipe.current = null;
67
+ if (!s.across)
68
+ return;
69
+ // Dropping the offset and closing in the same event, so the exit slides on from where the
70
+ // finger let go.
71
+ setOffset(null);
72
+ if (!cancelled && swipedOff(s, event.timeStamp))
73
+ dialog.current?.close();
74
+ };
75
+ return {
76
+ offset,
77
+ handlers: {
78
+ onPointerDown,
79
+ onPointerMove,
80
+ onPointerUp: (event) => release(event, false),
81
+ onPointerCancel: (event) => release(event, true),
82
+ },
83
+ };
84
+ }
10
85
  /**
11
86
  * A modal slide-over anchored to the right edge, on the browser's own `<dialog>`: it is opened
12
87
  * with `showModal()` on mount, so render it only while it is open. The page behind goes inert, Esc
13
88
  * closes it and focus stays inside; a click on the scrim (the `<dialog>` element itself, not its
14
- * contents) closes it too. The header holds the title, an optional `description` under it and a
15
- * close button; the body scrolls between
16
- * it and an optional pinned `footer`.
89
+ * contents) closes it too, and on touch a swipe to the right drags it off (a short one springs
90
+ * back). The header holds the title, an optional `description` under it and a close button; the
91
+ * body scrolls between it and an optional pinned `footer`, and a scroll in it never carries on to
92
+ * the page behind. `onSubmit` makes it a form and `error` shows what went wrong with the submit, as
93
+ * on a `Dialog`.
17
94
  */
18
- export function Drawer({ title, description, children, footer, width = "md", onClose, closeLabel = "Close", ...rest }) {
95
+ export function Drawer({ title, description, children, footer, onSubmit, error, width = "md", onClose, closeLabel = "Close", ...rest }) {
19
96
  const dialog = useRef(null);
20
97
  const titleId = useId();
21
98
  const closed = useModal(dialog, onClose);
22
99
  const backdrop = useBackdropClose(dialog);
23
- return (_jsx(ModalScope, { children: _jsxs("dialog", { ...rest, ref: dialog, "aria-labelledby": titleId, onClose: closed, ...backdrop, className: cx(PANEL, WIDTH[width]), children: [_jsxs("header", { className: "flex shrink-0 items-center justify-between gap-3 border-b border-slate-200 px-5.5 py-3.5", children: [_jsxs("div", { className: "min-w-0", children: [_jsx(SectionHeading, { id: titleId, children: title }), description && (_jsx("div", { className: "mt-1", children: _jsx(HeaderText, { children: description }) }))] }), _jsx(IconButton, { label: closeLabel, onClick: () => dialog.current?.close(), icon: "close" })] }), _jsx("div", { className: "min-h-0 flex-1 overflow-y-auto px-5.5 py-4", children: _jsx(BodyContext, { children: children }) }), footer && (_jsx("footer", { className: "flex shrink-0 justify-end gap-2 border-t border-slate-200 px-5.5 py-3.5", children: footer }))] }) }));
100
+ const { offset, handlers } = useSwipeClose(dialog);
101
+ return (_jsx(ModalScope, { children: _jsxs("dialog", { ...rest, ref: dialog, "aria-labelledby": titleId, onClose: closed, ...handlers, onPointerDown: (event) => {
102
+ backdrop.onPointerDown(event);
103
+ handlers.onPointerDown(event);
104
+ }, onClick: backdrop.onClick, "data-swiping": offset === null ? undefined : "", style: offset === null ? undefined : { translate: `${offset}px 0` }, className: cx(PANEL, WIDTH[width]), children: [_jsxs("header", { className: "flex shrink-0 items-center justify-between gap-3 border-b border-slate-200 px-5.5 py-3.5", children: [_jsxs("div", { className: "min-w-0", children: [_jsx(SectionHeading, { id: titleId, children: title }), description && (_jsx("div", { className: "mt-1", children: _jsx(HeaderText, { children: description }) }))] }), _jsx(IconButton, { label: closeLabel, onClick: () => dialog.current?.close(), icon: "close" })] }), _jsxs(FormColumn, { onSubmit: onSubmit, children: [_jsx(ScrollBody, { labelledBy: titleId, className: "min-h-0 flex-1 touch-pan-y overflow-y-auto overscroll-contain px-5.5 py-4", children: _jsx(BodyContext, { children: children }) }), _jsx(FormError, { error: error, space: "px-5.5 pb-4" }), footer && (_jsx("footer", { className: "flex shrink-0 justify-end gap-2 border-t border-slate-200 px-5.5 py-3.5", children: footer }))] })] }) }));
24
105
  }
@@ -0,0 +1,36 @@
1
+ import type { ReactElement, ReactNode } from "react";
2
+ import type { Passthrough } from "./props.js";
3
+ /**
4
+ * A rounded, clipped frame with a hairline, at a fixed height, for a map or an `<iframe>`: the
5
+ * embed in `children` fills it. `status` lays a centred overlay over the embed while it loads or
6
+ * after it failed; the embed stays mounted under it, so it can finish loading. The frame is a
7
+ * region named by `label`.
8
+ */
9
+ export declare function EmbedFrame({ label, height, status, loadingLabel, errorLabel, children, ...rest }: {
10
+ /** Names the frame's region: what the embed shows, as "Map of the shops". */
11
+ label: string;
12
+ /**
13
+ * `sm` 18rem, `md` 24rem, or `viewport`, 55% of the small viewport's height, for a map that is
14
+ * the page's main content.
15
+ * @default md
16
+ */
17
+ height?: "sm" | "md" | "viewport" | undefined;
18
+ /**
19
+ * `loading` lays a pulsing cover over the embed and marks the region busy; `error` lays
20
+ * `errorLabel` over it, announced. Set it from the embed's own load and error events.
21
+ * @default ready
22
+ */
23
+ status?: "ready" | "loading" | "error" | undefined;
24
+ /**
25
+ * What a screen reader hears while `status` is `loading`.
26
+ * @default Loading
27
+ */
28
+ loadingLabel?: string | undefined;
29
+ /**
30
+ * The words over the embed when `status` is `error`: say what failed and what to do.
31
+ * @default Could not load.
32
+ */
33
+ errorLabel?: string | undefined;
34
+ /** The embed: an `<iframe>` or a map's container. It fills the frame. */
35
+ children: ReactNode;
36
+ } & Passthrough): ReactElement;
@@ -0,0 +1,18 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { cx } from "./cx.js";
3
+ import { Bone } from "./skeleton.js";
4
+ /** How tall the frame is: `sm` 18rem, `md` 24rem, or `viewport`, 55% of the small viewport. */
5
+ const HEIGHT = {
6
+ sm: "h-72",
7
+ md: "h-96",
8
+ viewport: "h-[55svh]",
9
+ };
10
+ /**
11
+ * A rounded, clipped frame with a hairline, at a fixed height, for a map or an `<iframe>`: the
12
+ * embed in `children` fills it. `status` lays a centred overlay over the embed while it loads or
13
+ * after it failed; the embed stays mounted under it, so it can finish loading. The frame is a
14
+ * region named by `label`.
15
+ */
16
+ export function EmbedFrame({ label, height = "md", status = "ready", loadingLabel = "Loading", errorLabel = "Could not load.", children, ...rest }) {
17
+ return (_jsxs("section", { ...rest, "aria-label": label, ...(status === "loading" ? { "aria-busy": true } : {}), className: cx("relative isolate overflow-hidden rounded-lg border border-slate-200 bg-slate-100", HEIGHT[height]), children: [_jsx("div", { ...(status === "ready" ? {} : { inert: true }), className: "isolate size-full *:block *:size-full *:border-0", children: children }), status === "loading" && (_jsxs("div", { className: "absolute inset-0 z-10", children: [_jsx(Bone, { shape: "block size-full" }), _jsx("span", { className: "sr-only", children: loadingLabel })] })), status === "error" && (_jsx("div", { className: "absolute inset-0 z-10 grid place-items-center bg-slate-100 p-4", children: _jsx("p", { role: "alert", className: "max-w-prose text-center text-sm text-slate-600", children: errorLabel }) }))] }));
18
+ }
package/dist/Field.d.ts CHANGED
@@ -1,28 +1,65 @@
1
1
  import { type ReactElement, type ReactNode } from "react";
2
2
  import type { Passthrough } from "./props.js";
3
3
  import { type LoadingProps } from "./skeleton.js";
4
- /** The line under a control or a row: an error (`role="alert"`) replaces the hint; neither draws nothing. */
4
+ /**
5
+ * The error line: an alert icon (so the error is not told by colour alone) and the text in red. It
6
+ * carries no `role="alert"`: the text is announced once through the page's (or its dialog's) one polite live region.
7
+ */
8
+ export declare function ErrorLine({ id, error, }: {
9
+ id?: string | undefined;
10
+ error: ReactNode;
11
+ }): ReactElement;
12
+ /**
13
+ * The lines under a control or a row: the muted hint, and under it the error when there is one.
14
+ * The hint stays while an error shows, so the rule is still in view while the value is fixed.
15
+ * Neither draws nothing.
16
+ */
5
17
  export declare function fieldNote(hint: ReactNode, error: ReactNode, ids?: {
6
18
  hint: string;
7
19
  error: string;
8
20
  }): ReactElement | null;
21
+ /** The muted hint under a control, one type step below its label. */
22
+ export declare function Hint({ id, children, }: {
23
+ id?: string | undefined;
24
+ children: ReactNode;
25
+ }): ReactElement;
26
+ /** The ids a control's `aria-describedby` names for its note: the hint's, then the error's. */
27
+ export declare function noteDescribedBy(hint: ReactNode, error: ReactNode, ids: {
28
+ hint: string;
29
+ error: string;
30
+ }): string | undefined;
31
+ /**
32
+ * The marker after a required field's label: a red asterisk, hidden from assistive tech, since the
33
+ * control itself carries `required` and is read as required.
34
+ */
35
+ export declare function RequiredMark({ required }: {
36
+ required: boolean | undefined;
37
+ }): ReactNode;
9
38
  /**
10
- * A label above a control, with a hint or an error line under it. An error replaces the hint.
39
+ * A label above a control, with a hint line under it and, when set, an error line under the hint
40
+ * (an alert icon and red text, announced politely). The hint stays while the error shows.
41
+ * `required` marks the label with a red asterisk and makes the control inside `required`.
11
42
  * Inside a `FormGrid`, `span="full"` runs the field across both columns. The `Input`, `Select`,
12
43
  * `Textarea` or `FileDrop` inside takes the label, the note (`aria-describedby`) and, with an error,
13
44
  * `aria-invalid` and a red edge by itself: give it no `id` and the Field no `htmlFor`. While
14
45
  * `loading` the label is drawn and the control is a bone of its height, read from the density
15
46
  * around it (`sm` in a `sm` card or table).
16
47
  */
17
- export declare function Field({ label, htmlFor, hint, error, span, layout, labelHidden, loading, loadingLabel, children, ...rest }: {
48
+ export declare function Field({ label, htmlFor, hint, error, required, span, layout, labelHidden, loading, loadingLabel, children, ...rest }: {
18
49
  /** The text above the control. */
19
50
  label: ReactNode;
20
51
  /** A fixed id for the control inside, only when something else must name it. Unset, the Field makes one. */
21
52
  htmlFor?: string | undefined;
22
53
  /** A muted line under the control that says more. */
23
54
  hint?: ReactNode;
24
- /** Replaces the hint when set. */
55
+ /** A red line under the hint, with an alert icon; the control is `aria-invalid` while it shows. */
25
56
  error?: ReactNode;
57
+ /**
58
+ * The control must be filled: a red asterisk after the label (hidden from assistive tech) and
59
+ * `required` on the `Input`, `Select`, `Textarea` or `FileDrop` inside.
60
+ * @default false
61
+ */
62
+ required?: boolean | undefined;
26
63
  /** `full` spans every column of a `FormGrid`; unset takes one. It does nothing outside a `FormGrid`. */
27
64
  span?: "full" | undefined;
28
65
  /**