@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/Tabs.js CHANGED
@@ -1,46 +1,121 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { cx, focusRing } from "./cx.js";
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useId, useRef, useState } from "react";
3
+ import { hasReason } from "./blocked.js";
4
+ import { cx, focusRing, forcedFill } from "./cx.js";
3
5
  import { controlText, useTypeStep } from "./density.js";
6
+ import { useScrollEdges } from "./scrollEdges.js";
4
7
  import { Switcher } from "./switcher.js";
5
- const BASE = `-mb-px border-b-2 px-0.5 py-2 transition ${focusRing}`;
6
- const ON = "border-violet-600 font-medium text-violet-700";
7
- const OFF = "border-transparent text-slate-600";
8
+ // Every underline tab is `font-medium`, so choosing one does not widen it and shift the row. The
9
+ // focus ring is drawn inside the tab, since the row scrolls and would clip one drawn outside.
10
+ const BASE = "border-b-2 px-1 py-2 font-medium transition focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-violet-600";
11
+ // In forced colours a transparent border is painted in the text colour, so every tab would look
12
+ // underlined: the others take the page's Canvas, and the current one the system's Highlight. The
13
+ // rule under the row takes Canvas too, or it shows in the gaps between the tabs.
14
+ const ON = "border-violet-600 text-violet-700 forced-colors:border-[color:Highlight]!";
15
+ const OFF = "border-transparent text-slate-600 forced-colors:border-[color:Canvas]!";
8
16
  const OFF_LIVE = "hover:text-violet-700";
9
- // A transparent border, so a pill is as tall as a `Button` of the same size.
10
- const PILL = `rounded-lg border border-transparent transition ${focusRing}`;
17
+ // The rule under the row; the tab list inside it sits over the rule by a pixel, so the current
18
+ // tab's underline covers it.
19
+ const UNDERLINE_RULE = "border-b border-slate-200 forced-colors:border-[color:Canvas]!";
20
+ // One line that never wraps: a row wider than its box scrolls sideways, with no scrollbar, and
21
+ // fades out on the side that has more (a mask, so it follows any theme; it flips right to left).
22
+ // While the keyboard's focus is in the row the fade is off, so a focused tab at an edge stays whole.
23
+ const UNDERLINE_ROW = "-mb-px flex gap-x-4 overflow-x-auto whitespace-nowrap text-sm [scrollbar-width:none] *:shrink-0 [--fade-dir:to_right] rtl:[--fade-dir:to_left] data-more-start:[--fade-start:1.5rem] data-more-end:[--fade-end:1.5rem] data-more:[mask-image:linear-gradient(var(--fade-dir),transparent,#000_var(--fade-start,0px),#000_calc(100%_-_var(--fade-end,0px)),transparent)] data-more:has-focus-visible:[mask-image:none]";
24
+ // A transparent border, so a pill is as tall as a `Button` of the same size; the current pill's
25
+ // border shows, so it is told apart by its outline as well as its fill.
26
+ const PILL = `rounded-lg border transition ${focusRing}`;
11
27
  /** A pill's padding, by `size`; its text is a control's (`controlText`), so it lines up with a `Button`. */
12
28
  const PILL_SIZE = {
13
29
  sm: "px-2.5 py-1",
14
30
  md: "px-3 py-2",
15
31
  lg: "px-4 py-2.5",
16
32
  };
17
- /** The classes of one pill tab at the type `step` in force. A `disabled` one drops the hover fill. */
33
+ /**
34
+ * The classes of one pill tab at the type `step` in force. Every pill is `font-medium`, so the
35
+ * current one is no wider than it was; it has a fill and an outline. A `disabled` one drops the
36
+ * hover fill.
37
+ */
18
38
  export function pillTabClass(active, disabled = false, size = "md", step) {
19
- return cx(PILL, PILL_SIZE[size], controlText(size, step, false), active ? "bg-slate-100 font-medium text-slate-900" : "text-slate-600", !active && !disabled && "hover:bg-slate-100");
39
+ return cx(PILL, PILL_SIZE[size], controlText(size, step, false), "font-medium", active
40
+ ? cx("border-slate-300 bg-slate-100 text-slate-900",
41
+ // Forced colours paint every pill's fill the page's Canvas and its border the text
42
+ // colour, so the current one is the system's Highlight, as a selected option is there. It
43
+ // names only system colours, so it opts out of the backplate drawn behind text there.
44
+ forcedFill, "forced-colors:border-[color:Highlight]! forced-colors:text-[color:HighlightText]! forced-color-adjust-none")
45
+ : "border-transparent text-slate-600", !active && !disabled && "hover:bg-slate-100");
20
46
  }
21
47
  /**
22
- * Tabs for switching a view in place or between pages. Across (the default) they are underline
23
- * tabs: a row over a bottom rule, the current tab underlined in the accent. `orientation="vertical"`
24
- * is the pill rail instead, the current tab filled, for a `SidebarLayout` aside, and takes a
25
- * `size`. `items` are `{ value, label }` buttons (`value` and `onChange` are the caller's state;
26
- * the arrow keys, Home and End move between tabs) or links (`href`, an in-app one through
27
- * `LinkProvider`; `selected` on an item, or `value`, marks the current one, which gets
28
- * `aria-current`). An item may carry a `count`, and a button one `disabledReason` (it stays
29
- * reachable by the arrows and its reason is a tooltip) or a bare `disabled`; `disabled` on the row disables every tab. `label` names the tab list. The panel is
30
- * the caller's: give it `role="tabpanel"`, and a tab `controls` to point at it.
48
+ * One tab's panel. Hidden while its tab is not current; where the browser has it, hidden
49
+ * `until-found`, so find in page reaches the text and `beforematch` switches to the tab. That is
50
+ * applied after hydration (React renders `hidden` as a boolean), and not for a disabled tab.
31
51
  */
