@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
package/dist/Tabs.d.ts ADDED
@@ -0,0 +1,38 @@
1
+ import type { ReactElement } from "react";
2
+ import { type TypeStep } from "./density.js";
3
+ import type { Size } from "./size.js";
4
+ import { type SwitchItem, type SwitchProps } from "./switcher.js";
5
+ /** One tab of a Tabs row: a button with a `value`, or a link with an `href`; never both kinds in one row. */
6
+ export type Tab = SwitchItem;
7
+ /** The classes of one pill tab at the type `step` in force. A `disabled` one drops the hover fill. */
8
+ export declare function pillTabClass(active: boolean, disabled?: boolean, size?: Size, step?: TypeStep): string;
9
+ export type TabsProps = SwitchProps & ({
10
+ /**
11
+ * `horizontal` is a row of underline tabs over a bottom rule; `vertical` is the pill rail, a
12
+ * column at the rail's width for a `SidebarLayout` aside, where the up and down arrows move
13
+ * between button tabs.
14
+ * @default horizontal
15
+ */
16
+ orientation?: "horizontal";
17
+ /** Only the vertical rail takes a `size`. */
18
+ size?: undefined;
19
+ } | {
20
+ orientation: "vertical";
21
+ /**
22
+ * The pills' height and text, on the scale of a `Button`.
23
+ * @default md
24
+ */
25
+ size?: Size;
26
+ });
27
+ /**
28
+ * Tabs for switching a view in place or between pages. Across (the default) they are underline
29
+ * tabs: a row over a bottom rule, the current tab underlined in the accent. `orientation="vertical"`
30
+ * is the pill rail instead, the current tab filled, for a `SidebarLayout` aside, and takes a
31
+ * `size`. `items` are `{ value, label }` buttons (`value` and `onChange` are the caller's state;
32
+ * the arrow keys, Home and End move between tabs) or links (`href`, an in-app one through
33
+ * `LinkProvider`; `selected` on an item, or `value`, marks the current one, which gets
34
+ * `aria-current`). An item may carry a `count`, and a button one `disabledReason` (it stays
35
+ * reachable by the arrows and its reason is a tooltip) or a bare `disabled`; `disabled` on the row disables every tab. `label` names the tab list. The panel is
36
+ * the caller's: give it `role="tabpanel"`, and a tab `controls` to point at it.
37
+ */
38
+ export declare function Tabs({ size, orientation, ...props }: TabsProps): ReactElement;
package/dist/Tabs.js ADDED
@@ -0,0 +1,46 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { cx, focusRing } from "./cx.js";
3
+ import { controlText, useTypeStep } from "./density.js";
4
+ import { Switcher } from "./switcher.js";
5
+ const BASE = `-mb-px border-b-2 px-0.5 py-2 transition ${focusRing}`;
6
+ const ON = "border-violet-600 font-medium text-violet-700";
7
+ const OFF = "border-transparent text-slate-600";
8
+ const OFF_LIVE = "hover:text-violet-700";
9
+ // A transparent border, so a pill is as tall as a `Button` of the same size.
10
+ const PILL = `rounded-lg border border-transparent transition ${focusRing}`;
11
+ /** A pill's padding, by `size`; its text is a control's (`controlText`), so it lines up with a `Button`. */
12
+ const PILL_SIZE = {
13
+ sm: "px-2.5 py-1",
14
+ md: "px-3 py-2",
15
+ lg: "px-4 py-2.5",
16
+ };
17
+ /** The classes of one pill tab at the type `step` in force. A `disabled` one drops the hover fill. */
18
+ export function pillTabClass(active, disabled = false, size = "md", step) {
19
+ return cx(PILL, PILL_SIZE[size], controlText(size, step, false), active ? "bg-slate-100 font-medium text-slate-900" : "text-slate-600", !active && !disabled && "hover:bg-slate-100");
20
+ }
21
+ /**
22
+ * Tabs for switching a view in place or between pages. Across (the default) they are underline
23
+ * tabs: a row over a bottom rule, the current tab underlined in the accent. `orientation="vertical"`
24
+ * is the pill rail instead, the current tab filled, for a `SidebarLayout` aside, and takes a
25
+ * `size`. `items` are `{ value, label }` buttons (`value` and `onChange` are the caller's state;
26
+ * the arrow keys, Home and End move between tabs) or links (`href`, an in-app one through
27
+ * `LinkProvider`; `selected` on an item, or `value`, marks the current one, which gets
28
+ * `aria-current`). An item may carry a `count`, and a button one `disabledReason` (it stays
29
+ * reachable by the arrows and its reason is a tooltip) or a bare `disabled`; `disabled` on the row disables every tab. `label` names the tab list. The panel is
30
+ * the caller's: give it `role="tabpanel"`, and a tab `controls` to point at it.
31
+ */
32
+ export function Tabs({ size = "md", orientation = "horizontal", ...props }) {
33
+ const stacked = orientation === "vertical";
34
+ const step = useTypeStep();
35
+ return (_jsx(Switcher, { ...props, parts: {
36
+ group: "tablist",
37
+ item: "tab",
38
+ vertical: stacked,
39
+ stacked,
40
+ root: stacked ? "flex flex-col gap-1" : UNDERLINE_ROW,
41
+ option: (active, disabled) => stacked
42
+ ? pillTabClass(active, disabled, size, step)
43
+ : cx(BASE, active ? ON : OFF, !active && !disabled && OFF_LIVE),
44
+ } }));
45
+ }
46
+ const UNDERLINE_ROW = "flex flex-wrap gap-x-5 border-b border-slate-200 text-sm";
@@ -0,0 +1,51 @@
1
+ import type { ComponentPropsWithoutRef, ReactElement } from "react";
2
+ import type { Unstyled } from "./props.js";
3
+ import type { Size } from "./size.js";
4
+ import { type TextTone } from "./typography.js";
5
+ /** The classes of an inline text link, for a router's own <Link> that should look like one. */
6
+ export declare const linkClass: string;
7
+ /**
8
+ * Stretches a link's hit area over its nearest `relative` ancestor (a table row, a card), so the
9
+ * whole of it opens the link. Add it to the one link in the row; the ancestor needs `relative`.
10
+ * `link-stretch` marks the link, so a `TableRow` or `Card` that lifts its other links and buttons
11
+ * above it leaves this one alone.
12
+ */
13
+ export declare const linkStretchClass = "link-stretch after:absolute after:inset-0";
14
+ /** A TextLink's pinned type size, on the `Size` scale; left out, it takes the size of the text around it. */
15
+ export type TextLinkSize = Size;
16
+ type TextLinkProps = {
17
+ /**
18
+ * The link's own type size: `sm` is `text-xs`, `md` `text-sm` and `lg` `text-base`. Left out, it
19
+ * takes the size of the text around it: a link inside prose has no default size.
20
+ */
21
+ size?: TextLinkSize | undefined;
22
+ /**
23
+ * A meaning's colour, as on the inline roles: `warn` for a warning link, `danger`, `positive`,
24
+ * `info` or `muted`. Left out, the link is the accent colour.
25
+ */
26
+ tone?: TextTone | undefined;
27
+ /** The monospace face, for a path, an id or a command. */
28
+ mono?: boolean | undefined;
29
+ /** Opens in a new tab: adds `target="_blank"` and `rel="noreferrer"`. */
30
+ external?: boolean | undefined;
31
+ /**
32
+ * The link covers its nearest `relative` ancestor, so the whole row or card is the click target.
33
+ *
34
+ * Put it on the one link of a `Card` or a `TableRow` (a table row's first cell): any other link
35
+ * or button in it sits above the link and is clickable on its own. An action that is not
36
+ * navigation stays a `Button` in an actions column.
37
+ */
38
+ stretch?: boolean | undefined;
39
+ /** Always underlined, for a link set inside running text, where colour alone does not mark it (WCAG 1.4.1). */
40
+ underline?: boolean | undefined;
41
+ /** Where the link goes; an in-app path goes through the app's `LinkProvider`. */
42
+ href: string;
43
+ } & Unstyled<Omit<ComponentPropsWithoutRef<"a">, "href">>;
44
+ /**
45
+ * An inline text link in the accent colour. Every anchor prop goes on the `<a>`; an in-app `href`
46
+ * is drawn by the app's router link through `LinkProvider`.
47
+ * `size` pins the type size (`sm`, `md` or `lg`), `tone` gives it a meaning's colour and `mono` sets the
48
+ * monospace face.
49
+ */
50
+ export declare function TextLink({ size, tone, mono, external, stretch, underline, href, children, ...rest }: TextLinkProps): ReactElement;
51
+ export {};
@@ -0,0 +1,38 @@
1
+ import { cx, focusRing } from "./cx.js";
2
+ import { renderLink } from "./link.js";
3
+ import { TEXT_TONE } from "./typography.js";
4
+ const LINK = "rounded font-medium underline-offset-2 transition-colors";
5
+ /** The classes of an inline text link, for a router's own <Link> that should look like one. */
6
+ export const linkClass = cx(LINK, "text-violet-600 hover:text-violet-700", focusRing);
7
+ // A toned link takes its tone's text colour, shared with Table's cells and the inline roles, and
8
+ // underlines on hover in place of a hover shade.
9
+ const toneClass = (tone) => cx(LINK, TEXT_TONE[tone], "hover:underline", focusRing);
10
+ /**
11
+ * Stretches a link's hit area over its nearest `relative` ancestor (a table row, a card), so the
12
+ * whole of it opens the link. Add it to the one link in the row; the ancestor needs `relative`.
13
+ * `link-stretch` marks the link, so a `TableRow` or `Card` that lifts its other links and buttons
14
+ * above it leaves this one alone.
15
+ */
16
+ export const linkStretchClass = "link-stretch after:absolute after:inset-0";
17
+ // The tone's colour, or the accent with its hover shade.
18
+ const colourClass = (tone) => tone && tone !== "neutral" ? toneClass(tone) : linkClass;
19
+ const SIZE = {
20
+ sm: "text-xs/4",
21
+ md: "text-sm/5",
22
+ lg: "text-base/6",
23
+ };
24
+ /**
25
+ * An inline text link in the accent colour. Every anchor prop goes on the `<a>`; an in-app `href`
26
+ * is drawn by the app's router link through `LinkProvider`.
27
+ * `size` pins the type size (`sm`, `md` or `lg`), `tone` gives it a meaning's colour and `mono` sets the
28
+ * monospace face.
29
+ */
30
+ export function TextLink({ size, tone, mono = false, external = false, stretch = false, underline = false, href, children, ...rest }) {
31
+ return renderLink({
32
+ ...rest,
33
+ href,
34
+ external,
35
+ className: cx(colourClass(tone), size && SIZE[size], mono && "font-mono", stretch && linkStretchClass, underline && "underline"),
36
+ children,
37
+ });
38
+ }
@@ -0,0 +1,11 @@
1
+ import type { ComponentPropsWithoutRef, ReactElement, Ref } from "react";
2
+ import { type ControlProps } from "./control.js";
3
+ import type { Unstyled } from "./props.js";
4
+ export type TextareaProps = ControlProps & {
5
+ /** The monospace face, for pasted CSV or statement text, where the columns must line up. Off by default. */
6
+ mono?: boolean | undefined;
7
+ /** The `<textarea>` itself, for focus control. */
8
+ ref?: Ref<HTMLTextAreaElement> | undefined;
9
+ } & Unstyled<Omit<ComponentPropsWithoutRef<"textarea">, "width">>;
10
+ /** A multi-line text input, styled like `Input`. `rows` defaults to 3. Takes `size`, `width` and `mono` too. The `ref` reaches the `<textarea>`, for focus control. */
11
+ export declare function Textarea({ size, width, mono, ...rest }: TextareaProps): ReactElement;
@@ -0,0 +1,11 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { CONTROL_PAD, controlClass } from "./control.js";
3
+ import { cx } from "./cx.js";
4
+ import { useTypeStep } from "./density.js";
5
+ import { useFieldControl } from "./fieldControl.js";
6
+ /** A multi-line text input, styled like `Input`. `rows` defaults to 3. Takes `size`, `width` and `mono` too. The `ref` reaches the `<textarea>`, for focus control. */
7
+ export function Textarea({ size = "md", width = "full", mono = false, ...rest }) {
8
+ const step = useTypeStep();
9
+ const field = useFieldControl(rest);
10
+ return (_jsx("textarea", { rows: 3, ...rest, ...field, className: cx(controlClass(size, width, step), CONTROL_PAD[size].x, mono && "font-mono") }));
11
+ }
@@ -0,0 +1,31 @@
1
+ import { type ReactElement, type ReactNode } from "react";
2
+ import type { Tone } from "./tone.js";
3
+ import type { Passthrough } from "./props.js";
4
+ import { type LoadingProps } from "./skeleton.js";
5
+ /**
6
+ * A vertical list of events, newest or oldest first as the caller orders them. A named `<ol>` of
7
+ * `TimelineItem`s on a rail; with no children it draws `empty` (an `EmptyState`, one muted line here)
8
+ * instead of an empty list. While `loading` with no items it draws three items of bones, never
9
+ * `empty`.
10
+ */
11
+ export declare function Timeline({ label, empty, loading, loadingLabel, children, ...rest }: {
12
+ /** Names the list (`aria-label`), e.g. "Status history". */
13
+ label: string;
14
+ /** Drawn in place of the list when there are no items: an `EmptyState`. */
15
+ empty?: ReactNode;
16
+ children?: ReactNode;
17
+ } & LoadingProps & Passthrough): ReactElement | null;
18
+ /**
19
+ * One event: a `title` (a `Pill`, a heading), a `time` the app has already formatted, and the
20
+ * `children` as a note under them. `tone` colours the marker dot with the Callout's set. While
21
+ * `loading` an empty `title` is a bone.
22
+ */
23
+ export declare function TimelineItem({ title, time, tone, loading, loadingLabel, children, ...rest }: {
24
+ /** What happened: text, a `Pill` or a heading. */
25
+ title: ReactNode;
26
+ /** When, already formatted by the app, small and muted beside the title. */
27
+ time?: ReactNode;
28
+ /** The marker dot's colour. Defaults to `neutral`, a plain ring. Say it in the text too: colour alone says nothing to a screen reader. */
29
+ tone?: Tone;
30
+ children?: ReactNode;
31
+ } & LoadingProps & Passthrough): ReactElement;
@@ -0,0 +1,38 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Children } from "react";
3
+ import { cx } from "./cx.js";
4
+ import { EmptySlot } from "./emptySlot.js";
5
+ import { BoneLines, BusyLabel, busy, isEmptySlot, LoadingScope, useLoading, } from "./skeleton.js";
6
+ // The marker's colour is the tone's text colour, which every theme already remaps, drawn as a
7
+ // solid dot; `neutral` is the ring.
8
+ const DOT = {
9
+ neutral: "border-slate-300 bg-white",
10
+ info: "border-current bg-current text-blue-700",
11
+ positive: "border-current bg-current text-emerald-700",
12
+ warn: "border-current bg-current text-amber-700",
13
+ danger: "border-current bg-current text-red-700",
14
+ };
15
+ /**
16
+ * A vertical list of events, newest or oldest first as the caller orders them. A named `<ol>` of
17
+ * `TimelineItem`s on a rail; with no children it draws `empty` (an `EmptyState`, one muted line here)
18
+ * instead of an empty list. While `loading` with no items it draws three items of bones, never
19
+ * `empty`.
20
+ */
21
+ export function Timeline({ label, empty, loading, loadingLabel, children, ...rest }) {
22
+ const { loading: waiting, owner } = useLoading(loading);
23
+ const none = Children.toArray(children).length === 0;
24
+ if (none && !waiting) {
25
+ return empty == null ? null : _jsx(EmptySlot, { size: "sm", children: empty });
26
+ }
27
+ return (_jsxs("ol", { ...rest, ...busy(owner, waiting), "aria-label": label, className: "flex flex-col", children: [_jsx(LoadingScope, { loading: waiting, children: none ? [0, 1, 2].map((i) => _jsx(TimelineItem, { title: "" }, i)) : children }), owner && waiting && (_jsx("li", { className: "sr-only", children: _jsx(BusyLabel, { owner: owner, loading: waiting, label: loadingLabel }) }))] }));
28
+ }
29
+ /**
30
+ * One event: a `title` (a `Pill`, a heading), a `time` the app has already formatted, and the
31
+ * `children` as a note under them. `tone` colours the marker dot with the Callout's set. While
32
+ * `loading` an empty `title` is a bone.
33
+ */
34
+ export function TimelineItem({ title, time, tone = "neutral", loading, loadingLabel, children, ...rest }) {
35
+ const { loading: waiting, owner } = useLoading(loading);
36
+ const bone = waiting && isEmptySlot(title);
37
+ return (_jsxs("li", { ...rest, ...busy(owner, waiting), className: "relative border-l border-slate-300 pb-5 pl-5 last:border-transparent last:pb-0", children: [_jsx("span", { "aria-hidden": "true", className: cx("absolute -left-[5px] top-1.5 h-2.5 w-2.5 rounded-full border-2", DOT[tone]) }), _jsxs("div", { className: "flex flex-wrap items-center gap-x-3 gap-y-1", children: [_jsx("span", { className: cx("text-sm font-medium text-slate-900", bone && "w-1/3"), children: bone ? _jsx(BoneLines, { count: 1 }) : title }), time != null && _jsx("span", { className: "text-xs tabular-nums text-slate-500", children: time })] }), children != null && _jsx("div", { className: "mt-1 text-sm text-slate-700", children: children }), _jsx(BusyLabel, { owner: owner, loading: waiting, label: loadingLabel })] }));
38
+ }
@@ -0,0 +1,44 @@
1
+ import type { ReactElement, ReactNode } from "react";
2
+ import type { Passthrough } from "./props.js";
3
+ import type { Tone } from "./tone.js";
4
+ /** One notice in a `ToastRegion`. The caller holds the list; the region draws it. */
5
+ export type Toast = {
6
+ /** The React key, and what `onDismiss` hands back. */
7
+ id: string;
8
+ /** The bold line: the whole message for a short one ("Saved"). */
9
+ title: string;
10
+ /** A line of detail under the title. */
11
+ body?: ReactNode;
12
+ /**
13
+ * What the notice means, with `Callout`'s surfaces. A `warn` or `danger` toast never hides itself.
14
+ * @default neutral
15
+ */
16
+ tone?: Tone | undefined;
17
+ /** One `Button size="sm"`, as on a `Callout`. A toast with `actions` never hides itself. */
18
+ actions?: ReactNode;
19
+ };
20
+ /**
21
+ * The page's toasts: short notices fixed to the bottom of the viewport, from a list the app holds.
22
+ * Mount it once, at the root beside `AppShell`; add a toast to `toasts` to show it, and drop it in
23
+ * `onDismiss` to remove it. A `neutral`, `info` or `positive` toast with no `actions` leaves on its
24
+ * own after five seconds (paused while the pointer is over it or focus is in it); a `warn` or
25
+ * `danger` toast, or one with `actions`, stays until dismissed. The region is a named landmark with
26
+ * a polite `role="status"`, kept in the page while empty, so each new toast is read once. A toast
27
+ * raised while a `Dialog` or `Drawer` is open sits under it until it closes.
28
+ */
29
+ export declare function ToastRegion({ toasts, onDismiss, label, dismissLabel, ...rest }: {
30
+ /** What is shown, oldest first. `[]` shows nothing and keeps the live region in the page. */
31
+ toasts: readonly Toast[];
32
+ /** Called by a toast's close button and when a self-hiding toast's time is up: drop it from `toasts`. */
33
+ onDismiss: (id: string) => void;
34
+ /**
35
+ * The region's accessible name.
36
+ * @default Notifications
37
+ */
38
+ label?: string | undefined;
39
+ /**
40
+ * The close button's name.
41
+ * @default Dismiss
42
+ */
43
+ dismissLabel?: string | undefined;
44
+ } & Passthrough): ReactElement;
@@ -0,0 +1,37 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { TONE_SURFACE, TONE_TEXT } from "./Callout.js";
3
+ import { cx } from "./cx.js";
4
+ import { IconButton } from "./IconButton.js";
5
+ // The hide is CSS, not a timer. A toast that may leave on its own carries `data-toast-hide`: it is
6
+ // shown for five seconds, then fades for 200ms, and the animation's end calls `onDismiss`, so the
7
+ // caller drops it from the list, as `CopyButton` clears its copied state. Hovering the region or
8
+ // focusing anything in it pauses the run. Under reduced motion the same run holds a discrete
9
+ // `visibility` keyframe instead of the fade, so the toast still leaves at the same moment.
10
+ const css = `[data-toast-hide]{animation:hc-toast-hide .2s ease-in 5s forwards}[data-hc-toasts]:hover [data-toast-hide],[data-hc-toasts]:focus-within [data-toast-hide]{animation-play-state:paused}@keyframes hc-toast-hide{to{opacity:0}}@media (prefers-reduced-motion:reduce){[data-toast-hide]{animation-name:hc-toast-cut}}@keyframes hc-toast-cut{from,to{visibility:visible}}`;
11
+ /** Only a plain confirmation leaves on its own: no action to reach, nothing that must be read. */
12
+ function hides(toast) {
13
+ const tone = toast.tone ?? "neutral";
14
+ return toast.actions == null && (tone === "neutral" || tone === "info" || tone === "positive");
15
+ }
16
+ function ToastItem({ toast, dismissLabel, onDismiss, }) {
17
+ const tone = toast.tone ?? "neutral";
18
+ const hide = hides(toast);
19
+ return (_jsxs("div", { "data-toast": "", "data-toast-hide": hide ? "" : undefined, onAnimationEnd: (event) => {
20
+ // A child's animation (a busy Button's spinner) bubbles here too: only the toast's own
21
+ // animation, which is the hide, counts.
22
+ if (hide && event.target === event.currentTarget)
23
+ onDismiss(toast.id);
24
+ }, className: cx("pointer-events-auto flex items-start gap-3 rounded-xl border p-3 pl-4 text-sm shadow-lg", TONE_SURFACE[tone], TONE_TEXT[tone]), children: [_jsxs("div", { className: "min-w-0 flex-1 py-0.5", children: [_jsx("p", { className: "font-semibold", children: toast.title }), toast.body != null && _jsx("div", { className: "mt-1", children: toast.body })] }), toast.actions != null && (_jsx("div", { className: "flex shrink-0 items-center gap-2", children: toast.actions })), _jsx(IconButton, { size: "sm", variant: "ghost", icon: "close", label: dismissLabel, onClick: () => onDismiss(toast.id) })] }));
25
+ }
26
+ /**
27
+ * The page's toasts: short notices fixed to the bottom of the viewport, from a list the app holds.
28
+ * Mount it once, at the root beside `AppShell`; add a toast to `toasts` to show it, and drop it in
29
+ * `onDismiss` to remove it. A `neutral`, `info` or `positive` toast with no `actions` leaves on its
30
+ * own after five seconds (paused while the pointer is over it or focus is in it); a `warn` or
31
+ * `danger` toast, or one with `actions`, stays until dismissed. The region is a named landmark with
32
+ * a polite `role="status"`, kept in the page while empty, so each new toast is read once. A toast
33
+ * raised while a `Dialog` or `Drawer` is open sits under it until it closes.
34
+ */
35
+ export function ToastRegion({ toasts, onDismiss, label = "Notifications", dismissLabel = "Dismiss", ...rest }) {
36
+ return (_jsxs("section", { "aria-label": label, ...rest, "data-hc-toasts": "", className: "pointer-events-none fixed inset-x-0 bottom-0 z-50 flex justify-center px-4 pb-[max(1rem,env(safe-area-inset-bottom))]", children: [_jsx("style", { children: css }), _jsx("div", { role: "status", "aria-live": "polite", "aria-atomic": "false", className: "flex w-full max-w-sm flex-col gap-2", children: toasts.map((toast) => (_jsx(ToastItem, { toast: toast, dismissLabel: dismissLabel, onDismiss: onDismiss }, toast.id))) })] }));
37
+ }
@@ -0,0 +1,46 @@
1
+ import { type CSSProperties, type ReactElement, type FocusEvent, type KeyboardEvent, type PointerEvent, type ReactNode } from "react";
2
+ /** What a trigger may carry that the tooltip merges with. */
3
+ export type TriggerOwn<E extends Element> = {
4
+ title?: string | undefined;
5
+ "aria-describedby"?: string | undefined;
6
+ onPointerEnter?: ((event: PointerEvent<E>) => void) | undefined;
7
+ onPointerLeave?: ((event: PointerEvent<E>) => void) | undefined;
8
+ onPointerDown?: ((event: PointerEvent<E>) => void) | undefined;
9
+ onFocus?: ((event: FocusEvent<E>) => void) | undefined;
10
+ onBlur?: ((event: FocusEvent<E>) => void) | undefined;
11
+ onKeyDown?: ((event: KeyboardEvent<E>) => void) | undefined;
12
+ };
13
+ /** What to spread on the trigger after the caller's own props: the same keys, merged. */
14
+ export type TriggerProps<E extends Element> = TriggerOwn<E> & {
15
+ style?: CSSProperties;
16
+ };
17
+ type Options = {
18
+ /**
19
+ * The text describes the trigger (`aria-describedby`): a disabled reason, a pill's detail. Left
20
+ * false, the text is the trigger's name, already its `aria-label`, so the tooltip is hidden from
21
+ * assistive tech and links nothing.
22
+ */
23
+ describes: boolean;
24
+ /** A touch tap on the trigger shows the tooltip, and the next tap anywhere hides it. */
25
+ tap?: boolean | undefined;
26
+ };
27
+ /**
28
+ * Wires one internal tooltip to a trigger. Spread `props` on the trigger after the caller's own
29
+ * props: it holds the same keys, merged (`aria-describedby` and the handlers keep the caller's), and
30
+ * render `tooltip` right after the trigger. With no `text`, `props` is `own` unchanged and
31
+ * `tooltip` is null. Internal: not exported from the package.
32
+ */
33
+ export declare function useTooltip<E extends Element>(text: string | undefined, { describes, tap }: Options, own: TriggerOwn<E>): {
34
+ props: TriggerProps<E>;
35
+ tooltip: ReactNode;
36
+ };
37
+ /**
38
+ * `useTooltip` as a part, for a component that picks its element in a branch: `children` draws the
39
+ * trigger from the merged props, and the tooltip follows it. Internal.
40
+ */
41
+ export declare function Tipped<E extends Element>({ text, describes, tap, own, children, }: Options & {
42
+ text: string | undefined;
43
+ own: TriggerOwn<E>;
44
+ children: (props: TriggerProps<E>) => ReactElement;
45
+ }): ReactElement;
46
+ export {};
@@ -0,0 +1,181 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useCallback, useEffect, useId, useState, useSyncExternalStore, } from "react";
3
+ // The tooltip's layer is a native `popover="manual"` in the top layer, so a clipping table cell or
4
+ // card never cuts it off, placed above its trigger with CSS anchor positioning and flipped below
5
+ // when there is no room. Anchor positioning is newer than the browsers the library supports, so it
6
+ // is an enhancement: where the popover API or `CSS.supports("anchor-name: --a")` is missing, and on the server and the
7
+ // first client render, the trigger keeps the native `title` and no tooltip is drawn.
8
+ //
9
+ // Nothing here is a timer. Script reacts to events (enter, leave, focus, blur, Escape, a tap) and
10
+ // calls `showPopover()` and `hidePopover()`. The half-second wait before a hover shows is CSS: an
11
+ // animation with a delay holds the tooltip `visibility: hidden` (a discrete keyframe), and focus
12
+ // and a tap carry no animation, so they show at once. The popover's padding is the bridge the
13
+ // pointer crosses from the trigger to the tooltip, so moving onto it keeps it open.
14
+ const css = `[data-hc-tooltip]{position:fixed;inset:auto;margin:0;border:0;padding:.375rem 0;background:transparent;overflow:visible;width:max-content;max-width:min(20rem,calc(100vw - 2rem));position-area:top;position-try-fallbacks:flip-block}[data-hc-tooltip][data-via=pointer]{animation:hc-tooltip-in .01s linear .5s backwards}@keyframes hc-tooltip-in{from,to{visibility:hidden}}`;
15
+ const CHIP = "block rounded-md border border-slate-200 bg-white px-2 py-1 text-xs text-slate-900 shadow-lg whitespace-normal break-words";
16
+ /** Whether this browser has the popover API and places a popover by its anchor. Read after mount. */
17
+ function anchorPositioning() {
18
+ if (typeof HTMLElement === "undefined" || !("showPopover" in HTMLElement.prototype))
19
+ return false;
20
+ return typeof CSS !== "undefined" && typeof CSS.supports === "function"
21
+ ? CSS.supports("anchor-name: --a")
22
+ : false;
23
+ }
24
+ const never = () => () => { };
25
+ /**
26
+ * Whether the focus shows its ring: from the keyboard, not the focus a click or a modal opened by a
27
+ * click gives. A browser without `:focus-visible` counts every focus.
28
+ */
29
+ function focusVisible(element) {
30
+ try {
31
+ return element.matches(":focus-visible");
32
+ }
33
+ catch {
34
+ return true;
35
+ }
36
+ }
37
+ /** Shows the layer while `open`, hides it when not: the popover's own methods, never a timer. */
38
+ function useLayer(layer, open) {
39
+ useEffect(() => {
40
+ if (!layer)
41
+ return;
42
+ if (open)
43
+ layer.showPopover();
44
+ else
45
+ layer.hidePopover();
46
+ }, [layer, open]);
47
+ }
48
+ /** While a tap holds the tooltip open, the next tap anywhere but the trigger closes it. */
49
+ function useTapAway(on, trigger, close) {
50
+ useEffect(() => {
51
+ if (!on)
52
+ return undefined;
53
+ const away = (event) => {
54
+ const target = event.target;
55
+ if (target instanceof Node && trigger?.contains(target))
56
+ return;
57
+ close();
58
+ };
59
+ document.addEventListener("pointerdown", away, true);
60
+ return () => document.removeEventListener("pointerdown", away, true);
61
+ }, [on, trigger, close]);
62
+ }
63
+ /**
64
+ * While the tooltip is open, Escape closes it wherever focus is (WCAG 1.4.13): a hover opens it
65
+ * without moving focus, so the trigger's own key handler never sees the key. Capture on `document`,
66
+ * and no `preventDefault` or `stopPropagation`, so Escape still reaches a Dialog or Drawer in the
67
+ * same press.
68
+ */
69
+ function useEscape(on, close) {
70
+ useEffect(() => {
71
+ if (!on)
72
+ return undefined;
73
+ const escape = (event) => {
74
+ if (event.key === "Escape")
75
+ close();
76
+ };
77
+ document.addEventListener("keydown", escape, true);
78
+ return () => document.removeEventListener("keydown", escape, true);
79
+ }, [on, close]);
80
+ }
81
+ /** The pointer left the trigger or the tooltip: close a hover tip, unless it moved onto the other. */
82
+ function leave(tip, related, from) {
83
+ const other = from === "trigger" ? tip.layer : tip.trigger;
84
+ if (related instanceof Node && other?.contains(related))
85
+ return;
86
+ tip.setVia((current) => (current === "pointer" ? null : current));
87
+ }
88
+ /** The trigger's handlers: the caller's own first, then the tooltip's. */
89
+ function handlers(own, tip) {
90
+ return {
91
+ onPointerEnter: (event) => {
92
+ own.onPointerEnter?.(event);
93
+ tip.setTrigger(event.currentTarget);
94
+ if (event.pointerType !== "touch")
95
+ tip.setVia((current) => current ?? "pointer");
96
+ },
97
+ onPointerLeave: (event) => {
98
+ own.onPointerLeave?.(event);
99
+ leave(tip, event.relatedTarget, "trigger");
100
+ },
101
+ onPointerDown: (event) => {
102
+ own.onPointerDown?.(event);
103
+ tip.setTrigger(event.currentTarget);
104
+ // The focus this press gives the trigger pops nothing: only the keyboard's (or script's) does.
105
+ tip.setPressed(true);
106
+ if (event.pointerType === "touch" && tip.tap) {
107
+ tip.setVia((current) => (current === "tap" ? null : "tap"));
108
+ return;
109
+ }
110
+ // A press on the trigger is the action, not a request for the tip.
111
+ tip.setVia(null);
112
+ },
113
+ onFocus: (event) => {
114
+ own.onFocus?.(event);
115
+ tip.setTrigger(event.currentTarget);
116
+ // The focused element, not the trigger: a wrapper's focus is the button inside it.
117
+ if (!tip.pressed && focusVisible(event.target))
118
+ tip.setVia("focus");
119
+ tip.setPressed(false);
120
+ },
121
+ onBlur: (event) => {
122
+ own.onBlur?.(event);
123
+ // A click on a trigger that already has focus fires no focus event to clear the press.
124
+ tip.setPressed(false);
125
+ tip.setVia((current) => (current === "tap" ? current : null));
126
+ },
127
+ onKeyDown: (event) => {
128
+ own.onKeyDown?.(event);
129
+ // Dismissed where it stands (WCAG 1.4.13): focus stays. The key goes on, so Escape in a
130
+ // Dialog or Drawer still closes it in one press.
131
+ if (event.key === "Escape")
132
+ tip.setVia(null);
133
+ },
134
+ };
135
+ }
136
+ /**
137
+ * Wires one internal tooltip to a trigger. Spread `props` on the trigger after the caller's own
138
+ * props: it holds the same keys, merged (`aria-describedby` and the handlers keep the caller's), and
139
+ * render `tooltip` right after the trigger. With no `text`, `props` is `own` unchanged and
140
+ * `tooltip` is null. Internal: not exported from the package.
141
+ */
142
+ export function useTooltip(text, { describes, tap = false }, own) {
143
+ const id = useId();
144
+ // False in the server markup and while the client hydrates, so both render the native `title`.
145
+ const enhanced = useSyncExternalStore(never, anchorPositioning, () => false);
146
+ const [via, setVia] = useState(null);
147
+ const [trigger, setTrigger] = useState(null);
148
+ const [layer, setLayer] = useState(null);
149
+ const [pressed, setPressed] = useState(false);
150
+ const close = useCallback(() => setVia(null), []);
151
+ useLayer(layer, via !== null);
152
+ useTapAway(via === "tap", trigger, close);
153
+ useEscape(via !== null, close);
154
+ if (text === undefined || text === "")
155
+ return { props: own, tooltip: null };
156
+ if (!enhanced)
157
+ return { props: { ...own, title: text }, tooltip: null };
158
+ const tip = { via, setVia, trigger, setTrigger, layer, pressed, setPressed, tap };
159
+ const anchor = `--hc-tip${id.replaceAll(/[^a-zA-Z0-9_-]/g, "")}`;
160
+ const tipId = `${id}-tip`;
161
+ const describedBy = describes
162
+ ? [own["aria-describedby"], tipId].filter(Boolean).join(" ")
163
+ : own["aria-describedby"];
164
+ const props = {
165
+ ...handlers(own, tip),
166
+ // The native title goes: the tooltip shows the text, and both at once would double it.
167
+ title: undefined,
168
+ "aria-describedby": describedBy || undefined,
169
+ style: { anchorName: anchor },
170
+ };
171
+ const tooltip = (_jsxs(_Fragment, { children: [_jsx("style", { children: css }), _jsx("span", { ref: setLayer, id: tipId, role: "tooltip", popover: "manual", "data-hc-tooltip": "", "data-via": via ?? undefined, "aria-hidden": describes ? undefined : true, style: { positionAnchor: anchor }, onPointerLeave: (event) => leave(tip, event.relatedTarget, "tooltip"), children: _jsx("span", { className: CHIP, children: text }) })] }));
172
+ return { props, tooltip };
173
+ }
174
+ /**
175
+ * `useTooltip` as a part, for a component that picks its element in a branch: `children` draws the
176
+ * trigger from the merged props, and the tooltip follows it. Internal.
177
+ */
178
+ export function Tipped({ text, describes, tap, own, children, }) {
179
+ const { props, tooltip } = useTooltip(text, { describes, tap }, own);
180
+ return (_jsxs(_Fragment, { children: [children(props), tooltip] }));
181
+ }
@@ -0,0 +1,36 @@
1
+ import type { ReactElement } from "react";
2
+ import type { Passthrough } from "./props.js";
3
+ import { type LoadingProps } from "./skeleton.js";
4
+ import { type VizTone } from "./StackedBar.js";
5
+ /**
6
+ * One series of a `TrendChart`: its `label` (the table's column, the Legend's entry), its colour,
7
+ * and one value per bucket in the buckets' order. A `null`, or a list shorter than the buckets, is
8
+ * a missing value.
9
+ */
10
+ export type TrendSeries = {
11
+ label: string;
12
+ tone: VizTone;
13
+ values: readonly (number | null)[];
14
+ };
15
+ /**
16
+ * A chart of one or two series over ordered buckets (weeks, months), as bars or a line, on a
17
+ * y-axis from 0. The y-axis is labelled 0, half and a rounded maximum; the x-axis names the
18
+ * buckets. A screen reader gets the same figures as a table. While `loading` the frame, the bucket
19
+ * names and the key stay drawn and the plot is one bone, since 0 is a real value.
20
+ */
21
+ export declare function TrendChart({ label, buckets, series, kind, loading, loadingLabel, ...rest }: {
22
+ /** What the chart shows: its accessible name and the caption of its table. */
23
+ label: string;
24
+ /** The x-axis labels, in order (`"W12"`, `"Mar"`). */
25
+ buckets: readonly string[];
26
+ /**
27
+ * One or two series, each `{ label, tone, values }`. A `null` value, or a `values` list shorter
28
+ * than `buckets`, is missing. Two series draw a Legend under the chart.
29
+ */
30
+ series: readonly [TrendSeries] | readonly [TrendSeries, TrendSeries];
31
+ /**
32
+ * `bar` for a count in each bucket, `line` for a level over time.
33
+ * @default bar
34
+ */
35
+ kind?: "bar" | "line";
36
+ } & LoadingProps & Passthrough): ReactElement;