@slashsuite/ui-react 0.12.1 → 0.13.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (385) hide show
  1. package/MIGRATING.md +386 -8
  2. package/README.md +89 -44
  3. package/agent-docs/components/app-shell.md +9 -6
  4. package/agent-docs/components/article-layout.md +140 -0
  5. package/agent-docs/components/audio.md +42 -0
  6. package/agent-docs/components/badge.md +2 -1
  7. package/agent-docs/components/body-text.md +26 -15
  8. package/agent-docs/components/bottom-sheet.md +27 -17
  9. package/agent-docs/components/breadcrumbs.md +10 -6
  10. package/agent-docs/components/button.md +2 -2
  11. package/agent-docs/components/call-to-action.md +59 -0
  12. package/agent-docs/components/callout.md +4 -3
  13. package/agent-docs/components/card-grid.md +15 -7
  14. package/agent-docs/components/card.md +33 -18
  15. package/agent-docs/components/cart-button.md +63 -0
  16. package/agent-docs/components/chat-composer.md +4 -3
  17. package/agent-docs/components/checkbox.md +11 -5
  18. package/agent-docs/components/cluster.md +10 -8
  19. package/agent-docs/components/code-example.md +2 -2
  20. package/agent-docs/components/code.md +7 -5
  21. package/agent-docs/components/colour-scheme-toggle.md +12 -6
  22. package/agent-docs/components/colour-swatch.md +41 -0
  23. package/agent-docs/components/combobox.md +88 -0
  24. package/agent-docs/components/confirm-dialog.md +98 -0
  25. package/agent-docs/components/container.md +2 -1
  26. package/agent-docs/components/copy-button.md +7 -5
  27. package/agent-docs/components/copy-line.md +6 -5
  28. package/agent-docs/components/date-field.md +14 -11
  29. package/agent-docs/components/date-range-picker.md +16 -9
  30. package/agent-docs/components/date-time-field.md +73 -0
  31. package/agent-docs/components/dialog.md +22 -68
  32. package/agent-docs/components/disclosure.md +4 -0
  33. package/agent-docs/components/docs-layout.md +10 -6
  34. package/agent-docs/components/drawer.md +13 -4
  35. package/agent-docs/components/embed-frame.md +48 -0
  36. package/agent-docs/components/empty-state.md +4 -1
  37. package/agent-docs/components/field-dialog.md +6 -5
  38. package/agent-docs/components/field.md +10 -7
  39. package/agent-docs/components/fieldset.md +4 -4
  40. package/agent-docs/components/flow-diagram.md +87 -0
  41. package/agent-docs/components/form-layout.md +4 -1
  42. package/agent-docs/components/form-row.md +7 -7
  43. package/agent-docs/components/full-bleed-layout.md +0 -2
  44. package/agent-docs/components/headings.md +13 -7
  45. package/agent-docs/components/hero.md +11 -2
  46. package/agent-docs/components/icon-button.md +1 -3
  47. package/agent-docs/components/icon.md +6 -13
  48. package/agent-docs/components/image.md +24 -14
  49. package/agent-docs/components/input.md +8 -7
  50. package/agent-docs/components/key-value-list.md +4 -1
  51. package/agent-docs/components/lightbox.md +1 -1
  52. package/agent-docs/components/list-layout.md +5 -7
  53. package/agent-docs/components/list-row.md +37 -34
  54. package/agent-docs/components/loading.md +2 -2
  55. package/agent-docs/components/markdown.md +13 -13
  56. package/agent-docs/components/media-tile.md +8 -4
  57. package/agent-docs/components/menu.md +19 -12
  58. package/agent-docs/components/meta-list.md +2 -2
  59. package/agent-docs/components/morph.md +11 -5
  60. package/agent-docs/components/navigation-progress.md +2 -2
  61. package/agent-docs/components/number-field.md +75 -0
  62. package/agent-docs/components/outline-region.md +19 -8
  63. package/agent-docs/components/page-fade.md +2 -1
  64. package/agent-docs/components/pill.md +7 -6
  65. package/agent-docs/components/popover.md +63 -0
  66. package/agent-docs/components/price.md +49 -0
  67. package/agent-docs/components/product-tile.md +78 -0
  68. package/agent-docs/components/promo-banner.md +46 -0
  69. package/agent-docs/components/prose-layout.md +1 -1
  70. package/agent-docs/components/radio-group.md +9 -6
  71. package/agent-docs/components/scroll-strip.md +3 -3
  72. package/agent-docs/components/segmented-control.md +4 -2
  73. package/agent-docs/components/select.md +8 -3
  74. package/agent-docs/components/show.md +2 -2
  75. package/agent-docs/components/side-column.md +13 -9
  76. package/agent-docs/components/sidebar-layout.md +1 -1
  77. package/agent-docs/components/site-footer.md +4 -4
  78. package/agent-docs/components/site-search.md +21 -9
  79. package/agent-docs/components/slider.md +59 -0
  80. package/agent-docs/components/sortable-list.md +15 -10
  81. package/agent-docs/components/stack.md +3 -3
  82. package/agent-docs/components/stacked-bar.md +7 -4
  83. package/agent-docs/components/state-machine.md +95 -0
  84. package/agent-docs/components/status-pages.md +13 -6
  85. package/agent-docs/components/stepper.md +54 -0
  86. package/agent-docs/components/switch.md +4 -4
  87. package/agent-docs/components/table-of-contents.md +78 -0
  88. package/agent-docs/components/table.md +35 -24
  89. package/agent-docs/components/tabs.md +24 -26
  90. package/agent-docs/components/text-link.md +12 -7
  91. package/agent-docs/components/textarea.md +4 -2
  92. package/agent-docs/components/toast.md +19 -14
  93. package/agent-docs/components/video.md +7 -2
  94. package/agent-docs/llms.txt +22 -3
  95. package/dist/AppShell.d.ts +25 -9
  96. package/dist/AppShell.js +67 -33
  97. package/dist/AppShellMenu.d.ts +31 -18
  98. package/dist/AppShellMenu.js +72 -45
  99. package/dist/ArticleLayout.d.ts +36 -0
  100. package/dist/ArticleLayout.js +27 -0
  101. package/dist/Audio.d.ts +16 -0
  102. package/dist/Audio.js +11 -0
  103. package/dist/Badge.d.ts +2 -1
  104. package/dist/Badge.js +3 -2
  105. package/dist/BottomSheet.d.ts +17 -6
  106. package/dist/BottomSheet.js +62 -11
  107. package/dist/Breadcrumbs.d.ts +8 -6
  108. package/dist/Breadcrumbs.js +17 -7
  109. package/dist/Button.d.ts +4 -2
  110. package/dist/Button.js +9 -87
  111. package/dist/CallToAction.d.ts +25 -0
  112. package/dist/CallToAction.js +17 -0
  113. package/dist/Callout.d.ts +2 -2
  114. package/dist/Callout.js +2 -2
  115. package/dist/Card.d.ts +88 -31
  116. package/dist/Card.js +55 -92
  117. package/dist/CardBody.d.ts +2 -0
  118. package/dist/CardBody.js +33 -3
  119. package/dist/CardGrid.d.ts +32 -4
  120. package/dist/CardGrid.js +42 -8
  121. package/dist/CardParts.d.ts +7 -1
  122. package/dist/CardParts.js +7 -2
  123. package/dist/CartButton.d.ts +33 -0
  124. package/dist/CartButton.js +18 -0
  125. package/dist/ChatComposer.d.ts +10 -4
  126. package/dist/ChatComposer.js +35 -13
  127. package/dist/Checkbox.d.ts +21 -3
  128. package/dist/Checkbox.js +66 -20
  129. package/dist/Chevron.js +1 -1
  130. package/dist/Cluster.d.ts +28 -15
  131. package/dist/Cluster.js +21 -4
  132. package/dist/Code.d.ts +15 -3
  133. package/dist/Code.js +23 -3
  134. package/dist/CodeBlock.d.ts +4 -4
  135. package/dist/CodeBlock.js +2 -2
  136. package/dist/CodeBody.d.ts +1 -1
  137. package/dist/CodeBody.js +4 -10
  138. package/dist/CodeExample.d.ts +1 -1
  139. package/dist/CodeExample.js +3 -2
  140. package/dist/ColourSchemeToggle.d.ts +21 -5
  141. package/dist/ColourSchemeToggle.js +15 -9
  142. package/dist/ColourSwatch.d.ts +15 -0
  143. package/dist/ColourSwatch.js +14 -0
  144. package/dist/Combobox.d.ts +42 -0
  145. package/dist/Combobox.js +43 -0
  146. package/dist/ConfirmDialog.d.ts +40 -0
  147. package/dist/ConfirmDialog.js +36 -0
  148. package/dist/Container.d.ts +3 -3
  149. package/dist/Container.js +1 -1
  150. package/dist/CopyButton.d.ts +8 -2
  151. package/dist/CopyButton.js +38 -28
  152. package/dist/CopyLine.d.ts +4 -2
  153. package/dist/CopyLine.js +4 -4
  154. package/dist/DateCalendar.d.ts +2 -0
  155. package/dist/DateCalendar.js +11 -9
  156. package/dist/DateField.d.ts +52 -21
  157. package/dist/DateField.js +73 -37
  158. package/dist/DateFieldCalendar.d.ts +12 -8
  159. package/dist/DateFieldCalendar.js +37 -18
  160. package/dist/DateRangePicker.d.ts +23 -3
  161. package/dist/DateRangePicker.js +10 -8
  162. package/dist/DateTimeField.d.ts +31 -0
  163. package/dist/DateTimeField.js +19 -0
  164. package/dist/Dialog.d.ts +42 -6
  165. package/dist/Dialog.js +50 -12
  166. package/dist/Disclosure.js +9 -1
  167. package/dist/DocsLayout.d.ts +13 -5
  168. package/dist/DocsLayout.js +11 -9
  169. package/dist/Drawer.d.ts +22 -7
  170. package/dist/Drawer.js +89 -8
  171. package/dist/EmbedFrame.d.ts +36 -0
  172. package/dist/EmbedFrame.js +18 -0
  173. package/dist/Field.d.ts +41 -4
  174. package/dist/Field.js +61 -25
  175. package/dist/FieldDialog.d.ts +8 -3
  176. package/dist/FieldDialog.js +19 -9
  177. package/dist/Fieldset.d.ts +3 -3
  178. package/dist/Fieldset.js +7 -9
  179. package/dist/FileDrop.js +2 -1
  180. package/dist/FlowDiagram.d.ts +92 -0
  181. package/dist/FlowDiagram.js +100 -0
  182. package/dist/FormRow.d.ts +6 -4
  183. package/dist/FormRow.js +11 -9
  184. package/dist/Hero.d.ts +30 -7
  185. package/dist/Hero.js +23 -9
  186. package/dist/Icon.d.ts +1 -1
  187. package/dist/Icon.js +1 -1
  188. package/dist/IconButton.js +1 -1
  189. package/dist/Image.d.ts +33 -9
  190. package/dist/Image.js +61 -16
  191. package/dist/Input.d.ts +1 -1
  192. package/dist/Input.js +4 -4
  193. package/dist/InputShell.d.ts +7 -0
  194. package/dist/InputShell.js +18 -3
  195. package/dist/KeyValueList.d.ts +2 -2
  196. package/dist/Lightbox.js +5 -3
  197. package/dist/ListRow.d.ts +4 -5
  198. package/dist/ListRow.js +36 -26
  199. package/dist/Mark.d.ts +10 -0
  200. package/dist/Mark.js +9 -0
  201. package/dist/Markdown.d.ts +18 -4
  202. package/dist/Markdown.js +176 -37
  203. package/dist/MediaTile.d.ts +9 -3
  204. package/dist/MediaTile.js +8 -4
  205. package/dist/Menu.d.ts +19 -8
  206. package/dist/Menu.js +13 -11
  207. package/dist/MetaList.d.ts +4 -3
  208. package/dist/MetaList.js +12 -4
  209. package/dist/Morph.d.ts +15 -1
  210. package/dist/Morph.js +70 -22
  211. package/dist/NavigationProgress.d.ts +2 -2
  212. package/dist/NavigationProgress.js +7 -5
  213. package/dist/NumberField.d.ts +66 -0
  214. package/dist/NumberField.js +68 -0
  215. package/dist/OutlineRegion.d.ts +41 -10
  216. package/dist/OutlineRegion.js +31 -6
  217. package/dist/PageFade.d.ts +9 -5
  218. package/dist/PageFade.js +39 -8
  219. package/dist/PageLayouts.d.ts +15 -5
  220. package/dist/PageLayouts.js +3 -3
  221. package/dist/Pill.d.ts +9 -4
  222. package/dist/Pill.js +15 -6
  223. package/dist/Popover.d.ts +31 -0
  224. package/dist/Popover.js +43 -0
  225. package/dist/Price.d.ts +21 -0
  226. package/dist/Price.js +34 -0
  227. package/dist/ProductTile.d.ts +36 -0
  228. package/dist/ProductTile.js +31 -0
  229. package/dist/ProgressBar.js +4 -2
  230. package/dist/PromoBanner.d.ts +25 -0
  231. package/dist/PromoBanner.js +16 -0
  232. package/dist/RadioGroup.d.ts +18 -8
  233. package/dist/RadioGroup.js +42 -18
  234. package/dist/ScrollStrip.d.ts +1 -1
  235. package/dist/ScrollStrip.js +1 -1
  236. package/dist/SearchInput.d.ts +17 -2
  237. package/dist/SearchInput.js +72 -13
  238. package/dist/SegmentedField.d.ts +15 -0
  239. package/dist/SegmentedField.js +15 -0
  240. package/dist/Select.js +5 -4
  241. package/dist/Show.d.ts +1 -1
  242. package/dist/Show.js +1 -1
  243. package/dist/SideColumn.d.ts +42 -15
  244. package/dist/SideColumn.js +45 -19
  245. package/dist/SiteFooter.d.ts +3 -3
  246. package/dist/SiteFooter.js +4 -3
  247. package/dist/SiteSearch.d.ts +57 -27
  248. package/dist/SiteSearch.js +13 -93
  249. package/dist/Slider.d.ts +27 -0
  250. package/dist/Slider.js +58 -0
  251. package/dist/SortableList.d.ts +19 -35
  252. package/dist/SortableList.js +36 -88
  253. package/dist/Stack.d.ts +4 -4
  254. package/dist/StackedBar.d.ts +13 -4
  255. package/dist/StackedBar.js +12 -7
  256. package/dist/StateMachine.d.ts +65 -0
  257. package/dist/StateMachine.js +116 -0
  258. package/dist/StatusPages.d.ts +28 -10
  259. package/dist/StatusPages.js +10 -10
  260. package/dist/Stepper.d.ts +21 -0
  261. package/dist/Stepper.js +33 -0
  262. package/dist/Steps.js +4 -3
  263. package/dist/Switch.d.ts +3 -3
  264. package/dist/Switch.js +18 -14
  265. package/dist/Table.d.ts +32 -9
  266. package/dist/Table.js +50 -20
  267. package/dist/TableCells.d.ts +24 -21
  268. package/dist/TableCells.js +68 -27
  269. package/dist/TableEditCell.d.ts +1 -1
  270. package/dist/TableOfContents.d.ts +34 -0
  271. package/dist/TableOfContents.js +23 -0
  272. package/dist/Tabs.d.ts +31 -16
  273. package/dist/Tabs.js +97 -22
  274. package/dist/TextLink.d.ts +18 -5
  275. package/dist/TextLink.js +19 -6
  276. package/dist/Textarea.d.ts +12 -1
  277. package/dist/Textarea.js +15 -2
  278. package/dist/ToastRegion.d.ts +17 -9
  279. package/dist/ToastRegion.js +70 -13
  280. package/dist/Tooltip.d.ts +10 -2
  281. package/dist/Tooltip.js +32 -11
  282. package/dist/Video.d.ts +19 -4
  283. package/dist/Video.js +15 -5
  284. package/dist/cardContext.d.ts +7 -0
  285. package/dist/cardContext.js +14 -0
  286. package/dist/cardControl.d.ts +15 -0
  287. package/dist/cardControl.js +32 -0
  288. package/dist/cardForm.d.ts +39 -0
  289. package/dist/cardForm.js +81 -0
  290. package/dist/cardWait.js +2 -1
  291. package/dist/colourScheme.d.ts +12 -2
  292. package/dist/colourScheme.js +32 -6
  293. package/dist/control.d.ts +30 -8
  294. package/dist/control.js +74 -7
  295. package/dist/copyScript.d.ts +7 -8
  296. package/dist/copyScript.js +8 -9
  297. package/dist/core/button.d.ts +33 -0
  298. package/dist/core/button.js +89 -0
  299. package/dist/core/control.d.ts +15 -0
  300. package/dist/core/control.js +14 -0
  301. package/dist/core/fixtures/button.d.ts +26 -0
  302. package/dist/core/fixtures/button.js +52 -0
  303. package/dist/core/fixtures/types.d.ts +13 -0
  304. package/dist/core/fixtures/types.js +10 -0
  305. package/dist/core/focus.d.ts +7 -0
  306. package/dist/core/focus.js +7 -0
  307. package/dist/core/index.d.ts +12 -0
  308. package/dist/core/index.js +12 -0
  309. package/dist/core/parity.d.ts +22 -0
  310. package/dist/core/parity.js +53 -0
  311. package/dist/core/themeNative.d.ts +62 -0
  312. package/dist/core/themeNative.js +290 -0
  313. package/dist/cx.d.ts +17 -5
  314. package/dist/cx.js +18 -5
  315. package/dist/dateLocale.d.ts +17 -0
  316. package/dist/dateLocale.js +30 -0
  317. package/dist/density.d.ts +17 -3
  318. package/dist/density.js +30 -19
  319. package/dist/emptySlot.d.ts +1 -0
  320. package/dist/fieldAnnounce.d.ts +11 -0
  321. package/dist/fieldAnnounce.js +36 -0
  322. package/dist/fieldControl.d.ts +7 -2
  323. package/dist/fieldControl.js +6 -2
  324. package/dist/fieldWait.d.ts +3 -3
  325. package/dist/fieldWait.js +3 -4
  326. package/dist/flowLayout.d.ts +68 -0
  327. package/dist/flowLayout.js +105 -0
  328. package/dist/focus.d.ts +2 -0
  329. package/dist/focus.js +9 -0
  330. package/dist/fromXState.d.ts +73 -0
  331. package/dist/fromXState.js +110 -0
  332. package/dist/icons.d.ts +1 -1
  333. package/dist/icons.js +15 -0
  334. package/dist/index.d.ts +37 -11
  335. package/dist/index.js +24 -2
  336. package/dist/isoDate.d.ts +8 -1
  337. package/dist/isoDate.js +20 -1
  338. package/dist/labelWords.d.ts +16 -7
  339. package/dist/labelWords.js +14 -12
  340. package/dist/listRowProps.d.ts +17 -15
  341. package/dist/modal.d.ts +5 -0
  342. package/dist/modal.js +21 -1
  343. package/dist/navFold.js +6 -3
  344. package/dist/optionCard.d.ts +18 -0
  345. package/dist/optionCard.js +16 -0
  346. package/dist/scrollBody.d.ts +16 -0
  347. package/dist/scrollBody.js +15 -0
  348. package/dist/scrollEdges.d.ts +7 -0
  349. package/dist/scrollEdges.js +39 -5
  350. package/dist/scrollStop.d.ts +6 -2
  351. package/dist/scrollStop.js +24 -8
  352. package/dist/shownDate.d.ts +28 -10
  353. package/dist/shownDate.js +41 -22
  354. package/dist/siteSearchBody.d.ts +34 -0
  355. package/dist/siteSearchBody.js +117 -0
  356. package/dist/size.d.ts +7 -1
  357. package/dist/sortableDrop.d.ts +44 -0
  358. package/dist/sortableDrop.js +78 -0
  359. package/dist/sortableSlide.d.ts +9 -0
  360. package/dist/sortableSlide.js +70 -0
  361. package/dist/sortableTitle.d.ts +10 -0
  362. package/dist/sortableTitle.js +48 -0
  363. package/dist/stateMachineDots.d.ts +77 -0
  364. package/dist/stateMachineDots.js +188 -0
  365. package/dist/stickyColumn.d.ts +2 -2
  366. package/dist/stickyColumn.js +2 -2
  367. package/dist/switcher.d.ts +10 -5
  368. package/dist/switcher.js +7 -5
  369. package/dist/tableColumns.d.ts +17 -0
  370. package/dist/tableColumns.js +30 -2
  371. package/dist/tableEmpty.js +5 -5
  372. package/dist/tableRow.d.ts +26 -2
  373. package/dist/tableRow.js +23 -1
  374. package/dist/tableSort.d.ts +10 -5
  375. package/dist/tableSort.js +15 -4
  376. package/dist/target.d.ts +12 -0
  377. package/dist/target.js +12 -0
  378. package/dist/textBox.js +1 -1
  379. package/dist/truncated.d.ts +31 -0
  380. package/dist/truncated.js +51 -0
  381. package/dist/typography.d.ts +19 -11
  382. package/dist/typography.js +11 -13
  383. package/dist/useFlowLayout.d.ts +38 -0
  384. package/dist/useFlowLayout.js +122 -0
  385. package/package.json +5 -3