32
- export function Tabs({ size = "md", orientation = "horizontal", ...props }) {
33
- const stacked = orientation === "vertical";
52
+ function TabPanel({ id, tabId, active, findable, onFound, children, }) {
53
+ const panel = useRef(null);
54
+ useEffect(() => {
55
+ const el = panel.current;
56
+ if (!el || active || !findable || !("onbeforematch" in el))
57
+ return undefined;
58
+ el.setAttribute("hidden", "until-found");
59
+ el.addEventListener("beforematch", onFound);
60
+ return () => {
61
+ el.removeEventListener("beforematch", onFound);
62
+ // A panel that stays hidden but is no longer findable (its tab was disabled) is plainly
63
+ // hidden again; one that became current has had `hidden` removed by React already.
64
+ if (el.getAttribute("hidden") === "until-found")
65
+ el.setAttribute("hidden", "");
66
+ };
67
+ }, [active, findable, onFound]);
68
+ return (_jsx("div", { ref: panel, id: id, role: "tabpanel", "aria-labelledby": tabId, tabIndex: 0, hidden: !active, className: "min-w-0 flex-1 rounded-lg focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-violet-600", children: children }));
69
+ }
70
+ const hasPanels = (items) => items.some((item) => item.href === undefined && item.panel !== undefined);
71
+ /** The tab list on its own: the underline row in its rule, or the pill rail. */
72
+ function TabList({ size, stacked, ids, ...props }) {
34
73
  const step = useTypeStep();
35
- return (_jsx(Switcher, { ...props, parts: {
74
+ const [row, setRow] = useState(null);
75
+ useScrollEdges(stacked ? null : row, "x");
76
+ const list = (_jsx(Switcher, { ...props, parts: {
36
77
  group: "tablist",
37
78
  item: "tab",
38
79
  vertical: stacked,
39
80
  stacked,
40
81
  root: stacked ? "flex flex-col gap-1" : UNDERLINE_ROW,
82
+ onRoot: setRow,
83
+ ids,
41
84
  option: (active, disabled) => stacked
42
85
  ? pillTabClass(active, disabled, size, step)
43
86
  : cx(BASE, active ? ON : OFF, !active && !disabled && OFF_LIVE),
44
87
  } }));
88
+ return stacked ? list : _jsx("div", { className: UNDERLINE_RULE, children: list });
89
+ }
90
+ /**
91
+ * Tabs for switching a view in place or between pages. Across (the default) they are underline
92
+ * tabs: one line over a bottom rule, the current tab underlined in the accent, scrolling sideways
93
+ * with a fade when the row is too wide. `orientation="vertical"` is the pill rail instead, the
94
+ * current tab filled and outlined, for a `SidebarLayout` aside, and takes a `size`. `items` are
95
+ * `{ value, label, panel }` buttons (`value` and `onChange` are the caller's state; the arrow
96
+ * keys, Home and End move between tabs) or links (`href`, an in-app one through `LinkProvider`;
97
+ * `selected` on an item, or `value`, marks the current one, which gets `aria-current`). A button's
98
+ * `panel` is rendered as its `tabpanel`, wired to the tab and hidden while another is current. An
99
+ * item may carry a `count`, and a button one `disabledReason` (it stays reachable by the arrows and
100
+ * its reason is a tooltip) or a bare `disabled`; `disabled` on the row disables every tab. `label`
101
+ * names the tab list.
102
+ */
103
+ export function Tabs({ size = "md", orientation = "horizontal", ...props }) {
104
+ const stacked = orientation === "vertical";
105
+ const base = useId();
106
+ const items = props.items;
107
+ const panels = hasPanels(items) ? items : undefined;
108
+ const ids = (index) => panels?.[index]?.panel === undefined
109
+ ? undefined
110
+ : { tab: `${base}-tab-${index}`, panel: `${base}-panel-${index}` };
111
+ const list = _jsx(TabList, { ...props, size: size, stacked: stacked, ids: ids });
112
+ if (!panels || props.onChange === undefined)
113
+ return list;
114
+ const { value, onChange, disabled } = props;
115
+ return (_jsxs("div", { className: stacked ? "flex items-start gap-6" : "flex flex-col gap-4", children: [list, panels.map((item, index) => {
116
+ const own = ids(index);
117
+ if (!own)
118
+ return null;
119
+ return (_jsx(TabPanel, { id: own.panel, tabId: own.tab, active: item.value === value, findable: !(disabled || item.disabled || hasReason(item.disabledReason)), onFound: () => onChange(item.value), children: item.panel }, item.value));
120
+ })] }));
45
121
  }
46
- const UNDERLINE_ROW = "flex flex-wrap gap-x-5 border-b border-slate-200 text-sm";
@@ -1,4 +1,5 @@
1
1
  import type { ComponentPropsWithoutRef, ReactElement } from "react";
2
+ import { type IconName } from "./icons.js";
2
3
  import type { Unstyled } from "./props.js";
3
4
  import type { Size } from "./size.js";
4
5
  import { type TextTone } from "./typography.js";
@@ -11,6 +12,13 @@ export declare const linkClass: string;
11
12
  * above it leaves this one alone.
12
13
  */
13
14
  export declare const linkStretchClass = "link-stretch after:absolute after:inset-0";
15
+ /**
16
+ * A TextLink's colour: a text tone, as on the inline roles, or `quiet`, the primary ink at rest and
17
+ * the accent on hover, for a link in a row or list of links (a footer row, a table of contents),
18
+ * never inside a sentence, where with no colour or underline at rest it reads as plain text. This
19
+ * extends `TextTone` outward with `quiet`, a look only a link has.
20
+ */
21
+ export type TextLinkTone = TextTone | "quiet";
14
22
  /** A TextLink's pinned type size, on the `Size` scale; left out, it takes the size of the text around it. */
15
23
  export type TextLinkSize = Size;
16
24
  type TextLinkProps = {
@@ -21,9 +29,13 @@ type TextLinkProps = {
21
29
  size?: TextLinkSize | undefined;
22
30
  /**
23
31
  * A meaning's colour, as on the inline roles: `warn` for a warning link, `danger`, `positive`,
24
- * `info` or `muted`. Left out, the link is the accent colour.
32
+ * `info` or `muted`; or `quiet`, the primary ink at rest and the accent on hover, for a row or list
33
+ * of links and never inside a sentence. Left out, the
34
+ * link is the accent colour.
25
35
  */
26
- tone?: TextTone | undefined;
36
+ tone?: TextLinkTone | undefined;
37
+ /** An icon after the words (`chevron-right`, say), at one size on the baseline; it is decorative and hidden from assistive tech. */
38
+ icon?: IconName | undefined;
27
39
  /** The monospace face, for a path, an id or a command. */
28
40
  mono?: boolean | undefined;
29
41
  /** Opens in a new tab: adds `target="_blank"` and `rel="noreferrer"`. */
@@ -44,8 +56,9 @@ type TextLinkProps = {
44
56
  /**
45
57
  * An inline text link in the accent colour. Every anchor prop goes on the `<a>`; an in-app `href`
46
58
  * is drawn by the app's router link through `LinkProvider`.
47
- * `size` pins the type size (`sm`, `md` or `lg`), `tone` gives it a meaning's colour and `mono` sets the
48
- * monospace face.
59
+ * `size` pins the type size (`sm`, `md` or `lg`), `tone` gives it a meaning's colour (or `quiet`,
60
+ * ink that turns the accent on hover) and `mono` sets the monospace face. `icon` puts one of the
61
+ * library's icons after the words, hidden from assistive tech: the words name the link.
49
62
  */
50
- export declare function TextLink({ size, tone, mono, external, stretch, underline, href, children, ...rest }: TextLinkProps): ReactElement;
63
+ export declare function TextLink({ size, tone, mono, external, stretch, underline, href, icon, children, ...rest }: TextLinkProps): ReactElement;
51
64
  export {};
package/dist/TextLink.js CHANGED
@@ -1,4 +1,6 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
1
2
  import { cx, focusRing } from "./cx.js";
3
+ import { iconGlyph } from "./icons.js";
2
4
  import { renderLink } from "./link.js";
3
5
  import { TEXT_TONE } from "./typography.js";
4
6
  const LINK = "rounded font-medium underline-offset-2 transition-colors";
@@ -14,8 +16,18 @@ const toneClass = (tone) => cx(LINK, TEXT_TONE[tone], "hover:underline", focusRi
14
16
  * above it leaves this one alone.
15
17
  */
16
18
  export const linkStretchClass = "link-stretch after:absolute after:inset-0";
17
- // The tone's colour, or the accent with its hover shade.
18
- const colourClass = (tone) => tone && tone !== "neutral" ? toneClass(tone) : linkClass;
19
+ // The ink at rest, the accent on hover; focus draws the accent ring, as on every link.
20
+ const QUIET = cx(LINK, "text-slate-900 hover:text-violet-700", focusRing);
21
+ // The tone's colour, the quiet ink, or the accent with its hover shade.
22
+ function colourClass(tone) {
23
+ if (tone === "quiet")
24
+ return QUIET;
25
+ if (tone === undefined || tone === "neutral")
26
+ return linkClass;
27
+ return toneClass(tone);
28
+ }
29
+ // The trailing icon: one size, a touch under the text's, sitting on the baseline.
30
+ const ICON = "ms-1 inline-block size-[0.875em] align-[-0.125em] [&>svg]:size-full";
19
31
  const SIZE = {
20
32
  sm: "text-xs/4",
21
33
  md: "text-sm/5",
@@ -24,15 +36,16 @@ const SIZE = {
24
36
  /**
25
37
  * An inline text link in the accent colour. Every anchor prop goes on the `<a>`; an in-app `href`
26
38
  * is drawn by the app's router link through `LinkProvider`.
27
- * `size` pins the type size (`sm`, `md` or `lg`), `tone` gives it a meaning's colour and `mono` sets the
28
- * monospace face.
39
+ * `size` pins the type size (`sm`, `md` or `lg`), `tone` gives it a meaning's colour (or `quiet`,
40
+ * ink that turns the accent on hover) and `mono` sets the monospace face. `icon` puts one of the
41
+ * library's icons after the words, hidden from assistive tech: the words name the link.
29
42
  */
30
- export function TextLink({ size, tone, mono = false, external = false, stretch = false, underline = false, href, children, ...rest }) {
43
+ export function TextLink({ size, tone, mono = false, external = false, stretch = false, underline = false, href, icon, children, ...rest }) {
31
44
  return renderLink({
32
45
  ...rest,
33
46
  href,
34
47
  external,
35
48
  className: cx(colourClass(tone), size && SIZE[size], mono && "font-mono", stretch && linkStretchClass, underline && "underline"),
36
- children,
49
+ children: icon === undefined ? (children) : (_jsxs(_Fragment, { children: [children, _jsx("span", { "aria-hidden": "true", className: ICON, children: iconGlyph(icon) })] })),
37
50
  });
38
51
  }
@@ -1,6 +1,7 @@
1
1
  import type { ComponentPropsWithoutRef, ReactElement, Ref } from "react";
2
- import { type ControlProps } from "./control.js";
2
+ import { type ControlProps, type ControlSize, type ControlWidth } from "./control.js";
3
3
  import type { Unstyled } from "./props.js";
4
+ import type { ResponsiveSize } from "./size.js";
4
5
  export type TextareaProps = ControlProps & {
5
6
  /** The monospace face, for pasted CSV or statement text, where the columns must line up. Off by default. */
6
7
  mono?: boolean | undefined;
@@ -9,3 +10,13 @@ export type TextareaProps = ControlProps & {
9
10
  } & Unstyled<Omit<ComponentPropsWithoutRef<"textarea">, "width">>;
10
11
  /** A multi-line text input, styled like `Input`. `rows` defaults to 3. Takes `size`, `width` and `mono` too. The `ref` reaches the `<textarea>`, for focus control. */
11
12
  export declare function Textarea({ size, width, mono, ...rest }: TextareaProps): ReactElement;
13
+ /**
14
+ * `Textarea`, plus `grow` for the library's own boxes (`ChatComposer`): a `md` box that grows from 2
15
+ * rows to 8 with its text. Not exported from `index.ts`.
16
+ */
17
+ export declare function TextareaControl({ size, width, mono, grow, ...rest }: Omit<TextareaProps, "size" | "width" | "mono"> & {
18
+ size: ControlSize | ResponsiveSize;
19
+ width: ControlWidth;
20
+ mono: boolean;
21
+ grow?: boolean;
22
+ }): ReactElement;
package/dist/Textarea.js CHANGED
@@ -1,11 +1,24 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { CONTROL_PAD, controlClass } from "./control.js";
2
+ import { controlPad, controlClass, } from "./control.js";
3
3
  import { cx } from "./cx.js";
4
4
  import { useTypeStep } from "./density.js";
5
5
  import { useFieldControl } from "./fieldControl.js";
6
+ /**
7
+ * A box that grows with its text from 2 rows to 8, then scrolls: `field-sizing: content` where the
8
+ * browser has it (newer than the Baseline floor, so feature-detected), else a fixed 2 rows. For the
9
+ * `md` size, whose padding (`py-2`) and border the heights add.
10
+ */
11
+ const GROW = "supports-[field-sizing:content]:[field-sizing:content] supports-[field-sizing:content]:min-h-[calc(2lh+1rem+2px)] max-h-[calc(8lh+1rem+2px)]";
6
12
  /** A multi-line text input, styled like `Input`. `rows` defaults to 3. Takes `size`, `width` and `mono` too. The `ref` reaches the `<textarea>`, for focus control. */
7
13
  export function Textarea({ size = "md", width = "full", mono = false, ...rest }) {
14
+ return _jsx(TextareaControl, { ...rest, size: size, width: width, mono: mono });
15
+ }
16
+ /**
17
+ * `Textarea`, plus `grow` for the library's own boxes (`ChatComposer`): a `md` box that grows from 2
18
+ * rows to 8 with its text. Not exported from `index.ts`.
19
+ */
20
+ export function TextareaControl({ size, width, mono, grow = false, ...rest }) {
8
21
  const step = useTypeStep();
9
22
  const field = useFieldControl(rest);
10
- return (_jsx("textarea", { rows: 3, ...rest, ...field, className: cx(controlClass(size, width, step), CONTROL_PAD[size].x, mono && "font-mono") }));
23
+ return (_jsx("textarea", { rows: grow ? 2 : 3, ...rest, ...field, className: cx(controlClass(size, width, step), controlPad(size), mono && "font-mono", grow && GROW) }));
11
24
  }
@@ -1,4 +1,4 @@
1
- import type { ReactElement, ReactNode } from "react";
1
+ import { type ReactElement, type ReactNode } from "react";
2
2
  import type { Passthrough } from "./props.js";
3
3
  import type { Tone } from "./tone.js";
4
4
  /** One notice in a `ToastRegion`. The caller holds the list; the region draws it. */
@@ -8,7 +8,7 @@ export type Toast = {
8
8
  /** The bold line: the whole message for a short one ("Saved"). */
9
9
  title: string;
10
10
  /** A line of detail under the title. */
11
- body?: ReactNode;
11
+ description?: ReactNode;
12
12
  /**
13
13
  * What the notice means, with `Callout`'s surfaces. A `warn` or `danger` toast never hides itself.
14
14
  * @default neutral
@@ -19,17 +19,20 @@ export type Toast = {
19
19
  };
20
20
  /**
21
21
  * The page's toasts: short notices fixed to the bottom of the viewport, from a list the app holds.
22
- * Mount it once, at the root beside `AppShell`; add a toast to `toasts` to show it, and drop it in
22
+ * Mount it once, at the root beside `AppShell`; add a toast to `items` to show it, and drop it in
23
23
  * `onDismiss` to remove it. A `neutral`, `info` or `positive` toast with no `actions` leaves on its
24
- * own after five seconds (paused while the pointer is over it or focus is in it); a `warn` or
24
+ * own after eight seconds (paused while the pointer is over it or focus is in it); a `warn` or
25
25
  * `danger` toast, or one with `actions`, stays until dismissed. The region is a named landmark with
26
- * a polite `role="status"`, kept in the page while empty, so each new toast is read once. A toast
27
- * raised while a `Dialog` or `Drawer` is open sits under it until it closes.
26
+ * a polite `role="status"` kept in the page while empty, which reads each new toast's text once,
27
+ * followed by "Actions available" when it has actions; its buttons are not read out. A `danger`
28
+ * toast is read through a `role="alert"` beside it instead, so it interrupts. Dismissing the
29
+ * toast that holds focus moves focus to the next toast, or back where it was. A toast raised while a
30
+ * `Dialog`, `Drawer` or `Lightbox` is open is held back (those already shown stay), shown and read once the modal has closed.
28
31
  */
29
- export declare function ToastRegion({ toasts, onDismiss, label, dismissLabel, ...rest }: {
32
+ export declare function ToastRegion({ items, onDismiss, label, dismissLabel, actionsLabel, ...rest }: {
30
33
  /** What is shown, oldest first. `[]` shows nothing and keeps the live region in the page. */
31
- toasts: readonly Toast[];
32
- /** Called by a toast's close button and when a self-hiding toast's time is up: drop it from `toasts`. */
34
+ items: readonly Toast[];
35
+ /** Called by a toast's close button and when a self-hiding toast's time is up: drop it from `items`. */
33
36
  onDismiss: (id: string) => void;
34
37
  /**
35
38
  * The region's accessible name.
@@ -41,4 +44,9 @@ export declare function ToastRegion({ toasts, onDismiss, label, dismissLabel, ..
41
44
  * @default Dismiss
42
45
  */
43
46
  dismissLabel?: string | undefined;
47
+ /**
48
+ * Read after a toast that has `actions`, so a screen reader user knows to go and find them.
49
+ * @default Actions available
50
+ */
51
+ actionsLabel?: string | undefined;
44
52
  } & Passthrough): ReactElement;
@@ -1,37 +1,94 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useRef, useState, } from "react";
2
3
  import { TONE_SURFACE, TONE_TEXT } from "./Callout.js";
3
4
  import { cx } from "./cx.js";
4
5
  import { IconButton } from "./IconButton.js";
6
+ import { useModalOpen } from "./modal.js";
5
7
  // The hide is CSS, not a timer. A toast that may leave on its own carries `data-toast-hide`: it is
6
- // shown for five seconds, then fades for 200ms, and the animation's end calls `onDismiss`, so the
7
- // caller drops it from the list, as `CopyButton` clears its copied state. Hovering the region or
8
- // focusing anything in it pauses the run. Under reduced motion the same run holds a discrete
9
- // `visibility` keyframe instead of the fade, so the toast still leaves at the same moment.
10
- const css = `[data-toast-hide]{animation:hc-toast-hide .2s ease-in 5s forwards}[data-hc-toasts]:hover [data-toast-hide],[data-hc-toasts]:focus-within [data-toast-hide]{animation-play-state:paused}@keyframes hc-toast-hide{to{opacity:0}}@media (prefers-reduced-motion:reduce){[data-toast-hide]{animation-name:hc-toast-cut}}@keyframes hc-toast-cut{from,to{visibility:visible}}`;
8
+ // shown for eight seconds, then fades for 200ms, and the animation's end calls `onDismiss`, so the
9
+ // caller drops it from the list. Hovering the region or focusing anything in it pauses the run.
10
+ // Under reduced motion the same run holds a discrete `visibility` keyframe instead of the fade, so
11
+ // the toast still leaves at the same moment.
12
+ const css = `[data-toast-hide]{animation:hc-toast-hide .2s ease-in 8s forwards}[data-hc-toasts]:hover [data-toast-hide],[data-hc-toasts]:focus-within [data-toast-hide]{animation-play-state:paused}@keyframes hc-toast-hide{to{opacity:0}}@media (prefers-reduced-motion:reduce){[data-toast-hide]{animation-name:hc-toast-cut}}@keyframes hc-toast-cut{from,to{visibility:visible}}`;
11
13
  /** Only a plain confirmation leaves on its own: no action to reach, nothing that must be read. */
12
14
  function hides(toast) {
13
15
  const tone = toast.tone ?? "neutral";
14
16
  return toast.actions == null && (tone === "neutral" || tone === "info" || tone === "positive");
15
17
  }
16
- function ToastItem({ toast, dismissLabel, onDismiss, }) {
18
+ /**
19
+ * Puts the toast's words in the live region once, when it first shows, and takes them out when it
20
+ * goes: the title, the description's text, and `actionsLabel` when it has actions. The buttons themselves
21
+ * are never read out as part of the notice.
22
+ */
23
+ function useAnnounce(live, title, actionsLabel) {
24
+ const body = useRef(null);
25
+ useEffect(() => {
26
+ const line = document.createElement("p");
27
+ line.textContent = [title, body.current?.textContent, actionsLabel].filter(Boolean).join(". ");
28
+ live.current?.append(line);
29
+ return () => line.remove();
30
+ }, [live, title, actionsLabel]);
31
+ return body;
32
+ }
33
+ /**
34
+ * Where focus goes when the toast holding it is dismissed: the next toast's dismiss button, else the
35
+ * one before, else back where it was before it came into the region.
36
+ */
37
+ function focusAfter(toast, back) {
38
+ if (!toast.contains(document.activeElement))
39
+ return;
40
+ const sibling = toast.nextElementSibling ?? toast.previousElementSibling;
41
+ const next = sibling?.querySelector("[data-toast-dismiss]");
42
+ if (next)
43
+ return next.focus();
44
+ if (back.current?.isConnected)
45
+ back.current.focus();
46
+ back.current = null;
47
+ }
48
+ function ToastItem({ toast, dismissLabel, actionsLabel, live, alert, back, onDismiss, }) {
17
49
  const tone = toast.tone ?? "neutral";
18
50
  const hide = hides(toast);
51
+ const body = useAnnounce(tone === "danger" ? alert : live, toast.title, toast.actions == null ? null : actionsLabel);
19
52
  return (_jsxs("div", { "data-toast": "", "data-toast-hide": hide ? "" : undefined, onAnimationEnd: (event) => {
20
53
  // A child's animation (a busy Button's spinner) bubbles here too: only the toast's own
21
54
  // animation, which is the hide, counts.
22
55
  if (hide && event.target === event.currentTarget)
23
56
  onDismiss(toast.id);
24
- }, className: cx("pointer-events-auto flex items-start gap-3 rounded-xl border p-3 pl-4 text-sm shadow-lg", TONE_SURFACE[tone], TONE_TEXT[tone]), children: [_jsxs("div", { className: "min-w-0 flex-1 py-0.5", children: [_jsx("p", { className: "font-semibold", children: toast.title }), toast.body != null && _jsx("div", { className: "mt-1", children: toast.body })] }), toast.actions != null && (_jsx("div", { className: "flex shrink-0 items-center gap-2", children: toast.actions })), _jsx(IconButton, { size: "sm", variant: "ghost", icon: "close", label: dismissLabel, onClick: () => onDismiss(toast.id) })] }));
57
+ }, className: cx("pointer-events-auto flex items-start gap-3 rounded-xl border p-3 pl-4 text-sm shadow-lg", TONE_SURFACE[tone], TONE_TEXT[tone]), children: [_jsxs("div", { className: "min-w-0 flex-1 py-0.5", children: [_jsx("p", { className: "font-semibold", children: toast.title }), toast.description != null && (_jsx("div", { ref: body, className: "mt-1", children: toast.description }))] }), toast.actions != null && (_jsx("div", { className: "flex shrink-0 items-center gap-2", children: toast.actions })), _jsx(IconButton, { size: "sm", variant: "ghost", icon: "close", label: dismissLabel, "data-toast-dismiss": "", onClick: (event) => {
58
+ const box = event.currentTarget.closest("[data-toast]");
59
+ if (box)
60
+ focusAfter(box, back);
61
+ onDismiss(toast.id);
62
+ } })] }));
25
63
  }
26
64
  /**
27
65
  * The page's toasts: short notices fixed to the bottom of the viewport, from a list the app holds.
28
- * Mount it once, at the root beside `AppShell`; add a toast to `toasts` to show it, and drop it in
66
+ * Mount it once, at the root beside `AppShell`; add a toast to `items` to show it, and drop it in
29
67
  * `onDismiss` to remove it. A `neutral`, `info` or `positive` toast with no `actions` leaves on its
30
- * own after five seconds (paused while the pointer is over it or focus is in it); a `warn` or
68
+ * own after eight seconds (paused while the pointer is over it or focus is in it); a `warn` or
31
69
  * `danger` toast, or one with `actions`, stays until dismissed. The region is a named landmark with
32
- * a polite `role="status"`, kept in the page while empty, so each new toast is read once. A toast
33
- * raised while a `Dialog` or `Drawer` is open sits under it until it closes.
70
+ * a polite `role="status"` kept in the page while empty, which reads each new toast's text once,
71
+ * followed by "Actions available" when it has actions; its buttons are not read out. A `danger`
72
+ * toast is read through a `role="alert"` beside it instead, so it interrupts. Dismissing the
73
+ * toast that holds focus moves focus to the next toast, or back where it was. A toast raised while a
74
+ * `Dialog`, `Drawer` or `Lightbox` is open is held back (those already shown stay), shown and read once the modal has closed.
34
75
  */
35
- export function ToastRegion({ toasts, onDismiss, label = "Notifications", dismissLabel = "Dismiss", ...rest }) {
36
- return (_jsxs("section", { "aria-label": label, ...rest, "data-hc-toasts": "", className: "pointer-events-none fixed inset-x-0 bottom-0 z-50 flex justify-center px-4 pb-[max(1rem,env(safe-area-inset-bottom))]", children: [_jsx("style", { children: css }), _jsx("div", { role: "status", "aria-live": "polite", "aria-atomic": "false", className: "flex w-full max-w-sm flex-col gap-2", children: toasts.map((toast) => (_jsx(ToastItem, { toast: toast, dismissLabel: dismissLabel, onDismiss: onDismiss }, toast.id))) })] }));
76
+ export function ToastRegion({ items, onDismiss, label = "Notifications", dismissLabel = "Dismiss", actionsLabel = "Actions available", ...rest }) {
77
+ const live = useRef(null);
78
+ const alert = useRef(null);
79
+ /** What had focus before it came into the region, to hand it back when the last toast goes. */
80
+ const back = useRef(null);
81
+ const held = useModalOpen();
82
+ // The toasts on screen when a modal opened stay; only newer ones are held back. The ids shown
83
+ // are kept from the last render with no modal open, adjusted during render rather than in an effect.
84
+ const [kept, setKept] = useState([]);
85
+ const ids = items.map((toast) => toast.id);
86
+ if (!held && ids.join("\n") !== kept.join("\n"))
87
+ setKept(ids);
88
+ const visible = held ? items.filter((toast) => kept.includes(toast.id)) : items;
89
+ return (_jsxs("section", { "aria-label": label, ...rest, "data-hc-toasts": "", onFocus: (event) => {
90
+ const from = event.relatedTarget;
91
+ if (from instanceof HTMLElement && !event.currentTarget.contains(from))
92
+ back.current = from;
93
+ }, className: "pointer-events-none fixed inset-x-0 bottom-0 z-50 flex justify-center px-4 pb-[max(1rem,env(safe-area-inset-bottom))]", children: [_jsx("style", { children: css }), _jsx("div", { ref: live, role: "status", "aria-live": "polite", "aria-atomic": "false", className: "sr-only" }), _jsx("div", { ref: alert, role: "alert", "aria-atomic": "false", className: "sr-only" }), _jsx("div", { className: "flex w-full max-w-sm flex-col gap-2", children: visible.map((toast) => (_jsx(ToastItem, { toast: toast, dismissLabel: dismissLabel, actionsLabel: actionsLabel, live: live, alert: alert, back: back, onDismiss: onDismiss }, toast.id))) })] }));
37
94
  }
package/dist/Tooltip.d.ts CHANGED
@@ -23,16 +23,24 @@ type Options = {
23
23
  describes: boolean;
24
24
  /** A touch tap on the trigger shows the tooltip, and the next tap anywhere hides it. */
25
25
  tap?: boolean | undefined;
26
+ /**
27
+ * The keyboard's focus, for a trigger that cannot hear it: a run inside a grid row, where the row
28
+ * takes the focus. While `true` the tooltip shows as for a focus on the trigger; the caller sets
29
+ * it back to `false` on blur and on Escape.
30
+ */
31
+ focused?: boolean | undefined;
26
32
  };
27
33
  /**
28
34
  * Wires one internal tooltip to a trigger. Spread `props` on the trigger after the caller's own
29
35
  * props: it holds the same keys, merged (`aria-describedby` and the handlers keep the caller's), and
30
36
  * render `tooltip` right after the trigger. With no `text`, `props` is `own` unchanged and
31
- * `tooltip` is null. Internal: not exported from the package.
37
+ * `tooltip` is null. `enhanced` is false where the tooltip falls back to the native `title` (no
38
+ * anchor positioning, and the server markup), which a hover shows but focus never does. Internal: not exported from the package.
32
39
  */
33
- export declare function useTooltip<E extends Element>(text: string | undefined, { describes, tap }: Options, own: TriggerOwn<E>): {
40
+ export declare function useTooltip<E extends Element>(text: string | undefined, { describes, tap, focused }: Options, own: TriggerOwn<E>): {
34
41
  props: TriggerProps<E>;
35
42
  tooltip: ReactNode;
43
+ enhanced: boolean;
36
44
  };
37
45
  /**
38
46
  * `useTooltip` as a part, for a component that picks its element in a branch: `children` draws the
package/dist/Tooltip.js CHANGED
@@ -39,10 +39,19 @@ function useLayer(layer, open) {
39
39
  useEffect(() => {
40
40
  if (!layer)
41
41
  return;
42
- if (open)
43
- layer.showPopover();
44
- else
42
+ if (!open) {
45
43
  layer.hidePopover();
44
+ return;
45
+ }
46
+ // A popover that closes puts the focus back on its trigger while it is still hiding, and the
47
+ // browser refuses to show another one then: the tip stays shut, and the next focus shows it.
48
+ try {
49
+ layer.showPopover();
50
+ }
51
+ catch (error) {
52
+ if (!(error instanceof DOMException && error.name === "InvalidStateError"))
53
+ throw error;
54
+ }
46
55
  }, [layer, open]);
47
56
  }
48
57
  /** While a tap holds the tooltip open, the next tap anywhere but the trigger closes it. */
@@ -78,6 +87,12 @@ function useEscape(on, close) {
78
87
  return () => document.removeEventListener("keydown", escape, true);
79
88
  }, [on, close]);
80
89
  }
90
+ /** Why the tooltip shows: its own reason, else a focus the trigger cannot hear (the caller hides it again on Escape). */
91
+ function shownVia(via, focused) {
92
+ if (via !== null)
93
+ return via;
94
+ return focused ? "focus" : null;
95
+ }
81
96
  /** The pointer left the trigger or the tooltip: close a hover tip, unless it moved onto the other. */
82
97
  function leave(tip, related, from) {
83
98
  const other = from === "trigger" ? tip.layer : tip.trigger;
@@ -137,9 +152,10 @@ function handlers(own, tip) {
137
152
  * Wires one internal tooltip to a trigger. Spread `props` on the trigger after the caller's own
138
153
  * props: it holds the same keys, merged (`aria-describedby` and the handlers keep the caller's), and
139
154
  * render `tooltip` right after the trigger. With no `text`, `props` is `own` unchanged and
140
- * `tooltip` is null. Internal: not exported from the package.
155
+ * `tooltip` is null. `enhanced` is false where the tooltip falls back to the native `title` (no
156
+ * anchor positioning, and the server markup), which a hover shows but focus never does. Internal: not exported from the package.
141
157
  */
142
- export function useTooltip(text, { describes, tap = false }, own) {
158
+ export function useTooltip(text, { describes, tap = false, focused }, own) {
143
159
  const id = useId();
144
160
  // False in the server markup and while the client hydrates, so both render the native `title`.
145
161
  const enhanced = useSyncExternalStore(never, anchorPositioning, () => false);
@@ -148,13 +164,18 @@ export function useTooltip(text, { describes, tap = false }, own) {
148
164
  const [layer, setLayer] = useState(null);
149
165
  const [pressed, setPressed] = useState(false);
150
166
  const close = useCallback(() => setVia(null), []);
151
- useLayer(layer, via !== null);
167
+ const shown = shownVia(via, focused);
168
+ useLayer(layer, shown !== null);
152
169
  useTapAway(via === "tap", trigger, close);
153
170
  useEscape(via !== null, close);
154
- if (text === undefined || text === "")
155
- return { props: own, tooltip: null };
171
+ // A tip whose text went empty while open closes, so it does not come back open with new text.
172
+ if (!text) {
173
+ if (via !== null)
174
+ setVia(null);
175
+ return { props: own, tooltip: null, enhanced };
176
+ }
156
177
  if (!enhanced)
157
- return { props: { ...own, title: text }, tooltip: null };
178
+ return { props: { ...own, title: text }, tooltip: null, enhanced };
158
179
  const tip = { via, setVia, trigger, setTrigger, layer, pressed, setPressed, tap };
159
180
  const anchor = `--hc-tip${id.replaceAll(/[^a-zA-Z0-9_-]/g, "")}`;
160
181
  const tipId = `${id}-tip`;
@@ -168,8 +189,8 @@ export function useTooltip(text, { describes, tap = false }, own) {
168
189
  "aria-describedby": describedBy || undefined,
169
190
  style: { anchorName: anchor },
170
191
  };
171
- const tooltip = (_jsxs(_Fragment, { children: [_jsx("style", { children: css }), _jsx("span", { ref: setLayer, id: tipId, role: "tooltip", popover: "manual", "data-hc-tooltip": "", "data-via": via ?? undefined, "aria-hidden": describes ? undefined : true, style: { positionAnchor: anchor }, onPointerLeave: (event) => leave(tip, event.relatedTarget, "tooltip"), children: _jsx("span", { className: CHIP, children: text }) })] }));
172
- return { props, tooltip };
192
+ const tooltip = (_jsxs(_Fragment, { children: [_jsx("style", { children: css }), _jsx("span", { ref: setLayer, id: tipId, role: "tooltip", popover: "manual", "data-hc-tooltip": "", "data-via": shown ?? undefined, "aria-hidden": describes ? undefined : true, style: { positionAnchor: anchor }, onPointerLeave: (event) => leave(tip, event.relatedTarget, "tooltip"), children: _jsx("span", { className: CHIP, children: text }) })] }));
193
+ return { props, tooltip, enhanced };
173
194
  }
174
195
  /**
175
196
  * `useTooltip` as a part, for a component that picks its element in a branch: `children` draws the
package/dist/Video.d.ts CHANGED
@@ -1,13 +1,28 @@
1
1
  import type { ReactElement, VideoHTMLAttributes } from "react";
2
+ import { type ImageAspect } from "./Image.js";
2
3
  import type { Unstyled } from "./props.js";
3
4
  /**
4
- * A `<video>` with controls, full width and rounded; it loads metadata only, so the page does not
5
- * pull the file until it is played. `src` is the app's own video; `captions` is a WebVTT file,
6
- * offered as the default track. `children` is the fallback for a browser that cannot play it.
5
+ * `loading="lazy"` on a media element: the browser holds back even the metadata of one far below
6
+ * the fold. React passes the attribute through, but its types know it only on `<img>` and
7
+ * `<iframe>`, so it is spread from here; a browser without it ignores it and loads as before.
7
8
  */
8
- export declare function Video({ src, captions, children, ...rest }: {
9
+ export declare const LAZY_MEDIA: Record<string, string>;
10
+ /**
11
+ * A `<video>` with controls, full width and rounded, in a fixed shape: `aspect` reserves its space
12
+ * before it loads, so the page does not jump, and the video fits inside it whole. It loads metadata
13
+ * only, and lazily where the browser can, so the page does not pull the file until it is played.
14
+ * `src` is the app's own video; `captions` is a WebVTT file, offered as the default track.
15
+ * `children` is the fallback for a browser that cannot play it.
16
+ */
17
+ export declare function Video({ src, captions, aspect, children, ...rest }: {
9
18
  /** The video file, the app's own. */
10
19
  src: string;
11
20
  /** A WebVTT file, offered as the default captions track. */
12
21
  captions?: string | undefined;
22
+ /**
23
+ * The shape it reserves, as `Image`'s `aspect`: `16:9`, `16:10`, `4:3`, `3:2`, `square`, or the
24
+ * portrait `3:4` and `9:16`. A video of another shape fits inside it, letterboxed.
25
+ * @default 16:9
26
+ */
27
+ aspect?: Exclude<ImageAspect, "natural"> | undefined;
13
28
  } & Unstyled<Omit<VideoHTMLAttributes<HTMLVideoElement>, "src" | "controls">>): ReactElement;