@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/navFold.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { useEffect, useRef, useState } from "react";
2
+ import { observeItems } from "./scrollEdges.js";
2
3
  // AppShell's `md` step: below it the nav is always in the Menu, so nothing is measured there.
3
4
  const WIDE = "(width >= 48rem)";
4
5
  /**
@@ -23,6 +24,8 @@ export function useNavFold(row, enabled) {
23
24
  return undefined;
24
25
  const wide = window.matchMedia(WIDE);
25
26
  const check = () => {
27
+ // A slot hidden when the effect ran (the closed Menu below `md`) is picked up once shown.
28
+ observeItems(observer, row);
26
29
  if (!wide.matches)
27
30
  return;
28
31
  const now = state.current;
@@ -36,10 +39,10 @@ export function useNavFold(row, enabled) {
36
39
  };
37
40
  const observer = new ResizeObserver(check);
38
41
  // The row is the header's width, so it resizes only with the screen; its slots resize with
39
- // their content (a font swap, a label that changes), so they are watched too.
42
+ // their content (a font swap, a label that changes), so they are watched too, through the
43
+ // menu panel, which draws no box of its own in the row.
40
44
  observer.observe(row);
41
- for (const slot of row.children)
42
- observer.observe(slot);
45
+ observeItems(observer, row);
43
46
  return () => observer.disconnect();
44
47
  });
45
48
  return enabled && folded;
@@ -0,0 +1,18 @@
1
+ /** A choice's look: `plain` is the mark and its words; `card` puts them in a bordered box, the whole box the click target. */
2
+ export type ChoiceVariant = "plain" | "card";
3
+ /**
4
+ * The box of a `card` choice (a `Checkbox`, a `Radio`): full width, padded, the control's border
5
+ * colour, and the hover edge of a field. Its parent is `relative` (the touch target's), so the
6
+ * chosen edge below sits on it.
7
+ */
8
+ export declare const OPTION_CARD = "w-full rounded-lg border border-slate-300 bg-white p-3 transition";
9
+ /** A card's edge under the pointer, when it is enabled. */
10
+ export declare const OPTION_CARD_HOVER = "hover:border-violet-400";
11
+ /**
12
+ * The chosen card's edge: a 2px accent border drawn over the card's own, so the words do not move.
13
+ * It is shown by the caller (`visible` from the input's state), so a card that keeps its own state
14
+ * changes with no re-render.
15
+ */
16
+ export declare const OPTION_CARD_CHOSEN = "pointer-events-none absolute -inset-px rounded-lg border-2 border-violet-600";
17
+ /** The card's title: a step heavier than a plain choice's words, as a card's heading is. */
18
+ export declare const OPTION_CARD_TITLE = "font-medium text-slate-900";
@@ -0,0 +1,16 @@
1
+ /**
2
+ * The box of a `card` choice (a `Checkbox`, a `Radio`): full width, padded, the control's border
3
+ * colour, and the hover edge of a field. Its parent is `relative` (the touch target's), so the
4
+ * chosen edge below sits on it.
5
+ */
6
+ export const OPTION_CARD = "w-full rounded-lg border border-slate-300 bg-white p-3 transition";
7
+ /** A card's edge under the pointer, when it is enabled. */
8
+ export const OPTION_CARD_HOVER = "hover:border-violet-400";
9
+ /**
10
+ * The chosen card's edge: a 2px accent border drawn over the card's own, so the words do not move.
11
+ * It is shown by the caller (`visible` from the input's state), so a card that keeps its own state
12
+ * changes with no re-render.
13
+ */
14
+ export const OPTION_CARD_CHOSEN = "pointer-events-none absolute -inset-px rounded-lg border-2 border-violet-600";
15
+ /** The card's title: a step heavier than a plain choice's words, as a card's heading is. */
16
+ export const OPTION_CARD_TITLE = "font-medium text-slate-900";
@@ -0,0 +1,16 @@
1
+ import type { ReactElement, ReactNode } from "react";
2
+ /**
3
+ * A box that scrolls (a `Drawer`'s or a `BottomSheet`'s body, a filled `Card`'s body, a
4
+ * `CodeExample`'s preview), with the keyboard side `useScrollStop` gives it: while it overflows and
5
+ * holds nothing the keyboard can reach, it takes a tab stop, a group named by `label` or
6
+ * `labelledBy`. Its ring is drawn inside it, since each of these sits in a frame that clips.
7
+ * Internal: `className` is the library's own.
8
+ */
9
+ export declare function ScrollBody({ axis, label, labelledBy, id, className, children, }: {
10
+ axis?: "x" | "y";
11
+ label?: string | undefined;
12
+ labelledBy?: string | undefined;
13
+ id?: string | undefined;
14
+ className: string;
15
+ children: ReactNode;
16
+ }): ReactElement;
@@ -0,0 +1,15 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { cx, insetFocusRing } from "./cx.js";
3
+ import { scrollStopProps, useScrollStop } from "./scrollStop.js";
4
+ /**
5
+ * A box that scrolls (a `Drawer`'s or a `BottomSheet`'s body, a filled `Card`'s body, a
6
+ * `CodeExample`'s preview), with the keyboard side `useScrollStop` gives it: while it overflows and
7
+ * holds nothing the keyboard can reach, it takes a tab stop, a group named by `label` or
8
+ * `labelledBy`. Its ring is drawn inside it, since each of these sits in a frame that clips.
9
+ * Internal: `className` is the library's own.
10
+ */
11
+ export function ScrollBody({ axis = "y", label, labelledBy, id, className, children, }) {
12
+ const { attach, stop } = useScrollStop(axis);
13
+ const { props } = scrollStopProps(stop, { label, labelledBy });
14
+ return (_jsx("div", { ref: attach, id: id, ...props, className: cx(className, stop && insetFocusRing), children: children }));
15
+ }
@@ -1,3 +1,10 @@
1
+ /**
2
+ * Observes each child of `box` that draws a box and is not watched yet. A ResizeObserver never
3
+ * fires for a `display: contents` element (it has no box), so such a child is looked through and
4
+ * its own children are observed instead, down any depth. A hidden child is skipped; call it again
5
+ * once it may show (from the observer's callback), and only the new ones are added.
6
+ */
7
+ export declare function observeItems(observer: ResizeObserver, box: Element): void;
1
8
  /**
2
9
  * Marks a box that scrolls with which of its edges still has content past it, so the layout can fade
3
10
  * them: `data-more-start` (scrolled away from the start), `data-more-end` (more to scroll to) and
@@ -1,4 +1,28 @@
1
1
  import { useEffect } from "react";
2
+ // What each observer already watches. Observing an element again restarts it, which reports its
3
+ // size once more and, from inside the callback, would loop.
4
+ const watched = new WeakMap();
5
+ /**
6
+ * Observes each child of `box` that draws a box and is not watched yet. A ResizeObserver never
7
+ * fires for a `display: contents` element (it has no box), so such a child is looked through and
8
+ * its own children are observed instead, down any depth. A hidden child is skipped; call it again
9
+ * once it may show (from the observer's callback), and only the new ones are added.
10
+ */
11
+ export function observeItems(observer, box) {
12
+ const seen = watched.get(observer) ?? new WeakSet();
13
+ watched.set(observer, seen);
14
+ for (const child of box.children) {
15
+ const display = getComputedStyle(child).display;
16
+ if (display === "none")
17
+ continue;
18
+ if (display === "contents")
19
+ observeItems(observer, child);
20
+ else if (!seen.has(child)) {
21
+ seen.add(child);
22
+ observer.observe(child);
23
+ }
24
+ }
25
+ }
2
26
  /**
3
27
  * Marks a box that scrolls with which of its edges still has content past it, so the layout can fade
4
28
  * them: `data-more-start` (scrolled away from the start), `data-more-end` (more to scroll to) and
@@ -17,7 +41,8 @@ export function useScrollEdges(element, axis) {
17
41
  const el = element;
18
42
  const update = () => {
19
43
  const [position, scrollSize, clientSize] = axis === "x"
20
- ? [el.scrollLeft, el.scrollWidth, el.clientWidth]
44
+ ? // Right to left, scrollLeft runs from 0 at the start to negative at the end.
45
+ [Math.abs(el.scrollLeft), el.scrollWidth, el.clientWidth]
21
46
  : [el.scrollTop, el.scrollHeight, el.clientHeight];
22
47
  const start = position > 1;
23
48
  const end = scrollSize - clientSize - position > 1;
@@ -28,10 +53,19 @@ export function useScrollEdges(element, axis) {
28
53
  update();
29
54
  el.addEventListener("scroll", update, { passive: true });
30
55
  // jsdom (a consumer's own tests) has no ResizeObserver.
31
- const resize = typeof ResizeObserver === "undefined" ? undefined : new ResizeObserver(update);
32
- resize?.observe(el);
33
- for (const child of el.children)
34
- resize?.observe(child);
56
+ // Each resize looks for items again: one hidden when the effect ran (`display: none` below a
57
+ // breakpoint) is observed once it shows. Observing an item twice is a no-op.
58
+ const resize = typeof ResizeObserver === "undefined"
59
+ ? undefined
60
+ : new ResizeObserver(() => {
61
+ if (resize)
62
+ observeItems(resize, el);
63
+ update();
64
+ });
65
+ if (resize) {
66
+ resize.observe(el);
67
+ observeItems(resize, el);
68
+ }
35
69
  return () => {
36
70
  el.removeEventListener("scroll", update);
37
71
  resize?.disconnect();
@@ -11,13 +11,17 @@ export declare const TABBABLE = ":is(a[href], button, input:not([type=\"hidden\"
11
11
  * scrolls: "y" (down, the default) or "x" (sideways); overflow the other way is not measured,
12
12
  * since the box does not scroll that way. `measured` is false until the box has been measured once
13
13
  * and true after: a page rendered to HTML and never hydrated is never measured, and neither is a
14
- * box where `ResizeObserver` is missing (a consumer's jsdom tests with no stub).
14
+ * box where `ResizeObserver` is missing (a consumer's jsdom tests with no stub). `overflows` is
15
+ * whether the box overflowed when last measured. `wider`, for a box that may stop scrolling while it
16
+ * fits (a `Table`'s, which clips instead so its head can stick to the page), measures the overflow
17
+ * from the content instead of the box's own scroll width.
15
18
  */
