@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
@@ -3,7 +3,7 @@ import { useId, useRef, useState, } from "react";
3
3
  import { Button } from "./Button.js";
4
4
  import { Cluster, ClusterGrow } from "./Cluster.js";
5
5
  import { Field } from "./Field.js";
6
- import { Textarea } from "./Textarea.js";
6
+ import { TextareaControl } from "./Textarea.js";
7
7
  /**
8
8
  * An IME is still composing. Safari ends the composition before the Enter's keydown, so there
9
9
  * `isComposing` is already false and only the 229 keyCode tells the commit from a real Enter.
@@ -12,23 +12,45 @@ function isComposing({ nativeEvent }) {
12
12
  return nativeEvent.isComposing || nativeEvent.keyCode === 229;
13
13
  }
14
14
  /**
15
- * The box a message is typed into, with its button beside it. It keeps its own text. Enter sends
16
- * the trimmed text and clears the box; Shift+Enter is a newline; empty or whitespace-only text does
17
- * not send. While `busy` a reply is on its way: the button is Stop, Enter does not send, and typing
18
- * carries on with the text kept for the next send.
15
+ * The composer's text, and whether the last send found it empty; `type` sets the text and clears that.
16
+ * `send` sends the trimmed text and clears the box, or marks it empty; it does nothing while `busy`.
19
17
  */
