@slashsuite/ui-react 0.12.1 → 0.13.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (385) hide show
  1. package/MIGRATING.md +386 -8
  2. package/README.md +89 -44
  3. package/agent-docs/components/app-shell.md +9 -6
  4. package/agent-docs/components/article-layout.md +140 -0
  5. package/agent-docs/components/audio.md +42 -0
  6. package/agent-docs/components/badge.md +2 -1
  7. package/agent-docs/components/body-text.md +26 -15
  8. package/agent-docs/components/bottom-sheet.md +27 -17
  9. package/agent-docs/components/breadcrumbs.md +10 -6
  10. package/agent-docs/components/button.md +2 -2
  11. package/agent-docs/components/call-to-action.md +59 -0
  12. package/agent-docs/components/callout.md +4 -3
  13. package/agent-docs/components/card-grid.md +15 -7
  14. package/agent-docs/components/card.md +33 -18
  15. package/agent-docs/components/cart-button.md +63 -0
  16. package/agent-docs/components/chat-composer.md +4 -3
  17. package/agent-docs/components/checkbox.md +11 -5
  18. package/agent-docs/components/cluster.md +10 -8
  19. package/agent-docs/components/code-example.md +2 -2
  20. package/agent-docs/components/code.md +7 -5
  21. package/agent-docs/components/colour-scheme-toggle.md +12 -6
  22. package/agent-docs/components/colour-swatch.md +41 -0
  23. package/agent-docs/components/combobox.md +88 -0
  24. package/agent-docs/components/confirm-dialog.md +98 -0
  25. package/agent-docs/components/container.md +2 -1
  26. package/agent-docs/components/copy-button.md +7 -5
  27. package/agent-docs/components/copy-line.md +6 -5
  28. package/agent-docs/components/date-field.md +14 -11
  29. package/agent-docs/components/date-range-picker.md +16 -9
  30. package/agent-docs/components/date-time-field.md +73 -0
  31. package/agent-docs/components/dialog.md +22 -68
  32. package/agent-docs/components/disclosure.md +4 -0
  33. package/agent-docs/components/docs-layout.md +10 -6
  34. package/agent-docs/components/drawer.md +13 -4
  35. package/agent-docs/components/embed-frame.md +48 -0
  36. package/agent-docs/components/empty-state.md +4 -1
  37. package/agent-docs/components/field-dialog.md +6 -5
  38. package/agent-docs/components/field.md +10 -7
  39. package/agent-docs/components/fieldset.md +4 -4
  40. package/agent-docs/components/flow-diagram.md +87 -0
  41. package/agent-docs/components/form-layout.md +4 -1
  42. package/agent-docs/components/form-row.md +7 -7
  43. package/agent-docs/components/full-bleed-layout.md +0 -2
  44. package/agent-docs/components/headings.md +13 -7
  45. package/agent-docs/components/hero.md +11 -2
  46. package/agent-docs/components/icon-button.md +1 -3
  47. package/agent-docs/components/icon.md +6 -13
  48. package/agent-docs/components/image.md +24 -14
  49. package/agent-docs/components/input.md +8 -7
  50. package/agent-docs/components/key-value-list.md +4 -1
  51. package/agent-docs/components/lightbox.md +1 -1
  52. package/agent-docs/components/list-layout.md +5 -7
  53. package/agent-docs/components/list-row.md +37 -34
  54. package/agent-docs/components/loading.md +2 -2
  55. package/agent-docs/components/markdown.md +13 -13
  56. package/agent-docs/components/media-tile.md +8 -4
  57. package/agent-docs/components/menu.md +19 -12
  58. package/agent-docs/components/meta-list.md +2 -2
  59. package/agent-docs/components/morph.md +11 -5
  60. package/agent-docs/components/navigation-progress.md +2 -2
  61. package/agent-docs/components/number-field.md +75 -0
  62. package/agent-docs/components/outline-region.md +19 -8
  63. package/agent-docs/components/page-fade.md +2 -1
  64. package/agent-docs/components/pill.md +7 -6
  65. package/agent-docs/components/popover.md +63 -0
  66. package/agent-docs/components/price.md +49 -0
  67. package/agent-docs/components/product-tile.md +78 -0
  68. package/agent-docs/components/promo-banner.md +46 -0
  69. package/agent-docs/components/prose-layout.md +1 -1
  70. package/agent-docs/components/radio-group.md +9 -6
  71. package/agent-docs/components/scroll-strip.md +3 -3
  72. package/agent-docs/components/segmented-control.md +4 -2
  73. package/agent-docs/components/select.md +8 -3
  74. package/agent-docs/components/show.md +2 -2
  75. package/agent-docs/components/side-column.md +13 -9
  76. package/agent-docs/components/sidebar-layout.md +1 -1
  77. package/agent-docs/components/site-footer.md +4 -4
  78. package/agent-docs/components/site-search.md +21 -9
  79. package/agent-docs/components/slider.md +59 -0
  80. package/agent-docs/components/sortable-list.md +15 -10
  81. package/agent-docs/components/stack.md +3 -3
  82. package/agent-docs/components/stacked-bar.md +7 -4
  83. package/agent-docs/components/state-machine.md +95 -0
  84. package/agent-docs/components/status-pages.md +13 -6
  85. package/agent-docs/components/stepper.md +54 -0
  86. package/agent-docs/components/switch.md +4 -4
  87. package/agent-docs/components/table-of-contents.md +78 -0
  88. package/agent-docs/components/table.md +35 -24
  89. package/agent-docs/components/tabs.md +24 -26
  90. package/agent-docs/components/text-link.md +12 -7
  91. package/agent-docs/components/textarea.md +4 -2
  92. package/agent-docs/components/toast.md +19 -14
  93. package/agent-docs/components/video.md +7 -2
  94. package/agent-docs/llms.txt +22 -3
  95. package/dist/AppShell.d.ts +25 -9
  96. package/dist/AppShell.js +67 -33
  97. package/dist/AppShellMenu.d.ts +31 -18
  98. package/dist/AppShellMenu.js +72 -45
  99. package/dist/ArticleLayout.d.ts +36 -0
  100. package/dist/ArticleLayout.js +27 -0
  101. package/dist/Audio.d.ts +16 -0
  102. package/dist/Audio.js +11 -0
  103. package/dist/Badge.d.ts +2 -1
  104. package/dist/Badge.js +3 -2
  105. package/dist/BottomSheet.d.ts +17 -6
  106. package/dist/BottomSheet.js +62 -11
  107. package/dist/Breadcrumbs.d.ts +8 -6
  108. package/dist/Breadcrumbs.js +17 -7
  109. package/dist/Button.d.ts +4 -2
  110. package/dist/Button.js +9 -87
  111. package/dist/CallToAction.d.ts +25 -0
  112. package/dist/CallToAction.js +17 -0
  113. package/dist/Callout.d.ts +2 -2
  114. package/dist/Callout.js +2 -2
  115. package/dist/Card.d.ts +88 -31
  116. package/dist/Card.js +55 -92
  117. package/dist/CardBody.d.ts +2 -0
  118. package/dist/CardBody.js +33 -3
  119. package/dist/CardGrid.d.ts +32 -4
  120. package/dist/CardGrid.js +42 -8
  121. package/dist/CardParts.d.ts +7 -1
  122. package/dist/CardParts.js +7 -2
  123. package/dist/CartButton.d.ts +33 -0
  124. package/dist/CartButton.js +18 -0
  125. package/dist/ChatComposer.d.ts +10 -4
  126. package/dist/ChatComposer.js +35 -13
  127. package/dist/Checkbox.d.ts +21 -3
  128. package/dist/Checkbox.js +66 -20
  129. package/dist/Chevron.js +1 -1
  130. package/dist/Cluster.d.ts +28 -15
  131. package/dist/Cluster.js +21 -4
  132. package/dist/Code.d.ts +15 -3
  133. package/dist/Code.js +23 -3
  134. package/dist/CodeBlock.d.ts +4 -4
  135. package/dist/CodeBlock.js +2 -2
  136. package/dist/CodeBody.d.ts +1 -1
  137. package/dist/CodeBody.js +4 -10
  138. package/dist/CodeExample.d.ts +1 -1
  139. package/dist/CodeExample.js +3 -2
  140. package/dist/ColourSchemeToggle.d.ts +21 -5
  141. package/dist/ColourSchemeToggle.js +15 -9
  142. package/dist/ColourSwatch.d.ts +15 -0
  143. package/dist/ColourSwatch.js +14 -0
  144. package/dist/Combobox.d.ts +42 -0
  145. package/dist/Combobox.js +43 -0
  146. package/dist/ConfirmDialog.d.ts +40 -0
  147. package/dist/ConfirmDialog.js +36 -0
  148. package/dist/Container.d.ts +3 -3
  149. package/dist/Container.js +1 -1
  150. package/dist/CopyButton.d.ts +8 -2
  151. package/dist/CopyButton.js +38 -28
  152. package/dist/CopyLine.d.ts +4 -2
  153. package/dist/CopyLine.js +4 -4
  154. package/dist/DateCalendar.d.ts +2 -0
  155. package/dist/DateCalendar.js +11 -9
  156. package/dist/DateField.d.ts +52 -21
  157. package/dist/DateField.js +73 -37
  158. package/dist/DateFieldCalendar.d.ts +12 -8
  159. package/dist/DateFieldCalendar.js +37 -18
  160. package/dist/DateRangePicker.d.ts +23 -3
  161. package/dist/DateRangePicker.js +10 -8
  162. package/dist/DateTimeField.d.ts +31 -0
  163. package/dist/DateTimeField.js +19 -0
  164. package/dist/Dialog.d.ts +42 -6
  165. package/dist/Dialog.js +50 -12
  166. package/dist/Disclosure.js +9 -1
  167. package/dist/DocsLayout.d.ts +13 -5
  168. package/dist/DocsLayout.js +11 -9
  169. package/dist/Drawer.d.ts +22 -7
  170. package/dist/Drawer.js +89 -8
  171. package/dist/EmbedFrame.d.ts +36 -0
  172. package/dist/EmbedFrame.js +18 -0
  173. package/dist/Field.d.ts +41 -4
  174. package/dist/Field.js +61 -25
  175. package/dist/FieldDialog.d.ts +8 -3
  176. package/dist/FieldDialog.js +19 -9
  177. package/dist/Fieldset.d.ts +3 -3
  178. package/dist/Fieldset.js +7 -9
  179. package/dist/FileDrop.js +2 -1
  180. package/dist/FlowDiagram.d.ts +92 -0
  181. package/dist/FlowDiagram.js +100 -0
  182. package/dist/FormRow.d.ts +6 -4
  183. package/dist/FormRow.js +11 -9
  184. package/dist/Hero.d.ts +30 -7
  185. package/dist/Hero.js +23 -9
  186. package/dist/Icon.d.ts +1 -1
  187. package/dist/Icon.js +1 -1
  188. package/dist/IconButton.js +1 -1
  189. package/dist/Image.d.ts +33 -9
  190. package/dist/Image.js +61 -16
  191. package/dist/Input.d.ts +1 -1
  192. package/dist/Input.js +4 -4
  193. package/dist/InputShell.d.ts +7 -0
  194. package/dist/InputShell.js +18 -3
  195. package/dist/KeyValueList.d.ts +2 -2
  196. package/dist/Lightbox.js +5 -3
  197. package/dist/ListRow.d.ts +4 -5
  198. package/dist/ListRow.js +36 -26
  199. package/dist/Mark.d.ts +10 -0
  200. package/dist/Mark.js +9 -0
  201. package/dist/Markdown.d.ts +18 -4
  202. package/dist/Markdown.js +176 -37
  203. package/dist/MediaTile.d.ts +9 -3
  204. package/dist/MediaTile.js +8 -4
  205. package/dist/Menu.d.ts +19 -8
  206. package/dist/Menu.js +13 -11
  207. package/dist/MetaList.d.ts +4 -3
  208. package/dist/MetaList.js +12 -4
  209. package/dist/Morph.d.ts +15 -1
  210. package/dist/Morph.js +70 -22
  211. package/dist/NavigationProgress.d.ts +2 -2
  212. package/dist/NavigationProgress.js +7 -5
  213. package/dist/NumberField.d.ts +66 -0
  214. package/dist/NumberField.js +68 -0
  215. package/dist/OutlineRegion.d.ts +41 -10
  216. package/dist/OutlineRegion.js +31 -6
  217. package/dist/PageFade.d.ts +9 -5
  218. package/dist/PageFade.js +39 -8
  219. package/dist/PageLayouts.d.ts +15 -5
  220. package/dist/PageLayouts.js +3 -3
  221. package/dist/Pill.d.ts +9 -4
  222. package/dist/Pill.js +15 -6
  223. package/dist/Popover.d.ts +31 -0
  224. package/dist/Popover.js +43 -0
  225. package/dist/Price.d.ts +21 -0
  226. package/dist/Price.js +34 -0
  227. package/dist/ProductTile.d.ts +36 -0
  228. package/dist/ProductTile.js +31 -0
  229. package/dist/ProgressBar.js +4 -2
  230. package/dist/PromoBanner.d.ts +25 -0
  231. package/dist/PromoBanner.js +16 -0
  232. package/dist/RadioGroup.d.ts +18 -8
  233. package/dist/RadioGroup.js +42 -18
  234. package/dist/ScrollStrip.d.ts +1 -1
  235. package/dist/ScrollStrip.js +1 -1
  236. package/dist/SearchInput.d.ts +17 -2
  237. package/dist/SearchInput.js +72 -13
  238. package/dist/SegmentedField.d.ts +15 -0
  239. package/dist/SegmentedField.js +15 -0
  240. package/dist/Select.js +5 -4
  241. package/dist/Show.d.ts +1 -1
  242. package/dist/Show.js +1 -1
  243. package/dist/SideColumn.d.ts +42 -15
  244. package/dist/SideColumn.js +45 -19
  245. package/dist/SiteFooter.d.ts +3 -3
  246. package/dist/SiteFooter.js +4 -3
  247. package/dist/SiteSearch.d.ts +57 -27
  248. package/dist/SiteSearch.js +13 -93
  249. package/dist/Slider.d.ts +27 -0
  250. package/dist/Slider.js +58 -0
  251. package/dist/SortableList.d.ts +19 -35
  252. package/dist/SortableList.js +36 -88
  253. package/dist/Stack.d.ts +4 -4
  254. package/dist/StackedBar.d.ts +13 -4
  255. package/dist/StackedBar.js +12 -7
  256. package/dist/StateMachine.d.ts +65 -0
  257. package/dist/StateMachine.js +116 -0
  258. package/dist/StatusPages.d.ts +28 -10
  259. package/dist/StatusPages.js +10 -10
  260. package/dist/Stepper.d.ts +21 -0
  261. package/dist/Stepper.js +33 -0
  262. package/dist/Steps.js +4 -3
  263. package/dist/Switch.d.ts +3 -3
  264. package/dist/Switch.js +18 -14
  265. package/dist/Table.d.ts +32 -9
  266. package/dist/Table.js +50 -20
  267. package/dist/TableCells.d.ts +24 -21
  268. package/dist/TableCells.js +68 -27
  269. package/dist/TableEditCell.d.ts +1 -1
  270. package/dist/TableOfContents.d.ts +34 -0
  271. package/dist/TableOfContents.js +23 -0
  272. package/dist/Tabs.d.ts +31 -16
  273. package/dist/Tabs.js +97 -22
  274. package/dist/TextLink.d.ts +18 -5
  275. package/dist/TextLink.js +19 -6
  276. package/dist/Textarea.d.ts +12 -1
  277. package/dist/Textarea.js +15 -2
  278. package/dist/ToastRegion.d.ts +17 -9
  279. package/dist/ToastRegion.js +70 -13
  280. package/dist/Tooltip.d.ts +10 -2
  281. package/dist/Tooltip.js +32 -11
  282. package/dist/Video.d.ts +19 -4
  283. package/dist/Video.js +15 -5
  284. package/dist/cardContext.d.ts +7 -0
  285. package/dist/cardContext.js +14 -0
  286. package/dist/cardControl.d.ts +15 -0
  287. package/dist/cardControl.js +32 -0
  288. package/dist/cardForm.d.ts +39 -0
  289. package/dist/cardForm.js +81 -0
  290. package/dist/cardWait.js +2 -1
  291. package/dist/colourScheme.d.ts +12 -2
  292. package/dist/colourScheme.js +32 -6
  293. package/dist/control.d.ts +30 -8
  294. package/dist/control.js +74 -7
  295. package/dist/copyScript.d.ts +7 -8
  296. package/dist/copyScript.js +8 -9
  297. package/dist/core/button.d.ts +33 -0
  298. package/dist/core/button.js +89 -0
  299. package/dist/core/control.d.ts +15 -0
  300. package/dist/core/control.js +14 -0
  301. package/dist/core/fixtures/button.d.ts +26 -0
  302. package/dist/core/fixtures/button.js +52 -0
  303. package/dist/core/fixtures/types.d.ts +13 -0
  304. package/dist/core/fixtures/types.js +10 -0
  305. package/dist/core/focus.d.ts +7 -0
  306. package/dist/core/focus.js +7 -0
  307. package/dist/core/index.d.ts +12 -0
  308. package/dist/core/index.js +12 -0
  309. package/dist/core/parity.d.ts +22 -0
  310. package/dist/core/parity.js +53 -0
  311. package/dist/core/themeNative.d.ts +62 -0
  312. package/dist/core/themeNative.js +290 -0
  313. package/dist/cx.d.ts +17 -5
  314. package/dist/cx.js +18 -5
  315. package/dist/dateLocale.d.ts +17 -0
  316. package/dist/dateLocale.js +30 -0
  317. package/dist/density.d.ts +17 -3
  318. package/dist/density.js +30 -19
  319. package/dist/emptySlot.d.ts +1 -0
  320. package/dist/fieldAnnounce.d.ts +11 -0
  321. package/dist/fieldAnnounce.js +36 -0
  322. package/dist/fieldControl.d.ts +7 -2
  323. package/dist/fieldControl.js +6 -2
  324. package/dist/fieldWait.d.ts +3 -3
  325. package/dist/fieldWait.js +3 -4
  326. package/dist/flowLayout.d.ts +68 -0
  327. package/dist/flowLayout.js +105 -0
  328. package/dist/focus.d.ts +2 -0
  329. package/dist/focus.js +9 -0
  330. package/dist/fromXState.d.ts +73 -0
  331. package/dist/fromXState.js +110 -0
  332. package/dist/icons.d.ts +1 -1
  333. package/dist/icons.js +15 -0
  334. package/dist/index.d.ts +37 -11
  335. package/dist/index.js +24 -2
  336. package/dist/isoDate.d.ts +8 -1
  337. package/dist/isoDate.js +20 -1
  338. package/dist/labelWords.d.ts +16 -7
  339. package/dist/labelWords.js +14 -12
  340. package/dist/listRowProps.d.ts +17 -15
  341. package/dist/modal.d.ts +5 -0
  342. package/dist/modal.js +21 -1
  343. package/dist/navFold.js +6 -3
  344. package/dist/optionCard.d.ts +18 -0
  345. package/dist/optionCard.js +16 -0
  346. package/dist/scrollBody.d.ts +16 -0
  347. package/dist/scrollBody.js +15 -0
  348. package/dist/scrollEdges.d.ts +7 -0
  349. package/dist/scrollEdges.js +39 -5
  350. package/dist/scrollStop.d.ts +6 -2
  351. package/dist/scrollStop.js +24 -8
  352. package/dist/shownDate.d.ts +28 -10
  353. package/dist/shownDate.js +41 -22
  354. package/dist/siteSearchBody.d.ts +34 -0
  355. package/dist/siteSearchBody.js +117 -0
  356. package/dist/size.d.ts +7 -1
  357. package/dist/sortableDrop.d.ts +44 -0
  358. package/dist/sortableDrop.js +78 -0
  359. package/dist/sortableSlide.d.ts +9 -0
  360. package/dist/sortableSlide.js +70 -0
  361. package/dist/sortableTitle.d.ts +10 -0
  362. package/dist/sortableTitle.js +48 -0
  363. package/dist/stateMachineDots.d.ts +77 -0
  364. package/dist/stateMachineDots.js +188 -0
  365. package/dist/stickyColumn.d.ts +2 -2
  366. package/dist/stickyColumn.js +2 -2
  367. package/dist/switcher.d.ts +10 -5
  368. package/dist/switcher.js +7 -5
  369. package/dist/tableColumns.d.ts +17 -0
  370. package/dist/tableColumns.js +30 -2
  371. package/dist/tableEmpty.js +5 -5
  372. package/dist/tableRow.d.ts +26 -2
  373. package/dist/tableRow.js +23 -1
  374. package/dist/tableSort.d.ts +10 -5
  375. package/dist/tableSort.js +15 -4
  376. package/dist/target.d.ts +12 -0
  377. package/dist/target.js +12 -0
  378. package/dist/textBox.js +1 -1
  379. package/dist/truncated.d.ts +31 -0
  380. package/dist/truncated.js +51 -0
  381. package/dist/typography.d.ts +19 -11
  382. package/dist/typography.js +11 -13
  383. package/dist/useFlowLayout.d.ts +38 -0
  384. package/dist/useFlowLayout.js +122 -0
  385. package/package.json +5 -3