16
- export declare function useScrollStop(axis?: "x" | "y"): {
19
+ export declare function useScrollStop(axis?: "x" | "y", wider?: (box: HTMLElement) => boolean): {
17
20
  element: HTMLElement | null;
18
21
  attach: (el: HTMLDivElement | null) => void;
19
22
  stop: boolean;
20
23
  measured: boolean;
24
+ overflows: boolean;
21
25
  };
22
26
  /**
23
27
  * The props a scroller takes while it holds the tab stop: focusable, ringed and, when the column
@@ -22,21 +22,31 @@ function holdsTabbable(scroller) {
22
22
  * scrolls: "y" (down, the default) or "x" (sideways); overflow the other way is not measured,
23
23
  * since the box does not scroll that way. `measured` is false until the box has been measured once
24
24
  * and true after: a page rendered to HTML and never hydrated is never measured, and neither is a
25
- * box where `ResizeObserver` is missing (a consumer's jsdom tests with no stub).
25
+ * box where `ResizeObserver` is missing (a consumer's jsdom tests with no stub). `overflows` is
26
+ * whether the box overflowed when last measured. `wider`, for a box that may stop scrolling while it
27
+ * fits (a `Table`'s, which clips instead so its head can stick to the page), measures the overflow
28
+ * from the content instead of the box's own scroll width.
26
29
  */
27
- export function useScrollStop(axis = "y") {
30
+ export function useScrollStop(axis = "y", wider) {
28
31
  const [element, setElement] = useState(null);
29
32
  const [stop, setStop] = useState(false);
30
33
  const [measured, setMeasured] = useState(false);
34
+ const [overflowing, setOverflowing] = useState(false);
31
35
  useEffect(() => {
32
36
  // jsdom (a consumer's own tests) has no ResizeObserver.
33
37
  if (!element || typeof ResizeObserver === "undefined")
34
38
  return undefined;
35
- const overflows = () => axis === "y"
36
- ? element.scrollHeight > element.clientHeight
37
- : element.scrollWidth > element.clientWidth;
39
+ const overflows = () => {
40
+ if (wider)
41
+ return wider(element);
42
+ return axis === "y"
43
+ ? element.scrollHeight > element.clientHeight
44
+ : element.scrollWidth > element.clientWidth;
45
+ };
38
46
  const measure = () => {
39
- setStop(overflows() && !holdsTabbable(element));
47
+ const over = overflows();
48
+ setOverflowing(over);
49
+ setStop(over && !holdsTabbable(element));
40
50
  setMeasured(true);
41
51
  };
42
52
  // Each observer reports once when it starts, and again when the box is resized, its content
@@ -56,8 +66,14 @@ export function useScrollStop(axis = "y") {
56
66
  resize.disconnect();
57
67
  change.disconnect();
58
68
  };
59
- }, [element, axis]);
60
- return { element, attach: setElement, stop: stop && element !== null, measured };
69
+ }, [element, axis, wider]);
70
+ return {
71
+ element,
72
+ attach: setElement,
73
+ stop: stop && element !== null,
74
+ measured,
75
+ overflows: overflowing && element !== null,
76
+ };
61
77
  }
