@slashsuite/ui-react 0.0.0-stage → 0.11.3

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 (304) hide show
  1. package/LICENSE +21 -0
  2. package/MIGRATING.md +540 -0
  3. package/README.md +548 -2
  4. package/dist/AppShell.d.ts +127 -0
  5. package/dist/AppShell.js +119 -0
  6. package/dist/AppShellMenu.d.ts +26 -0
  7. package/dist/AppShellMenu.js +66 -0
  8. package/dist/Avatar.d.ts +75 -0
  9. package/dist/Avatar.js +95 -0
  10. package/dist/AvatarStack.d.ts +31 -0
  11. package/dist/AvatarStack.js +34 -0
  12. package/dist/Badge.d.ts +15 -0
  13. package/dist/Badge.js +15 -0
  14. package/dist/BottomSheet.d.ts +36 -0
  15. package/dist/BottomSheet.js +142 -0
  16. package/dist/Breadcrumbs.d.ts +27 -0
  17. package/dist/Breadcrumbs.js +29 -0
  18. package/dist/BulletList.d.ts +18 -0
  19. package/dist/BulletList.js +18 -0
  20. package/dist/Button.d.ts +121 -0
  21. package/dist/Button.js +182 -0
  22. package/dist/ButtonGroup.d.ts +15 -0
  23. package/dist/ButtonGroup.js +10 -0
  24. package/dist/Callout.d.ts +43 -0
  25. package/dist/Callout.js +45 -0
  26. package/dist/Card.d.ts +148 -0
  27. package/dist/Card.js +171 -0
  28. package/dist/CardBadge.d.ts +7 -0
  29. package/dist/CardBadge.js +12 -0
  30. package/dist/CardBody.d.ts +28 -0
  31. package/dist/CardBody.js +30 -0
  32. package/dist/CardGrid.d.ts +53 -0
  33. package/dist/CardGrid.js +52 -0
  34. package/dist/CardParts.d.ts +40 -0
  35. package/dist/CardParts.js +41 -0
  36. package/dist/ChatComposer.d.ts +35 -0
  37. package/dist/ChatComposer.js +50 -0
  38. package/dist/ChatMessage.d.ts +26 -0
  39. package/dist/ChatMessage.js +21 -0
  40. package/dist/ChatThread.d.ts +25 -0
  41. package/dist/ChatThread.js +60 -0
  42. package/dist/Checkbox.d.ts +42 -0
  43. package/dist/Checkbox.js +63 -0
  44. package/dist/Chevron.d.ts +5 -0
  45. package/dist/Chevron.js +6 -0
  46. package/dist/Cluster.d.ts +70 -0
  47. package/dist/Cluster.js +47 -0
  48. package/dist/Code.d.ts +6 -0
  49. package/dist/Code.js +5 -0
  50. package/dist/CodeBlock.d.ts +46 -0
  51. package/dist/CodeBlock.js +21 -0
  52. package/dist/CodeBody.d.ts +20 -0
  53. package/dist/CodeBody.js +38 -0
  54. package/dist/CodeExample.d.ts +25 -0
  55. package/dist/CodeExample.js +17 -0
  56. package/dist/CodeText.d.ts +11 -0
  57. package/dist/CodeText.js +64 -0
  58. package/dist/ColourSchemeToggle.d.ts +36 -0
  59. package/dist/ColourSchemeToggle.js +64 -0
  60. package/dist/Container.d.ts +22 -0
  61. package/dist/Container.js +26 -0
  62. package/dist/CopyButton.d.ts +17 -0
  63. package/dist/CopyButton.js +39 -0
  64. package/dist/CopyLine.d.ts +9 -0
  65. package/dist/CopyLine.js +7 -0
  66. package/dist/DateCalendar.d.ts +23 -0
  67. package/dist/DateCalendar.js +89 -0
  68. package/dist/DateField.d.ts +124 -0
  69. package/dist/DateField.js +111 -0
  70. package/dist/DateFieldCalendar.d.ts +24 -0
  71. package/dist/DateFieldCalendar.js +50 -0
  72. package/dist/DateRangePicker.d.ts +47 -0
  73. package/dist/DateRangePicker.js +44 -0
  74. package/dist/Dialog.d.ts +56 -0
  75. package/dist/Dialog.js +94 -0
  76. package/dist/Disclosure.d.ts +29 -0
  77. package/dist/Disclosure.js +23 -0
  78. package/dist/Divider.d.ts +4 -0
  79. package/dist/Divider.js +5 -0
  80. package/dist/DocsLayout.d.ts +69 -0
  81. package/dist/DocsLayout.js +64 -0
  82. package/dist/Drawer.d.ts +30 -0
  83. package/dist/Drawer.js +24 -0
  84. package/dist/EmptyState.d.ts +47 -0
  85. package/dist/EmptyState.js +34 -0
  86. package/dist/Field.d.ts +44 -0
  87. package/dist/Field.js +51 -0
  88. package/dist/FieldDialog.d.ts +26 -0
  89. package/dist/FieldDialog.js +31 -0
  90. package/dist/Fieldset.d.ts +21 -0
  91. package/dist/Fieldset.js +22 -0
  92. package/dist/FileDrop.d.ts +17 -0
  93. package/dist/FileDrop.js +14 -0
  94. package/dist/FormRow.d.ts +46 -0
  95. package/dist/FormRow.js +39 -0
  96. package/dist/Hero.d.ts +23 -0
  97. package/dist/Hero.js +28 -0
  98. package/dist/Icon.d.ts +40 -0
  99. package/dist/Icon.js +30 -0
  100. package/dist/IconButton.d.ts +72 -0
  101. package/dist/IconButton.js +65 -0
  102. package/dist/Image.d.ts +58 -0
  103. package/dist/Image.js +69 -0
  104. package/dist/InlineEdit.d.ts +22 -0
  105. package/dist/InlineEdit.js +60 -0
  106. package/dist/Input.d.ts +40 -0
  107. package/dist/Input.js +42 -0
  108. package/dist/InputShell.d.ts +24 -0
  109. package/dist/InputShell.js +40 -0
  110. package/dist/Kbd.d.ts +6 -0
  111. package/dist/Kbd.js +5 -0
  112. package/dist/KeyValueList.d.ts +34 -0
  113. package/dist/KeyValueList.js +35 -0
  114. package/dist/Lightbox.d.ts +45 -0
  115. package/dist/Lightbox.js +46 -0
  116. package/dist/ListRow.d.ts +26 -0
  117. package/dist/ListRow.js +151 -0
  118. package/dist/Markdown.d.ts +11 -0
  119. package/dist/Markdown.js +49 -0
  120. package/dist/MediaTile.d.ts +66 -0
  121. package/dist/MediaTile.js +50 -0
  122. package/dist/Menu.d.ts +64 -0
  123. package/dist/Menu.js +86 -0
  124. package/dist/MetaList.d.ts +23 -0
  125. package/dist/MetaList.js +20 -0
  126. package/dist/Morph.d.ts +41 -0
  127. package/dist/Morph.js +107 -0
  128. package/dist/NavigationProgress.d.ts +20 -0
  129. package/dist/NavigationProgress.js +26 -0
  130. package/dist/OutlineRegion.d.ts +60 -0
  131. package/dist/OutlineRegion.js +51 -0
  132. package/dist/PageFade.d.ts +30 -0
  133. package/dist/PageFade.js +46 -0
  134. package/dist/PageHeader.d.ts +26 -0
  135. package/dist/PageHeader.js +18 -0
  136. package/dist/PageLayouts.d.ts +100 -0
  137. package/dist/PageLayouts.js +78 -0
  138. package/dist/Pagination.d.ts +38 -0
  139. package/dist/Pagination.js +65 -0
  140. package/dist/Pill.d.ts +79 -0
  141. package/dist/Pill.js +121 -0
  142. package/dist/ProgressBar.d.ts +47 -0
  143. package/dist/ProgressBar.js +47 -0
  144. package/dist/RadioGroup.d.ts +55 -0
  145. package/dist/RadioGroup.js +53 -0
  146. package/dist/ScrollStrip.d.ts +21 -0
  147. package/dist/ScrollStrip.js +12 -0
  148. package/dist/SearchInput.d.ts +9 -0
  149. package/dist/SearchInput.js +55 -0
  150. package/dist/Section.d.ts +93 -0
  151. package/dist/Section.js +55 -0
  152. package/dist/SegmentedControl.d.ts +47 -0
  153. package/dist/SegmentedControl.js +78 -0
  154. package/dist/Select.d.ts +28 -0
  155. package/dist/Select.js +19 -0
  156. package/dist/Show.d.ts +33 -0
  157. package/dist/Show.js +27 -0
  158. package/dist/SideColumn.d.ts +50 -0
  159. package/dist/SideColumn.js +45 -0
  160. package/dist/SidebarLayout.d.ts +32 -0
  161. package/dist/SidebarLayout.js +77 -0
  162. package/dist/SiteFooter.d.ts +31 -0
  163. package/dist/SiteFooter.js +24 -0
  164. package/dist/SiteSearch.d.ts +40 -0
  165. package/dist/SiteSearch.js +150 -0
  166. package/dist/SortableList.d.ts +86 -0
  167. package/dist/SortableList.js +191 -0
  168. package/dist/SplitBar.d.ts +29 -0
  169. package/dist/SplitBar.js +22 -0
  170. package/dist/Stack.d.ts +114 -0
  171. package/dist/Stack.js +76 -0
  172. package/dist/StackedBar.d.ts +64 -0
  173. package/dist/StackedBar.js +58 -0
  174. package/dist/StatTile.d.ts +33 -0
  175. package/dist/StatTile.js +44 -0
  176. package/dist/StatusPages.d.ts +49 -0
  177. package/dist/StatusPages.js +63 -0
  178. package/dist/Steps.d.ts +29 -0
  179. package/dist/Steps.js +43 -0
  180. package/dist/StickyBar.d.ts +12 -0
  181. package/dist/StickyBar.js +10 -0
  182. package/dist/Switch.d.ts +56 -0
  183. package/dist/Switch.js +91 -0
  184. package/dist/Table.d.ts +92 -0
  185. package/dist/Table.js +92 -0
  186. package/dist/TableCells.d.ts +97 -0
  187. package/dist/TableCells.js +104 -0
  188. package/dist/TableEditCell.d.ts +31 -0
  189. package/dist/TableEditCell.js +17 -0
  190. package/dist/TableExpandCell.d.ts +25 -0
  191. package/dist/TableExpandCell.js +15 -0
  192. package/dist/Tabs.d.ts +38 -0
  193. package/dist/Tabs.js +46 -0
  194. package/dist/TextLink.d.ts +51 -0
  195. package/dist/TextLink.js +38 -0
  196. package/dist/Textarea.d.ts +11 -0
  197. package/dist/Textarea.js +11 -0
  198. package/dist/Timeline.d.ts +31 -0
  199. package/dist/Timeline.js +38 -0
  200. package/dist/ToastRegion.d.ts +44 -0
  201. package/dist/ToastRegion.js +37 -0
  202. package/dist/Tooltip.d.ts +46 -0
  203. package/dist/Tooltip.js +181 -0
  204. package/dist/TrendChart.d.ts +36 -0
  205. package/dist/TrendChart.js +58 -0
  206. package/dist/Video.d.ts +13 -0
  207. package/dist/Video.js +9 -0
  208. package/dist/blocked.d.ts +31 -0
  209. package/dist/blocked.js +31 -0
  210. package/dist/cardContext.d.ts +8 -0
  211. package/dist/cardContext.js +14 -0
  212. package/dist/cardWait.d.ts +13 -0
  213. package/dist/cardWait.js +16 -0
  214. package/dist/colourScheme.d.ts +22 -0
  215. package/dist/colourScheme.js +53 -0
  216. package/dist/control.d.ts +29 -0
  217. package/dist/control.js +37 -0
  218. package/dist/copyScript.d.ts +13 -0
  219. package/dist/copyScript.js +13 -0
  220. package/dist/cx.d.ts +19 -0
  221. package/dist/cx.js +21 -0
  222. package/dist/density.d.ts +38 -0
  223. package/dist/density.js +77 -0
  224. package/dist/emptySlot.d.ts +11 -0
  225. package/dist/emptySlot.js +16 -0
  226. package/dist/fieldControl.d.ts +23 -0
  227. package/dist/fieldControl.js +24 -0
  228. package/dist/fieldWait.d.ts +30 -0
  229. package/dist/fieldWait.js +27 -0
  230. package/dist/foldedColumn.d.ts +18 -0
  231. package/dist/foldedColumn.js +51 -0
  232. package/dist/headingLevel.d.ts +10 -0
  233. package/dist/headingLevel.js +18 -0
  234. package/dist/highlight.d.ts +18 -0
  235. package/dist/highlight.js +306 -0
  236. package/dist/highlightConsole.d.ts +9 -0
  237. package/dist/highlightConsole.js +42 -0
  238. package/dist/highlightHtml.d.ts +7 -0
  239. package/dist/highlightHtml.js +132 -0
  240. package/dist/highlightKit.d.ts +16 -0
  241. package/dist/highlightKit.js +23 -0
  242. package/dist/highlightYaml.d.ts +3 -0
  243. package/dist/highlightYaml.js +143 -0
  244. package/dist/icons.d.ts +16 -0
  245. package/dist/icons.js +108 -0
  246. package/dist/index.d.ts +99 -0
  247. package/dist/index.js +92 -0
  248. package/dist/isoDate.d.ts +5 -0
  249. package/dist/isoDate.js +16 -0
  250. package/dist/labelWords.d.ts +20 -0
  251. package/dist/labelWords.js +28 -0
  252. package/dist/layoutWait.d.ts +15 -0
  253. package/dist/layoutWait.js +18 -0
  254. package/dist/link.d.ts +82 -0
  255. package/dist/link.js +68 -0
  256. package/dist/listRowProps.d.ts +108 -0
  257. package/dist/listRowProps.js +1 -0
  258. package/dist/listRowWait.d.ts +6 -0
  259. package/dist/listRowWait.js +14 -0
  260. package/dist/modal.d.ts +25 -0
  261. package/dist/modal.js +61 -0
  262. package/dist/navFold.d.ts +15 -0
  263. package/dist/navFold.js +46 -0
  264. package/dist/pillTip.d.ts +8 -0
  265. package/dist/pillTip.js +25 -0
  266. package/dist/props.d.ts +26 -0
  267. package/dist/props.js +14 -0
  268. package/dist/scrollEdges.d.ts +12 -0
  269. package/dist/scrollEdges.js +40 -0
  270. package/dist/scrollStop.d.ts +32 -0
  271. package/dist/scrollStop.js +79 -0
  272. package/dist/sheetSnap.d.ts +27 -0
  273. package/dist/sheetSnap.js +45 -0
  274. package/dist/shownDate.d.ts +88 -0
  275. package/dist/shownDate.js +186 -0
  276. package/dist/size.d.ts +45 -0
  277. package/dist/size.js +12 -0
  278. package/dist/skeleton.d.ts +83 -0
  279. package/dist/skeleton.js +88 -0
  280. package/dist/stackGap.d.ts +9 -0
  281. package/dist/stackGap.js +16 -0
  282. package/dist/stickyColumn.d.ts +38 -0
  283. package/dist/stickyColumn.js +38 -0
  284. package/dist/switcher.d.ts +93 -0
  285. package/dist/switcher.js +78 -0
  286. package/dist/tableColumns.d.ts +31 -0
  287. package/dist/tableColumns.js +72 -0
  288. package/dist/tableEmpty.d.ts +15 -0
  289. package/dist/tableEmpty.js +26 -0
  290. package/dist/tableRow.d.ts +67 -0
  291. package/dist/tableRow.js +49 -0
  292. package/dist/tableSort.d.ts +22 -0
  293. package/dist/tableSort.js +19 -0
  294. package/dist/textBox.d.ts +10 -0
  295. package/dist/textBox.js +23 -0
  296. package/dist/tone.d.ts +11 -0
  297. package/dist/tone.js +1 -0
  298. package/dist/trend.d.ts +26 -0
  299. package/dist/trend.js +64 -0
  300. package/dist/typography.d.ts +203 -0
  301. package/dist/typography.js +242 -0
  302. package/dist/useImageFailed.d.ts +19 -0
  303. package/dist/useImageFailed.js +21 -0
  304. package/package.json +84 -4
