@slashsuite/ui-react 0.0.0-stage → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (304) hide show
  1. package/LICENSE +21 -0
  2. package/MIGRATING.md +540 -0
  3. package/README.md +549 -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,58 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Bone, BusyLabel, busy, LoadingScope, useLoading } from "./skeleton.js";
3
+ import { Legend, VIZ_TONE } from "./StackedBar.js";
4
+ import { drawn, largest, plotY, round, runs, scaleMax } from "./trend.js";
5
+ /** The most x labels drawn; past it, every k-th label is, starting with the first. */
6
+ const MAX_X_LABELS = 8;
7
+ /** Share of a bucket's width the bars of one bucket take, centred; the rest is the gap between buckets. */
8
+ const BAR_SPAN = 0.7;
9
+ const FORMAT = new Intl.NumberFormat("en-US");
10
+ /** A value as the table says it: as given, or blank when missing. */
11
+ const spoken = (value) => value == null || !Number.isFinite(value) ? null : FORMAT.format(value);
12
+ /**
13
+ * A chart of one or two series over ordered buckets (weeks, months), as bars or a line, on a
14
+ * y-axis from 0. The y-axis is labelled 0, half and a rounded maximum; the x-axis names the
15
+ * buckets. A screen reader gets the same figures as a table. While `loading` the frame, the bucket
16
+ * names and the key stay drawn and the plot is one bone, since 0 is a real value.
17
+ */
18
+ export function TrendChart({ label, buckets, series, kind = "bar", loading, loadingLabel, ...rest }) {
19
+ const { loading: waiting, owner } = useLoading(loading);
20
+ const values = series.map((s) => buckets.map((_, i) => drawn(s.values[i])));
21
+ const max = scaleMax(largest(values));
22
+ const ticks = [max, max / 2, 0];
23
+ return (_jsxs("figure", { ...rest, ...busy(owner, waiting), "aria-label": label, className: "flex flex-col gap-3", children: [_jsxs("div", { "aria-hidden": "true", className: "flex gap-2 pt-2 text-xs tabular-nums text-slate-500", children: [_jsx(YAxis, { ticks: waiting ? [] : ticks, max: max }), _jsxs("div", { className: "flex min-w-0 flex-1 flex-col gap-1.5", children: [waiting ? (_jsx(Bone, { shape: "block h-48 rounded-lg" })) : (_jsx(Plot, { ticks: ticks, max: max, kind: kind, series: series, values: values })), _jsx(XAxis, { buckets: buckets })] })] }), series.length === 2 && (_jsx(LoadingScope, { loading: false, children: _jsx(Legend, { items: series.map((s) => ({ label: s.label, tone: s.tone })) }) })), waiting ? (_jsx(BusyLabel, { owner: owner, loading: waiting, label: loadingLabel })) : (_jsx(FigureTable, { label: label, buckets: buckets, series: series }))] }));
24
+ }
25
+ /** The plot: a gridline per tick, and the series' bars or lines over them. */
26
+ function Plot({ ticks, max, kind, series, values, }) {
27
+ return (_jsxs("div", { className: "relative h-48", children: [ticks.map((tick) => (_jsx("span", { className: "absolute inset-x-0 border-t border-slate-200", style: { top: `${plotY(tick, max)}%` } }, tick))), _jsx("svg", { viewBox: "0 0 100 100", preserveAspectRatio: "none", className: "absolute inset-0 size-full overflow-visible", children: kind === "bar" ? (_jsx(Bars, { series: series, values: values, max: max })) : (_jsx(Lines, { series: series, values: values, max: max })) })] }));
28
+ }
29
+ /** The y labels, each centred on its gridline; the widest (the top) sets the column's width. */
30
+ function YAxis({ ticks, max }) {
31
+ return (_jsxs("div", { className: "relative h-48 shrink-0 text-right", children: [_jsx("span", { className: "invisible block", children: FORMAT.format(max) }), ticks.map((tick) => (_jsx("span", { className: "absolute right-0 -translate-y-1/2", style: { top: `${plotY(tick, max)}%` }, children: FORMAT.format(tick) }, tick)))] }));
32
+ }
33
+ /** One equal column per bucket; past 8 buckets, every k-th label from the first. */
34
+ function XAxis({ buckets }) {
35
+ const every = Math.max(1, Math.ceil(buckets.length / MAX_X_LABELS));
36
+ return (_jsx("div", { className: "grid text-center", style: { gridTemplateColumns: `repeat(${buckets.length}, minmax(0, 1fr))` }, children: buckets.map((bucket, i) => (_jsx("span", { className: "whitespace-nowrap", children: i % every === 0 ? bucket : null }, `${bucket}-${i}`))) }));
37
+ }
38
+ /** A rect per present value, the series side by side in each bucket. */
39
+ function Bars({ series, values, max }) {
40
+ const width = 100 / Math.max(1, values[0]?.length ?? 1);
41
+ const bar = (width * BAR_SPAN) / series.length;
42
+ const inset = (width * (1 - BAR_SPAN)) / 2;
43
+ return (_jsx(_Fragment, { children: series.map((s, si) => values[si]?.map((value, i) => {
44
+ if (value === null)
45
+ return null;
46
+ const y = plotY(value, max);
47
+ return (_jsx("rect", { "data-bucket": i, className: VIZ_TONE[s.tone], fill: "currentColor", x: round(width * i + inset + bar * si), y: round(y), width: round(bar), height: round(100 - y) }, `${si}-${i}`));
48
+ })) }));
49
+ }
50
+ /** A polyline per run of present values, through the middle of each bucket. */
51
+ function Lines({ series, values, max }) {
52
+ const width = 100 / Math.max(1, values[0]?.length ?? 1);
53
+ return (_jsx(_Fragment, { children: series.map((s, si) => runs((values[si] ?? []).map((value, i) => value === null ? null : { x: width * (i + 0.5), y: plotY(value, max) })).map((points) => (_jsx("polyline", { className: VIZ_TONE[s.tone], points: points, fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", strokeLinejoin: "round", vectorEffect: "non-scaling-stroke" }, `${si}-${points}`)))) }));
54
+ }
55
+ /** The chart's figures for a screen reader: a row per bucket, a column per series. */
56
+ function FigureTable({ label, buckets, series, }) {
57
+ return (_jsxs("table", { className: "sr-only", children: [_jsx("caption", { children: label }), _jsx("thead", { children: _jsxs("tr", { children: [_jsx("td", {}), series.map((s, si) => (_jsx("th", { scope: "col", children: s.label }, si)))] }) }), _jsx("tbody", { children: buckets.map((bucket, i) => (_jsxs("tr", { children: [_jsx("th", { scope: "row", children: bucket }), series.map((s, si) => (_jsx("td", { children: spoken(s.values[i]) }, si)))] }, `${bucket}-${i}`))) })] }));
58
+ }
@@ -0,0 +1,13 @@
1
+ import type { ReactElement, VideoHTMLAttributes } from "react";
2
+ import type { Unstyled } from "./props.js";
3
+ /**
4
+ * A `<video>` with controls, full width and rounded; it loads metadata only, so the page does not
5
+ * pull the file until it is played. `src` is the app's own video; `captions` is a WebVTT file,
6
+ * offered as the default track. `children` is the fallback for a browser that cannot play it.
7
+ */
8
+ export declare function Video({ src, captions, children, ...rest }: {
9
+ /** The video file, the app's own. */
10
+ src: string;
11
+ /** A WebVTT file, offered as the default captions track. */
12
+ captions?: string | undefined;
13
+ } & Unstyled<Omit<VideoHTMLAttributes<HTMLVideoElement>, "src" | "controls">>): ReactElement;
package/dist/Video.js ADDED
@@ -0,0 +1,9 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /**
3
+ * A `<video>` with controls, full width and rounded; it loads metadata only, so the page does not
4
+ * pull the file until it is played. `src` is the app's own video; `captions` is a WebVTT file,
5
+ * offered as the default track. `children` is the fallback for a browser that cannot play it.
6
+ */
7
+ export function Video({ src, captions, children, ...rest }) {
8
+ return (_jsxs("video", { controls: true, preload: "metadata", src: src, ...rest, className: "w-full rounded-lg", children: [captions && _jsx("track", { kind: "captions", src: captions, default: true }), children] }));
9
+ }
@@ -0,0 +1,31 @@
1
+ import type { ReactNode, SyntheticEvent } from "react";
2
+ import { type TriggerOwn, type TriggerProps } from "./Tooltip.js";
3
+ /**
4
+ * The blocked state of a control that says why it cannot be used (`disabledReason`): marked
5
+ * `aria-disabled` rather than `disabled`, so it stays in the tab order and the keyboard reaches its
6
+ * reason, and its click is swallowed (Enter and Space on a button arrive as a click). Spread it
7
+ * last on the control, over the caller's own `onClick`. Internal.
8
+ */
9
+ export declare function blockedProps(): {
10
+ "aria-disabled": true;
11
+ onClick: (event: SyntheticEvent) => void;
12
+ };
13
+ /** Whether a `disabledReason` blocks: an empty one says nothing, so it blocks nothing either. */
14
+ export declare function hasReason(reason: string | undefined): reason is string;
15
+ type Blocked = {
16
+ "aria-disabled"?: true;
17
+ onClick?: (event: SyntheticEvent) => void;
18
+ };
19
+ /**
20
+ * `disabledReason` on one control, the same on every part that takes it: with a reason the control
21
+ * is blocked (`blockedProps`) and the reason is its tooltip, shown on hover, keyboard focus and a
22
+ * tap, and read out as its description; with none, `props` is the tooltip-free `own`. Spread `props`
23
+ * last on the control and render `tooltip` after it, outside any `<label>` (whose text would
24
+ * otherwise join the control's name). Internal.
25
+ */
26
+ export declare function useBlocked<E extends Element>(reason: string | undefined, own: TriggerOwn<E>): {
27
+ props: TriggerProps<E> & Blocked;
28
+ tooltip: ReactNode;
29
+ blocked: boolean;
30
+ };
31
+ export {};
@@ -0,0 +1,31 @@
1
+ import { useTooltip } from "./Tooltip.js";
2
+ /** Swallows an activation: no handler runs, and a `type="submit"` button submits nothing. */
3
+ function swallow(event) {
4
+ event.preventDefault();
5
+ event.stopPropagation();
6
+ }
7
+ /**
8
+ * The blocked state of a control that says why it cannot be used (`disabledReason`): marked
9
+ * `aria-disabled` rather than `disabled`, so it stays in the tab order and the keyboard reaches its
10
+ * reason, and its click is swallowed (Enter and Space on a button arrive as a click). Spread it
11
+ * last on the control, over the caller's own `onClick`. Internal.
12
+ */
13
+ export function blockedProps() {
14
+ return { "aria-disabled": true, onClick: swallow };
15
+ }
16
+ /** Whether a `disabledReason` blocks: an empty one says nothing, so it blocks nothing either. */
17
+ export function hasReason(reason) {
18
+ return reason !== undefined && reason !== "";
19
+ }
20
+ /**
21
+ * `disabledReason` on one control, the same on every part that takes it: with a reason the control
22
+ * is blocked (`blockedProps`) and the reason is its tooltip, shown on hover, keyboard focus and a
23
+ * tap, and read out as its description; with none, `props` is the tooltip-free `own`. Spread `props`
24
+ * last on the control and render `tooltip` after it, outside any `<label>` (whose text would
25
+ * otherwise join the control's name). Internal.
26
+ */
27
+ export function useBlocked(reason, own) {
28
+ const { props, tooltip } = useTooltip(reason, { describes: true, tap: true }, own);
29
+ const blocked = hasReason(reason);
30
+ return { props: blocked ? { ...props, ...blockedProps() } : props, tooltip, blocked };
31
+ }
@@ -0,0 +1,8 @@
1
+ import { type ReactElement, type ReactNode } from "react";
2
+ /** Marks `children` as inside a card, or, with `value={false}`, as out of one: a modal opened from a card. */
3
+ export declare function InCard({ value, children, }: {
4
+ value?: boolean;
5
+ children: ReactNode;
6
+ }): ReactElement;
7
+ /** `true` inside a `Card`. */
8
+ export declare function useInCard(): boolean;
@@ -0,0 +1,14 @@
1
+ import { createContext, createElement, useContext } from "react";
2
+ /**
3
+ * Whether a part sits inside a `Card`: an `EmptyState` draws its own dashed frame only when it
4
+ * stands alone. Internal: not exported from the package.
5
+ */
6
+ const CardContext = createContext(false);
7
+ /** Marks `children` as inside a card, or, with `value={false}`, as out of one: a modal opened from a card. */
8
+ export function InCard({ value = true, children, }) {
9
+ return createElement(CardContext.Provider, { value }, children);
10
+ }
11
+ /** `true` inside a `Card`. */
12
+ export function useInCard() {
13
+ return useContext(CardContext);
14
+ }
@@ -0,0 +1,13 @@
1
+ import type { ReactElement, ReactNode } from "react";
2
+ /**
3
+ * What a card holds while it may be waiting: its children, or, loading with none yet, three lines
4
+ * of text bones (three `ListRow` bones in a `flush` card, the compact list it usually holds); then
5
+ * the owner's hidden label.
6
+ */
7
+ export declare function CardWait({ loading, owner, label, flush, children, }: {
8
+ loading: boolean;
9
+ owner: boolean;
10
+ label: string | undefined;
11
+ flush: boolean | undefined;
12
+ children: ReactNode;
13
+ }): ReactElement;
@@ -0,0 +1,16 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { ListRow } from "./ListRow.js";
3
+ import { BoneLines, BusyLabel, isEmptySlot } from "./skeleton.js";
4
+ /**
5
+ * What a card holds while it may be waiting: its children, or, loading with none yet, three lines
6
+ * of text bones (three `ListRow` bones in a `flush` card, the compact list it usually holds); then
7
+ * the owner's hidden label.
8
+ */
9
+ export function CardWait({ loading, owner, label, flush, children, }) {
10
+ return (_jsxs(_Fragment, { children: [loading && isEmptySlot(children) ? _jsx(CardBones, { flush: flush ?? false }) : children, _jsx(BusyLabel, { owner: owner, loading: loading, label: label })] }));
11
+ }
12
+ function CardBones({ flush }) {
13
+ if (!flush)
14
+ return _jsx(BoneLines, {});
15
+ return (_jsx(_Fragment, { children: [0, 1, 2].map((i) => (_jsx(ListRow, { divided: i > 0, children: null }, i))) }));
16
+ }
@@ -0,0 +1,22 @@
1
+ /** The two colour schemes a site switches between: `light` and `dark`. */
2
+ export type ColourScheme = "light" | "dark";
3
+ /** The class each scheme puts on `<html>`: none for light and `dark` for dark, unless the app's theme says otherwise (a light theme with a scope class of its own). */
4
+ export type ColourSchemeClasses = {
5
+ light: string;
6
+ dark: string;
7
+ };
8
+ /** The class for `scheme`: what to render on `<html>` on the server so the first paint is right. `""` for the default light scheme. */
9
+ export declare function schemeClass(scheme: ColourScheme, schemes?: ColourSchemeClasses): string;
10
+ /** Which scheme `root` is in: dark when it carries the dark class, else light. */
11
+ export declare function appliedColourScheme(root?: HTMLElement, schemes?: ColourSchemeClasses): ColourScheme;
12
+ /** Put `scheme` on `root` (the `<html>` element by default): its class from `schemes` (default `dark` for dark and none for light), the other scheme's class taken off, and `color-scheme` so native controls and scrollbars follow. */
13
+ export declare function applyColourScheme(scheme: ColourScheme, root?: HTMLElement, schemes?: ColourSchemeClasses): void;
14
+ /** The stored choice, else the system preference. `fallback` (default `"light"`) is for when neither is available: server rendering, or storage that throws with no `matchMedia`. */
15
+ export declare function readColourScheme(fallback?: ColourScheme): ColourScheme;
16
+ /** Remember `scheme` for the next visit. A storage error is swallowed, so private mode does not crash. */
17
+ export declare function storeColourScheme(scheme: ColourScheme): void;
18
+ /**
19
+ * JavaScript to inline in `<head>`, before first paint: applies the stored scheme, else the
20
+ * system one, to `<html>` as `applyColourScheme` does. Without it a light user sees a dark flash.
21
+ */
22
+ export declare const colourSchemeScript: string;
@@ -0,0 +1,53 @@
1
+ const STORAGE_KEY = "hackcove:colour-scheme";
2
+ const DARK_QUERY = "(prefers-color-scheme: dark)";
3
+ const isScheme = (value) => value === "light" || value === "dark";
4
+ const DEFAULT_CLASSES = { light: "", dark: "dark" };
5
+ /** The class for `scheme`: what to render on `<html>` on the server so the first paint is right. `""` for the default light scheme. */
6
+ export function schemeClass(scheme, schemes = DEFAULT_CLASSES) {
7
+ return schemes[scheme];
8
+ }
9
+ /** Which scheme `root` is in: dark when it carries the dark class, else light. */
10
+ export function appliedColourScheme(root = document.documentElement, schemes = DEFAULT_CLASSES) {
11
+ return schemes.dark !== "" && root.classList.contains(schemes.dark) ? "dark" : "light";
12
+ }
13
+ /** Put `scheme` on `root` (the `<html>` element by default): its class from `schemes` (default `dark` for dark and none for light), the other scheme's class taken off, and `color-scheme` so native controls and scrollbars follow. */
14
+ export function applyColourScheme(scheme, root = document.documentElement, schemes = DEFAULT_CLASSES) {
15
+ const other = scheme === "dark" ? "light" : "dark";
16
+ if (schemes[other] !== "")
17
+ root.classList.remove(schemes[other]);
18
+ if (schemes[scheme] !== "")
19
+ root.classList.add(schemes[scheme]);
20
+ root.style.colorScheme = scheme;
21
+ }
22
+ function storedScheme() {
23
+ try {
24
+ const stored = localStorage.getItem(STORAGE_KEY);
25
+ return isScheme(stored) ? stored : undefined;
26
+ }
27
+ catch {
28
+ return undefined; // storage blocked: private mode, or no window at all
29
+ }
30
+ }
31
+ function systemScheme() {
32
+ if (typeof matchMedia !== "function")
33
+ return undefined;
34
+ return matchMedia(DARK_QUERY).matches ? "dark" : "light";
35
+ }
36
+ /** The stored choice, else the system preference. `fallback` (default `"light"`) is for when neither is available: server rendering, or storage that throws with no `matchMedia`. */
37
+ export function readColourScheme(fallback = "light") {
38
+ return storedScheme() ?? systemScheme() ?? fallback;
39
+ }
40
+ /** Remember `scheme` for the next visit. A storage error is swallowed, so private mode does not crash. */
41
+ export function storeColourScheme(scheme) {
42
+ try {
43
+ localStorage.setItem(STORAGE_KEY, scheme);
44
+ }
45
+ catch {
46
+ // Not remembered; the page still switches for this visit.
47
+ }
48
+ }
49
+ /**
50
+ * JavaScript to inline in `<head>`, before first paint: applies the stored scheme, else the
51
+ * system one, to `<html>` as `applyColourScheme` does. Without it a light user sees a dark flash.
52
+ */
53
+ export const colourSchemeScript = `(function(){var r=document.documentElement,s;try{s=localStorage.getItem(${JSON.stringify(STORAGE_KEY)})}catch(e){}if(s!=="light"&&s!=="dark")s=typeof matchMedia==="function"?matchMedia(${JSON.stringify(DARK_QUERY)}).matches?"dark":"light":null;if(s){r.classList.toggle("dark",s==="dark");r.style.colorScheme=s}})()`;
@@ -0,0 +1,29 @@
1
+ import { type TypeStep } from "./density.js";
2
+ import type { Size } from "./size.js";
3
+ /** A control's size: the library's one `Size` scale. */
4
+ export type ControlSize = Size;
5
+ /** `full` fills the parent (the default); `fill` grows to the space left in a flex row; `auto` adds no width class, so the control is as wide as the browser makes it; the rest are fixed. */
6
+ export type ControlWidth = "full" | "fill" | "auto" | "xs" | "sm" | "md" | "lg";
7
+ /** The props `Input`, `Select` and `Textarea` share. They replace the native `size` and `width`. */
8
+ export type ControlProps = {
9
+ /**
10
+ * `sm` is compact, `text-sm` with less padding, for dense forms and table rows; `md` is `text-base`;
11
+ * `lg` is `text-lg` with more padding, for a hero form. Under an `AppShell density="compact"` each
12
+ * is one type step down, and on a touch screen a field is never under 16px.
13
+ * @default md
14
+ */
15
+ size?: ControlSize | undefined;
16
+ /** `full` (default) fills the parent; `fill` grows to fill the room left in a row beside other items (it can shrink to nothing, so buttons stay on the line); `xs`, `sm`, `md`, `lg` are fixed; `auto` adds no width class, so the control is as wide as the browser makes it. */
17
+ width?: ControlWidth | undefined;
18
+ };
19
+ /** One width class per control, so a fixed width never fights `w-full`. `auto` has none. */
20
+ export declare const CONTROL_WIDTH: Record<ControlWidth, string | undefined>;
21
+ /** A `numeric` `Input`'s figures: right-aligned and tabular, as a `numeric` table cell's. */
22
+ export declare const NUMERIC_VALUE = "text-right tabular-nums";
23
+ /** The horizontal padding of a control, and of an `Input`'s icon gutter. */
24
+ export declare const CONTROL_PAD: Record<ControlSize, {
25
+ x: string;
26
+ icon: string;
27
+ }>;
28
+ /** Shared look of text controls; `size` and the type `step` set the height and type, `width` the one width class. */
29
+ export declare function controlClass(size?: ControlSize, width?: ControlWidth, step?: TypeStep): string;
@@ -0,0 +1,37 @@
1
+ import { focusRing } from "./cx.js";
2
+ import { controlText } from "./density.js";
3
+ /** The vertical padding of a control; its type size is `controlText`'s, from the size and the type step. */
4
+ const CONTROL_PAD_Y = {
5
+ sm: "py-1",
6
+ md: "py-2",
7
+ lg: "py-2.5",
8
+ };
9
+ /** One width class per control, so a fixed width never fights `w-full`. `auto` has none. */
10
+ export const CONTROL_WIDTH = {
11
+ full: "w-full",
12
+ fill: "w-full min-w-0 flex-1",
13
+ auto: undefined,
14
+ xs: "w-20",
15
+ sm: "w-28",
16
+ md: "w-36",
17
+ lg: "w-48",
18
+ };
19
+ /** A `numeric` `Input`'s figures: right-aligned and tabular, as a `numeric` table cell's. */
20
+ export const NUMERIC_VALUE = "text-right tabular-nums";
21
+ /** The horizontal padding of a control, and of an `Input`'s icon gutter. */
22
+ export const CONTROL_PAD = {
23
+ sm: { x: "px-2", icon: "pr-2 pl-7" },
24
+ md: { x: "px-3", icon: "pr-3 pl-9" },
25
+ lg: { x: "px-4", icon: "pr-4 pl-11" },
26
+ };
27
+ /** Shared look of text controls; `size` and the type `step` set the height and type, `width` the one width class. */
28
+ export function controlClass(size = "md", width = "full", step) {
29
+ return [
30
+ CONTROL_WIDTH[width],
31
+ CONTROL_PAD_Y[size],
32
+ controlText(size, step, true),
33
+ `rounded-lg border border-slate-300 bg-white text-slate-900 placeholder:text-slate-400 text-ellipsis transition hover:border-violet-400 aria-invalid:border-red-200 disabled:opacity-50 ${focusRing}`,
34
+ ]
35
+ .filter(Boolean)
36
+ .join(" ");
37
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * JavaScript to inline once on a page that is rendered to static HTML and never hydrated, so every
3
+ * `CopyButton` (and the `CopyLine`, `CodeBlock` and `CodeExample` copy buttons) works there too.
4
+ * One click listener on `document` reads what to copy from the button's data attributes, writes the
5
+ * clipboard, then does what `CopyButton` does: sets `data-copied` again after a reflow, so the CSS
6
+ * that shows the copied label for two seconds starts over, and puts a new node holding the copied
7
+ * label in the status region beside the button, so a screen reader hears each copy. No timer: the
8
+ * label goes back when the animation ends, and its end clears `data-copied` (a second listener), so a
9
+ * button hidden and shown again does not replay it. A refused or missing clipboard leaves it alone.
10
+ * Whichever of the script and a hydrated button's own handler hears a click first copies and flags
11
+ * the event (`copyHandled`), and the other skips it: one copy per click.
12
+ */
13
+ export declare const copyScript: string;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * JavaScript to inline once on a page that is rendered to static HTML and never hydrated, so every
3
+ * `CopyButton` (and the `CopyLine`, `CodeBlock` and `CodeExample` copy buttons) works there too.
4
+ * One click listener on `document` reads what to copy from the button's data attributes, writes the
5
+ * clipboard, then does what `CopyButton` does: sets `data-copied` again after a reflow, so the CSS
6
+ * that shows the copied label for two seconds starts over, and puts a new node holding the copied
7
+ * label in the status region beside the button, so a screen reader hears each copy. No timer: the
8
+ * label goes back when the animation ends, and its end clears `data-copied` (a second listener), so a
9
+ * button hidden and shown again does not replay it. A refused or missing clipboard leaves it alone.
10
+ * Whichever of the script and a hydrated button's own handler hears a click first copies and flags
11
+ * the event (`copyHandled`), and the other skips it: one copy per click.
12
+ */
13
+ export const copyScript = `document.addEventListener("click",function(e){var b=e.target.closest&&e.target.closest("[data-copy-text]"),c=navigator.clipboard;if(!b||!c||e.copyHandled||b.disabled)return;e.copyHandled=1;c.writeText(b.dataset.copyText).then(function(){var r=b.nextElementSibling;b.removeAttribute("data-copied");void b.offsetWidth;b.setAttribute("data-copied","");if(r&&r.matches("[data-copy-status]"))r.replaceChildren(b.dataset.copyCopied)},function(){})});document.addEventListener("animationend",function(e){var b=e.target.closest&&e.target.closest("[data-copied]");if(b)b.removeAttribute("data-copied")})`;
package/dist/cx.d.ts ADDED
@@ -0,0 +1,19 @@
1
+ /** Join class names, dropping falsy parts. */
2
+ export declare function cx(...parts: Array<string | false | null | undefined>): string;
3
+ /** The keyboard focus ring every interactive control shares. */
4
+ export declare const focusRing = "focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-violet-600";
5
+ /**
6
+ * On a row or card that holds a stretched link (`link-stretch`): every interactive descendant sits
7
+ * above that link and is clickable on its own. `z-10` needs a position, so each gets `relative`,
8
+ * except one that is already `absolute` and the stretched link itself. The row or card is `isolate`,
9
+ * its own stacking context: its `z-10` descendants rank only inside it, so they cannot tie with or
10
+ * paint over the page's sticky bars (AppShell's header, a StickyBar).
11
+ */
12
+ export declare const liftInteractive = "isolate [&_:is(a,button,label,select,textarea,input,summary):not(.link-stretch):not(.absolute)]:relative [&_:is(a,button,label,select,textarea,input,summary):not(.link-stretch)]:z-10";
13
+ /**
14
+ * A thin scrollbar in the theme's muted ink instead of the heavy native one, for a box that
15
+ * scrolls sideways (code). `scrollbar-color` takes no Tailwind colour utility, so the thumb is the
16
+ * element's own text colour (`currentColor`, a palette utility every theme remaps) and the track is
17
+ * transparent. The element must not hold text of its own: put the readable colour on an inner box.
18
+ */
19
+ export declare const themedScrollbar = "text-slate-400 [scrollbar-width:thin] [scrollbar-color:currentColor_transparent]";
package/dist/cx.js ADDED
@@ -0,0 +1,21 @@
1
+ /** Join class names, dropping falsy parts. */
2
+ export function cx(...parts) {
3
+ return parts.filter(Boolean).join(" ");
4
+ }
5
+ /** The keyboard focus ring every interactive control shares. */
6
+ export const focusRing = "focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-violet-600";
7
+ /**
8
+ * On a row or card that holds a stretched link (`link-stretch`): every interactive descendant sits
9
+ * above that link and is clickable on its own. `z-10` needs a position, so each gets `relative`,
10
+ * except one that is already `absolute` and the stretched link itself. The row or card is `isolate`,
11
+ * its own stacking context: its `z-10` descendants rank only inside it, so they cannot tie with or
12
+ * paint over the page's sticky bars (AppShell's header, a StickyBar).
13
+ */
14
+ export const liftInteractive = "isolate [&_:is(a,button,label,select,textarea,input,summary):not(.link-stretch):not(.absolute)]:relative [&_:is(a,button,label,select,textarea,input,summary):not(.link-stretch)]:z-10";
15
+ /**
16
+ * A thin scrollbar in the theme's muted ink instead of the heavy native one, for a box that
17
+ * scrolls sideways (code). `scrollbar-color` takes no Tailwind colour utility, so the thumb is the
18
+ * element's own text colour (`currentColor`, a palette utility every theme remaps) and the track is
19
+ * transparent. The element must not hold text of its own: put the readable colour on an inner box.
20
+ */
21
+ export const themedScrollbar = "text-slate-400 [scrollbar-width:thin] [scrollbar-color:currentColor_transparent]";
@@ -0,0 +1,38 @@
1
+ import { type ReactElement, type ReactNode } from "react";
2
+ import { type ResponsiveSize, type Size } from "./size.js";
3
+ /**
4
+ * The type step a whole app may set once: `compact` is one step down for text, headings and
5
+ * controls, for an app's chrome; unset is the default, a site's. Only `AppShell` sets it.
6
+ */
7
+ export type TypeStep = "compact";
8
+ /**
9
+ * Sets the density for its children: what it leaves out, it keeps from the nearest one above, and
10
+ * `size={null}` clears the size, for a container of the default size or a modal that opens inside a
11
+ * compact one. Internal: not exported from the package.
12
+ */
13
+ export declare function DensityProvider({ size, type, children, }: {
14
+ size?: Size | null | undefined;
15
+ type?: TypeStep | undefined;
16
+ children: ReactNode;
17
+ }): ReactElement;
18
+ /** A control's size: its own `size`, else the nearest container's, else `md`. */
19
+ export declare function useDensity(size: Size | undefined): Size;
20
+ /**
21
+ * A control's size where it may also be responsive: its own `size` as given, else the nearest
22
+ * container's, else `md`.
23
+ */
24
+ export declare function useResponsiveDensity(size: Size | ResponsiveSize | undefined): Size | ResponsiveSize;
25
+ /** The type step in force: `compact` under an app that set it, else undefined (the default). */
26
+ export declare function useTypeStep(): TypeStep | undefined;
27
+ /** The size twins, for the data test that each is its table with `md:` on every class. */
28
+ export declare const controlTextTables: {
29
+ text: Record<"compact" | "default", Record<Size, string>>;
30
+ textMd: Record<"compact" | "default", Record<Size, string>>;
31
+ leading: Record<Size, string>;
32
+ leadingMd: Record<Size, string>;
33
+ };
34
+ /**
35
+ * The type class of a control of `size` at `step`; `entry` adds the 16px floor on touch for a field
36
+ * a person types in. A responsive size adds its `md` size from the breakpoint up.
37
+ */
38
+ export declare function controlText(size: Size | ResponsiveSize, step: TypeStep | undefined, entry: boolean): string;
@@ -0,0 +1,77 @@
1
+ import { createContext, createElement, useContext, useMemo, } from "react";
2
+ import { isResponsive } from "./size.js";
3
+ const DensityContext = createContext({ size: undefined, type: undefined });
4
+ /**
5
+ * Sets the density for its children: what it leaves out, it keeps from the nearest one above, and
6
+ * `size={null}` clears the size, for a container of the default size or a modal that opens inside a
7
+ * compact one. Internal: not exported from the package.
8
+ */
9
+ export function DensityProvider({ size, type, children, }) {
10
+ const outer = useContext(DensityContext);
11
+ const value = useMemo(() => ({ size: size === null ? undefined : (size ?? outer.size), type: type ?? outer.type }), [size, type, outer]);
12
+ return createElement(DensityContext.Provider, { value }, children);
13
+ }
14
+ /** A control's size: its own `size`, else the nearest container's, else `md`. */
15
+ export function useDensity(size) {
16
+ const container = useContext(DensityContext).size;
17
+ return size ?? container ?? "md";
18
+ }
19
+ /**
20
+ * A control's size where it may also be responsive: its own `size` as given, else the nearest
21
+ * container's, else `md`.
22
+ */
23
+ export function useResponsiveDensity(size) {
24
+ const container = useContext(DensityContext).size;
25
+ return size ?? container ?? "md";
26
+ }
27
+ /** The type step in force: `compact` under an app that set it, else undefined (the default). */
28
+ export function useTypeStep() {
29
+ return useContext(DensityContext).type;
30
+ }
31
+ /** A control's type size at each step: `md` is 16px at the default step, and `compact` is one step down. */
32
+ const CONTROL_TEXT = {
33
+ default: { sm: "text-sm", md: "text-base", lg: "text-lg" },
34
+ compact: { sm: "text-xs", md: "text-sm", lg: "text-base" },
35
+ };
36
+ /** `CONTROL_TEXT` from the `md` breakpoint up, for a responsive size. */
37
+ const CONTROL_TEXT_MD = {
38
+ default: { sm: "md:text-sm", md: "md:text-base", lg: "md:text-lg" },
39
+ compact: { sm: "md:text-xs", md: "md:text-sm", lg: "md:text-base" },
40
+ };
41
+ /**
42
+ * Where a text-entry control would be under 16px, it is 16px on a touch screen, so iOS Safari does
43
+ * not zoom the page when it takes the focus.
44
+ */
45
+ const TOUCH_TEXT = "pointer-coarse:text-base";
46
+ /**
47
+ * A control's line height by `size`, whatever its type step: 16, 20 and 24px, so with its padding
48
+ * every control is 26, 38 and 46px tall at both steps, and a `Select`, an `IconButton` and a
49
+ * `DateRangePicker`, whose heights are fixed, line up with it.
50
+ */
51
+ const CONTROL_LEADING = { sm: "leading-4", md: "leading-5", lg: "leading-6" };
52
+ /** `CONTROL_LEADING` from the `md` breakpoint up, for a responsive size. */
53
+ const CONTROL_LEADING_MD = {
54
+ sm: "md:leading-4",
55
+ md: "md:leading-5",
56
+ lg: "md:leading-6",
57
+ };
58
+ /** The size twins, for the data test that each is its table with `md:` on every class. */
59
+ export const controlTextTables = {
60
+ text: CONTROL_TEXT,
61
+ textMd: CONTROL_TEXT_MD,
62
+ leading: CONTROL_LEADING,
63
+ leadingMd: CONTROL_LEADING_MD,
64
+ };
65
+ /**
66
+ * The type class of a control of `size` at `step`; `entry` adds the 16px floor on touch for a field
67
+ * a person types in. A responsive size adds its `md` size from the breakpoint up.
68
+ */
69
+ export function controlText(size, step, entry) {
70
+ // The touch floor is judged on `base` only: no text-entry control takes a responsive size yet.
71
+ const base = isResponsive(size) ? size.base : size;
72
+ const plain = `${CONTROL_TEXT[step ?? "default"][base]} ${CONTROL_LEADING[base]}`;
73
+ const text = entry && !/text-(base|lg)/.test(plain) ? `${plain} ${TOUCH_TEXT}` : plain;
74
+ if (!isResponsive(size))
75
+ return text;
76
+ return `${text} ${CONTROL_TEXT_MD[step ?? "default"][size.md]} ${CONTROL_LEADING_MD[size.md]}`;
77
+ }
@@ -0,0 +1,11 @@
1
+ import { type ReactElement, type ReactNode } from "react";
2
+ export type EmptySize = "sm" | "md";
3
+ /** The size an `EmptyState` takes: its own, else its slot's, else `md`. */
4
+ export declare function useEmptySize(own: EmptySize | undefined): EmptySize;
5
+ /** Draws `empty` at the slot's size. Renders no element of its own. */
6
+ export declare function EmptySlot({ size, children, }: {
7
+ size: EmptySize;
8
+ children?: ReactNode;
9
+ }): ReactElement;
10
+ /** No children: an empty array, `null`, `false` or nothing at all. */
11
+ export declare function hasNoChildren(children: ReactNode): boolean;
@@ -0,0 +1,16 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Children, createContext, useContext } from "react";
3
+ const EmptySizeContext = createContext(undefined);
4
+ /** The size an `EmptyState` takes: its own, else its slot's, else `md`. */
5
+ export function useEmptySize(own) {
6
+ const slot = useContext(EmptySizeContext);
7
+ return own ?? slot ?? "md";
8
+ }
9
+ /** Draws `empty` at the slot's size. Renders no element of its own. */
10
+ export function EmptySlot({ size, children, }) {
11
+ return _jsx(EmptySizeContext.Provider, { value: size, children: children });
12
+ }
13
+ /** No children: an empty array, `null`, `false` or nothing at all. */
14
+ export function hasNoChildren(children) {
15
+ return Children.toArray(children).length === 0;
16
+ }
@@ -0,0 +1,23 @@
1
+ /** What a `Field` tells the control inside it. Internal: not exported from the package. */
2
+ export type FieldControlContext = {
3
+ /** The control's id, which the Field's label names. */
4
+ id: string;
5
+ /** The id of the note the Field draws (the error, or else the hint), none when it draws neither. */
6
+ describedBy: string | undefined;
7
+ /** `true` when the Field shows an error. */
8
+ invalid: boolean;
9
+ };
10
+ export declare const FieldContext: import("react").Context<FieldControlContext | undefined>;
11
+ type ControlA11y = {
12
+ id?: string | undefined;
13
+ "aria-describedby"?: string | undefined;
14
+ "aria-invalid"?: boolean | "true" | "false" | "grammar" | "spelling" | undefined;
15
+ };
16
+ /**
17
+ * Merges the enclosing `Field`'s id, note and invalid state into a control's own props. Inside a
18
+ * `Field` the id is the Field's, so its label always names the control; the caller's
19
+ * `aria-describedby` comes first and the Field's note after it; the caller's `aria-invalid` wins.
20
+ * Outside a `Field` it returns the props unchanged.
21
+ */
22
+ export declare function useFieldControl(own: ControlA11y): ControlA11y;
23
+ export {};
@@ -0,0 +1,24 @@
1
+ import { createContext, useContext } from "react";
2
+ export const FieldContext = createContext(undefined);
3
+ /**
4
+ * Merges the enclosing `Field`'s id, note and invalid state into a control's own props. Inside a
5
+ * `Field` the id is the Field's, so its label always names the control; the caller's
6
+ * `aria-describedby` comes first and the Field's note after it; the caller's `aria-invalid` wins.
7
+ * Outside a `Field` it returns the props unchanged.
8
+ */
9
+ export function useFieldControl(own) {
10
+ const field = useContext(FieldContext);
11
+ if (field === undefined) {
12
+ return {
13
+ id: own.id,
14
+ "aria-describedby": own["aria-describedby"],
15
+ "aria-invalid": own["aria-invalid"],
16
+ };
17
+ }
18
+ const describedBy = [own["aria-describedby"], field.describedBy].filter(Boolean).join(" ");
19
+ return {
20
+ id: field.id,
21
+ "aria-describedby": describedBy === "" ? undefined : describedBy,
22
+ "aria-invalid": own["aria-invalid"] ?? (field.invalid ? true : undefined),
23
+ };
24
+ }