62
78
  /**
63
79
  * The props a scroller takes while it holds the tab stop: focusable, ringed and, when the column
@@ -1,12 +1,28 @@
1
- import type { CalendarDate } from "@internationalized/date";
1
+ import { type CalendarDate, type CalendarDateTime, type DateValue } from "@internationalized/date";
2
2
  import { type FocusEvent, type ReactElement } from "react";
3
3
  import type { FieldProps, Read } from "./DateField.js";
4
- type ValueKeys = "value" | "defaultValue" | "onChange" | "minValue" | "maxValue" | "isRequired";
4
+ /** What a typed field holds: its value type, how it is written as ISO text, and how fine it is. */
5
+ export type Kind<T extends CalendarDate | CalendarDateTime> = {
6
+ granularity: "day" | "minute";
7
+ toISO: (value: T | null | undefined) => string;
8
+ fromISO: (iso: string) => T | null;
9
+ /** The field's value as this kind's own type. */
10
+ narrow: (value: DateValue | null) => T | null;
11
+ /** The message for a required field left partly typed. */
12
+ whole: string;
13
+ };
14
+ /** A day: `YYYY-MM-DD`. */
15
+ export declare const DATE: Kind<CalendarDate>;
16
+ /** A day and a time to the minute: `YYYY-MM-DDTHH:mm`. */
17
+ export declare const DATE_TIME: Kind<CalendarDateTime>;
5
18
  /** The value props, each of which may be passed as `undefined`. */