20
- export function ChatComposer({ label, placeholder, disabled = false, busy = false, onSend, onStop, sendLabel = "Send", stopLabel = "Stop", ...rest }) {
21
- const id = useId();
22
- const box = useRef(null);
18
+ function useComposerText(busy, onSend) {
23
19
  const [text, setText] = useState("");
24
- const trimmed = text.trim();
25
- const stop = busy && onStop !== undefined;
20
+ const [empty, setEmpty] = useState(false);
21
+ const type = (next) => {
22
+ setText(next);
23
+ setEmpty(false);
24
+ };
26
25
  const send = () => {
27
- if (busy || trimmed === "")
26
+ if (busy)
27
+ return;
28
+ const trimmed = text.trim();
29
+ if (trimmed === "") {
30
+ setEmpty(true);
28
31
  return;
32
+ }
29
33
  onSend(trimmed);
30
34
  setText("");
31
35
  };
36
+ return { text, type, empty, send };
37
+ }
38
+ /** The composer's one submit button: Send, or Stop while a reply can be stopped. */
39
+ function SendOrStop({ stop, disabled, sendLabel = "Send", stopLabel = "Stop", }) {
40
+ return (_jsx(Button, { type: "submit", variant: stop ? "outline" : "primary", disabled: disabled, children: stop ? stopLabel : sendLabel }));
41
+ }
42
+ /**
43
+ * The box a message is typed into, with its button beside it. It keeps its own text, and the box
44
+ * grows with it from 2 rows to 8. Enter sends the trimmed text and clears the box; Shift+Enter is a
45
+ * newline. Send stays enabled on an empty box: sending empty or whitespace-only text sends nothing
46
+ * and shows `emptyReason` under the box until the next keystroke. While `busy` a reply is on its way: the button is Stop, Enter does not send, and typing
47
+ * carries on with the text kept for the next send.
48
+ */
49
+ export function ChatComposer({ label, placeholder, disabled = false, busy = false, onSend, onStop, sendLabel, stopLabel, emptyReason = "Write a message first.", ...rest }) {
50
+ const id = useId();
51
+ const box = useRef(null);
52
+ const { text, type, empty, send } = useComposerText(busy, onSend);
53
+ const stop = busy && onStop !== undefined;
32
54
  const onKeyDown = (event) => {
33
55
  if (event.key !== "Enter" || event.shiftKey || isComposing(event))
34
56
  return;
@@ -36,7 +58,7 @@ export function ChatComposer({ label, placeholder, disabled = false, busy = fals
36
58
  send();
37
59
  };
38
60
  // One submit button that is Send or Stop, so it is the same element across the swap and keeps its
39
- // focus. Send goes back to the box: the empty box has just disabled the button under the focus.
61
+ // focus. Send goes back to the box, to type the next message or the missing one.
40
62
  const onSubmit = (event) => {
41
63
  event.preventDefault();
42
64
  if (busy) {
@@ -46,5 +68,5 @@ export function ChatComposer({ label, placeholder, disabled = false, busy = fals
46
68
  send();
47
69
  box.current?.focus();
48
70
  };
49
- return (_jsx("form", { ...rest, onSubmit: onSubmit, children: _jsxs(Cluster, { align: "end", gap: "sm", children: [_jsx(ClusterGrow, { children: _jsx(Field, { label: label, htmlFor: id, labelHidden: true, children: _jsx(Textarea, { ref: box, id: id, rows: 2, value: text, placeholder: placeholder, disabled: disabled, onChange: (event) => setText(event.target.value), onKeyDown: onKeyDown }) }) }), _jsx(Button, { type: "submit", variant: stop ? "outline" : "primary", disabled: disabled || (busy ? !stop : trimmed === ""), children: stop ? stopLabel : sendLabel })] }) }));
71
+ return (_jsx("form", { ...rest, onSubmit: onSubmit, children: _jsxs(Cluster, { align: "end", gap: "sm", children: [_jsx(ClusterGrow, { children: _jsx(Field, { label: label, htmlFor: id, labelHidden: true, error: empty ? emptyReason : undefined, children: _jsx(TextareaControl, { ref: box, id: id, size: "md", width: "full", mono: false, grow: true, value: text, placeholder: placeholder, disabled: disabled, onChange: (event) => type(event.target.value), onKeyDown: onKeyDown }) }) }), _jsx(SendOrStop, { stop: stop, disabled: disabled || (busy && !stop), sendLabel: sendLabel, stopLabel: stopLabel })] }) }));
50
72
  }
@@ -2,13 +2,14 @@ import type { ComponentPropsWithoutRef, ReactElement, ReactNode, Ref } from "rea
2
2
  import type { Unstyled } from "./props.js";
3
3
  import type { Size } from "./size.js";
4
4
  import { type LoadingProps } from "./skeleton.js";
5
+ import { type ChoiceVariant } from "./optionCard.js";
5
6
  /** The props of a `Checkbox`. */
6
7
  type CheckboxProps = {
7
8
  /** The text beside the box. Leave it out for a bare box (a table cell) and name it with `aria-label`. */
8
9
  label?: ReactNode;
9
10
  /** A muted line under the label that says more. It is the box's `aria-describedby`. */
10
11
  hint?: ReactNode;
11
- /** Replaces the hint with a red line (`role="alert"`) and makes the box `aria-invalid`. */
12
+ /** A red line under the hint, with an alert icon, announced politely; makes the box `aria-invalid`. */
12
13
  error?: ReactNode;
13
14
  /**
14
15
  * The label's text size and the box with it.
@@ -23,6 +24,20 @@ type CheckboxProps = {
23
24
  * keyboard focus and a tap, read out as its description.
24
25
  */
25
26
  disabledReason?: string | undefined;
27
+ /**
28
+ * Mixed: some of what the box stands for is chosen and some is not, as a select-all box over a
29
+ * partly chosen list. It draws a dash and is read as "mixed"; a click checks it. The caller owns
30
+ * it: work it out from the list on every render.
31
+ * @default false
32
+ */
33
+ indeterminate?: boolean | undefined;
34
+ /**
35
+ * `plain` is the box and its words. `card` puts them in a bordered box the width of its parent,
36
+ * the label a title and the `hint` its description: for a few options that each need a line of
37
+ * explaining. The whole card is the click target, and a ticked one takes an accent edge.
38
+ * @default plain
39
+ */
40
+ variant?: ChoiceVariant | undefined;
26
41
  /** The `<input>`, for focus control. */
27
42
  ref?: Ref<HTMLInputElement> | undefined;
28
43
  } & Unstyled<Omit<ComponentPropsWithoutRef<"input">, "type" | "size" | "width" | "onChange">>;
@@ -33,9 +48,12 @@ type CheckboxProps = {
33
48
  * `size="sm"` is `text-xs` and a smaller box, for a dense row; `size="lg"` is `text-base` and a
34
49
  * larger box. Leave `label` out for a bare box in a table cell, and name it with `aria-label`. The
35
50
  * box sits on the label's first line, so a label that wraps reads from the box. `hint` is a muted
36
- * line under the label that says more, like a `Field`'s; `error` replaces it with a red line
37
- * (`role="alert"`) and makes the box `aria-invalid`. The note is the box's `aria-describedby`.
51
+ * line under the label that says more, like a `Field`'s; `error` adds a red line under it, with an alert
52
+ * icon, and makes the box `aria-invalid` and red-edged. The note is the box's `aria-describedby`.
38
53
  * `onChange` gets the new checked state; take `checked` with it, or `defaultChecked` alone.
54
+ * `indeterminate` draws a dash for a select-all box over a partly chosen list. `variant="card"`
55
+ * draws it as an option card: a bordered box with the label as its title and the hint under it. Under a finger the
56
+ * hit area grows to 44px.
39
57
  * While `loading` the label is drawn and the box is a bone of its size.
40
58
  */
41
59
  export declare function Checkbox({ loading, loadingLabel, ...props }: CheckboxProps & LoadingProps): ReactElement;
package/dist/Checkbox.js CHANGED
@@ -1,24 +1,62 @@
1
1
  import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { INVALID_EDGE, INVALID_EDGE_WITHIN } from "./control.js";
2
3
  import { cx, focusRing } from "./cx.js";
4
+ import { controlText, useTypeStep } from "./density.js";
3
5
  import { useNote, Words } from "./labelWords.js";
6
+ import { TOUCH_TARGET } from "./target.js";
4
7
  import { WaitingChoice } from "./fieldWait.js";
5
8
  import { useLoading } from "./skeleton.js";
6
9
  import { useBlocked } from "./blocked.js";
7
- /** The label's gap and text, the box, and the box's drop onto the label's first line, by `size`. */
10
+ import { OPTION_CARD, OPTION_CARD_CHOSEN, OPTION_CARD_HOVER, OPTION_CARD_TITLE, } from "./optionCard.js";
11
+ /**
12
+ * The label's gap, the box, and the box's drop onto the label's first line, by `size`. The label's
13
+ * type is a control's of that size (`controlText`), whose line height the drop is set for.
14
+ */
8
15
  const SIZE = {
9
- sm: { label: "gap-1.5 text-xs", box: "h-3.5 w-3.5", start: "mt-px" },
10
- md: { label: "gap-2 text-sm", box: "h-4 w-4", start: "mt-0.5" },
11
- lg: { label: "gap-2.5 text-base", box: "h-5 w-5", start: "mt-0.5" },
16
+ sm: { gap: "gap-1.5", box: "h-3.5 w-3.5", start: "mt-px" },
17
+ md: { gap: "gap-2", box: "h-4 w-4", start: "mt-0.5" },
18
+ lg: { gap: "gap-2.5", box: "h-5 w-5", start: "mt-0.5" },
19
+ };
20
+ /** The mark over a checked box: a tick, or a dash for a mixed one. */
21
+ const MARK = {
22
+ tick: {
23
+ path: "M4 8.5l2.5 2.5L12 5.5",
24
+ shown: "group-has-[input:checked:not(:indeterminate)]/checkbox:visible",
25
+ },
26
+ dash: { path: "M4.5 8h7", shown: "group-has-[input:indeterminate]/checkbox:visible" },
12
27
  };
13
- /** The tick: shown over the box when it is checked. */
14
- function Tick({ size, onFirstLine }) {
28
+ /**
29
+ * The mark over the box: the tick when it is checked, the dash when it is mixed (`indeterminate`).
30
+ * Both read the input's own state, so an uncontrolled Checkbox changes with no re-render.
31
+ */
32
+ function Tick({ size, onFirstLine, mark, }) {
15
33
  /* The checked box: a filled accent square at the input's own place (an absolutely
16
34
  positioned flex child sits where the first flex item would, so it needs no insets), shown
17
35
  by the label's `:has(:checked)` so an uncontrolled Checkbox changes with no re-render.
18
36
  Inside a Card or table row the input is lifted to `z-10` by `liftInteractive` (cx.ts), and
19
37
  it comes later in the DOM, so the tick ranks `z-20` there to paint over it. Scoped to the
20
38
  `isolate` ancestor like the Input icon (InputShell.tsx), so it never outranks a sticky bar. */
21
- return (_jsx("span", { "aria-hidden": "true", className: cx(SIZE[size].box, onFirstLine && SIZE[size].start, "pointer-events-none invisible absolute in-[.isolate]:z-20 block rounded border border-violet-600 bg-violet-600 text-violet-50 group-has-checked/checkbox:visible"), children: _jsx("svg", { viewBox: "0 0 16 16", fill: "none", className: "h-full w-full", children: _jsx("path", { d: "M4 8.5l2.5 2.5L12 5.5", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }) }) }));
39
+ return (_jsx("span", { "aria-hidden": "true", className: cx(SIZE[size].box, onFirstLine && SIZE[size].start, "pointer-events-none invisible absolute in-[.isolate]:z-20 block rounded border border-violet-600 bg-violet-600 text-violet-50", MARK[mark].shown), children: _jsx("svg", { viewBox: "0 0 16 16", fill: "none", className: "h-full w-full", children: _jsx("path", { d: MARK[mark].path, stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }) }) }));
40
+ }
41
+ /**
42
+ * The label round the box: faded and not-allowed unless the box is enabled. Written as
43
+ * `has-enabled` so the label carries no `disabled` class text: the disabled state belongs on the
44
+ * input. A blocked box is enabled (it keeps its focus) and fades as a disabled one does. A card
45
+ * draws its box and takes the focus ring from the input.
46
+ */
47
+ function labelLook(blocked, card) {
48
+ return cx("group/checkbox inline-flex items-start text-slate-700", TOUCH_TARGET, blocked
49
+ ? "cursor-not-allowed opacity-50"
50
+ : "cursor-not-allowed opacity-50 has-enabled:cursor-pointer has-enabled:opacity-100", card &&
51
+ cx(OPTION_CARD, OPTION_CARD_HOVER, INVALID_EDGE_WITHIN, "has-focus-visible:outline-2 has-focus-visible:outline-offset-2 has-focus-visible:outline-violet-600"));
52
+ }
53
+ /** A ticked card's accent edge, shown by the input's own state so an uncontrolled card needs no re-render. */
54
+ function CardEdge() {
55
+ return (_jsx("span", { "aria-hidden": "true", className: cx(OPTION_CARD_CHOSEN, "invisible group-has-[input:checked]/checkbox:visible") }));
56
+ }
57
+ /** A card's label, in the card title's weight. */
58
+ function CardTitle({ label }) {
59
+ return label == null ? label : _jsx("span", { className: OPTION_CARD_TITLE, children: label });
22
60
  }
23
61
  /**
24
62
  * A checkbox with its label. It is a real `<input type="checkbox">`, drawn by the library (an
@@ -27,37 +65,45 @@ function Tick({ size, onFirstLine }) {
27
65
  * `size="sm"` is `text-xs` and a smaller box, for a dense row; `size="lg"` is `text-base` and a
28
66
  * larger box. Leave `label` out for a bare box in a table cell, and name it with `aria-label`. The
29
67
  * box sits on the label's first line, so a label that wraps reads from the box. `hint` is a muted
30
- * line under the label that says more, like a `Field`'s; `error` replaces it with a red line
31
- * (`role="alert"`) and makes the box `aria-invalid`. The note is the box's `aria-describedby`.
68
+ * line under the label that says more, like a `Field`'s; `error` adds a red line under it, with an alert
69
+ * icon, and makes the box `aria-invalid` and red-edged. The note is the box's `aria-describedby`.
32
70
  * `onChange` gets the new checked state; take `checked` with it, or `defaultChecked` alone.
71
+ * `indeterminate` draws a dash for a select-all box over a partly chosen list. `variant="card"`
72
+ * draws it as an option card: a bordered box with the label as its title and the hint under it. Under a finger the
73
+ * hit area grows to 44px.
33
74
  * While `loading` the label is drawn and the box is a bone of its size.
34
75
  */
35
76
  export function Checkbox({ loading, loadingLabel, ...props }) {
77
+ const step = useTypeStep();
36
78
  if (useLoading(loading).loading) {
37
79
  const size = props.size ?? "md";
38
- return (_jsx(WaitingChoice, { own: loading, loadingLabel: loadingLabel, label: props.label, look: SIZE[size].label, shape: cx(SIZE[size].box, props.label != null && SIZE[size].start, "rounded"), attrs: props }));
80
+ return (_jsx(WaitingChoice, { own: loading, loadingLabel: loadingLabel, label: props.label, look: cx(SIZE[size].gap, controlText(size, step, false), props.variant === "card" && OPTION_CARD), shape: cx(SIZE[size].box, props.label != null && SIZE[size].start, "rounded"), attrs: props }));
39
81
  }
40
82
  return _jsx(ShownCheckbox, { ...props });
41
83
  }
42
84
  /** A checkbox with its box drawn. */
43
- function ShownCheckbox({ label, hint, error, size = "md", onChange, disabledReason, "aria-describedby": describedBy, ...rest }) {
44
- const { noteId, describedIds, invalid } = useNote(hint, error, describedBy);
85
+ function ShownCheckbox({ label, hint, error, size = "md", onChange, disabledReason, indeterminate = false, variant, ref, "aria-describedby": describedBy, ...rest }) {
86
+ const { ids: noteIds, describedIds, invalid } = useNote(hint, error, describedBy);
87
+ const step = useTypeStep();
45
88
  const { props: guard, tooltip, blocked, } = useBlocked(disabledReason, {
46
89
  ...rest,
47
90
  "aria-describedby": describedIds || undefined,
48
91
  });
49
- return (_jsxs(_Fragment, { children: [_jsxs("label", { className: cx(
50
- // Faded and default-cursor unless the box is enabled. Written as `has-enabled` so the
51
- // label carries no `disabled` class text: the disabled state belongs on the input. A
52
- // blocked box is enabled (it keeps its focus) and fades as a disabled one does.
53
- "group/checkbox inline-flex items-start text-slate-700", blocked
54
- ? "cursor-not-allowed opacity-50"
55
- : "cursor-default opacity-50 has-enabled:cursor-pointer has-enabled:opacity-100", SIZE[size].label), children: [_jsx(Tick, { size: size, onFirstLine: label != null }), _jsx("input", { type: "checkbox", className: cx(SIZE[size].box, "shrink-0", label != null && SIZE[size].start, "appearance-none rounded border border-slate-300 bg-white hover:border-violet-400", focusRing), ...(invalid ? { "aria-invalid": true } : {}), ...rest, ...guard, ...(onChange
92
+ const card = variant === "card";
93
+ return (_jsxs(_Fragment, { children: [_jsxs("label", { className: cx(labelLook(blocked, card), SIZE[size].gap, controlText(size, step, false)), children: [card ? _jsx(CardEdge, {}) : null, _jsx(Tick, { size: size, onFirstLine: label != null, mark: "tick" }), indeterminate ? _jsx(Tick, { size: size, onFirstLine: label != null, mark: "dash" }) : null, _jsx("input", { type: "checkbox", className: cx(SIZE[size].box, "shrink-0", label != null && SIZE[size].start, "appearance-none rounded border border-slate-300 bg-white hover:border-violet-400", INVALID_EDGE, !card && focusRing), "aria-invalid": invalid, ...rest, ref: (node) => {
94
+ if (node)
95
+ node.indeterminate = indeterminate;
96
+ if (typeof ref === "function")
97
+ return ref(node);
98
+ if (ref)
99
+ ref.current = node;
100
+ return undefined;
101
+ }, ...guard, ...(onChange
56
102
  ? {
57
103
  onChange: (event) => {
58
104
  if (!blocked)
59
105
  onChange(event.target.checked);
60
106
  },
61
107
  }
62
- : {}) }), _jsx(Words, { label: label, hint: hint, error: error, id: noteId })] }), tooltip] }));
108
+ : {}) }), _jsx(Words, { label: card ? _jsx(CardTitle, { label: label }) : label, hint: hint, error: error, ids: noteIds })] }), tooltip] }));
63
109
  }
package/dist/Chevron.js CHANGED
@@ -2,5 +2,5 @@ import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { cx } from "./cx.js";
3
3
  /** The right-pointing chevron of a collapsible header; it turns down when `open`. */
4
4
  export function Chevron({ open }) {
5
- return (_jsx("svg", { "aria-hidden": "true", viewBox: "0 0 20 20", fill: "currentColor", className: cx("h-4 w-4 shrink-0 text-slate-400", open && "rotate-90"), children: _jsx("path", { fillRule: "evenodd", d: "M7.2 4.8a.75.75 0 0 1 1.06 0l4.7 4.67a.75.75 0 0 1 0 1.06l-4.7 4.67a.75.75 0 1 1-1.06-1.06L11.37 10 7.2 5.86a.75.75 0 0 1 0-1.06Z", clipRule: "evenodd" }) }));
5
+ return (_jsx("svg", { "aria-hidden": "true", viewBox: "0 0 20 20", fill: "currentColor", className: cx("h-4 w-4 shrink-0 text-slate-400 motion-safe:transition-transform", open && "rotate-90"), children: _jsx("path", { fillRule: "evenodd", d: "M7.2 4.8a.75.75 0 0 1 1.06 0l4.7 4.67a.75.75 0 0 1 0 1.06l-4.7 4.67a.75.75 0 1 1-1.06-1.06L11.37 10 7.2 5.86a.75.75 0 0 1 0-1.06Z", clipRule: "evenodd" }) }));
6
6
  }
package/dist/Cluster.d.ts CHANGED
@@ -1,12 +1,12 @@
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 StackGap } from "./Stack.js";
4
4
  /** The first three steps of `Stack`'s scale: `xs` between items in a line, `sm` inside a group, `md` between blocks. */
5
5
  export type ClusterGap = Extract<StackGap, "xs" | "sm" | "md">;
6
6
  /** Where a `Cluster`'s items sit across the row: `center`, `baseline` for mixed text sizes, `start` or `end`. */
7
7
  export type ClusterAlign = "center" | "baseline" | "start" | "end";
8
- /** Where a `Cluster`'s items sit along the row: `start`, `end`, or `between` to spread them to both ends. */
9
- export type ClusterJustify = "start" | "between" | "end";
8
+ /** Where a `Cluster`'s items sit along the row: `start`, `center`, `end`, or `between` to spread them to both ends. */
9
+ export type ClusterJustify = "start" | "center" | "between" | "end";
10
10
  /**
11
11
  * A horizontal row of items a fixed `gap` apart (`sm` by default): the row counterpart of `Stack`. `align` is the
12
12
  * cross axis (`center` default, `baseline` for mixed text sizes, `start`, `end`) and `justify` the
@@ -19,18 +19,12 @@ export type ClusterJustify = "start" | "between" | "end";
19
19
  * `ButtonGroup` is the row for buttons; use `Cluster` for any other row. `as="span"` is for a row
20
20
  * inside phrasing content, such as a `PageHeader` description (a `<p>`): its items must be phrasing
21
21
  * content too, so no `ClusterGrow`. `as="ul"` or `as="ol"` is a wrapping list with no markers
22
- * (tags, chips): as in a `Stack` list the Cluster does not wrap its children, so each child is an
23
- * `<li>` the caller writes, and a `ClusterGrow` (a `div`) does not belong in it.
22
+ * (tags, chips), as in `CardGrid`: the Cluster wraps each child in its own `<li>`, so the caller
23
+ * writes the items (`Pill`s) and never an `<li>`. `as="nav"` is a row of links (a footer's or a
24
+ * section's): a `<nav>` named by its required `aria-label`, holding a list with each link in its
25
+ * own `<li>`.
24
26
  */
25
- export declare function Cluster({ as: Tag, gap, align, justify, wrap, children, ...rest }: {
26
- /**
27
- * The element: `div`, `span` for a row inside a `<p>` or other phrasing content, or `ul` or `ol`
28
- * for a list (no markers; each child is an `<li>`).
29
- *
30
- * In a `span` the items must be phrasing content, so no `ClusterGrow`.
31
- * @default div
32
- */
33
- as?: "div" | "span" | "ul" | "ol" | undefined;
27
+ export declare function Cluster({ as, gap, align, justify, wrap, children, ...rest }: ClusterElement & {
34
28
  /**
35
29
  * The space between items: the first steps of the gap scale. Its default is one of those the
36
30
  * `Size` type lists as not `md`.
@@ -43,7 +37,7 @@ export declare function Cluster({ as: Tag, gap, align, justify, wrap, children,
43
37
  */
44
38
  align?: ClusterAlign | undefined;
45
39
  /**
46
- * The main axis: `start`, `between` (the first and last items at the two ends) or `end`.
40
+ * The main axis: `start`, `center`, `between` (the first and last items at the two ends) or `end`.
47
41
  * @default start
48
42
  */
49
43
  justify?: ClusterJustify | undefined;
@@ -54,6 +48,24 @@ export declare function Cluster({ as: Tag, gap, align, justify, wrap, children,
54
48
  wrap?: boolean | undefined;
55
49
  children?: ReactNode;
56
50
  } & Passthrough): ReactElement;
51
+ /** A `Cluster`'s element, and the name a `nav` needs. */
52
+ type ClusterElement = {
53
+ /**
54
+ * The element: `div`, `span` for a row inside a `<p>` or other phrasing content, `ul` or `ol`
55
+ * for a list (no markers; the Cluster wraps each child in an `<li>`), or `nav` for a row of
56
+ * links (a `<nav>` named by `aria-label`, around such a list).
57
+ *
58
+ * In a `span` the items must be phrasing content, so no `ClusterGrow`.
59
+ * @default div
60
+ */
61
+ as?: "div" | "span" | "ul" | "ol" | undefined;
62
+ /** The accessible name; required with `as="nav"`, where it names the landmark, such as "Footer". */
63
+ "aria-label"?: string | undefined;
64
+ } | {
65
+ as: "nav";
66
+ /** The accessible name; required with `as="nav"`, where it names the landmark, such as "Footer". */
67
+ "aria-label": string;
68
+ };
57
69
  /** The narrowest a `ClusterGrow` gets before the row wraps: `sm` or `md`. */
58
70
  export type ClusterGrowMinWidth = "sm" | "md";
59
71
  /**
@@ -68,3 +80,4 @@ export declare function ClusterGrow({ minWidth, children, ...rest }: {
68
80
  minWidth?: ClusterGrowMinWidth | undefined;
69
81
  children?: ReactNode;
70
82
  } & Passthrough): ReactElement;
83
+ export {};
package/dist/Cluster.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Children, isValidElement } from "react";
2
3
  import { cx } from "./cx.js";
3
4
  import { STACK_GAP } from "./Stack.js";
4
5
  const ALIGN = {
@@ -9,9 +10,17 @@ const ALIGN = {
9
10
  };
10
11
  const JUSTIFY = {
11
12
  start: "justify-start",
13
+ center: "justify-center",
12
14
  between: "justify-between",
13
15
  end: "justify-end",
14
16
  };
17
+ /** A Cluster that is a `ul`, `ol` or `nav` is a list: its role, and each child in its own `<li>`. */
18
+ function listOf(tag, children) {
19
+ if (tag !== "ul" && tag !== "ol" && tag !== "nav")
20
+ return { items: children };
21
+ const items = Children.toArray(children).map((child, index) => (_jsx("li", { className: "flex", children: child }, isValidElement(child) ? child.key : index)));
22
+ return { role: "list", items };
23
+ }
15
24
  /**
16
25
  * A horizontal row of items a fixed `gap` apart (`sm` by default): the row counterpart of `Stack`. `align` is the
17
26
  * cross axis (`center` default, `baseline` for mixed text sizes, `start`, `end`) and `justify` the
@@ -24,11 +33,19 @@ const JUSTIFY = {
24
33
  * `ButtonGroup` is the row for buttons; use `Cluster` for any other row. `as="span"` is for a row
25
34
  * inside phrasing content, such as a `PageHeader` description (a `<p>`): its items must be phrasing
26
35
  * content too, so no `ClusterGrow`. `as="ul"` or `as="ol"` is a wrapping list with no markers
27
- * (tags, chips): as in a `Stack` list the Cluster does not wrap its children, so each child is an
28
- * `<li>` the caller writes, and a `ClusterGrow` (a `div`) does not belong in it.
36
+ * (tags, chips), as in `CardGrid`: the Cluster wraps each child in its own `<li>`, so the caller
37
+ * writes the items (`Pill`s) and never an `<li>`. `as="nav"` is a row of links (a footer's or a
38
+ * section's): a `<nav>` named by its required `aria-label`, holding a list with each link in its
39
+ * own `<li>`.
29
40
  */
30
- export function Cluster({ as: Tag = "div", gap = "sm", align = "center", justify = "start", wrap = true, children, ...rest }) {
31
- return (_jsx(Tag, { ...rest, className: cx("flex", (Tag === "ul" || Tag === "ol") && "list-none", STACK_GAP[gap], ALIGN[align], JUSTIFY[justify], wrap && "flex-wrap"), children: children }));
41
+ export function Cluster({ as = "div", gap = "sm", align = "center", justify = "start", wrap = true, children, ...rest }) {
42
+ const { role, items } = listOf(as, children);
43
+ const className = cx("flex", role && "list-none", STACK_GAP[gap], ALIGN[align], JUSTIFY[justify], wrap && "flex-wrap");
44
+ if (as === "nav") {
45
+ return (_jsx("nav", { ...rest, children: _jsx("ul", { role: "list", className: className, children: items }) }));
46
+ }
47
+ const Tag = as;
48
+ return (_jsx(Tag, { role: role, ...rest, className: className, children: items }));
32
49
  }
33
50
  /** The narrowest a `ClusterGrow` gets before it wraps under, the same two steps as `CardGrid`'s `minWidth`. */
34
51
  const GROW_MIN_WIDTH = {
package/dist/Code.d.ts CHANGED
@@ -1,6 +1,18 @@
1
- import type { ReactElement, ReactNode } from "react";
1
+ import { type ReactElement, type ReactNode } from "react";
2
2
  import type { Passthrough } from "./props.js";
3
- /** Inline code: mono, on a subtle inset background. It takes the surrounding text colour and size (a touch smaller, for the mono face). */
4
- export declare function Code({ children, ...rest }: {
3
+ /**
4
+ * Inline code: mono, on a subtle inset background. It takes the surrounding text colour and size (a
5
+ * touch smaller, for the mono face). `lines={1}` keeps a long value (a hash, a path) on one line,
6
+ * cut with an ellipsis, and shows its whole text in a tooltip while it is cut; `breakWords` instead breaks a long unbroken
7
+ * value at the edge of its box, as `Text` does.
8
+ */
9
+ export declare function Code({ lines, breakWords, children, ...rest }: {
5
10
  children: ReactNode;
11
+ /** `1` keeps it on one line, cut with an ellipsis; while it is cut, its whole text shows in a tooltip. */
12
+ lines?: 1 | undefined;
13
+ /**
14
+ * Breaks a long unbroken value (a URL, a hash) at the edge of its box.
15
+ * @default false
16
+ */
17
+ breakWords?: boolean | undefined;
6
18
  } & Passthrough): ReactElement;
package/dist/Code.js CHANGED
@@ -1,5 +1,25 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- /** Inline code: mono, on a subtle inset background. It takes the surrounding text colour and size (a touch smaller, for the mono face). */
3
- export function Code({ children, ...rest }) {
4
- return (_jsx("code", { ...rest, className: "rounded bg-slate-100 px-1 py-0.5 font-mono text-[0.9em]", children: children }));
2
+ import { Children } from "react";
3
+ import { cx } from "./cx.js";
4
+ import { layoutClass } from "./textBox.js";
5
+ import { Truncated } from "./truncated.js";
6
+ /**
7
+ * Inline code: mono, on a subtle inset background. It takes the surrounding text colour and size (a
8
+ * touch smaller, for the mono face). `lines={1}` keeps a long value (a hash, a path) on one line,
9
+ * cut with an ellipsis, and shows its whole text in a tooltip while it is cut; `breakWords` instead breaks a long unbroken
10
+ * value at the edge of its box, as `Text` does.
11
+ */
12
+ export function Code({ lines, breakWords = false, children, ...rest }) {
13
+ const look = cx("rounded bg-slate-100 px-1 py-0.5 font-mono text-[0.9em]", layoutClass(undefined, lines), breakWords && "break-words");
14
+ if (lines === 1) {
15
+ return (_jsx(Truncated, { as: "code", attrs: rest, text: plainText(children), className: look, children: children }));
16
+ }
17
+ return (_jsx("code", { ...rest, className: look, children: children }));
18
+ }
19
+ /** The whole text of children made only of strings and numbers (`sha256:{hash}`), else undefined. */
20
+ function plainText(children) {
21
+ const parts = Children.toArray(children);
22
+ return parts.every((part) => typeof part === "string" || typeof part === "number")
23
+ ? parts.join("")
24
+ : undefined;
5
25
  }
@@ -1,6 +1,6 @@
1
- import { type ComponentPropsWithoutRef, type ReactElement } from "react";
1
+ import { type ReactElement } from "react";
2
2
  import type { CodeLanguage } from "./highlight.js";
3
- import type { Unstyled } from "./props.js";
3
+ import type { Passthrough } from "./props.js";
4
4
  /** Exactly one of `children` (a string, newlines kept) or `lines` (one array entry per line). */
5
5
  type CodeBlockSource = {
6
6
  children: string;
@@ -20,7 +20,7 @@ type CodeBlockSource = {
20
20
  * `$ `. `label` names the language or file (`bash`, `css`) in a caption above the code. `text` (the
21
21
  * default) leaves the code in one colour, for a block that is not a language. Give the text as `children` or as `lines`. Long lines wrap, so
22
22
  * nothing is cut off and a command stays one copyable line; `overflow="scroll"` keeps lines whole
23
- * and scrolls them sideways under a thin themed scrollbar, for code whose layout matters. With
23
+ * and scrolls them sideways under a themed scrollbar, for code whose layout matters. With
24
24
  * `overflow="scroll"`, a strip wider than its box is a tab stop named by `label`, else "Code". Every
25
25
  * other figure prop goes on the root `<figure>`. For one short line to copy, `CopyLine` is the
26
26
  * smaller box.
@@ -42,5 +42,5 @@ export declare function CodeBlock({ label, language, overflow, copy, children, l
42
42
  * @default false
43
43
  */
44
44
  copy?: boolean;
45
- } & CodeBlockSource & Unstyled<Omit<ComponentPropsWithoutRef<"figure">, "children">>): ReactElement;
45
+ } & CodeBlockSource & Passthrough): ReactElement;
46
46
  export {};
package/dist/CodeBlock.js CHANGED
@@ -10,12 +10,12 @@ import { CodeBody } from "./CodeBody.js";
10
10
  * `$ `. `label` names the language or file (`bash`, `css`) in a caption above the code. `text` (the
11
11
  * default) leaves the code in one colour, for a block that is not a language. Give the text as `children` or as `lines`. Long lines wrap, so
12
12
  * nothing is cut off and a command stays one copyable line; `overflow="scroll"` keeps lines whole
13
- * and scrolls them sideways under a thin themed scrollbar, for code whose layout matters. With
13
+ * and scrolls them sideways under a themed scrollbar, for code whose layout matters. With
14
14
  * `overflow="scroll"`, a strip wider than its box is a tab stop named by `label`, else "Code". Every
15
15
  * other figure prop goes on the root `<figure>`. For one short line to copy, `CopyLine` is the
16
16
  * smaller box.
17
17
  */
18
18
  export function CodeBlock({ label, language = "text", overflow = "wrap", copy = false, children, lines, ...rest }) {
19
19
  const captionId = useId();
20
- return (_jsxs("figure", { ...rest, className: "overflow-hidden rounded-lg border border-slate-200 bg-slate-50 font-mono text-[12.5px] leading-normal text-slate-900", children: [label && (_jsx("figcaption", { id: captionId, className: "border-b border-slate-200 px-3 py-1.5 text-xs text-slate-500", children: label })), _jsx(CodeBody, { code: lines ? lines.join("\n") : children, language: language, wrap: overflow === "wrap", copy: copy, labelledBy: label ? captionId : undefined })] }));
20
+ return (_jsxs("figure", { ...rest, className: "overflow-hidden rounded-lg border border-slate-200 bg-slate-50 font-mono text-[0.78125rem] leading-normal text-slate-900", children: [label && (_jsx("figcaption", { id: captionId, className: "border-b border-slate-200 px-3 py-1.5 text-xs text-slate-500", children: label })), _jsx(CodeBody, { code: lines ? lines.join("\n") : children, language: language, wrap: overflow === "wrap", copy: copy, labelledBy: label ? captionId : undefined })] }));
21
21
  }
@@ -5,7 +5,7 @@ import { type CodeLanguage } from "./highlight.js";
5
5
  * it that copies `code` exactly as given (wrapping is CSS, so it adds no characters), except in a
6
6
  * `console` block, where it copies only the commands (see `consoleCommands`). `wrap` wraps
7
7
  * long lines at whitespace only (a flag with hyphens stays whole; a word wider than the box still
8
- * breaks inside itself); without it they scroll sideways under a themed thin scrollbar. The button's column has
8
+ * breaks inside itself); without it they scroll sideways under a themed scrollbar. The button's column has
9
9
  * a fixed width, so "copy" turning into "copied" never rewraps the code beside it. The button needs
10
10
  * client JS, which is why it is opt-in: a page rendered to static HTML needs `copyScript` inlined
11
11
  * or the button is dead.
package/dist/CodeBody.js CHANGED
@@ -1,15 +1,9 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { CodeText } from "./CodeText.js";
3
3
  import { CopyButton } from "./CopyButton.js";
4
- import { cx, themedScrollbar } from "./cx.js";
4
+ import { cx, insetFocusRing, themedScrollbar } from "./cx.js";
5
5
  import { consoleCommands } from "./highlight.js";
6
6
  import { scrollStopProps, useScrollStop } from "./scrollStop.js";
7
- /**
8
- * The strip's focus ring, drawn inside it: the frame around the code clips anything outside the
9
- * strip. `focusRing` with `-outline-offset-2` added would not do, since `outline-offset-2` comes
10
- * later in the CSS and wins.
11
- */
12
- const INSET_RING = "focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-violet-600";
13
7
  /** Whether a strip that scrolls sideways takes its tab stop: always, until it has been measured. */
14
8
  function takesStop(measured, stop) {
15
9
  return measured ? stop : true;
@@ -19,7 +13,7 @@ function takesStop(measured, stop) {
19
13
  * it that copies `code` exactly as given (wrapping is CSS, so it adds no characters), except in a
20
14
  * `console` block, where it copies only the commands (see `consoleCommands`). `wrap` wraps
21
15
  * long lines at whitespace only (a flag with hyphens stays whole; a word wider than the box still
22
- * breaks inside itself); without it they scroll sideways under a themed thin scrollbar. The button's column has
16
+ * breaks inside itself); without it they scroll sideways under a themed scrollbar. The button's column has
23
17
  * a fixed width, so "copy" turning into "copied" never rewraps the code beside it. The button needs
24
18
  * client JS, which is why it is opt-in: a page rendered to static HTML needs `copyScript` inlined
25
19
  * or the button is dead.
@@ -31,8 +25,8 @@ export function CodeBody({ code, language, wrap, copy, labelledBy, }) {
31
25
  // hydrated is never measured and still needs the stop. Once measured, a strip that fits drops it.
32
26
  const { attach, stop, measured } = useScrollStop("x");
33
27
  const tabStop = !wrap && takesStop(measured, stop);
34
- // The ring stays INSET_RING: scrollStopProps' own ring is drawn outside the box, which the strip's
28
+ // The ring is insetFocusRing: scrollStopProps' own ring is drawn outside the box, which the strip's
35
29
  // overflow-hidden frame would clip.
36
30
  const { props: stopProps } = scrollStopProps(tabStop, labelledBy !== undefined ? { labelledBy } : { label: "Code" });
37
- return (_jsxs("div", { className: cx("flex items-start", copy && "gap-1 pr-1.5"), children: [_jsx("div", { ref: wrap ? undefined : attach, ...stopProps, className: cx("min-w-0 flex-1", !wrap && `overflow-x-auto ${themedScrollbar}`, tabStop && INSET_RING), children: _jsx("pre", { className: cx("px-3 py-2.5 font-mono text-[12.5px] leading-normal text-slate-900", wrap ? "break-words whitespace-pre-wrap" : "w-max min-w-full whitespace-pre"), children: _jsx(CodeText, { code: code, language: language, breakAtSpaces: wrap }) }) }), copy && (_jsx("div", { className: "flex w-14 shrink-0 justify-end pt-2", children: _jsx(CopyButton, { text: language === "console" ? consoleCommands(code) : code }) }))] }));
31
+ return (_jsxs("div", { className: cx("flex items-start", copy && "gap-1 pr-1.5"), children: [_jsx("div", { ref: wrap ? undefined : attach, ...stopProps, className: cx("min-w-0 flex-1", !wrap && `overflow-x-auto ${themedScrollbar}`, tabStop && insetFocusRing), children: _jsx("pre", { className: cx("px-3 py-2.5 font-mono text-[0.78125rem] leading-normal text-slate-900", wrap ? "break-words whitespace-pre-wrap" : "w-max min-w-full whitespace-pre"), children: _jsx(CodeText, { code: code, language: language, breakAtSpaces: wrap }) }) }), copy && (_jsx("div", { className: "flex w-14 shrink-0 justify-end pt-2", children: _jsx(CopyButton, { text: language === "console" ? consoleCommands(code) : code }) }))] }));
38
32
  }
@@ -6,7 +6,7 @@ import type { Passthrough } from "./props.js";
6
6
  * button beside the code copies it exactly as given (client JS; off by default). An optional `caption` is the frame's last band. The code is React, so
7
7
  * it is coloured as TSX. The preview is its own height, never padded to match a neighbour, down to
8
8
  * a shared minimum so two frames side by side start alike. A wide preview or a long line of code
9
- * scrolls inside the frame, under a thin themed scrollbar, instead of widening the page or
9
+ * scrolls inside the frame, under a themed scrollbar, instead of widening the page or
10
10
  * wrapping. Inside a `Prose` the preview stays on the app scale, so a demo looks as the component
11
11
  * does anywhere else; the caption is outside it.
12
12
  */
@@ -1,6 +1,7 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { CodeBody } from "./CodeBody.js";
3
3
  import { themedScrollbar } from "./cx.js";
4
+ import { ScrollBody } from "./scrollBody.js";
4
5
  import { AppScale } from "./typography.js";
5
6
  /**
6
7
  * One framed example: the rendered `children` on top and the `code` that makes them attached
@@ -8,10 +9,10 @@ import { AppScale } from "./typography.js";
8
9
  * button beside the code copies it exactly as given (client JS; off by default). An optional `caption` is the frame's last band. The code is React, so
9
10
  * it is coloured as TSX. The preview is its own height, never padded to match a neighbour, down to
10
11
  * a shared minimum so two frames side by side start alike. A wide preview or a long line of code
11
- * scrolls inside the frame, under a thin themed scrollbar, instead of widening the page or
12
+ * scrolls inside the frame, under a themed scrollbar, instead of widening the page or
12
13
  * wrapping. Inside a `Prose` the preview stays on the app scale, so a demo looks as the component
13
14
  * does anywhere else; the caption is outside it.
14
15
  */
15
16
  export function CodeExample({ code, caption, copy = false, children, ...rest }) {
16
- return (_jsxs("figure", { ...rest, className: "overflow-hidden rounded-lg border border-slate-200 bg-white", children: [_jsx("div", { className: `min-h-24 overflow-x-auto p-5 ${themedScrollbar}`, children: _jsx("div", { className: "text-slate-900", children: _jsx(AppScale, { children: children }) }) }), _jsx("div", { className: "border-t border-slate-200 bg-slate-50", children: _jsx(CodeBody, { code: code, language: "tsx", wrap: false, copy: copy }) }), caption && (_jsx("figcaption", { className: "border-t border-slate-200 px-3 py-2.5 text-sm/5 text-slate-500", children: caption }))] }));
17
+ return (_jsxs("figure", { ...rest, className: "overflow-hidden rounded-lg border border-slate-200 bg-white", children: [_jsx(ScrollBody, { axis: "x", label: "Preview", className: `min-h-24 overflow-x-auto p-5 ${themedScrollbar}`, children: _jsx("div", { className: "text-slate-900", children: _jsx(AppScale, { children: children }) }) }), _jsx("div", { className: "border-t border-slate-200 bg-slate-50", children: _jsx(CodeBody, { code: code, language: "tsx", wrap: false, copy: copy }) }), caption && (_jsx("figcaption", { className: "border-t border-slate-200 px-3 py-2.5 text-sm/5 text-slate-500", children: caption }))] }));
17
18
  }