package/dist/Field.js CHANGED
@@ -3,49 +3,85 @@ import { useId } from "react";
3
3
  import { cx } from "./cx.js";
4
4
  import { FieldContext } from "./fieldControl.js";
5
5
  import { ControlBone } from "./fieldWait.js";
6
+ import { useErrorAnnouncement } from "./fieldAnnounce.js";
7
+ import { useFieldType } from "./density.js";
8
+ import { Icon } from "./Icon.js";
6
9
  import { BusyLabel, busy, useLoading } from "./skeleton.js";
7
- /** The line under a control or a row: an error (`role="alert"`) replaces the hint; neither draws nothing. */
10
+ /**
11
+ * The error line: an alert icon (so the error is not told by colour alone) and the text in red. It
12
+ * carries no `role="alert"`: the text is announced once through the page's (or its dialog's) one polite live region.
13
+ */
14
+ export function ErrorLine({ id, error, }) {
15
+ const { anchor, announcement } = useErrorAnnouncement(error);
16
+ const type = useFieldType();
17
+ return (_jsxs("span", { ref: anchor, id: id, className: cx("flex items-start gap-1 text-red-700", type.note), children: [_jsx("span", { className: cx("flex shrink-0 items-center", type.line), children: _jsx(Icon, { name: "alert", size: "sm" }) }), _jsx("span", { className: "min-w-0", children: error }), announcement] }));
18
+ }
19
+ /**
20
+ * The lines under a control or a row: the muted hint, and under it the error when there is one.
21
+ * The hint stays while an error shows, so the rule is still in view while the value is fixed.
22
+ * Neither draws nothing.
23
+ */
8
24
  export function fieldNote(hint, error, ids) {
9
- if (error) {
10
- return (_jsx("p", { id: ids?.error, role: "alert", className: "text-xs text-red-700", children: error }));
11
- }
12
- if (hint) {
13
- return (_jsx("p", { id: ids?.hint, className: "text-xs text-slate-500", children: hint }));
14
- }
15
- return null;
16
- }
17
- /** The control's id, the note's id and the note itself: the error, or else the hint, or nothing. */
18
- function useFieldNote(htmlFor, hint, error) {
25
+ if (!hint && !error)
26
+ return null;
27
+ return _jsx(NoteLines, { hint: hint, error: error, ids: ids });
28
+ }
29
+ /** `fieldNote`'s lines, a component so the hint can read the type step. */
30
+ function NoteLines({ hint, error, ids, }) {
31
+ return (_jsxs("div", { className: "flex flex-col gap-0.5", children: [hint ? _jsx(Hint, { id: ids?.hint, children: hint }) : null, error ? _jsx(ErrorLine, { id: ids?.error, error: error }) : null] }));
32
+ }
33
+ /** The muted hint under a control, one type step below its label. */
34
+ export function Hint({ id, children, }) {
35
+ return (_jsx("span", { id: id, className: cx("block text-slate-500", useFieldType().note), children: children }));
36
+ }
37
+ /** The ids a control's `aria-describedby` names for its note: the hint's, then the error's. */
38
+ export function noteDescribedBy(hint, error, ids) {
39
+ const named = [hint ? ids.hint : undefined, error ? ids.error : undefined].filter(Boolean);
40
+ return named.length > 0 ? named.join(" ") : undefined;
41
+ }
42
+ /** The control's id, the note's ids and the note itself: the hint, the error under it, or nothing. */
43
+ function useFieldNote(htmlFor, hint, error, required) {
19
44
  const generatedId = useId();
20
45
  const ids = { hint: useId(), error: useId() };
21
- const note = fieldNote(hint, error, ids);
22
- let describedBy;
23
- if (error)
24
- describedBy = ids.error;
25
- else if (hint)
26
- describedBy = ids.hint;
27
46
  return {
28
- control: { id: htmlFor ?? generatedId, describedBy, invalid: Boolean(error) },
29
- note,
47
+ control: {
48
+ id: htmlFor ?? generatedId,
49
+ describedBy: noteDescribedBy(hint, error, ids),
50
+ invalid: Boolean(error),
51
+ required,
52
+ },
53
+ note: fieldNote(hint, error, ids),
30
54
  };
31
55
  }