6
- type ValueProps = {
7
- [K in ValueKeys]?: (FieldProps & {
8
- isRequired?: boolean;
9
- })[K] | undefined;
19
+ type ValueProps<T> = {
20
+ value?: T | null | undefined;
21
+ defaultValue?: T | null | undefined;
22
+ onChange?: ((value: T | null) => void) | null | undefined;
23
+ minValue?: DateValue | null | undefined;
24
+ maxValue?: DateValue | null | undefined;
25
+ isRequired?: boolean | undefined;
10
26
  };
11
27
  /**
12
28
  * The value the field reports is always what it shows: the typed date when it is complete, exists
@@ -27,13 +43,13 @@ type ValueProps = {
27
43
  *
28
44
  * `shown` (`YYYY-MM-DD` or `""`) is what the hidden `name` input posts.
29
45
  */
30
- export declare function useShownDate(props: ValueProps): {
31
- inner: CalendarDate | null;
32
- setInner: import("react").Dispatch<import("react").SetStateAction<CalendarDate | null>>;
46
+ export declare function useShownDate<T extends CalendarDate | CalendarDateTime>(props: ValueProps<T>, kind: Kind<T>): {
47
+ inner: T | null;
48
+ setInner: import("react").Dispatch<import("react").SetStateAction<T | null>>;
33
49
  shown: string;
34
50
  impossible: string | null;
35
51
  onRead: (next: Read) => void;
36
- validate: () => "Enter the whole date." | null;
52
+ validate: () => string | null;
37
53
  leaving: boolean;
38
54
  onBlurCapture: (event: FocusEvent<HTMLElement>) => void;
39
55
  onLeft: () => void;
@@ -50,6 +66,8 @@ type RangeProps = {
50
66
  minValue?: FieldProps["minValue"] | undefined;
51
67
  maxValue?: FieldProps["maxValue"] | undefined;
52
68
  isRequired?: boolean | undefined;
69
+ /** The start and end side's names, which start an impossible day's message. */
70
+ labels: [string, string];
53
71
  };
54
72
  /**
55
73
  * `useShownDate` for a range: each side's segments are read on their own, and the range reported is
package/dist/shownDate.js CHANGED
@@ -1,15 +1,34 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { toCalendarDate, toCalendarDateTime, } from "@internationalized/date";
2
3
  import { useCallback, useEffect, useRef, useState, } from "react";
3
4
  import { flushSync } from "react-dom";
4
- import { fromISODate, toISODate } from "./isoDate.js";
5
+ import { fromISODate, fromISODateTime, toISODate, toISODateTime } from "./isoDate.js";
6
+ /** A day: `YYYY-MM-DD`. */
7
+ export const DATE = {
8
+ granularity: "day",
9
+ toISO: toISODate,
10
+ fromISO: fromISODate,
11
+ narrow: (value) => value && toCalendarDate(value),
12
+ whole: "Enter the whole date.",
13
+ };
14
+ /** A day and a time to the minute: `YYYY-MM-DDTHH:mm`. */
15
+ export const DATE_TIME = {
16
+ granularity: "minute",
17
+ toISO: toISODateTime,
18
+ fromISO: fromISODateTime,
19
+ narrow: (value) => value && toCalendarDateTime(value),
20
+ whole: "Enter the whole date and time.",
21
+ };
22
+ /** `a` is before (negative), at (0) or after (positive) `b`, to the minute. */
23
+ const compare = (a, b) => toCalendarDateTime(a).compare(toCalendarDateTime(b));
5
24
  /** `iso` when it is a date within min/max, else `""`. */
6
- function withinRange(iso, { minValue, maxValue }) {
7
- const date = fromISODate(iso);
25
+ function withinRange(iso, { minValue, maxValue }, kind) {
26
+ const date = kind.fromISO(iso);
8
27
  if (!date)
9
28
  return "";
10
- if (minValue && date.compare(minValue) < 0)
29
+ if (minValue && compare(date, minValue) < 0)
11
30
  return "";
12
- if (maxValue && date.compare(maxValue) > 0)
31
+ if (maxValue && compare(date, maxValue) > 0)
13
32
  return "";
14
33
  return iso;
15
34
  }
@@ -32,23 +51,23 @@ function withinRange(iso, { minValue, maxValue }) {
32
51
  *
33
52
  * `shown` (`YYYY-MM-DD` or `""`) is what the hidden `name` input posts.
34
53
  */
35
- export function useShownDate(props) {
54
+ export function useShownDate(props, kind) {
36
55
  const { value, defaultValue, onChange, isRequired } = props;
37
56
  const [inner, setInner] = useState(value ?? defaultValue ?? null);
38
57
  const [read, setRead] = useState({
39
- typed: toISODate(inner),
58
+ typed: kind.toISO(inner),
40
59
  impossible: null,
41
60
  partial: false,
42
61
  });
43
62
  const side = useLeaving(read.impossible);
44
- const shown = withinRange(read.typed, props);
63
+ const shown = withinRange(read.typed, props, kind);
45
64
  const reported = useRef(shown);
46
65
  const report = useRef(onChange);
47
66
  useEffect(() => {
48
67
  report.current = onChange;
49
68
  });
50
- const given = value === undefined ? undefined : toISODate(value);
51
- const givenShown = withinRange(given ?? "", props);
69
+ const given = value === undefined ? undefined : kind.toISO(value);
70
+ const givenShown = withinRange(given ?? "", props, kind);
52
71
  const lastGiven = useRef(given);
53
72
  useEffect(() => {
54
73
  if (given === lastGiven.current)
@@ -57,22 +76,22 @@ export function useShownDate(props) {
57
76
  if (given === undefined || given === reported.current)
58
77
  return;
59
78
  reported.current = givenShown;
60
- setInner(fromISODate(given));
61
- }, [given, givenShown]);
79
+ setInner(kind.fromISO(given));
80
+ }, [given, givenShown, kind]);
62
81
  const onRead = useCallback((next) => setRead(next), []);
63
82
  useEffect(() => {
64
83
  if (shown === reported.current)
65
84
  return;
66
85
  reported.current = shown;
67
- report.current?.(fromISODate(shown));
68
- }, [shown]);
86
+ report.current?.(kind.fromISO(shown));
87
+ }, [shown, kind]);
69
88
  return {
70
89
  inner,
71
90
  setInner,
72
91
  shown,
73
92
  impossible: read.impossible,
74
93
  onRead,
75
- validate: () => (isRequired && read.partial ? "Enter the whole date." : null),
94
+ validate: () => (isRequired && read.partial ? kind.whole : null),
76
95
  ...side,
77
96
  };
78
97
  }
@@ -107,14 +126,14 @@ function givenKey(value, bounds) {
107
126
  return "";
108
127
  const [start, end] = [toISODate(value.start), toISODate(value.end)];
109
128
  return bounds
110
- ? rangeKey(withinRange(start, bounds), withinRange(end, bounds))
129
+ ? rangeKey(withinRange(start, bounds, DATE), withinRange(end, bounds, DATE))
111
130
  : `${start}/${end}`;
112
131
  }
113
132
  /** An impossible day, naming its side, or else an end before the start; `null` for neither. */
114
- function problemOf(start, end, startShown, endShown) {
133
+ function problemOf([start, end], [startLabel, endLabel], startShown, endShown) {
115
134
  const impossible = [
116
- start.impossible && `Start date: ${start.impossible}`,
117
- end.impossible && `End date: ${end.impossible}`,
135
+ start.impossible && `${startLabel}: ${start.impossible}`,
136
+ end.impossible && `${endLabel}: ${end.impossible}`,
118
137
  ].filter(Boolean);
119
138
  if (impossible.length > 0)
120
139
  return impossible.join(" ");
@@ -140,10 +159,10 @@ export function useShownRange(props) {
140
159
  const onReadEnd = useCallback((next) => setEnd(next), []);
141
160
  const startSide = useLeaving(start.impossible);
142
161
  const endSide = useLeaving(end.impossible);
143
- const startShown = withinRange(start.typed, props);
144
- const endShown = withinRange(end.typed, props);
162
+ const startShown = withinRange(start.typed, props, DATE);
163
+ const endShown = withinRange(end.typed, props, DATE);
145
164
  const shown = rangeKey(startShown, endShown);
146
- const problem = problemOf(start, end, startShown, endShown);
165
+ const problem = problemOf([start, end], props.labels, startShown, endShown);
147
166
  const reported = useRef(shown);
148
167
  const report = useRef(onChange);
149
168
  useEffect(() => {
@@ -0,0 +1,34 @@
1
+ /** One page the search can find. */
2
+ export type SiteSearchItem = {
3
+ /** The page's name: the row's label and the first thing matched. */
4
+ label: string;
5
+ /** A muted line under the label, matched last. */
6
+ description?: string | undefined;
7
+ /** Where the row goes. */
8
+ href: string;
9
+ /** Other names the page answers to (the exports it documents), matched like the label but not shown. */
10
+ keywords?: string[] | undefined;
11
+ };
12
+ /**
13
+ * The items that match `text`, best first: the label starts with it, then the label contains it,
14
+ * then a keyword contains it, then the description does. Case is ignored, and items of the same
15
+ * rank keep their order in `items`. Empty text matches nothing.
16
+ */
17
+ export declare function rankSiteSearch(items: readonly SiteSearchItem[], text: string): SiteSearchItem[];
18
+ /** What the live region says for a result count, in English. */
19
+ export declare function englishCount(count: number): string;
20
+ /** The words `SearchBody` renders, each a `SiteSearch` prop with its English default. */
21
+ export type BodyWords = {
22
+ resultsLabel: string;
23
+ placeholder: string;
24
+ hintLabel: string;
25
+ noResultsLabel: string;
26
+ countLabel: (count: number) => string;
27
+ allResultsLabel: string;
28
+ };
29
+ export declare function SearchBody({ items, label, resultsHref, words: { resultsLabel, placeholder, hintLabel, noResultsLabel, countLabel, allResultsLabel }, }: {
30
+ items: readonly SiteSearchItem[];
31
+ label: string;
32
+ resultsHref: ((query: string) => string) | undefined;
33
+ words: BodyWords;
34
+ }): import("react").JSX.Element;
@@ -0,0 +1,117 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useRef, useState, } from "react";
3
+ import { Input } from "./Input.js";
4
+ import { ListRow } from "./ListRow.js";
5
+ import { Text } from "./typography.js";
6
+ /**
7
+ * The items that match `text`, best first: the label starts with it, then the label contains it,
8
+ * then a keyword contains it, then the description does. Case is ignored, and items of the same
9
+ * rank keep their order in `items`. Empty text matches nothing.
10
+ */
11
+ export function rankSiteSearch(items, text) {
12
+ const query = text.trim().toLowerCase();
13
+ if (query === "")
14
+ return [];
15
+ const rankOf = (item) => {
16
+ const label = item.label.toLowerCase();
17
+ if (label.startsWith(query))
18
+ return 0;
19
+ if (label.includes(query))
20
+ return 1;
21
+ if (item.keywords?.some((keyword) => keyword.toLowerCase().includes(query)))
22
+ return 2;
23
+ if (item.description?.toLowerCase().includes(query))
24
+ return 3;
25
+ return -1;
26
+ };
27
+ return items
28
+ .map((item, index) => ({ item, index, rank: rankOf(item) }))
29
+ .filter((entry) => entry.rank >= 0)
30
+ .toSorted((a, b) => a.rank - b.rank || a.index - b.index)
31
+ .map((entry) => entry.item);
32
+ }
33
+ /** What the live region says for a result count, in English. */
34
+ export function englishCount(count) {
35
+ if (count === 0)
36
+ return "No results";
37
+ return count === 1 ? "1 result" : `${count} results`;
38
+ }
39
+ /**
40
+ * An Enter that commits an input method's composition (a Japanese or Chinese keyboard) is not a
41
+ * submit. Safari has already cleared `isComposing` by then, and only the 229 keyCode tells.
42
+ */
43
+ function isComposing({ nativeEvent }) {
44
+ return nativeEvent.isComposing || nativeEvent.keyCode === 229;
45
+ }
46
+ // A link that stays on the page (a hash, an app's router) still closes the search; one opened in a
47
+ // new tab or window leaves it open.
48
+ function onListClick(event) {
49
+ if (event.ctrlKey || event.metaKey || event.shiftKey)
50
+ return;
51
+ if (event.target instanceof Element && event.target.closest("a[href]")) {
52
+ event.currentTarget.closest("dialog")?.close();
53
+ }
54
+ }
55
+ /** The result links in the list, in order. */
56
+ function linksIn(list) {
57
+ return list ? [...list.querySelectorAll("a[href]")] : [];
58
+ }
59
+ /** The muted line under the field: the prompt before anything is typed, the no-match line after. */
60
+ function SearchNote({ query, found, words: { hintLabel, noResultsLabel }, }) {
61
+ if (query.trim() === "")
62
+ return _jsx(Text, { tone: "muted", children: hintLabel });
63
+ if (found)
64
+ return null;
65
+ return (_jsxs(Text, { tone: "muted", children: [noResultsLabel, " ", query.trim()] }));
66
+ }
67
+ /** The matches, then the link to the full results page when there is one. */
68
+ function SearchResults({ list, results, all, label, onKeyDown, }) {
69
+ if (results.length === 0 && all === undefined)
70
+ return null;
71
+ return (_jsxs("ul", { ref: list, "aria-label": label, onKeyDown: onKeyDown, onClick: onListClick, className: "border-slate-200/70 *:not-first:border-t *:not-first:border-inherit", children: [results.map((item) => (_jsx("li", { children: _jsx(ListRow, { href: item.href, size: "sm", secondary: item.description, children: item.label }) }, item.href))), all !== undefined && (_jsx("li", { children: _jsx(ListRow, { href: all.href, size: "sm", children: all.text }) }))] }));
72
+ }
73
+ export function SearchBody({ items, label, resultsHref, words: { resultsLabel, placeholder, hintLabel, noResultsLabel, countLabel, allResultsLabel }, }) {
74
+ const [query, setQuery] = useState("");
75
+ const box = useRef(null);
76
+ const list = useRef(null);
77
+ const results = rankSiteSearch(items, query);
78
+ const typed = query.trim() !== "";
79
+ const all = typed && resultsHref ? resultsHref(query.trim()) : undefined;
80
+ const onFieldKey = (event) => {
81
+ if (event.key === "Escape") {
82
+ // Close here, so no engine spends the first Esc clearing the search field.
83
+ event.preventDefault();
84
+ event.currentTarget.closest("dialog")?.close();
85
+ }
86
+ else if (event.key === "Enter") {
87
+ if (isComposing(event))
88
+ return;
89
+ event.preventDefault();
90
+ // The field highlights no result, so with a results page Enter goes there (its link is last).
91
+ const links = linksIn(list.current);
92
+ (all === undefined ? links[0] : links.at(-1))?.click();
93
+ }
94
+ else if (event.key === "ArrowDown") {
95
+ const first = linksIn(list.current)[0];
96
+ if (first) {
97
+ event.preventDefault();
98
+ first.focus();
99
+ }
100
+ }
101
+ };
102
+ const onListKey = (event) => {
103
+ if (event.key !== "ArrowDown" && event.key !== "ArrowUp")
104
+ return;
105
+ const links = linksIn(list.current);
106
+ const at = links.findIndex((link) => link === document.activeElement);
107
+ if (at < 0)
108
+ return;
109
+ event.preventDefault();
110
+ const next = at + (event.key === "ArrowDown" ? 1 : -1);
111
+ if (next < 0)
112
+ box.current?.querySelector("input")?.focus();
113
+ else
114
+ links[Math.min(next, links.length - 1)]?.focus();
115
+ };
116
+ return (_jsxs("search", { ref: box, role: "search", className: "flex flex-col gap-3", children: [_jsx(Input, { type: "search", icon: "search", "aria-label": label, placeholder: placeholder, autoComplete: "off", autoCorrect: "off", autoCapitalize: "off", spellCheck: false, value: query, onChange: (event) => setQuery(event.target.value), onKeyDown: onFieldKey }), _jsx("div", { role: "status", "aria-live": "polite", className: "sr-only", children: typed ? countLabel(results.length) : "" }), _jsx(SearchNote, { query: query, found: results.length > 0, words: { hintLabel, noResultsLabel } }), _jsx(SearchResults, { list: list, results: results, all: all === undefined ? undefined : { href: all, text: `${allResultsLabel} ${query.trim()}` }, label: resultsLabel, onKeyDown: onListKey })] }));
117
+ }
package/dist/size.d.ts CHANGED
@@ -9,6 +9,8 @@
9
9
  * - `Cluster` and `ScrollStrip` `gap`: `xs`, `sm` and `md`, the first steps of the gap scale.
10
10
  * - `Icon` `size`: also `feature`, the mark of a feature card.
11
11
  * - `Dialog` `width`: also `full`, the whole screen. `ChatThread` `height`: also `fill`, its parent's.
12
+ * - `ImageWidth` (`Image`, `RegionFrame` and `MediaTile` `width`): also `xl` and `full`, the
13
+ * parent's width; `sm`, `md`, `lg` and `xl` are 96, 160, 256 and 448px.
12
14
  *
13
15
  * Defaults that are not `md`:
14
16
  * - `Table` `size` is `sm`, its row padding, and the buttons and pills in a table take that size;
@@ -17,11 +19,15 @@
17
19
  * column.
18
20
  * - `Stack` and `Section` `gap` are `xs` inside a `Card`, `Dialog`, `Drawer`, `BottomSheet`,
19
21
  * `Callout` or `ListRow`.
22
+ * - `Image` and `RegionFrame` `width` are `full`: a picture fills its column unless it is a
23
+ * thumbnail. `MediaTile` `width` is `md`, one tile of a grid of them.
20
24
  * - A `Pill`, `Button` or `IconButton` with no `size` takes the size of the `Card`, `ListRow` or
21
25
  * `Table` it sits in; an `EmptyState` takes its slot's.
22
26
  *
23
27
  * A responsive size, `{ base, md }` (`ResponsiveSize`), changes at Tailwind's `md` breakpoint (48rem)
24
- * in CSS, with no script: `Button`, `IconButton`, `SegmentedControl` and `Icon` take it.
28
+ * in CSS, with no script: `Button`, `IconButton`, `SegmentedControl` and `Icon` take it, and so do
29
+ * the text fields, `Input`, `Select`, `Textarea`, `DateField`, `DateTimeField` and
30
+ * `DateRangePicker`, so a field and the button beside it stay aligned at both widths.
25
31
  *
26
32
  * With no `size` at all, because they take the size of the text or the control they sit on:
27
33
  * `Callout`, `CopyButton`, `Kbd`, `Badge` and `Breadcrumbs`.