@@ -0,0 +1,51 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useRef, useState, } from "react";
3
+ import { cx, focusRing } from "./cx.js";
4
+ import { useTooltip } from "./Tooltip.js";
5
+ // A one-line run cut with an ellipsis shows its whole text in the library's tooltip on hover,
6
+ // keyboard focus and a tap, not only in a native `title` (which the keyboard and touch never reach).
7
+ // The tooltip shows only while the text is cut: a ResizeObserver compares the run's scroll width
8
+ // with its box, so a run that fits says nothing twice. The tooltip repeats the run's own words, so it
9
+ // is hidden from assistive tech, which reads the whole text from the page already.
10
+ /** What can take focus inside a run: a link or a control. A run with none is made a stop itself. */
11
+ const FOCUSABLE = "a[href], button, input, select, textarea, [tabindex]";
12
+ /**
13
+ * Whether the run in `ref` is cut by its box, and whether it holds its own focusable. Measured on
14
+ * each resize and when `text` changes. jsdom (a consumer's own tests) has no ResizeObserver, so
15
+ * there it reads never cut.
16
+ */
17
+ export function useCut(ref, text) {
18
+ const [state, setState] = useState({ cut: false, inner: false });
19
+ useEffect(() => {
20
+ const run = ref.current;
21
+ if (!run || text === undefined || typeof ResizeObserver === "undefined") {
22
+ setState((last) => (last.cut || last.inner ? { cut: false, inner: false } : last));
23
+ return undefined;
24
+ }
25
+ const measure = () => {
26
+ const cut = run.scrollWidth > run.clientWidth;
27
+ const inner = run.querySelector(FOCUSABLE) !== null;
28
+ setState((last) => (last.cut === cut && last.inner === inner ? last : { cut, inner }));
29
+ };
30
+ const observer = new ResizeObserver(measure);
31
+ observer.observe(run);
32
+ return () => observer.disconnect();
33
+ }, [ref, text]);
34
+ return state;
35
+ }
36
+ /**
37
+ * A one-line truncated run (`truncate` plus the caller's width) that shows its whole `text` in a
38
+ * tooltip while it is cut. A run that holds a link takes the link's focus; a plain one becomes a
39
+ * focus stop only while it is cut and the tooltip is the library's own, so the keyboard can reach
40
+ * it. Internal.
41
+ */
42
+ export function Truncated({ text, as: Tag = "div", attrs, className, children, }) {
43
+ const ref = useRef(null);
44
+ const { cut, inner } = useCut(ref, text);
45
+ const { props, tooltip, enhanced } = useTooltip(cut ? text : undefined, { describes: false, tap: true }, { "aria-describedby": attrs?.["aria-describedby"] });
46
+ // A focus stop only where focus shows the tooltip: a native title never shows on focus.
47
+ const stop = cut && !inner && enhanced;
48
+ return (_jsxs(_Fragment, { children: [_jsx(Tag, { ...attrs, ref: (run) => {
49
+ ref.current = run;
50
+ }, ...props, tabIndex: stop ? 0 : undefined, className: cx("truncate", className, stop && cx("rounded-sm", focusRing)), children: children }), tooltip] }));
51
+ }
@@ -1,4 +1,4 @@
1
- import { type ComponentPropsWithoutRef, type ElementType, type ReactElement, type ReactNode } from "react";
1
+ import { type ElementType, type ReactElement, type ReactNode } from "react";
2
2
  import { type TextAlign, type TextLines } from "./textBox.js";