56
+ /**
57
+ * The marker after a required field's label: a red asterisk, hidden from assistive tech, since the
58
+ * control itself carries `required` and is read as required.
59
+ */
60
+ export function RequiredMark({ required }) {
61
+ if (!required)
62
+ return null;
63
+ return (_jsx("span", { "aria-hidden": "true", className: "text-red-700", children: " *" }));
64
+ }
32
65
  /** A field's label: hidden, or drawn, and free to wrap anywhere beside a control in a row. */
33
- function labelLook(hidden, row) {
66
+ function labelLook(hidden, row, type) {
34
67
  return hidden
35
68
  ? "sr-only"
36
- : cx("text-sm font-medium text-slate-700", row && "min-w-0 wrap-anywhere");
69
+ : cx(type, "font-medium text-slate-700", row && "min-w-0 wrap-anywhere");
37
70
  }
38
71
  /**
39
- * A label above a control, with a hint or an error line under it. An error replaces the hint.
72
+ * A label above a control, with a hint line under it and, when set, an error line under the hint
73
+ * (an alert icon and red text, announced politely). The hint stays while the error shows.
74
+ * `required` marks the label with a red asterisk and makes the control inside `required`.
40
75
  * Inside a `FormGrid`, `span="full"` runs the field across both columns. The `Input`, `Select`,
41
76
  * `Textarea` or `FileDrop` inside takes the label, the note (`aria-describedby`) and, with an error,
42
77
  * `aria-invalid` and a red edge by itself: give it no `id` and the Field no `htmlFor`. While
43
78
  * `loading` the label is drawn and the control is a bone of its height, read from the density
44
79
  * around it (`sm` in a `sm` card or table).
45
80
  */
46
- export function Field({ label, htmlFor, hint, error, span, layout = "column", labelHidden = false, loading, loadingLabel, children, ...rest }) {
81
+ export function Field({ label, htmlFor, hint, error, required = false, span, layout = "column", labelHidden = false, loading, loadingLabel, children, ...rest }) {
47
82
  const row = layout === "row" && !labelHidden;
48
- const { control, note } = useFieldNote(htmlFor, hint, error);
83
+ const { control, note } = useFieldNote(htmlFor, hint, error, required);
49
84
  const { loading: waiting, owner } = useLoading(loading);
50
- return (_jsxs("div", { ...rest, ...busy(owner, waiting), className: cx(row ? "grid grid-cols-[8rem_1fr] items-center gap-x-3 gap-y-1.5" : "flex flex-col gap-1.5", span === "full" && "col-span-full"), children: [_jsx("label", { htmlFor: control.id, className: labelLook(labelHidden, row), children: label }), _jsx(FieldContext.Provider, { value: control, children: waiting ? _jsx(ControlBone, {}) : children }), note && row ? _jsx("div", { className: "col-start-2", children: note }) : note, _jsx(BusyLabel, { owner: owner, loading: waiting, label: loadingLabel })] }));
85
+ const labelType = useFieldType().label;
86
+ return (_jsxs("div", { ...rest, ...busy(owner, waiting), className: cx(row ? "grid grid-cols-[8rem_1fr] items-center gap-x-3 gap-y-1.5" : "flex flex-col gap-1.5", span === "full" && "col-span-full"), children: [_jsxs("label", { htmlFor: control.id, className: labelLook(labelHidden, row, labelType), children: [label, _jsx(RequiredMark, { required: required })] }), _jsx(FieldContext.Provider, { value: control, children: waiting ? _jsx(ControlBone, {}) : children }), note && row ? _jsx("div", { className: "col-start-2", children: note }) : note, _jsx(BusyLabel, { owner: owner, loading: waiting, label: loadingLabel })] }));
51
87
  }
@@ -9,18 +9,23 @@ export type FieldDialogProps = {
9
9
  label: string;
10
10
  /** The field's placeholder. */
11
11
  placeholder: string;
12
- /** A muted line under the field; `emptyReason` takes its place while the field is empty. */
12
+ /** A muted line under the field. */
13
13
  hint: string;
14
- /** Said when the field is empty and the submit button is blocked. */
14
+ /** The field's error when it is submitted empty: the submit button stays enabled, so this says what is missing. */
15
15
  emptyReason: string;
16
16
  /** The submit button's text. */
17
17
  submit: string;
18
18
  /** What the submit button says while `onSubmit` runs. */
19
19
  busyLabel: string;
20
+ /**
21
+ * The button that closes the dialog without submitting, for an app in another language.
22
+ * @default Cancel
23
+ */
24
+ cancelLabel?: string | undefined;
20
25
  /** Gets the trimmed value. Resolving closes the dialog; a rejection shows its message in it. */
21
26
  onSubmit: (value: string) => Promise<unknown>;
22
27
  /** Called when the dialog closes: Cancel, Esc, the backdrop, or a resolved `onSubmit`. */
23
28
  onClose: () => void;
24
29
  } & Passthrough;
25
30
  /** A `Dialog` with one text field and Cancel / submit buttons. Render it only while open. */
26
- export declare function FieldDialog({ title, description, label, placeholder, hint, emptyReason, submit, busyLabel, onSubmit, onClose, ...rest }: FieldDialogProps): ReactElement;
31
+ export declare function FieldDialog({ title, description, label, placeholder, hint, emptyReason, submit, busyLabel, cancelLabel, onSubmit, onClose, ...rest }: FieldDialogProps): ReactElement;
@@ -4,15 +4,25 @@ import { Button } from "./Button.js";
4
4
  import { Dialog } from "./Dialog.js";
5
5
  import { Field } from "./Field.js";
6
6
  import { Input } from "./Input.js";
7
- /** The field's value and its in-flight state; `send` is the form's submit handler. */
8
- function useFieldSubmit(onSubmit) {
9
- const [value, setValue] = useState("");
7
+ /**
8
+ * The field's value and its in-flight state; `send` is the form's submit handler. An empty submit
9
+ * reports `emptyReason` as the field's error (the dialog then focuses the field); typing clears it.
10
+ */
11
+ function useFieldSubmit(onSubmit, emptyReason) {
12
+ const [value, setTyped] = useState("");
10
13
  const [busy, setBusy] = useState(false);
11
14
  const [error, setError] = useState(null);
12
- const empty = value.trim().length === 0;
15
+ const setValue = (next) => {
16
+ setTyped(next);
17
+ setError(null);
18
+ };
13
19
  const send = (event) => {
14
- if (empty || busy)
20
+ if (busy)
21
+ return;
22
+ if (value.trim().length === 0) {
23
+ setError(emptyReason);
15
24
  return;
25
+ }
16
26
  // Close the <dialog> itself, so it animates out before `onClose` unmounts it.
17
27
  const dialog = event.currentTarget.closest("dialog");
18
28
  setError(null);
@@ -22,10 +32,10 @@ function useFieldSubmit(onSubmit) {
22
32
  setError(e instanceof Error ? e.message : String(e));
23
33
  });
24
34
  };
25
- return { value, setValue, busy, error, empty, send };
35
+ return { value, setValue, busy, error, send };
26
36
  }
27
37
  /** A `Dialog` with one text field and Cancel / submit buttons. Render it only while open. */
28
- export function FieldDialog({ title, description, label, placeholder, hint, emptyReason, submit, busyLabel, onSubmit, onClose, ...rest }) {
29
- const { value, setValue, busy, error, empty, send } = useFieldSubmit(onSubmit);
30
- return (_jsx(Dialog, { ...rest, title: title, description: description, onClose: onClose, onSubmit: send, footer: _jsxs(_Fragment, { children: [_jsx(Button, { variant: "ghost", onClick: (event) => event.currentTarget.closest("dialog")?.close(), children: "Cancel" }), _jsx(Button, { type: "submit", disabledReason: empty ? emptyReason : undefined, busy: busy && (busyLabel || true), children: submit })] }), children: _jsx(Field, { label: label, hint: empty ? emptyReason : hint, error: error ?? undefined, children: _jsx(Input, { autoFocus: true, placeholder: placeholder, value: value, onChange: (e) => setValue(e.target.value), autoComplete: "off" }) }) }));
38
+ export function FieldDialog({ title, description, label, placeholder, hint, emptyReason, submit, busyLabel, cancelLabel = "Cancel", onSubmit, onClose, ...rest }) {
39
+ const { value, setValue, busy, error, send } = useFieldSubmit(onSubmit, emptyReason);
40
+ return (_jsx(Dialog, { ...rest, title: title, description: description, onClose: onClose, onSubmit: send, footer: _jsxs(_Fragment, { children: [_jsx(Button, { variant: "ghost", onClick: (event) => event.currentTarget.closest("dialog")?.close(), children: cancelLabel }), _jsx(Button, { type: "submit", busy: busy && (busyLabel || true), children: submit })] }), children: _jsx(Field, { label: label, hint: hint, error: error ?? undefined, required: true, children: _jsx(Input, { autoFocus: true, placeholder: placeholder, value: value, onChange: (e) => setValue(e.target.value), autoComplete: "off" }) }) }));
31
41
  }
@@ -5,8 +5,8 @@ import type { Unstyled } from "./props.js";
5
5
  * belong together, or the filter chips of one facet (a `ButtonGroup` of `outline` `sm` pressed
6
6
  * `Button`s). It is a `<fieldset>` named by its `label`, drawn as its `<legend>` in the `Field`
7
7
  * label's look, over the children in one column; a `ButtonGroup` or a `FormGrid` inside lays out a
8
- * row. `hint` is a muted line under the group and its `aria-describedby`; `error` replaces it in red
9
- * with `role="alert"`. `disabled` disables every control inside. One choice of several is a
8
+ * row. `hint` is a muted line under the group and its `aria-describedby`; `error` adds a red line
9
+ * under it with an alert icon, announced politely. `disabled` disables every control inside. One choice of several is a
10
10
  * `RadioGroup`, never inside a `Fieldset`. Other props go on the `<fieldset>`.
11
11
  */
12
12
  export declare function Fieldset({ label, hint, error, children, "aria-describedby": ownDescribedBy, ...rest }: {
@@ -14,7 +14,7 @@ export declare function Fieldset({ label, hint, error, children, "aria-described
14
14
  label: ReactNode;
15
15
  /** A muted line under the group. */
16
16
  hint?: ReactNode;
17
- /** A red line under the group, in place of the hint, announced as an alert. */
17
+ /** A red line under the hint, with an alert icon, announced politely. */
18
18
  error?: ReactNode;
19
19
  /** `Checkbox`es, `Field`s (in a `FormGrid` for a row), or a `ButtonGroup` of chips. */
20
20
  children: ReactNode;
package/dist/Fieldset.js CHANGED
@@ -1,22 +1,20 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useId } from "react";
3
- import { fieldNote } from "./Field.js";
3
+ import { cx } from "./cx.js";
4
+ import { useFieldType } from "./density.js";
5
+ import { fieldNote, noteDescribedBy } from "./Field.js";
4
6
  /**
5
7
  * A labelled group of controls: several `Checkbox`es answering one question, a set of `Field`s that
6
8
  * belong together, or the filter chips of one facet (a `ButtonGroup` of `outline` `sm` pressed
7
9
  * `Button`s). It is a `<fieldset>` named by its `label`, drawn as its `<legend>` in the `Field`
8
10
  * label's look, over the children in one column; a `ButtonGroup` or a `FormGrid` inside lays out a
9
- * row. `hint` is a muted line under the group and its `aria-describedby`; `error` replaces it in red
10
- * with `role="alert"`. `disabled` disables every control inside. One choice of several is a
11
+ * row. `hint` is a muted line under the group and its `aria-describedby`; `error` adds a red line
12
+ * under it with an alert icon, announced politely. `disabled` disables every control inside. One choice of several is a
11
13
  * `RadioGroup`, never inside a `Fieldset`. Other props go on the `<fieldset>`.
12
14
  */
13
15
  export function Fieldset({ label, hint, error, children, "aria-describedby": ownDescribedBy, ...rest }) {
14
16
  const ids = { hint: useId(), error: useId() };
15
- let note;
16
- if (error)
17
- note = ids.error;
18
- else if (hint)
19
- note = ids.hint;
17
+ const note = noteDescribedBy(hint, error, ids);
20
18
  const describedBy = [ownDescribedBy, note].filter(Boolean).join(" ");
21
- return (_jsxs("fieldset", { ...rest, "aria-describedby": describedBy === "" ? undefined : describedBy, className: "min-w-0", children: [_jsx("legend", { className: "text-sm font-medium text-slate-700", children: label }), _jsx("div", { className: "mt-2 flex flex-col gap-2.5", children: children }), (error || hint) && _jsx("div", { className: "mt-1.5", children: fieldNote(hint, error, ids) })] }));
19
+ return (_jsxs("fieldset", { ...rest, "aria-describedby": describedBy === "" ? undefined : describedBy, className: "min-w-0", children: [_jsx("legend", { className: cx(useFieldType().label, "font-medium text-slate-700"), children: label }), _jsx("div", { className: "mt-2 flex flex-col gap-2.5", children: children }), (error || hint) && _jsx("div", { className: "mt-1.5", children: fieldNote(hint, error, ids) })] }));
22
20
  }
package/dist/FileDrop.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { INVALID_EDGE_WITHIN } from "./control.js";
2
3
  import { cx } from "./cx.js";
3
4
  import { useFieldControl } from "./fieldControl.js";
4
5
  const PAD = { sm: "px-3 py-2", md: "px-4 py-6", lg: "px-5 py-8" };
@@ -10,5 +11,5 @@ const PAD = { sm: "px-3 py-2", md: "px-4 py-6", lg: "px-5 py-8" };
10
11
  */
11
12
  export function FileDrop({ size = "md", children, ...rest }) {
12
13
  const field = useFieldControl(rest);
13
- return (_jsxs("label", { className: cx("relative flex items-center justify-center rounded-lg border border-dashed border-slate-300 text-center text-sm text-slate-500 transition hover:border-violet-400 has-aria-invalid:border-red-200 has-focus-visible:outline-2 has-focus-visible:outline-offset-2 has-focus-visible:outline-violet-600", PAD[size], rest.disabled && "opacity-50"), children: [_jsx("input", { type: "file", className: "absolute inset-0 h-full w-full cursor-pointer rounded-lg opacity-0 disabled:cursor-not-allowed", ...rest, ...field }), children] }));
14
+ return (_jsxs("label", { className: cx("relative flex items-center justify-center rounded-lg border border-dashed border-slate-300 text-center text-sm text-slate-500 transition hover:border-violet-400 has-focus-visible:outline-2 has-focus-visible:outline-offset-2 has-focus-visible:outline-violet-600", PAD[size], INVALID_EDGE_WITHIN, rest.disabled && "opacity-50"), children: [_jsx("input", { type: "file", className: "absolute inset-0 h-full w-full cursor-pointer rounded-lg opacity-0 disabled:cursor-not-allowed", ...rest, ...field }), children] }));
14
15
  }
@@ -0,0 +1,92 @@
1
+ import { type ReactElement, type ReactNode } from "react";
2
+ import type { FlowDirection, FlowLayout } from "./flowLayout.js";
3
+ import type { Passthrough } from "./props.js";
4
+ import { type LoadingProps } from "./skeleton.js";
5
+ import type { Tone } from "./tone.js";
6
+ import { useFlowLayout } from "./useFlowLayout.js";
7
+ /**
8
+ * One box of a `FlowDiagram`: its `id` (what an arrow's `from` and `to` name), its `label`, a
9
+ * `tone` that says what it means, the `group` it is framed in, and `content` drawn under the
10
+ * label (a few `Pill`s, a short list).
11
+ */
12
+ export type FlowNode = {
13
+ /** Unique in the diagram; an arrow's `from` and `to` name it. */
14
+ id: string;
15
+ /** The box's title. The box is as wide as it, up to 18rem; a longer one wraps. */
16
+ label: string;
17
+ /**
18
+ * What the box means: `neutral` (default) is a plain box, the others take the `Callout`'s fill
19
+ * and ink. Say it in the label or the content too: colour alone tells a screen reader nothing.
20
+ */
21
+ tone?: Tone | undefined;
22
+ /** Boxes with the same `group` are laid out together in a dashed frame named by it. */
23
+ group?: string | undefined;
24
+ /** Drawn under the label, inside the box, which grows to hold it: a few `Pill`s, a short list. Display only: no links or buttons. */
25
+ content?: ReactNode;
26
+ };
27
+ /** One arrow of a `FlowDiagram`, from one node's `id` to another's, with an optional short `label` on it. */
28
+ export type FlowEdge = {
29
+ from: string;
30
+ to: string;
31
+ /** A word or two on the arrow: the event or the action that moves along it. */
32
+ label?: string | undefined;
33
+ };
34
+ /**
35
+ * Boxes joined by arrows, laid out for you: a flow, a pipeline, a state machine. Give it the
36
+ * `nodes` and the `edges` between them and it places every box in ranks `direction` (`down` or
37
+ * `right`) and routes every arrow round them, loops and arrows back up included (dagre's layered
38
+ * layout). Each box is as wide as its label and its `content`, so no text spills; boxes with a
39
+ * `group` share a dashed frame; `active` rings one box in the accent.
40
+ *
41
+ * The diagram is drawn at its own size and scrolls inside its own box when it is wider or taller
42
+ * than the room it has, so it never makes the page scroll sideways. It is an image named by
43
+ * `label`; every box and every arrow is also a visually hidden list after it.
44
+ *
45
+ * `overlay` draws on top of the diagram in its own coordinates: it is handed the laid-out
46
+ * `FlowLayout` (each box's place and each arrow's SVG path), for a marker that follows an arrow.
47
+ * It is not hit by the pointer, and it is hidden from a screen reader.
48
+ *
49
+ * While `loading` with no nodes it draws one bone the height of a small diagram.
50
+ */
51
+ export declare function FlowDiagram({ label, nodes, edges, direction, active, overlay, loading, loadingLabel, ...rest }: {
52
+ /** What the diagram shows: its accessible name, and the name of its hidden list. */
53
+ label: string;
54
+ /** The boxes, each with a unique `id`. Their order is only a hint: the layout ranks them by the arrows. */
55
+ nodes: readonly FlowNode[];
56
+ /** The arrows. One whose `from` or `to` is not a node's `id` is not drawn. */
57
+ edges: readonly FlowEdge[];
58
+ /**
59
+ * Where the arrows run: `down` (top to bottom) or `right` (start to end).
60
+ * @default down
61
+ */
62
+ direction?: FlowDirection;
63
+ /** The `id` of the one box to ring in the accent: the current step, the state a thing is in now. */
64
+ active?: string | undefined;
65
+ /** Draws on top of the diagram, in its coordinates, from the laid-out boxes and arrow paths. */
66
+ overlay?: ((layout: FlowLayout) => ReactNode) | undefined;
67
+ } & LoadingProps & Passthrough): ReactElement;
68
+ /** A box's tone in the internal view: the public tones, and `muted` for a box that is over. */
69
+ export type ViewTone = Tone | "muted";
70
+ /** A box of the internal view: a `FlowNode` that may also be `muted`. */
71
+ export type ViewNode = Omit<FlowNode, "tone"> & {
72
+ tone?: ViewTone | undefined;
73
+ };
74
+ /**
75
+ * The laid-out diagram, drawn: `FlowDiagram` without its loading bone, and with `layer`, which
76
+ * `StateMachine` draws its dots in. The caller lays it out (`useFlowLayout`) and hands over the
77
+ * `canvas` ref and the layout `drawn`. Unlike `overlay`, the layer is read by a screen reader and its
78
+ * children may take the pointer (`pointer-events-auto`), so they can be links. With a layer, the
79
+ * image is the drawing alone and the scrolling box round it is a group named by `label`. With `fit`,
80
+ * a drawing wider than its room is shrunk to the room's width instead of scrolling. Internal.
81
+ */
82
+ export declare function FlowView({ label, nodes, edges, active, overlay, layer, canvas, drawn, fit, ...rest }: {
83
+ label: string;
84
+ nodes: readonly ViewNode[];
85
+ edges: readonly FlowEdge[];
86
+ active: string | undefined;
87
+ overlay?: ((layout: FlowLayout) => ReactNode) | undefined;
88
+ layer?: ((layout: FlowLayout) => ReactNode) | undefined;
89
+ canvas: ReturnType<typeof useFlowLayout>["canvas"];
90
+ drawn: FlowLayout;
91
+ fit?: boolean | undefined;
92
+ } & Passthrough): ReactElement;
@@ -0,0 +1,100 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useId } from "react";
3
+ import { TONE_SURFACE, TONE_TEXT } from "./Callout.js";
4
+ import { cx } from "./cx.js";
5
+ import { Bone, BusyLabel, busy, useLoading } from "./skeleton.js";
6
+ import { edgeKey, nodeKey, useFit, useFlowLayout } from "./useFlowLayout.js";
7
+ /** A box's frame by tone: the Callout's soft surfaces, a white box for `neutral`, a grey one for `muted`. */
8
+ const NODE_TONE = {
9
+ ...TONE_SURFACE,
10
+ neutral: "border-slate-300 bg-white",
11
+ muted: "border-slate-200 bg-slate-50",
12
+ };
13
+ /** A box's ink by tone; `neutral` is the primary ink, `muted` the quiet one. */
14
+ const NODE_INK = {
15
+ ...TONE_TEXT,
16
+ neutral: "text-slate-900",
17
+ muted: "text-slate-500",
18
+ };
19
+ /**
20
+ * Boxes joined by arrows, laid out for you: a flow, a pipeline, a state machine. Give it the
21
+ * `nodes` and the `edges` between them and it places every box in ranks `direction` (`down` or
22
+ * `right`) and routes every arrow round them, loops and arrows back up included (dagre's layered
23
+ * layout). Each box is as wide as its label and its `content`, so no text spills; boxes with a
24
+ * `group` share a dashed frame; `active` rings one box in the accent.
25
+ *
26
+ * The diagram is drawn at its own size and scrolls inside its own box when it is wider or taller
27
+ * than the room it has, so it never makes the page scroll sideways. It is an image named by
28
+ * `label`; every box and every arrow is also a visually hidden list after it.
29
+ *
30
+ * `overlay` draws on top of the diagram in its own coordinates: it is handed the laid-out
31
+ * `FlowLayout` (each box's place and each arrow's SVG path), for a marker that follows an arrow.
32
+ * It is not hit by the pointer, and it is hidden from a screen reader.
33
+ *
34
+ * While `loading` with no nodes it draws one bone the height of a small diagram.
35
+ */
36
+ export function FlowDiagram({ label, nodes, edges, direction = "down", active, overlay, loading, loadingLabel, ...rest }) {
37
+ const { loading: waiting, owner } = useLoading(loading);
38
+ const { canvas, drawn } = useFlowLayout(nodes, edges, direction);
39
+ if (waiting && nodes.length === 0) {
40
+ 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 })] }));
41
+ }
42
+ return (_jsx(FlowView, { ...rest, label: label, nodes: nodes, edges: edges, active: active, overlay: overlay, canvas: canvas, drawn: drawn }));
43
+ }
44
+ /**
45
+ * The laid-out diagram, drawn: `FlowDiagram` without its loading bone, and with `layer`, which
46
+ * `StateMachine` draws its dots in. The caller lays it out (`useFlowLayout`) and hands over the
47
+ * `canvas` ref and the layout `drawn`. Unlike `overlay`, the layer is read by a screen reader and its
48
+ * children may take the pointer (`pointer-events-auto`), so they can be links. With a layer, the
49
+ * image is the drawing alone and the scrolling box round it is a group named by `label`. With `fit`,
50
+ * a drawing wider than its room is shrunk to the room's width instead of scrolling. Internal.
51
+ */
52
+ export function FlowView({ label, nodes, edges, active, overlay, layer, canvas, drawn, fit = false, ...rest }) {
53
+ const { frame, scale } = useFit(fit ? drawn.width : 0);
54
+ const known = new Set(nodes.map((n) => n.id));
55
+ const shown = edges.flatMap((edge, index) => known.has(edge.from) && known.has(edge.to) ? [{ edge, index }] : []);
56
+ const image = {
57
+ role: "img",
58
+ "aria-label": `${label}: ${count(known.size, "box", "boxes")} and ${count(shown.length, "arrow", "arrows")}`,
59
+ };
60
+ const drawing = _jsx(FlowCanvas, { drawn: drawn, nodes: nodes, edges: shown, active: active });
61
+ return (_jsxs("div", { ...rest, className: "flex min-w-0 flex-col", children: [_jsx("div", { ...(layer ? { role: "group", "aria-label": label } : image),
62
+ // A diagram wider than its room scrolls, so it takes the focus for the arrow keys.
63
+ tabIndex: 0, ref: frame, className: "max-w-full overflow-auto rounded-lg outline-offset-2 focus-visible:outline-2 focus-visible:outline-violet-600", children: _jsx("div", { className: "mx-auto", style: { width: drawn.width * scale, height: drawn.height * scale }, children: _jsxs("div", { ref: canvas, className: "relative origin-top-left", style: {
64
+ width: drawn.width,
65
+ height: drawn.height,
66
+ ...(scale < 1 ? { transform: `scale(${scale})` } : {}),
67
+ }, children: [layer ? (_jsx("div", { ...image, className: "absolute inset-0", children: drawing })) : (drawing), overlay && (_jsx("div", { "aria-hidden": "true", className: "pointer-events-none absolute inset-0", children: overlay(drawn) })), layer && _jsx("div", { className: "pointer-events-none absolute inset-0", children: layer(drawn) })] }) }) }), _jsx(FlowList, { label: label, nodes: nodes, edges: shown, active: active })] }));
68
+ }
69
+ /** `1 box`, `3 boxes`. */
70
+ const count = (n, one, many) => `${n} ${n === 1 ? one : many}`;
71
+ /** The drawing itself: the group frames, the arrows, their labels and the boxes. */
72
+ function FlowCanvas({ drawn, nodes, edges, active, }) {
73
+ const marker = `flow-arrow-${useId().replace(/[^a-zA-Z0-9_-]/g, "")}`;
74
+ const byId = new Map(nodes.map((n) => [n.id, n]));
75
+ const paths = new Map(drawn.edges.map((e) => [e.index, e]));
76
+ return (_jsxs(_Fragment, { children: [drawn.groups.map((g) => (_jsx("div", { className: "absolute rounded-xl border border-dashed border-slate-300", style: { left: g.x, top: g.y, width: g.width, height: g.height }, children: _jsx("span", { className: "absolute left-3 top-1 text-xs font-medium text-slate-500", children: g.name }) }, g.name))), _jsx(FlowArrows, { drawn: drawn, marker: marker }), edges.map(({ edge, index }) => {
77
+ const at = paths.get(index)?.labelAt;
78
+ return edge.label && at ? (_jsx("span", { "data-measure": edgeKey(index), className: "absolute -translate-x-1/2 -translate-y-1/2 whitespace-nowrap rounded bg-white px-1 text-xs text-slate-600", style: { left: at.x, top: at.y }, children: edge.label }, index)) : null;
79
+ }), drawn.nodes.map((b) => {
80
+ const node = byId.get(b.id);
81
+ return node ? (_jsx(FlowBoxView, { box: b, node: node, active: active === b.id }, b.id)) : null;
82
+ })] }));
83
+ }
84
+ /** Every arrow as an SVG path, with its arrowhead. */
85
+ function FlowArrows({ drawn, marker }) {
86
+ return (_jsxs("svg", { width: drawn.width, height: drawn.height, className: "absolute inset-0 overflow-visible text-slate-400", children: [_jsx("defs", { children: _jsx("marker", { id: marker, viewBox: "0 0 10 10", refX: "9", refY: "5", markerWidth: "8", markerHeight: "8", markerUnits: "userSpaceOnUse", orient: "auto-start-reverse", children: _jsx("path", { d: "M0,0L10,5L0,10z", fill: "currentColor" }) }) }), drawn.edges.map((e) => (_jsx("path", { d: e.path, fill: "none", stroke: "currentColor", strokeWidth: 1.5, markerEnd: `url(#${marker})` }, e.index)))] }));
87
+ }
88
+ /** One box, placed: its label and content, sized by them, centred in the slot the layout gave it. */
89
+ function FlowBoxView({ box, node, active, }) {
90
+ const tone = node.tone ?? "neutral";
91
+ return (_jsx("div", { className: "absolute flex items-center justify-center", style: { left: box.x, top: box.y, width: box.width, height: box.height }, children: _jsxs("div", { "data-measure": nodeKey(box.id), className: cx("w-max max-w-72 shrink-0 rounded-lg border px-3 py-2 text-sm", NODE_TONE[tone], NODE_INK[tone], active && "outline-2 outline-offset-2 outline-violet-600"), children: [_jsx("div", { className: "font-medium", children: node.label }), node.content != null && _jsx("div", { className: "mt-2", children: node.content })] }) }));
92
+ }
93
+ /** The diagram as text for a screen reader: each box, its content, and the arrows out of it. */
94
+ function FlowList({ label, nodes, edges, active, }) {
95
+ const names = new Map(nodes.map((n) => [n.id, n.label]));
96
+ return (_jsx("ul", { "aria-label": label, className: "sr-only", children: nodes.map((n) => {
97
+ const out = edges.filter(({ edge }) => edge.from === n.id);
98
+ return (_jsxs("li", { children: [n.label, active === n.id && ", current", n.group && `, in ${n.group}`, n.content != null && _jsx("div", { children: n.content }), out.length > 0 && (_jsx("ul", { children: out.map(({ edge, index }) => (_jsxs("li", { children: [`to ${names.get(edge.to) ?? edge.to}`, edge.label && `, on ${edge.label}`] }, index))) }))] }, n.id));
99
+ }) }));
100
+ }
package/dist/FormRow.d.ts CHANGED
@@ -4,8 +4,9 @@ import { type LoadingProps } from "./skeleton.js";
4
4
  /** Relative widths in a `FormRow`: a field of `span` 2 is twice as wide as one of `span` 1. */