@@ -0,0 +1,78 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Children } from "react";
3
+ import { Callout } from "./Callout.js";
4
+ import { Card } from "./Card.js";
5
+ import { cx } from "./cx.js";
6
+ import { PageHeader, PageHeaderContent } from "./PageHeader.js";
7
+ import { STACK_WIDTH, Stack } from "./Stack.js";
8
+ import { SplitColumns } from "./SideColumn.js";
9
+ import { StickyBar } from "./StickyBar.js";
10
+ import { EmptySlot } from "./emptySlot.js";
11
+ import { useWait } from "./layoutWait.js";
12
+ export { CardGrid } from "./CardGrid.js";
13
+ import { LoadingScope } from "./skeleton.js";
14
+ // Compositions of the layout foundation. None sets a page width or outer padding of its own; the
15
+ // ones that narrow their content do it inside the Container they are rendered in.
16
+ /** A list page: header, an optional `filters` slot, then the list, or `empty` when there are no children. While `loading` it owns the wait and passes it to everything inside, the header too. With no children yet it draws a card of row bones, never `empty`. */
17
+ export function ListLayout({ filters, empty, children, breadcrumbs, title, description, actions, tabs, loading, loadingLabel, ...rest }) {
18
+ const wait = useWait(loading, loadingLabel);
19
+ return (_jsxs(LoadingScope, { loading: wait.loading, children: [_jsx(PageHeader, { breadcrumbs: breadcrumbs, title: title, description: description, actions: actions, tabs: tabs }), _jsxs(Stack, { ...rest, ...wait.attrs, children: [filters, _jsx(ListBody, { loading: wait.loading, empty: empty, children: children }), wait.label] })] }));
20
+ }
21
+ /** A list page's records; with none, a card of row bones while loading (loading beats empty), else `empty`. */
22
+ function ListBody({ loading, empty, children, }) {
23
+ if (Children.toArray(children).length > 0)
24
+ return children;
25
+ if (loading)
26
+ return _jsx(Card, { flush: true, children: null });
27
+ return _jsx(EmptySlot, { size: "md", children: empty });
28
+ }
29
+ /**
30
+ * A detail page: header, then `children` (two thirds from `lg`) beside `aside` (one third), which
31
+ * stacks below on a smaller screen: a `SideColumn asideWidth="third"` under a `PageHeader`. `sticky` keeps the aside in view from `lg` as a long page
32
+ * scrolls: it sticks under AppShell's header and, if it is taller than the room left, scrolls
33
+ * itself so its end stays reachable. While `loading` it owns the wait and passes it to everything inside, the header too.
34
+ */
35
+ export function DetailLayout({ aside, asideLabel, sticky = false, children, breadcrumbs, title, description, actions, tabs, loading, loadingLabel, ...rest }) {
36
+ const wait = useWait(loading, loadingLabel);
37
+ return (_jsxs(LoadingScope, { loading: wait.loading, children: [_jsx(PageHeader, { breadcrumbs: breadcrumbs, title: title, description: description, actions: actions, tabs: tabs }), _jsx(SplitColumns, { ...rest, ...wait.attrs, asideWidth: "third", label: asideLabel, fold: false, sticky: sticky, aside: _jsx(Stack, { children: aside }), children: _jsxs(Stack, { children: [children, wait.label] }) })] }));
38
+ }
39
+ /** A form page: header (no header `actions`), then a `max-w-3xl` column that starts at the Container's start edge (it is not re-centred), with an `actions` row at the end. `error` is the submit's failure, a danger `Callout` (an alert) directly above that row. Other props go on the `<form>`. While `loading` it owns the wait and passes it to everything inside, the header too. */
40
+ export function FormLayout({ actions, error, children, breadcrumbs, title, description, tabs, loading, loadingLabel, ...form }) {
41
+ const wait = useWait(loading, loadingLabel);
42
+ return (_jsxs(LoadingScope, { loading: wait.loading, children: [_jsx(PageHeader, { breadcrumbs: breadcrumbs, title: title, description: description, tabs: tabs }), _jsxs("form", { ...form, ...wait.attrs, className: "max-w-3xl", children: [_jsxs(Stack, { children: [children, error && _jsx(Callout, { tone: "danger", children: error }), actions && _jsx("div", { className: "flex flex-wrap items-center gap-2", children: actions })] }), wait.label] })] }));
43
+ }
44
+ /**
45
+ * A text page: header, then `children` stacked `gap` apart (`md` by default), all in one column that
46
+ * starts at the Container's start edge (it is not re-centred, so the title does not jump). `width`
47
+ * sets the column: `narrow` (`max-w-3xl`, the default) is a reading measure; `wide` (`max-w-5xl`) and
48
+ * `full` (the Container's whole width) suit a page that is not long prose, such as a pricing page.
49
+ * Paragraphs (`Text`) and the header's lede keep their own reading measure whatever the width.
50
+ * Unlike `FormLayout` the header sits inside the column, so its `actions` stay beside the text
51
+ * instead of at the Container's far edge. While `loading` it owns the wait and passes it to everything inside, the header too.
52
+ */
53
+ export function ProseLayout({ width = "narrow", gap = "md", children, breadcrumbs, title, description, actions, tabs, loading, loadingLabel, ...rest }) {
54
+ const wait = useWait(loading, loadingLabel);
55
+ return (_jsx(LoadingScope, { loading: wait.loading, children: _jsxs("div", { ...rest, ...wait.attrs, className: STACK_WIDTH[width], children: [_jsx(PageHeader, { breadcrumbs: breadcrumbs, title: title, description: description, actions: actions, tabs: tabs }), _jsx(Stack, { gap: gap, children: children }), wait.label] }) }));
56
+ }
57
+ /**
58
+ * Edge-to-edge `children` with an optional `aside` at the end (`lg:w-72`) that stacks below on a smaller
59
+ * screen. Render it in `<AppShell bleed>`. It deliberately breaks the shared start edge: a viewer
60
+ * that needs the whole width has no Container of its own, so `children` start at the viewport's
61
+ * start edge. `padded` gives them the Container's padding instead (`px-4`, `sm:px-6`, `py-8`), for
62
+ * a page of ordinary content beside a full-height `aside`. A `bar` is a `StickyBar` above both: the
63
+ * full width, on the surface with a bottom line, sticking under AppShell's header as the page scrolls.
64
+ * While `loading` it owns the wait and passes it to everything inside, the header too.
65
+ */
66
+ export function FullBleedLayout({ bar, aside, asideLabel, padded = false, children, loading, loadingLabel, ...rest }) {
67
+ const wait = useWait(loading, loadingLabel);
68
+ const row = (_jsxs(_Fragment, { children: [_jsx("div", { className: cx("min-w-0 flex-1", padded && "px-4 py-8 sm:px-6"), children: children }), aside && (_jsx("aside", { className: "w-full shrink-0 border-t border-slate-200 bg-slate-50 p-4 lg:w-72 lg:border-t-0 lg:border-l", "aria-label": asideLabel, children: aside }))] }));
69
+ if (!bar) {
70
+ return (_jsxs("div", { ...rest, ...wait.attrs, className: "flex min-h-0 flex-1 flex-col lg:flex-row", children: [_jsx(LoadingScope, { loading: wait.loading, children: row }), wait.label] }));
71
+ }
72
+ return (_jsxs("div", { ...rest, ...wait.attrs, className: "flex min-h-0 flex-1 flex-col", children: [_jsxs(LoadingScope, { loading: wait.loading, children: [_jsx(StickyBar, { children: bar }), _jsx("div", { className: "flex min-h-0 flex-1 flex-col lg:flex-row", children: row })] }), wait.label] }));
73
+ }
74
+ /** A narrow card (`max-w-md`) centred in the Container at a fixed offset from the top, for sign-in, landing, not-found and error pages. The one layout that does not share the start edge. While `loading` it owns the wait and passes it to everything inside, the header too. */
75
+ export function CenteredLayout({ mark, title, description, children, loading, loadingLabel, ...rest }) {
76
+ const wait = useWait(loading, loadingLabel);
77
+ return (_jsx(LoadingScope, { loading: wait.loading, children: _jsxs("div", { ...rest, ...wait.attrs, className: "mx-auto w-full max-w-md pt-16", children: [_jsx(Card, { children: _jsxs(Stack, { gap: "md", children: [mark, _jsx(PageHeaderContent, { title: title, description: description }), children] }) }), wait.label] }) }));
78
+ }
@@ -0,0 +1,38 @@
1
+ import type { ReactElement } from "react";
2
+ import type { Passthrough } from "./props.js";
3
+ /**
4
+ * The slots of the number row: always the first and the last page, the current page and its two
5
+ * neighbours, and a gap for a run of two or more hidden pages. A gap never hides a single page,
6
+ * and the row never holds more than seven slots. Page 1 of 20 is `1 2 3 4 5 … 20`, page 10 is
7
+ * `1 … 9 10 11 … 20`.
8
+ */
9
+ export declare function pageWindow(page: number, pageCount: number): Array<number | "gap">;
10
+ /**
11
+ * Page links for a long list: Previous, the page numbers and Next, in a `<nav>` named by `label`.
12
+ * Each is a link to `pageHref(page)`, drawn by the app's router link through `LinkProvider`, so the
13
+ * page lives in the URL and back, a new tab and a shared link all work. The current page is a link
14
+ * with `aria-current="page"`. Below `sm` the numbers give way to `pageLabel` ("Page 2 of 4").
15
+ * Renders nothing for one page. The count line ("21 to 40 of 312") is the caller's `Caption`.
16
+ */
17
+ export declare function Pagination({ label, page, pageCount, pageHref, previousLabel, nextLabel, pageLabel, ...rest }: {
18
+ /** Names the `<nav>`. Two pagers on a page (above and below a list) each need their own. */
19
+ label: string;
20
+ /** The page shown, from 1. Drawn clamped into `1` to `pageCount`. */
21
+ page: number;
22
+ /** How many pages there are. One or none draws nothing. */
23
+ pageCount: number;
24
+ /** The URL of one page, called for every link drawn: `(page) => (page > 1 ? `?page=${page}` : "?")`. */
25
+ pageHref: (page: number) => string;
26
+ /**
27
+ * The previous-page link's text.
28
+ * @default Previous
29
+ */
30
+ previousLabel?: string | undefined;
31
+ /**
32
+ * The next-page link's text.
33
+ * @default Next
34
+ */
35
+ nextLabel?: string | undefined;
36
+ /** The summary shown in place of the numbers below `sm`. Default: `Page 2 of 4`. */
37
+ pageLabel?: ((page: number, pageCount: number) => string) | undefined;
38
+ } & Passthrough): ReactElement | null;
@@ -0,0 +1,65 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { blockedButtonClass, buttonClass } from "./Button.js";
3
+ import { cx } from "./cx.js";
4
+ import { useTypeStep } from "./density.js";
5
+ import { renderLink } from "./link.js";
6
+ import { pillTabClass } from "./Tabs.js";
7
+ /** The most slots the number row holds, so it keeps one width as the page moves. */
8
+ const SLOTS = 7;
9
+ /** `page` moved into `1` to `pageCount`, so a stale `?page=9` of 4 draws page 4. */
10
+ function clamp(page, pageCount) {
11
+ return Math.min(Math.max(page, 1), pageCount);
12
+ }
13
+ /** The pages `from` to `to`, both included. */
14
+ function range(from, to) {
15
+ return Array.from({ length: to - from + 1 }, (_, index) => from + index);
16
+ }
17
+ /**
18
+ * The slots of the number row: always the first and the last page, the current page and its two
19
+ * neighbours, and a gap for a run of two or more hidden pages. A gap never hides a single page,
20
+ * and the row never holds more than seven slots. Page 1 of 20 is `1 2 3 4 5 … 20`, page 10 is
21
+ * `1 … 9 10 11 … 20`.
22
+ */
23
+ export function pageWindow(page, pageCount) {
24
+ if (pageCount <= SLOTS)
25
+ return range(1, pageCount);
26
+ const at = clamp(page, pageCount);
27
+ if (at <= 4)
28
+ return [...range(1, 5), "gap", pageCount];
29
+ if (at >= pageCount - 3)
30
+ return [1, "gap", ...range(pageCount - 4, pageCount)];
31
+ return [1, "gap", at - 1, at, at + 1, "gap", pageCount];
32
+ }
33
+ /** Previous or Next: a link in the outline look, or the same box as plain text at the edge. */
34
+ function Edge({ to, pageCount, pageHref, rel, step, children, }) {
35
+ if (to < 1 || to > pageCount) {
36
+ // Not a link: no dead stop in the tab order, and the row does not jump.
37
+ return _jsx("span", { className: blockedButtonClass("outline", { size: "sm" }, step), children: children });
38
+ }
39
+ return renderLink({
40
+ href: pageHref(to),
41
+ rel,
42
+ className: buttonClass("outline", { size: "sm" }, step),
43
+ children,
44
+ });
45
+ }
46
+ /**
47
+ * Page links for a long list: Previous, the page numbers and Next, in a `<nav>` named by `label`.
48
+ * Each is a link to `pageHref(page)`, drawn by the app's router link through `LinkProvider`, so the
49
+ * page lives in the URL and back, a new tab and a shared link all work. The current page is a link
50
+ * with `aria-current="page"`. Below `sm` the numbers give way to `pageLabel` ("Page 2 of 4").
51
+ * Renders nothing for one page. The count line ("21 to 40 of 312") is the caller's `Caption`.
52
+ */
53
+ export function Pagination({ label, page, pageCount, pageHref, previousLabel = "Previous", nextLabel = "Next", pageLabel = (at, count) => `Page ${at} of ${count}`, ...rest }) {
54
+ const step = useTypeStep();
55
+ if (pageCount <= 1)
56
+ return null;
57
+ const at = clamp(page, pageCount);
58
+ const edge = { pageCount, pageHref, step };
59
+ return (_jsx("nav", { ...rest, "aria-label": label, children: _jsxs("div", { className: "flex items-center gap-1", children: [_jsx(Edge, { to: at - 1, rel: "prev", ...edge, children: previousLabel }), _jsx("ol", { className: "hidden items-center gap-1 sm:flex", children: pageWindow(at, pageCount).map((slot, index) => slot === "gap" ? (_jsx("li", { "aria-hidden": "true", className: "px-1 text-sm text-slate-400", children: "\u2026" }, `gap-${index}`)) : (_jsx("li", { children: renderLink({
60
+ href: pageHref(slot),
61
+ "aria-current": slot === at ? "page" : undefined,
62
+ className: cx(pillTabClass(slot === at, false, "sm", step), "inline-flex min-w-8 justify-center tabular-nums"),
63
+ children: slot,
64
+ }) }, slot))) }), _jsx("span", { className: "px-2 text-sm text-slate-600 tabular-nums sm:hidden", children: pageLabel(at, pageCount) }), _jsx(Edge, { to: at + 1, rel: "next", ...edge, children: nextLabel })] }) }));
65
+ }
package/dist/Pill.d.ts ADDED
@@ -0,0 +1,79 @@
1
+ import type { MouseEventHandler, ReactElement, ReactNode } from "react";
2
+ import type { Passthrough } from "./props.js";
3
+ import { type LoadingProps } from "./skeleton.js";
4
+ import type { Size } from "./size.js";
5
+ import type { Tone } from "./tone.js";
6
+ /** A Pill's tones: the five meanings, and `accent` for a category that is none of them. */
7
+ export type PillTone = Tone | "accent";
8
+ type PillBase = LoadingProps & {
9
+ /** The pill's text; while `loading`, none yet draws the pill as a bone of its size. */
10
+ children?: ReactNode;
11
+ /**
12
+ * What the pill means: `neutral`, `info`, `positive`, `warn` or `danger`, or `accent` for a
13
+ * category that is none of those.
14
+ * @default neutral
15
+ */
16
+ tone?: PillTone;
17
+ /**
18
+ * `sm` is smaller text, for a dense row; `lg` larger, beside a heading. Left out, a Pill takes
19
+ * the size of the `Card`, `ListRow` or `Table` it sits in, else `md`.
20
+ * @default the container's, else md
21
+ */
22
+ size?: Size | undefined;
23
+ /** A leading dot in the pill's own text colour. */
24
+ dot?: boolean;
25
+ /** A full pill shape in place of the rounded-md corners. */
26
+ round?: boolean;
27
+ /**
28
+ * The detail behind a pill whose text is short or cut off (the full status, a date): its tooltip
29
+ * on hover, keyboard focus and a tap, and its description. A plain pill with a title is focusable.
30
+ *
31
+ * Keep anything a reader needs on the pill itself.
32
+ */
33
+ title?: string | undefined;
34
+ /**
35
+ * The name half of a two-tone `name: value` pill: `children` is the value. The name keeps the
36
+ * tone's tint and the value sits on a plain surface beside it, in a hairline border. Keep the
37
+ * name to a word or two (`Weight`, `Sleep`).
38
+ */
39
+ name?: string | undefined;
40
+ };
41
+ type Removable = {
42
+ onRemove?: undefined;
43
+ removeLabel?: undefined;
44
+ } | {
45
+ /** Adds a small x button after the text that calls this: for a chip the reader can drop (an attachment, a filter). It sits beside a link or button pill, never inside it. */
46
+ onRemove: () => void;
47
+ /** The x button's accessible name and tooltip: `Remove invoice.pdf`. Required with `onRemove`. */
48
+ removeLabel: string;
49
+ };
50
+ type PillProps = PillBase & Removable & Passthrough & ({
51
+ href?: undefined;
52
+ external?: undefined;
53
+ onClick?: undefined;
54
+ } | {
55
+ /** A Pill that is a button: runs `onClick`. Defaults to `type="button"`. */
56
+ onClick: MouseEventHandler<HTMLButtonElement>;
57
+ href?: undefined;
58
+ external?: undefined;
59
+ } | {
60
+ onClick?: undefined;
61
+ /** Opens in a new tab: adds `target="_blank"` and `rel="noreferrer"`. */
62
+ external?: boolean | undefined;
63
+ /** Makes the pill a link to this URL; an in-app path goes through the app's `LinkProvider`. */
64
+ href: string;
65
+ });
66
+ /**
67
+ * A small tinted label whose `tone` says what it means; `dot` adds a leading dot in the pill's own
68
+ * text colour, `round` swaps the rounded-md corners for a full pill shape, and `size` steps the
69
+ * text (with none, it takes its container's). `name` makes it two-tone, `name: value`: the name
70
+ * keeps the tone's tint and the children, the value, sit on the surface beside it. `href` makes it
71
+ * a link (the app's router link through `LinkProvider` for an in-app path, else a plain `<a>`;
72
+ * `external` opens a new tab) and `onClick` makes it
73
+ * a button, each with a hover dim and the focus ring. `onRemove` adds an x button after the text
74
+ * (named by `removeLabel`), a separate button beside a link or button pill rather than nested in
75
+ * it. `title` is its tooltip and description; a plain pill with one takes a tab stop. While
76
+ * `loading` with no text yet it is a bone of its size.
77
+ */
78
+ export declare function Pill(props: PillProps): ReactElement;
79
+ export {};
package/dist/Pill.js ADDED
@@ -0,0 +1,121 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { cx, focusRing } from "./cx.js";
3
+ import { useDensity } from "./density.js";
4
+ import { renderLink } from "./link.js";
5
+ import { isEmptySlot, passthroughOf, useLoading, WaitingBone, } from "./skeleton.js";
6
+ import { splitTip } from "./pillTip.js";
7
+ import { Tipped } from "./Tooltip.js";
8
+ const PILL_TONES = {
9
+ neutral: "bg-slate-100 text-slate-600",
10
+ warn: "bg-amber-50 text-amber-700",
11
+ positive: "bg-emerald-50 text-emerald-700",
12
+ info: "bg-blue-50 text-blue-700",
13
+ danger: "bg-red-50 text-red-900",
14
+ accent: "bg-violet-50 text-violet-700",
15
+ };
16
+ /** The text size of each step: `md` is the pill as it has always been. */
17
+ const TEXT = { sm: "text-[11px]", md: "text-xs", lg: "text-sm" };
18
+ /** A loading pill's height at each step: the pill's own line box. */
19
+ const BONE_HEIGHT = { sm: "h-4", md: "h-5", lg: "h-6" };
20
+ const INTERACTIVE = cx("transition hover:opacity-80", focusRing);
21
+ /** The x on a removable pill: two strokes in the pill's text colour. */
22
+ const REMOVE_MARK = (_jsx("svg", { "aria-hidden": "true", viewBox: "0 0 12 12", className: "size-3", fill: "none", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", children: _jsx("path", { d: "M3 3l6 6M9 3l-6 6" }) }));
23
+ /** The two-tone pill is a hairline-bordered box: the label half carries the tint, the value half sits on the surface. */
24
+ const SPLIT = "inline-flex overflow-hidden border border-slate-200 font-medium";
25
+ /** The box a one-piece pill draws, or the whole pill when it is a single element. */
26
+ function pillClass({ tone, size, round, dot, labelled }, interactive) {
27
+ return cx(round ? "rounded-full" : "rounded-md", TEXT[size], labelled ? SPLIT : cx("px-1.5 py-0.5 font-medium", PILL_TONES[tone]), dot && !labelled && "inline-flex items-center gap-1", interactive && INTERACTIVE);
28
+ }
29
+ /** The shell round a pill with an x: it carries the tint and the corners, and the text and the x are its two children. */
30
+ function shellClass({ tone, size, round, labelled }) {
31
+ return cx(round ? "rounded-full" : "rounded-md", "inline-flex items-center font-medium", TEXT[size], labelled ? "overflow-hidden border border-slate-200" : PILL_TONES[tone]);
32
+ }
33
+ /** The text half of a removable pill, which is a link, a button or a span beside the x. */
34
+ function mainClass({ dot, labelled }, interactive) {
35
+ return cx(labelled ? "inline-flex self-stretch" : "py-0.5 pl-1.5 pr-1", dot && !labelled && "inline-flex items-center gap-1", interactive && INTERACTIVE);
36
+ }
37
+ function removeClass({ labelled }) {
38
+ return cx("inline-flex cursor-pointer items-center", labelled ? "self-stretch bg-white pl-0.5 pr-1.5 text-slate-900" : "py-0.5 pl-0.5 pr-1.5", INTERACTIVE);
39
+ }
40
+ /** The inside of a pill: the dot and the text, or for a two-tone one the tinted name beside the value. */
41
+ function PillBody({ look: { tone, dot, removable }, name, children, }) {
42
+ const mark = dot && _jsx("span", { "aria-hidden": "true", className: "h-1.5 w-1.5 rounded-full bg-current" });
43
+ if (name === undefined) {
44
+ return (_jsxs(_Fragment, { children: [mark, children] }));
45
+ }
46
+ return (_jsxs(_Fragment, { children: [_jsxs("span", { className: cx("px-1.5 py-px", PILL_TONES[tone], dot && "inline-flex items-center gap-1"), children: [mark, name, _jsx("span", { className: "sr-only", children: ":" })] }), _jsx("span", { className: cx("bg-white py-px text-slate-900", removable ? "pl-1.5 pr-0.5" : "px-1.5"), children: children })] }));
47
+ }
48
+ /** The pill itself, or the text half of a removable one: a link, a button or a span. */
49
+ function renderMain(parts) {
50
+ const { interactive, look, rest, tip, focusable, href, external, onClick, body } = parts;
51
+ const className = cx(look.removable ? mainClass(look, interactive) : pillClass(look, interactive), focusable && focusRing);
52
+ // A removable pill's attributes go on its link or button. On a plain one the shell is the pill
53
+ // and keeps them, and the text half takes only the tooltip, so the x's own events never open it.
54
+ const own = look.removable && !interactive ? tip : rest;
55
+ if (href !== undefined) {
56
+ return renderLink({ ...own, href, external, className, children: body });
57
+ }
58
+ if (onClick) {
59
+ return (_jsx("button", { type: "button", ...own, onClick: onClick, className: cx(className, "cursor-pointer"), children: body }));
60
+ }
61
+ return (_jsx("span", { ...own, className: className, children: body }));
62
+ }
63
+ /** The shell round a removable pill: the text half and the x button beside it. */
64
+ function RemoveShell({ look, remove: { onRemove, removeLabel }, attrs, interactive, children, }) {
65
+ return (_jsxs("span", { ...(interactive ? {} : attrs), className: shellClass(look), children: [children, _jsx(Tipped, { text: removeLabel, describes: false, own: {}, children: (tip) => (_jsx("button", { type: "button", "aria-label": removeLabel, ...tip, onClick: onRemove, className: removeClass(look), children: REMOVE_MARK })) })] }));
66
+ }
67
+ /**
68
+ * A small tinted label whose `tone` says what it means; `dot` adds a leading dot in the pill's own
69
+ * text colour, `round` swaps the rounded-md corners for a full pill shape, and `size` steps the
70
+ * text (with none, it takes its container's). `name` makes it two-tone, `name: value`: the name
71
+ * keeps the tone's tint and the children, the value, sit on the surface beside it. `href` makes it
72
+ * a link (the app's router link through `LinkProvider` for an in-app path, else a plain `<a>`;
73
+ * `external` opens a new tab) and `onClick` makes it
74
+ * a button, each with a hover dim and the focus ring. `onRemove` adds an x button after the text
75
+ * (named by `removeLabel`), a separate button beside a link or button pill rather than nested in
76
+ * it. `title` is its tooltip and description; a plain pill with one takes a tab stop. While
77
+ * `loading` with no text yet it is a bone of its size.
78
+ */
79
+ export function Pill(props) {
80
+ const size = useDensity(props.size);
81
+ if (useLoading(props.loading).loading && isEmptySlot(props.children)) {
82
+ const corners = props.round ? "rounded-full" : "rounded-md";
83
+ return (_jsx(WaitingBone, { own: props.loading, label: props.loadingLabel, attrs: passthroughOf(props), root: "inline-flex align-middle", shape: cx("inline-block w-14", BONE_HEIGHT[size], corners) }));
84
+ }
85
+ return _jsx(ShownPill, { ...props, size: size });
86
+ }
87
+ /** A pill with its text. */
88
+ function ShownPill({ children, tone = "neutral", size, dot = false, round = false, name, href, external = false, onClick, onRemove, removeLabel, loading: _loading, loadingLabel: _loadingLabel, ...rest }) {
89
+ const interactive = href !== undefined || onClick !== undefined;
90
+ const look = {
91
+ tone,
92
+ size,
93
+ round,
94
+ dot,
95
+ labelled: name !== undefined,
96
+ removable: onRemove !== undefined,
97
+ };
98
+ const body = (_jsx(PillBody, { look: look, name: name, children: children }));
99
+ // The title is the pill's detail: a description, shown on hover, keyboard focus and (on a plain
100
+ // pill, whose tap does nothing else) a tap. A plain titled pill takes a tab stop for it.
101
+ const { title, ...own } = rest;
102
+ // An empty title shows nothing, so it takes no tab stop either.
103
+ const titled = title !== undefined && title !== "";
104
+ const focusable = titled && !interactive;
105
+ return (_jsx(Tipped, { text: title, describes: true, tap: !interactive, own: { ...own, title }, children: (tip) => {
106
+ const attrs = { ...own, ...tip, ...(focusable ? { tabIndex: 0 } : {}) };
107
+ const { wiring, rest: shell } = titled ? splitTip(attrs) : { wiring: {}, rest: attrs };
108
+ const main = renderMain({
109
+ interactive,
110
+ look,
111
+ rest: attrs,
112
+ tip: wiring,
113
+ focusable,
114
+ href,
115
+ external,
116
+ onClick,
117
+ body,
118
+ });
119
+ return onRemove === undefined ? (main) : (_jsx(RemoveShell, { look: look, remove: { onRemove, removeLabel }, attrs: shell, interactive: interactive, children: main }));
120
+ } }));
121
+ }
@@ -0,0 +1,47 @@
1
+ import type { ReactElement } from "react";
2
+ import type { Passthrough } from "./props.js";
3
+ import type { Size } from "./size.js";
4
+ import { type LoadingProps } from "./skeleton.js";
5
+ /** The colour of a bar's fill. */
6
+ export type BarTone = "accent" | "positive" | "warn" | "danger";
7
+ /** 6px, 8px or 12px tall. */
8
+ export type BarSize = Size;
9
+ export declare const BAR_FILL: Record<BarTone, string>;
10
+ export declare const BAR_TRACK: Record<BarSize, string>;
11
+ /** `part` as a percent of `whole`, held between 0 and 100; 0 when either is not positive. */
12
+ export declare function sharePercent(part: number, whole: number): number;
13
+ /** The share as a whole percent for a screen reader: never 0 or 100 unless it truly is. */
14
+ export declare function announcedPercent(part: number, whole: number): number;
15
+ /**
16
+ * A bar with no figures yet: one bone the track's height across the full width. `attrs` keeps the
17
+ * bar's role and name, so it is still its progressbar or picture while it waits.
18
+ */
19
+ export declare function WaitingBar({ own, label, size, attrs, }: {
20
+ own: boolean | undefined;
21
+ label: string | undefined;
22
+ size: BarSize;
23
+ attrs: object;
24
+ }): ReactElement;
25
+ /**
26
+ * A thin horizontal bar with a filled share, for progress toward a total. `value` is held
27
+ * between 0 and `max`. `label` names what it measures, for a screen reader, which also hears the percentage.
28
+ * While `loading` it is one bone the bar's size, since 0 is a real value.
29
+ */
30
+ export declare function ProgressBar({ value, max, label, tone, size, loading, loadingLabel, ...rest }: {
31
+ /** How far along, held between 0 and `max`. */
32
+ value: number;
33
+ /** The value that fills the bar; `value` is drawn as its share of this. Defaults to 100. */
34
+ max?: number;
35
+ /** What the bar measures, for a screen reader, which also hears the percentage. */
36
+ label: string;
37
+ /**
38
+ * What the progress means: `accent` (the default) plain progress, `positive` done or on track,
39
+ * `warn` at risk, `danger` over a limit or failed.
40
+ */
41
+ tone?: BarTone;
42
+ /**
43
+ * The bar's height: `sm` 6px, `md` 8px, `lg` 12px.
44
+ * @default md
45
+ */
46
+ size?: BarSize;
47
+ } & LoadingProps & Passthrough): ReactElement;
@@ -0,0 +1,47 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { cx } from "./cx.js";
3
+ import { useLoading, WaitingBone } from "./skeleton.js";
4
+ export const BAR_FILL = {
5
+ accent: "bg-violet-600",
6
+ positive: "bg-emerald-600",
7
+ warn: "bg-amber-600",
8
+ danger: "bg-red-600",
9
+ };
10
+ export const BAR_TRACK = {
11
+ sm: "h-1.5",
12
+ md: "h-2",
13
+ lg: "h-3",
14
+ };
15
+ /** `part` as a percent of `whole`, held between 0 and 100; 0 when either is not positive. */
16
+ export function sharePercent(part, whole) {
17
+ if (!(whole > 0) || !(part > 0))
18
+ return 0;
19
+ return Math.min(100, (part / whole) * 100);
20
+ }
21
+ /** The share as a whole percent for a screen reader: never 0 or 100 unless it truly is. */
22
+ export function announcedPercent(part, whole) {
23
+ const share = sharePercent(part, whole);
24
+ return share <= 0 || share >= 100 ? share : Math.min(99, Math.max(1, Math.round(share)));
25
+ }
26
+ /**
27
+ * A bar with no figures yet: one bone the track's height across the full width. `attrs` keeps the
28
+ * bar's role and name, so it is still its progressbar or picture while it waits.
29
+ */
30
+ export function WaitingBar({ own, label, size, attrs, }) {
31
+ return (_jsx(WaitingBone, { own: own, label: label, shape: cx("block w-full rounded-full", BAR_TRACK[size]), root: "block", attrs: attrs }));
32
+ }
33
+ /**
34
+ * A thin horizontal bar with a filled share, for progress toward a total. `value` is held
35
+ * between 0 and `max`. `label` names what it measures, for a screen reader, which also hears the percentage.
36
+ * While `loading` it is one bone the bar's size, since 0 is a real value.
37
+ */
38
+ export function ProgressBar({ value, max = 100, label, tone = "accent", size = "md", loading, loadingLabel, ...rest }) {
39
+ const waiting = useLoading(loading).loading;
40
+ if (waiting) {
41
+ // No `aria-valuenow`: a progressbar with no value is indeterminate.
42
+ const attrs = { ...rest, role: "progressbar", "aria-label": label };
43
+ return _jsx(WaitingBar, { own: loading, label: loadingLabel, size: size, attrs: attrs });
44
+ }
45
+ const share = sharePercent(value, max);
46
+ return (_jsx("div", { ...rest, role: "progressbar", "aria-label": label, "aria-valuemin": 0, "aria-valuemax": 100, "aria-valuenow": announcedPercent(value, max), className: cx("overflow-hidden rounded-full bg-slate-100", BAR_TRACK[size]), children: _jsx("div", { className: cx("h-full", BAR_FILL[tone]), style: { width: `${share}%` } }) }));
47
+ }
@@ -0,0 +1,55 @@
1
+ import { type ReactElement, type ReactNode } from "react";
2
+ import { type Passthrough } from "./props.js";
3
+ import type { Size } from "./size.js";
4
+ import { type LoadingProps } from "./skeleton.js";
5
+ /**
6
+ * A named group of radios, one chosen. The `label` names the group; `hint` is a muted line under
7
+ * the options that says more (the group's description); an `error` replaces it with a red line
8
+ * (`role="alert"`) and marks the group invalid. Give it `value` and `onChange`, or
9
+ * `defaultValue` and let it keep the choice. `name` posts the choice in a form.
10
+ * The arrow keys move between the radios and choose, and the group is one tab stop. `size` sizes
11
+ * every radio in the group, the same scale as a `Checkbox`. While `loading` the labels are drawn and
12
+ * each circle is a bone.
13
+ */
14
+ export declare function RadioGroup({ label, hint, error, size, disabled, required, loading, loadingLabel, children, ...rest }: {
15
+ /** The group's visible name, above the options. */
16
+ label: ReactNode;
17
+ /** A muted line under the options that says more; it describes the group. Replaced by `error`. */
18
+ hint?: ReactNode;
19
+ /** Shown under the options in red with `role="alert"`; marks the group invalid. Like `Field`'s `error`. */
20
+ error?: ReactNode;
21
+ /** The `value` of the chosen radio. */
22
+ value?: string;
23
+ /** The `value` chosen to begin with, when the group keeps its own choice. */
24
+ defaultValue?: string;
25
+ /** Called with the chosen radio's `value`. */
26
+ onChange?: (value: string) => void;
27
+ /** The form field the choice posts under. */
28
+ name?: string;
29
+ /** Disables every radio. */
30
+ disabled?: boolean | undefined;
31
+ /** Marks the choice required: the group is `aria-required`, and a form will not submit with no option chosen. */
32
+ required?: boolean | undefined;
33
+ /**
34
+ * The size of every radio in the group: `sm` is `text-xs` and a smaller circle, `lg` `text-base`
35
+ * and a larger one.
36
+ * @default md
37
+ */
38
+ size?: Size;
39
+ /** The `Radio`s. */
40
+ children: ReactNode;
41
+ } & LoadingProps & Passthrough): ReactElement;
42
+ /** The props of a `Radio`. */
43
+ type RadioProps = {
44
+ /** The text beside the circle. */
45
+ label: ReactNode;
46
+ /** A muted line under the label that says more. It is the radio's `aria-describedby`. */
47
+ hint?: ReactNode;
48
+ /** What the group's `value` becomes when this one is chosen. */
49
+ value: string;
50
+ /** Disables this radio alone. */
51
+ disabled?: boolean | undefined;
52
+ } & Passthrough;
53
+ /** One option of a `RadioGroup`: a `label` and, under it, an optional `hint`. Click the label or the circle. While `loading` the circle is a bone. */
54
+ export declare function Radio({ loading, loadingLabel, ...props }: RadioProps & LoadingProps): ReactElement;
55
+ export {};
@@ -0,0 +1,53 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { createContext, useContext, useId } from "react";
3
+ import { FieldError, Label, Radio as AriaRadio, RadioGroup as AriaRadioGroup, Text, } from "react-aria-components";
4
+ import { cx } from "./cx.js";
5
+ import { definedProps } from "./props.js";
6
+ import { WaitingChoice } from "./fieldWait.js";
7
+ import { BusyLabel, busy, LoadingScope, useLoading } from "./skeleton.js";
8
+ /** A radio's circle, its dot, its drop onto the label's first line and the label's text, by the group's `size`. */
9
+ const SIZE = {
10
+ sm: { circle: "mt-px h-3.5 w-3.5", dot: "h-1.5 w-1.5", label: "text-xs", gap: "gap-2" },
11
+ md: { circle: "mt-0.5 h-4 w-4", dot: "h-2 w-2", label: "text-sm", gap: "gap-2.5" },
12
+ lg: { circle: "mt-0.5 h-5 w-5", dot: "h-2.5 w-2.5", label: "text-base", gap: "gap-3" },
13
+ };
14
+ /** The group's `size`, read by each `Radio` in it. */
15
+ const RadioSize = createContext("md");
16
+ /**
17
+ * A named group of radios, one chosen. The `label` names the group; `hint` is a muted line under
18
+ * the options that says more (the group's description); an `error` replaces it with a red line
19
+ * (`role="alert"`) and marks the group invalid. Give it `value` and `onChange`, or
20
+ * `defaultValue` and let it keep the choice. `name` posts the choice in a form.
21
+ * The arrow keys move between the radios and choose, and the group is one tab stop. `size` sizes
22
+ * every radio in the group, the same scale as a `Checkbox`. While `loading` the labels are drawn and
23
+ * each circle is a bone.
24
+ */
25
+ export function RadioGroup({ label, hint, error, size = "md", disabled, required, loading, loadingLabel, children, ...rest }) {
26
+ const { loading: waiting, owner } = useLoading(loading);
27
+ return (_jsxs(AriaRadioGroup, { ...definedProps(rest), ...(error ? { isInvalid: true } : {}), ...(disabled ? { isDisabled: true } : {}), ...(required ? { isRequired: true } : {}), className: "flex flex-col gap-2", children: [_jsx(Label, { className: "text-sm font-medium text-slate-700", children: label }), _jsxs("div", { ...busy(owner, waiting), className: "flex flex-col gap-2.5", children: [_jsx(RadioSize.Provider, { value: size, children: _jsx(LoadingScope, { loading: waiting, children: children }) }), _jsx(BusyLabel, { owner: owner, loading: waiting, label: loadingLabel })] }), hint && !error ? (_jsx(Text, { slot: "description", className: "text-xs text-slate-500", children: hint })) : null, _jsx(FieldError, { className: "text-xs text-red-700", children: _jsx("span", { role: "alert", children: error }) })] }));
28
+ }
29
+ function ringTone(invalid, selected) {
30
+ if (invalid)
31
+ return "border-red-600";
32
+ return selected ? "border-violet-600" : "border-slate-300";
33
+ }
34
+ /** One option of a `RadioGroup`: a `label` and, under it, an optional `hint`. Click the label or the circle. While `loading` the circle is a bone. */
35
+ export function Radio({ loading, loadingLabel, ...props }) {
36
+ const size = SIZE[useContext(RadioSize)];
37
+ if (useLoading(loading).loading) {
38
+ return (_jsx(WaitingChoice, { own: loading, loadingLabel: loadingLabel, label: props.label, look: cx(size.gap, size.label), shape: cx(size.circle, "rounded-full"), attrs: props }));
39
+ }
40
+ return _jsx(ShownRadio, { ...props });
41
+ }
42
+ /** A radio with its circle drawn. */
43
+ function ShownRadio({ label, hint, value, disabled, "aria-describedby": describedBy, ...rest }) {
44
+ const descriptionId = useId();
45
+ const size = SIZE[useContext(RadioSize)];
46
+ return (_jsx(AriaRadio, { ...definedProps(rest), value: value, ...(describedBy || hint
47
+ ? {
48
+ "aria-describedby": [describedBy, hint ? descriptionId : undefined]
49
+ .filter(Boolean)
50
+ .join(" "),
51
+ }
52
+ : {}), ...(disabled ? { isDisabled: true } : {}), className: ({ isDisabled: off }) => cx("flex cursor-pointer items-start rounded-md has-focus-visible:outline-2 has-focus-visible:outline-offset-2 has-focus-visible:outline-violet-600", size.gap, off && "cursor-default opacity-50"), children: ({ isSelected, isInvalid }) => (_jsxs(_Fragment, { children: [_jsx("span", { "aria-hidden": "true", className: cx("flex shrink-0 items-center justify-center rounded-full border bg-white transition hover:border-violet-400", size.circle, ringTone(isInvalid, isSelected)), children: isSelected ? _jsx("span", { className: cx("rounded-full bg-violet-600", size.dot) }) : null }), _jsxs("span", { className: "flex flex-col gap-0.5", children: [_jsx("span", { className: cx("text-slate-700", size.label), children: label }), hint ? (_jsx("span", { id: descriptionId, className: "text-xs text-slate-500", children: hint })) : null] })] })) }));
53
+ }
@@ -0,0 +1,21 @@
1
+ import type { ReactElement, ReactNode } from "react";
2
+ import type { ClusterGap } from "./Cluster.js";
3
+ import type { Passthrough } from "./props.js";
4
+ export type ScrollStripProps = {
5
+ /** Names the strip for a screen reader, e.g. "Recent statuses". */
6
+ label: string;
7
+ /** The items, one after another: `MediaTile`s, `Avatar`s. They keep their own width. */
8
+ children: ReactNode;
9
+ /**
10
+ * The space between items, as `Cluster`'s `gap`.
11
+ * @default sm
12
+ */
13
+ gap?: ClusterGap | undefined;
14
+ } & Passthrough;
15
+ /**
16
+ * A single row of items that scrolls sideways when it runs past the width of its parent, with a
17
+ * thin themed scrollbar and the items snapping into place: a strip of `MediaTile`s or `Avatar`s.
18
+ * Items never shrink or wrap. The strip takes the keyboard focus, so the arrow keys scroll it
19
+ * without a pointer. A grid that wraps is a `CardGrid` or a `Cluster`.
20
+ */
21
+ export declare function ScrollStrip({ label, children, gap, ...rest }: ScrollStripProps): ReactElement;
@@ -0,0 +1,12 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { cx, focusRing, themedScrollbar } from "./cx.js";
3
+ import { STACK_GAP } from "./Stack.js";
4
+ /**
5
+ * A single row of items that scrolls sideways when it runs past the width of its parent, with a
6
+ * thin themed scrollbar and the items snapping into place: a strip of `MediaTile`s or `Avatar`s.
7
+ * Items never shrink or wrap. The strip takes the keyboard focus, so the arrow keys scroll it
8
+ * without a pointer. A grid that wraps is a `CardGrid` or a `Cluster`.
9
+ */
10
+ export function ScrollStrip({ label, children, gap = "sm", ...rest }) {
11
+ return (_jsx("div", { ...rest, role: "group", "aria-label": label, tabIndex: 0, className: cx("overflow-x-auto rounded-lg pb-2 [scroll-snap-type:x_proximity]", themedScrollbar, focusRing), children: _jsx("div", { className: cx("flex w-max min-w-full text-slate-900 *:shrink-0 *:snap-start", STACK_GAP[gap]), children: children }) }));
12
+ }