3
3
  import type { Passthrough } from "./props.js";
4
4
  import { type LoadingProps } from "./skeleton.js";
@@ -52,21 +52,26 @@ type RunOwnProps = {
52
52
  italic?: boolean | undefined;
53
53
  /** Break a long unbroken string (a URL, a token) where the container ends, instead of overflowing. */
54
54
  breakWords?: boolean | undefined;
55
+ /** The full text on hover, for a run that `lines` cuts and whose content is not plain text. */
56
+ title?: string | undefined;
55
57
  };
56
58
  type Own = OwnProps & InlineOwnProps;
57
- /** Polymorphic props: own props + `as` + the intrinsic props of whichever element `as` selects. */
59
+ /**
60
+ * Own props + `as` + what every part takes through (`id`, `data-*`, `aria-*`). The element varies,
61
+ * its own attributes do not follow it: a role is text, so it takes no `role` or handler (`Text` and `Caption` take a `title` for `lines`).
62
+ */
58
63
  type TypographyProps<E extends ElementType> = OwnProps & {
59
- /** The element to render (each role has a semantic default); the other props follow it. */
64
+ /** The element to render; each role has a semantic default. */
60
65
  as?: E;
61
- } & Omit<ComponentPropsWithoutRef<E>, keyof OwnProps | "as" | "className" | "style" | "color">;
66
+ } & Passthrough;
62
67
  /**
63
68
  * The props of an inline role: `TypographyProps` plus `tone`, `numeric`, `mono` and `align`.
64
- * Spelled out like `TypographyProps`, not as an `Omit` of it, so the docs read its real types.
69
+ * Spelled out like `TypographyProps`, not as an intersection with it, so the docs read its real types.
65
70
  */