5
5
  export type FormRowSpan = 1 | 2 | 3 | 4;
6
6
  /**
7
- * Two columns of `Field`s from `md`, one below it. A `Field` takes one column; `span="full"` runs
8
- * it across both, and a `FormRow` is always full width.
7
+ * Two columns of `Field`s once the grid is 36rem wide, one below that. It folds by its own width,
8
+ * not the viewport's, so it stays one column in a `Dialog` or a side column. A `Field` takes one
9
+ * column; `span="full"` runs it across both, and a `FormRow` is always full width.
9
10
  */
10
11
  export declare function FormGrid({ children, ...rest }: {
11
12
  children: ReactNode;
@@ -14,7 +15,8 @@ export declare function FormGrid({ children, ...rest }: {
14
15
  * An inline-edit row: several controls side by side with proportional widths (`FormRowField`
15
16
  * `span` 1 to 4), optional `actions` after them (a save button), and one `hint` or `error` line
16
17
  * under the whole row. Every control sits on the bottom edge, so the actions line up with them
17
- * whatever the labels do. Under `md` the fields and the actions stack.
18
+ * whatever the labels do. Narrower than 36rem (the row's own width, not the viewport's) the fields
19
+ * and the actions stack.
18
20
  *
19
21
  * The row owns the note, so the fields beside each other keep their height: a `FormRowField` has
20
22
  * no `hint` or `error` of its own.
@@ -24,7 +26,7 @@ export declare function FormRow({ actions, hint, error, children, ...rest }: {
24
26
  actions?: ReactNode;
25
27
  /** One muted line under the whole row. */
26
28
  hint?: ReactNode;
27
- /** Replaces the hint when set, as `Field`'s does. */
29
+ /** A red line under the hint, announced politely, as `Field`'s is. */
28
30
  error?: ReactNode;
29
31
  children: ReactNode;
30
32
  } & Passthrough): ReactElement;
package/dist/FormRow.js CHANGED
@@ -4,30 +4,32 @@ import { fieldNote } from "./Field.js";
4
4
  import { ControlBone } from "./fieldWait.js";
5
5
  import { BusyLabel, busy, useLoading } from "./skeleton.js";
6
6
  const SPAN = {
7
- 1: "md:flex-1",
8
- 2: "md:flex-2",
9
- 3: "md:flex-3",
10
- 4: "md:flex-4",
7
+ 1: "@xl:flex-1",
8
+ 2: "@xl:flex-2",
9
+ 3: "@xl:flex-3",
10
+ 4: "@xl:flex-4",
11
11
  };
12
12
  /**
13
- * Two columns of `Field`s from `md`, one below it. A `Field` takes one column; `span="full"` runs
14
- * it across both, and a `FormRow` is always full width.
13
+ * Two columns of `Field`s once the grid is 36rem wide, one below that. It folds by its own width,
14
+ * not the viewport's, so it stays one column in a `Dialog` or a side column. A `Field` takes one
15
+ * column; `span="full"` runs it across both, and a `FormRow` is always full width.
15
16
  */
16
17
  export function FormGrid({ children, ...rest }) {
17
- return (_jsx("div", { ...rest, className: "grid grid-cols-1 gap-4 md:grid-cols-2", children: children }));
18
+ return (_jsx("div", { ...rest, className: "@container w-full", children: _jsx("div", { className: "grid grid-cols-1 gap-4 @xl:grid-cols-2", children: children }) }));
18
19
  }
19
20
  /**
20
21
  * An inline-edit row: several controls side by side with proportional widths (`FormRowField`
21
22
  * `span` 1 to 4), optional `actions` after them (a save button), and one `hint` or `error` line
22
23
  * under the whole row. Every control sits on the bottom edge, so the actions line up with them
23
- * whatever the labels do. Under `md` the fields and the actions stack.
24
+ * whatever the labels do. Narrower than 36rem (the row's own width, not the viewport's) the fields
25
+ * and the actions stack.
24
26
  *
25
27
  * The row owns the note, so the fields beside each other keep their height: a `FormRowField` has
26
28
  * no `hint` or `error` of its own.
27
29
  */
28
30
  export function FormRow({ actions, hint, error, children, ...rest }) {
29
31
  const note = fieldNote(hint, error);
30
- return (_jsxs("div", { ...rest, className: "col-span-full flex flex-col gap-1.5", children: [_jsxs("div", { className: "flex flex-col gap-3 md:flex-row md:items-end", children: [children, actions && _jsx("div", { className: "flex items-center gap-2 md:shrink-0", children: actions })] }), note] }));
32
+ return (_jsxs("div", { ...rest, className: "@container col-span-full flex flex-col gap-1.5", children: [_jsxs("div", { className: "flex flex-col gap-3 @xl:flex-row @xl:items-end", children: [children, actions && _jsx("div", { className: "flex items-center gap-2 @xl:shrink-0", children: actions })] }), note] }));
31
33
  }
32
34
  /**
33
35
  * A compact label over one control, for a `FormRow`. `span` is its share of the row (1 default).
package/dist/Hero.d.ts CHANGED
@@ -9,15 +9,38 @@ export type HeroProps = {
9
9
  title: ReactNode;
10
10
  /** What follows the title: a `Lead`, and the page's first actions if it has any. */
11
11
  children?: ReactNode;
12
- };
12
+ /**
13
+ * The name of the control that holds the glow still, for an app in another language.
14
+ * @default Pause the background motion
15
+ */
16
+ pauseLabel?: string | undefined;
17
+ } & ({
18
+ /**
19
+ * A picture beside the words from `md` up, and under them on a phone: an `Image` of the
20
+ * product, at `width="full"`. The words keep the glow; the picture sits clear of it.
21
+ */
22
+ media: ReactNode;
23
+ align?: "start" | undefined;
24
+ } | {
25
+ media?: undefined;
26
+ /**
27
+ * `center` sets the words in the middle of the page, under a centred glow: a landing page
28
+ * with no picture whose actions are one or two buttons. Pass the actions' `Cluster`
29
+ * `justify="center"` too.
30
+ * @default start
31
+ */
32
+ align?: "start" | "center" | undefined;
33
+ });
13
34
  /**
14
35
  * A landing page's top block: an overline, the display title (the page's `h1`) and the lede under
15
36
  * it, over a soft glow of three tilted ribbons that drift slowly behind the text. The glow is always
16
37
  * there and its colours and strength are the theme's (the palette's `glow` role), so a paper theme
17
- * keeps it faint. It is anchored to the text's own column (`max-w-3xl`, at the parent's start edge),
18
- * never the viewport, and clipped to it, so nothing scrolls sideways on a phone. It is
19
- * `aria-hidden`, and the text sits above it. Under `prefers-reduced-motion: reduce` it stands still.
20
- * Pure markup and one inline stylesheet: it works rendered on the server with no script.
21
- * One per page, on a landing page; every other page opens with a `PageHeader`.
38
+ * keeps it faint. It is anchored to the text's own column (`max-w-3xl`, at the parent's start edge,
39
+ * or in its middle with `align="center"`), never the viewport, and clipped to it, so nothing scrolls
40
+ * sideways on a phone. It is `aria-hidden`, and the text sits above it. `media` puts a picture
41
+ * beside the words from `md` up. A small checkbox in the top corner holds the drift still, since it
42
+ * never ends on its own; under `prefers-reduced-motion: reduce` the glow stands still and the
43
+ * checkbox is not drawn. Pure markup and one inline stylesheet: it works rendered on the server with
44
+ * no script. One per page, on a landing page; every other page opens with a `PageHeader`.
22
45
  */
23
- export declare function Hero({ overline, title, children, ...rest }: HeroProps & Passthrough): ReactElement;
46
+ export declare function Hero({ overline, title, children, media, align, pauseLabel, ...rest }: HeroProps & Passthrough): ReactElement;