66
71
  export type InlineTypographyProps<E extends ElementType> = Own & {
67
- /** The element to render (each role has a semantic default); the other props follow it. */
72
+ /** The element to render; each role has a semantic default. */
68
73
  as?: E;
69
- } & Omit<ComponentPropsWithoutRef<E>, keyof Own | "as" | "className" | "style" | "color">;
74
+ } & Passthrough;
70
75
  /**
71
76
  * Marketing-scale headline: the one line at the top of a public page. `h1`,
72
77
  * text-4xl/tight semibold, primary text, growing to text-6xl on wider screens.
@@ -133,18 +138,21 @@ export type SubsectionHeadingSize = Size;
133
138
  * body size set apart by its weight) for a form-group caption or a dense card, or up to `lg`
134
139
  * (text-xl) for a drawer title; `md` is the default. Under an `AppShell density="compact"` each is one step down. Inside a `Prose`
135
140
  * `md` is text-xl/7 (the h3 of a doc), `sm` text-base/7 (the h4: body size, set apart by its weight)
136
- * and `lg` text-2xl/8, the size of a `SectionHeading` there. `truncate` keeps it on
141
+ * and `lg` text-2xl/8, the size of a `SectionHeading` there. `lines={1}` keeps it on
137
142
  * one line and cuts it with an ellipsis where its container ends, the full text as the `title`.
138
143
  */
139
- export declare function SubsectionHeading<E extends ElementType = "h3">({ size, truncate, ...props }: TypographyProps<E> & {
144
+ export declare function SubsectionHeading<E extends ElementType = "h3">({ size, ...props }: TypographyProps<E> & {
140
145
  /**
141
146
  * The heading's type size: `sm` is text-base/6, `md` text-lg/7 and `lg` text-xl/7 (one step down
142
147
  * each under an `AppShell density="compact"`).
143
148
  * @default md
144
149
  */
145
150
  size?: SubsectionHeadingSize;
146
- /** One line, cut with an ellipsis where the container ends; the full text becomes the `title`. */
147
- truncate?: boolean | undefined;
151
+ /**
152
+ * Show at most this many lines (1 to 4) and end in an ellipsis, as on `Text`: `1` cuts the
153
+ * heading where its container ends. With plain-text content the full text becomes the `title`.
154
+ */
155
+ lines?: TextLines | undefined;
148
156
  }): ReactElement;
149
157
  /**
150
158
  * Small all-caps label above a group. `span`, text-xs semibold uppercase, tertiary. `tone`,
@@ -1,6 +1,6 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Children, createContext, useContext, } from "react";
3
- import { cx } from "./cx.js";
3
+ import { balanced, cx, pretty } from "./cx.js";
4
4
  import { useStackGap } from "./stackGap.js";
5
5
  import { useTypeStep } from "./density.js";
6
6
  import { layoutClass } from "./textBox.js";
@@ -69,14 +69,15 @@ function plainText(children) {
69
69
  * `PageHeading` is the title of an ordinary page, a step below; a brochure hero needs a display
70
70
  * scale, so it gets its own pinned role rather than callers overriding PageHeading's size.
71
71
  */
72
- export const Display = typography("Display", "h1", "text-4xl/[1.1] font-semibold tracking-tight sm:text-5xl/[1.05] lg:text-6xl/[1.05]", "default");
72
+ export const Display = typography("Display", "h1", cx("text-4xl/[1.1] font-semibold tracking-tight sm:text-5xl/[1.05] lg:text-6xl/[1.05]", balanced), "default");
73
+ const LEAD = cx("text-lg/7 font-normal sm:text-xl/8", pretty);
73
74
  /** The supporting sentence under a `Display`. `p`, text-lg/7 normal, secondary. */
74
- export const Lead = typography("Lead", "p", "text-lg/7 font-normal sm:text-xl/8", "secondary");
75
+ export const Lead = typography("Lead", "p", LEAD, "secondary");
75
76
  /**
76
77
  * Page title. `h1`, text-3xl/9 bold (text-4xl/10 from `sm`), tight, primary text: well above the
77
78
  * `Lead` under it and the body text after it, so the page's title reads first.
78
79
  */
79
- export const PageHeading = typography("PageHeading", "h1", "text-3xl/9 font-bold tracking-tight sm:text-4xl/10", "default");
80
+ export const PageHeading = typography("PageHeading", "h1", cx("text-3xl/9 font-bold tracking-tight sm:text-4xl/10", balanced), "default");
80
81
  // --- Prose: the long-form scale ---------------------------------------------
81
82
  /**
82
83
  * Whether the text roles below are in a `Prose`. `Text`, `SectionHeading`, `SubsectionHeading` and
@@ -151,9 +152,9 @@ export function SectionHeading({ rule, description, ...props }) {
151
152
  // An `id` makes the heading a link target, so an anchor jump leaves it clear of the sticky header.
152
153
  const scroll = props.id === undefined ? undefined : SCROLL_TARGET;
153
154
  if (!hasDescription) {
154
- return pinned("h2", cx(rule && hairline, size, scroll), "default", props);
155
+ return pinned("h2", cx(rule && hairline, size, balanced, scroll), "default", props);
155
156
  }
156
- return (_jsxs("div", { className: cx("flex flex-col gap-1", rule && hairline), children: [pinned("h2", cx(size, scroll), "default", props), _jsx(Text, { tone: "muted", children: description })] }));
157
+ return (_jsxs("div", { className: cx("flex flex-col gap-1", rule && hairline), children: [pinned("h2", cx(size, balanced, scroll), "default", props), _jsx(Text, { tone: "muted", children: description })] }));
157
158
  }
158
159
  const SUBSECTION_SIZE = {
159
160
  sm: {
@@ -177,14 +178,11 @@ const SUBSECTION_SIZE = {
177
178
  * body size set apart by its weight) for a form-group caption or a dense card, or up to `lg`
178
179
  * (text-xl) for a drawer title; `md` is the default. Under an `AppShell density="compact"` each is one step down. Inside a `Prose`
179
180
  * `md` is text-xl/7 (the h3 of a doc), `sm` text-base/7 (the h4: body size, set apart by its weight)
180
- * and `lg` text-2xl/8, the size of a `SectionHeading` there. `truncate` keeps it on
181
+ * and `lg` text-2xl/8, the size of a `SectionHeading` there. `lines={1}` keeps it on
181
182
  * one line and cuts it with an ellipsis where its container ends, the full text as the `title`.
182
183
  */
183
- export function SubsectionHeading({ size = "md", truncate, ...props }) {
184
- return pinned("h3", useScale(SUBSECTION_SIZE[size]), "default", {
185
- ...props,
186
- lines: truncate ? 1 : undefined,
187
- });
184
+ export function SubsectionHeading({ size = "md", ...props }) {
185
+ return pinned("h3", cx(useScale(SUBSECTION_SIZE[size]), balanced), "default", props);
188
186
  }
189
187
  // --- Inline roles -------------------------------------------------------------
190
188
  const OVERLINE = "text-xs font-semibold uppercase tracking-wide";
@@ -228,7 +226,7 @@ export function HeaderText({ children }) {
228
226
  }
229
227
  const TEXT = { app: "text-base/6", compact: "text-sm/5", prose: "text-base/7" };
230
228
  function textVariant(strong, preserveNewlines, measure, size) {
231
- return cx(preserveNewlines && "whitespace-pre-line", measure && "max-w-[72ch]", size, strong ? "font-medium" : "font-normal");
229
+ return cx(preserveNewlines && "whitespace-pre-line", measure && cx("max-w-[72ch]", pretty), size, strong ? "font-medium" : "font-normal");
232
230
  }
233
231
  /**
234
232
  * Fine print / metadata. A paragraph (`p`; `as="span"` inline), text-sm/5 normal, tertiary
@@ -0,0 +1,38 @@
1
+ import { type RefObject } from "react";
2
+ import type { FlowEdge, FlowNode } from "./FlowDiagram.js";
3
+ import { type FlowDirection, type FlowLayout } from "./flowLayout.js";
4
+ type Size = {
5
+ width: number;
6
+ height: number;
7
+ };
8
+ /**
9
+ * What the layout reads from a node. A caller that knows its content's size (`StateMachine`, whose
10
+ * boxes are a fixed size) gives it as `contentSize`, so the first layout, the one a server render
11
+ * shows, already has each box at its drawn size.
12
+ */
13
+ export type SizedNode = Pick<FlowNode, "id" | "label" | "group" | "content"> & {
14
+ contentSize?: Size | undefined;
15
+ };
16
+ export declare function guessNode(node: SizedNode): Size;
17
+ export declare const nodeKey: (id: string) => string;
18
+ export declare const edgeKey: (index: number) => string;
19
+ /**
20
+ * How far to shrink a diagram `width` wide so it fits the box `frame` refers to: 1 when it fits
21
+ * or the room is not known yet (the server render, a test's DOM), else the room over the width.
22
+ * The observer follows the room as it changes.
23
+ */
24
+ export declare function useFit(width: number): {
25
+ frame: RefObject<HTMLDivElement | null>;
26
+ scale: number;
27
+ };
28
+ /**
29
+ * Lays the diagram out, first at guessed sizes, then at the sizes the browser draws each box and
30
+ * arrow label at: every render measures them, and lays out again when one's size is not the one
31
+ * the layout used. A box's size never depends on where it is placed, so this settles after one
32
+ * pass; the observer catches a later change (a web font arriving).
33
+ */
34
+ export declare function useFlowLayout(nodes: readonly SizedNode[], edges: readonly FlowEdge[], direction: FlowDirection): {
35
+ canvas: RefObject<HTMLDivElement | null>;
36
+ drawn: FlowLayout;
37
+ };
38
+ export {};
@@ -0,0 +1,122 @@
1
+ import { useLayoutEffect, useMemo, useRef, useState } from "react";
2
+ import { layoutFlow, } from "./flowLayout.js";
3
+ /**
4
+ * The size a box or a label is drawn at before it can be measured (the server render, and a
5
+ * test's DOM, which has no layout): the label's characters at an average width, inside the
6
+ * padding and the border, wrapping at the 18rem cap. The browser then measures every box and lays
7
+ * the diagram out again at the real sizes.
8
+ */
9
+ const NODE_MAX = 288;
10
+ const NODE_CHAR = 7.4;
11
+ const NODE_PAD_X = 26;
12
+ const NODE_PAD_Y = 18;
13
+ const NODE_LINE = 20;
14
+ const CONTENT_GUESS = 32;
15
+ /** The gap between a box's label and its content (`mt-2`). */
16
+ const CONTENT_GAP = 8;
17
+ const EDGE_CHAR = 6.6;
18
+ const EDGE_PAD = 8;
19
+ const EDGE_LINE = 16;
20
+ export function guessNode(node) {
21
+ const text = Math.ceil(node.label.length * NODE_CHAR);
22
+ const lines = Math.max(1, Math.ceil(text / (NODE_MAX - NODE_PAD_X)));
23
+ const content = node.contentSize ?? { width: 0, height: CONTENT_GUESS - CONTENT_GAP };
24
+ return {
25
+ width: Math.min(NODE_MAX, Math.max(text, content.width) + NODE_PAD_X),
26
+ height: lines * NODE_LINE + NODE_PAD_Y + (node.content == null ? 0 : CONTENT_GAP + content.height),
27
+ };
28
+ }
29
+ const guessLabel = (label) => ({
30
+ width: Math.ceil(label.length * EDGE_CHAR) + EDGE_PAD,
31
+ height: EDGE_LINE,
32
+ });
33
+ export const nodeKey = (id) => `n:${id}`;
34
+ export const edgeKey = (index) => `e:${index}`;
35
+ /**
36
+ * Reads the drawn size of every box and arrow label under `root`, keyed by `data-measure`, in the
37
+ * diagram's own space: a canvas scaled to fit (`useFit`) is drawn smaller, so its sizes are read
38
+ * back at full scale. The small allowance keeps a rounding error from adding a pixel.
39
+ */
40
+ function measure(root) {
41
+ const out = {};
42
+ const drawnWidth = root.getBoundingClientRect().width;
43
+ const scale = root.offsetWidth > 0 && drawnWidth > 0 ? drawnWidth / root.offsetWidth : 1;
44
+ const full = (n) => Math.ceil(scale === 1 ? n : n / scale - 0.01);
45
+ for (const el of root.querySelectorAll("[data-measure]")) {
46
+ const rect = el.getBoundingClientRect();
47
+ const key = el.dataset["measure"];
48
+ if (key && rect.width > 0 && rect.height > 0) {
49
+ out[key] = { width: full(rect.width), height: full(rect.height) };
50
+ }
51
+ }
52
+ return out;
53
+ }
54
+ /**
55
+ * How far to shrink a diagram `width` wide so it fits the box `frame` refers to: 1 when it fits
56
+ * or the room is not known yet (the server render, a test's DOM), else the room over the width.
57
+ * The observer follows the room as it changes.
58
+ */
59
+ export function useFit(width) {
60
+ const frame = useRef(null);
61
+ const [room, setRoom] = useState(0);
62
+ useLayoutEffect(() => {
63
+ const box = frame.current;
64
+ if (!box)
65
+ return undefined;
66
+ const update = () => setRoom(box.clientWidth);
67
+ update();
68
+ if (typeof ResizeObserver === "undefined")
69
+ return undefined;
70
+ const observer = new ResizeObserver(update);
71
+ observer.observe(box);
72
+ return () => observer.disconnect();
73
+ }, []);
74
+ const scale = room > 0 && width > room ? room / width : 1;
75
+ return { frame, scale };
76
+ }
77
+ const sameSizes = (a, b) => {
78
+ const keys = Object.keys(a);
79
+ return (keys.length === Object.keys(b).length &&
80
+ keys.every((k) => a[k]?.width === b[k]?.width && a[k]?.height === b[k]?.height));
81
+ };
82
+ /**
83
+ * Lays the diagram out, first at guessed sizes, then at the sizes the browser draws each box and
84
+ * arrow label at: every render measures them, and lays out again when one's size is not the one
85
+ * the layout used. A box's size never depends on where it is placed, so this settles after one
86
+ * pass; the observer catches a later change (a web font arriving).
87
+ */
88
+ export function useFlowLayout(nodes, edges, direction) {
89
+ const canvas = useRef(null);
90
+ const [measured, setMeasured] = useState({});
91
+ const layoutNodes = nodes.map((n) => ({
92
+ id: n.id,
93
+ group: n.group,
94
+ ...(measured[nodeKey(n.id)] ?? guessNode(n)),
95
+ }));
96
+ const layoutEdges = edges.map((e, index) => ({
97
+ from: e.from,
98
+ to: e.to,
99
+ label: e.label ? (measured[edgeKey(index)] ?? guessLabel(e.label)) : undefined,
100
+ }));
101
+ const key = JSON.stringify([direction, layoutNodes, layoutEdges]);
102
+ // The key holds every input the layout reads, so the layout reruns only when one changes.
103
+ // oxlint-disable-next-line react-hooks/exhaustive-deps -- keyed on the serialised input above
104
+ const drawn = useMemo(() => layoutFlow(layoutNodes, layoutEdges, direction), [key]);
105
+ useLayoutEffect(() => {
106
+ const root = canvas.current;
107
+ if (!root)
108
+ return undefined;
109
+ const update = () => {
110
+ const next = measure(root);
111
+ setMeasured((prev) => (sameSizes(prev, next) ? prev : next));
112
+ };
113
+ update();
114
+ if (typeof ResizeObserver === "undefined")
115
+ return undefined;
116
+ const observer = new ResizeObserver(update);
117
+ for (const el of root.querySelectorAll("[data-measure]"))
118
+ observer.observe(el);
119
+ return () => observer.disconnect();
120
+ });
121
+ return { canvas, drawn };
122
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@slashsuite/ui-react",
3
- "version": "0.12.1",
3
+ "version": "0.13.1",
4
4
  "description": "UISlash React components: primitives, typography roles and a safe Markdown renderer, written against Tailwind v4 utilities. Pair with a theme from @slashsuite/themes.",
5
5
  "keywords": [
6
6
  "components",
@@ -43,19 +43,21 @@
43
43
  "./package.json": "./package.json"
44
44
  },
45
45
  "scripts": {
46
- "build": "rm -rf dist && tsc -p tsconfig.build.json",
46
+ "build": "rm -rf dist && tsc -p tsconfig.build.json && bun scripts/vendor-core.ts",
47
47
  "typecheck": "tsc --noEmit",
48
48
  "lint": "oxlint -c .oxlintrc.json --type-aware --deny-warnings --report-unused-disable-directives && bun ../../scripts/check-slop.ts",
49
49
  "test": "vitest run",
50
- "agent-docs": "bun ../../apps/hack-cove-site/scripts/agent-docs.ts",
50
+ "agent-docs": "bun ../../tools/docs/scripts/agent-docs.ts",
51
51
  "pack-check": "npm pack --dry-run --ignore-scripts && bun scripts/pack-docs.ts && bun scripts/consumer-types.ts",
52
52
  "prepack": "bun run build && bun run agent-docs"
53
53
  },
54
54
  "dependencies": {
55
+ "@dagrejs/dagre": "^3.1.3",
55
56
  "@internationalized/date": "^3.12.4",
56
57
  "react-aria-components": "^1.22.1"
57
58
  },
58
59
  "devDependencies": {
60
+ "@slashsuite/core": "0.0.0",
59
61
  "@testing-library/dom": "10.4.2",
60
62
  "@testing-library/react": "16.3.3",
61
63
  "@testing-library/user-event": "14.6.12",