@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,25 @@
1
+ import type { ReactElement, ReactNode } from "react";
2
+ import type { Passthrough } from "./props.js";
3
+ /**
4
+ * One framed example: the rendered `children` on top and the `code` that makes them attached
5
+ * underneath, in a single bordered box with one divider between. With `copy`, a copy
6
+ * button beside the code copies it exactly as given (client JS; off by default). An optional `caption` is the frame's last band. The code is React, so
7
+ * it is coloured as TSX. The preview is its own height, never padded to match a neighbour, down to
8
+ * a shared minimum so two frames side by side start alike. A wide preview or a long line of code
9
+ * scrolls inside the frame, under a thin themed scrollbar, instead of widening the page or
10
+ * wrapping. Inside a `Prose` the preview stays on the app scale, so a demo looks as the component
11
+ * does anywhere else; the caption is outside it.
12
+ */
13
+ export declare function CodeExample({ code, caption, copy, children, ...rest }: {
14
+ /** The source shown under the preview, newlines kept. */
15
+ code: string;
16
+ /** One note on the example, under the code. */
17
+ caption?: ReactNode;
18
+ /**
19
+ * A copy button beside the code. On a page rendered to static HTML without hydration, inline
20
+ * `copyScript` and it works there too.
21
+ * @default false
22
+ */
23
+ copy?: boolean;
24
+ children: ReactNode;
25
+ } & Passthrough): ReactElement;
@@ -0,0 +1,17 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { CodeBody } from "./CodeBody.js";
3
+ import { themedScrollbar } from "./cx.js";
4
+ import { AppScale } from "./typography.js";
5
+ /**
6
+ * One framed example: the rendered `children` on top and the `code` that makes them attached
7
+ * underneath, in a single bordered box with one divider between. With `copy`, a copy
8
+ * button beside the code copies it exactly as given (client JS; off by default). An optional `caption` is the frame's last band. The code is React, so
9
+ * it is coloured as TSX. The preview is its own height, never padded to match a neighbour, down to
10
+ * a shared minimum so two frames side by side start alike. A wide preview or a long line of code
11
+ * scrolls inside the frame, under a thin themed scrollbar, instead of widening the page or
12
+ * wrapping. Inside a `Prose` the preview stays on the app scale, so a demo looks as the component
13
+ * does anywhere else; the caption is outside it.
14
+ */
15
+ export function CodeExample({ code, caption, copy = false, children, ...rest }) {
16
+ return (_jsxs("figure", { ...rest, className: "overflow-hidden rounded-lg border border-slate-200 bg-white", children: [_jsx("div", { className: `min-h-24 overflow-x-auto p-5 ${themedScrollbar}`, children: _jsx("div", { className: "text-slate-900", children: _jsx(AppScale, { children: children }) }) }), _jsx("div", { className: "border-t border-slate-200 bg-slate-50", children: _jsx(CodeBody, { code: code, language: "tsx", wrap: false, copy: copy }) }), caption && (_jsx("figcaption", { className: "border-t border-slate-200 px-3 py-2.5 text-sm/5 text-slate-500", children: caption }))] }));
17
+ }
@@ -0,0 +1,11 @@
1
+ import type { ReactElement } from "react";
2
+ import { type CodeLanguage } from "./highlight.js";
3
+ /**
4
+ * The `<code>` for a `<pre>`: the source in mono, one span per coloured run. With `breakAtSpaces` a
5
+ * long line may break only at whitespace (see `wholeWords` above).
6
+ */
7
+ export declare function CodeText({ code, language, breakAtSpaces, }: {
8
+ code: string;
9
+ language: CodeLanguage;
10
+ breakAtSpaces?: boolean;
11
+ }): ReactElement;
@@ -0,0 +1,64 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { highlight } from "./highlight.js";
3
+ /**
4
+ * Each kind borrows a colour family already in `palette.json`, so a theme recolours code like
5
+ * anything else: keywords and element names read as the accent, strings as positive
6
+ * (emerald), numbers as warn (amber), attribute names as sky, calls as info (blue), comments muted.
7
+ * The `$ ` prompt of a console block is dimmer still and `select-none`, so selecting a command by
8
+ * hand does not pick it up.
9
+ */
10
+ const TOKEN_CLASS = {
11
+ plain: "",
12
+ comment: "text-slate-500 italic",
13
+ keyword: "text-violet-700",
14
+ tag: "text-red-700",
15
+ attr: "text-sky-700",
16
+ string: "text-emerald-700",
17
+ number: "text-amber-700",
18
+ function: "text-blue-700",
19
+ prompt: "text-slate-400 select-none",
20
+ };
21
+ /** One coloured run: bare text for plain, a span with the kind's palette utility otherwise. */
22
+ const colour = (kind, key, text) => kind === "plain" ? (text) : (_jsx("span", { className: TOKEN_CLASS[kind], children: text }, key));
23
+ /**
24
+ * The tokens regrouped into whitespace-separated words, each word one atomic inline box, with the
25
+ * whitespace between them left as text. A browser may break a line after a hyphen (`--skip` splits
26
+ * into `-` and `-skip`), but never inside an inline box, so a flag or a word stays whole. The box
27
+ * is capped at the line's width, so a word wider than the line still breaks inside itself instead
28
+ * of clipping. The characters are untouched: no joiner or non-breaking hyphen is swapped in, so
29
+ * selecting and copying gives the source.
30
+ */
31
+ function wholeWords(code, language) {
32
+ const out = [];
33
+ let word = [];
34
+ const flush = () => {
35
+ if (word.length > 0) {
36
+ out.push(_jsx("span", { className: "inline-block max-w-full align-top", children: word }, `w${out.length}`));
37
+ word = [];
38
+ }
39
+ };
40
+ for (const token of highlight(code, language)) {
41
+ for (const piece of token.text.split(/(\s+)/)) {
42
+ if (piece === "")
43
+ continue;
44
+ if (/^\s/.test(piece)) {
45
+ flush();
46
+ out.push(colour(token.kind, out.length, piece));
47
+ }
48
+ else {
49
+ word.push(colour(token.kind, word.length, piece));
50
+ }
51
+ }
52
+ }
53
+ flush();
54
+ return out;
55
+ }
56
+ /**
57
+ * The `<code>` for a `<pre>`: the source in mono, one span per coloured run. With `breakAtSpaces` a
58
+ * long line may break only at whitespace (see `wholeWords` above).
59
+ */
60
+ export function CodeText({ code, language, breakAtSpaces = false, }) {
61
+ return (_jsx("code", { children: breakAtSpaces
62
+ ? wholeWords(code, language)
63
+ : highlight(code, language).map((token, index) => colour(token.kind, index, token.text)) }));
64
+ }
@@ -0,0 +1,36 @@
1
+ import { type ComponentPropsWithoutRef, type ReactElement } from "react";
2
+ import { type ColourScheme, type ColourSchemeClasses } from "./colourScheme.js";
3
+ import type { Unstyled } from "./props.js";
4
+ import type { Size } from "./size.js";
5
+ /**
6
+ * A sun/moon button that switches `<html>` between light and dark and remembers the choice. It shows the scheme you would switch to. Pair it with `colourSchemeScript` in `<head>`, unless you pass `schemes` or `defaultValue`: the script knows only the `dark` class and the stored choice, so an app that sets the scheme itself leaves it out.
7
+ *
8
+ * An app whose light scheme has a class of its own passes `schemes` (`{ light: "my-light", dark: "dark" }`);
9
+ * the toggle swaps those classes, and `schemeClass` gives the same one for the server to render on `<html>`.
10
+ * An app that knows the scheme on the server (from a cookie) passes it as `defaultValue`, so the server
11
+ * markup, the hydrating client and the `<html>` class agree; persist a change from `onChange`.
12
+ * The icon and the button's accessible name follow the class on `<html>` through CSS (the name is
13
+ * two visually hidden "Switch to …" spans, one hidden by `display:none`), so even without `defaultValue`
14
+ * a dark page shows the sun and is named "Switch to light theme" from the first frame, with no
15
+ * script. Only the tooltip catches up once the client has hydrated.
16
+ * `store={false}` skips `localStorage`, for an app that keeps the choice in a server cookie and
17
+ * writes it from `onChange`. Every other button prop (`id`, `data-*`, `aria-*`) goes on the button.
18
+ */
19
+ export declare function ColourSchemeToggle({ onChange, schemes, defaultValue, store, size, ...rest }: {
20
+ /**
21
+ * The button's height, as an `IconButton`'s.
22
+ * @default md
23
+ */
24
+ size?: Size | undefined;
25
+ /** Called with the new scheme after a click, for an app that persists the choice itself (a cookie). */
26
+ onChange?: (scheme: ColourScheme) => void;
27
+ /** The class each scheme puts on `<html>`. */
28
+ schemes?: ColourSchemeClasses | undefined;
29
+ /**
30
+ * The scheme the server rendered. What the server and the hydrating client show; the real state follows right after.
31
+ * @default light
32
+ */
33
+ defaultValue?: ColourScheme | undefined;
34
+ /** Remember the choice in `localStorage`. `false` leaves persisting to `onChange`. */
35
+ store?: boolean | undefined;
36
+ } & Unstyled<Omit<ComponentPropsWithoutRef<"button">, "onChange" | "onClick" | "children" | "aria-label" | "title">>): ReactElement;
@@ -0,0 +1,64 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useSyncExternalStore } from "react";
3
+ import { appliedColourScheme, applyColourScheme, storeColourScheme, } from "./colourScheme.js";
4
+ import { look } from "./IconButton.js";
5
+ import { Tipped } from "./Tooltip.js";
6
+ const sun = (_jsxs("svg", { "data-scheme-icon": "sun", viewBox: "0 0 24 24", className: "h-4 w-4", fill: "none", stroke: "currentColor", strokeWidth: "1.8", strokeLinecap: "round", "aria-hidden": "true", children: [_jsx("circle", { cx: "12", cy: "12", r: "4" }), _jsx("path", { d: "M12 2v2M12 20v2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M2 12h2M20 12h2M4.9 19.1l1.4-1.4M17.7 6.3l1.4-1.4" })] }));
7
+ const moon = (_jsx("svg", { "data-scheme-icon": "moon", viewBox: "0 0 24 24", className: "h-4 w-4", fill: "none", stroke: "currentColor", strokeWidth: "1.8", strokeLinecap: "round", "aria-hidden": "true", children: _jsx("path", { d: "M21 12.8A9 9 0 1 1 11.2 3a7 7 0 0 0 9.8 9.8Z" }) }));
8
+ // Both icons are always drawn and the page's own class picks one, so the first frame is right before
9
+ // React runs: a dark visitor with no cookie has the dark class on <html> from the head script, but the
10
+ // server rendered "light". The icon shows the scheme you would switch to: the moon on a light page,
11
+ // the sun on a dark one. The button's name is picked the same way: both "Switch to … theme" spans are
12
+ // always drawn and `display:none` takes the wrong one out of the accessible name too. The classes are
13
+ // the app's (`schemes`), so the rule is written here: a dark page has the dark class, or, when dark
14
+ // has none, lacks the light one.
15
+ function schemeRules(schemes) {
16
+ const sunIcon = '[data-scheme-icon="sun"]';
17
+ const moonIcon = '[data-scheme-icon="moon"]';
18
+ const toLight = '[data-scheme-name="light"]';
19
+ const toDark = '[data-scheme-name="dark"]';
20
+ let dark = "";
21
+ if (schemes.dark !== "")
22
+ dark = `:root[class~=${JSON.stringify(schemes.dark)}]`;
23
+ else if (schemes.light !== "")
24
+ dark = `:root:not([class~=${JSON.stringify(schemes.light)}])`;
25
+ return (`${sunIcon}{display:none}${toLight}{display:none}` +
26
+ (dark === ""
27
+ ? ""
28
+ : `${dark} ${sunIcon}{display:inline}${dark} ${moonIcon}{display:none}` +
29
+ `${dark} ${toLight}{display:inline}${dark} ${toDark}{display:none}`));
30
+ }
31
+ // The scheme's class on <html> is the source of truth: the head script or the server set it before React ran.
32
+ function subscribe(onChange) {
33
+ const observer = new MutationObserver(onChange);
34
+ observer.observe(document.documentElement, { attributes: true, attributeFilter: ["class"] });
35
+ return () => observer.disconnect();
36
+ }
37
+ // False in the server markup and while the client hydrates, true after: `title` is the one thing CSS
38
+ // cannot choose, so it is rendered only once the client knows the scheme.
39
+ const never = () => () => { };
40
+ /**
41
+ * A sun/moon button that switches `<html>` between light and dark and remembers the choice. It shows the scheme you would switch to. Pair it with `colourSchemeScript` in `<head>`, unless you pass `schemes` or `defaultValue`: the script knows only the `dark` class and the stored choice, so an app that sets the scheme itself leaves it out.
42
+ *
43
+ * An app whose light scheme has a class of its own passes `schemes` (`{ light: "my-light", dark: "dark" }`);
44
+ * the toggle swaps those classes, and `schemeClass` gives the same one for the server to render on `<html>`.
45
+ * An app that knows the scheme on the server (from a cookie) passes it as `defaultValue`, so the server
46
+ * markup, the hydrating client and the `<html>` class agree; persist a change from `onChange`.
47
+ * The icon and the button's accessible name follow the class on `<html>` through CSS (the name is
48
+ * two visually hidden "Switch to …" spans, one hidden by `display:none`), so even without `defaultValue`
49
+ * a dark page shows the sun and is named "Switch to light theme" from the first frame, with no
50
+ * script. Only the tooltip catches up once the client has hydrated.
51
+ * `store={false}` skips `localStorage`, for an app that keeps the choice in a server cookie and
52
+ * writes it from `onChange`. Every other button prop (`id`, `data-*`, `aria-*`) goes on the button.
53
+ */
54
+ export function ColourSchemeToggle({ onChange, schemes = { light: "", dark: "dark" }, defaultValue, store = true, size = "md", ...rest }) {
55
+ const scheme = useSyncExternalStore(subscribe, () => appliedColourScheme(document.documentElement, schemes), () => defaultValue ?? "light");
56
+ const hydrated = useSyncExternalStore(never, () => true, () => false);
57
+ const next = scheme === "dark" ? "light" : "dark";
58
+ return (_jsx(Tipped, { text: hydrated ? `Switch to ${next} theme` : undefined, describes: false, own: rest, children: (tip) => (_jsxs("button", { type: "button", ...rest, ...tip, className: look({ size }), onClick: () => {
59
+ applyColourScheme(next, document.documentElement, schemes);
60
+ if (store)
61
+ storeColourScheme(next);
62
+ onChange?.(next);
63
+ }, children: [_jsx("style", { children: schemeRules(schemes) }), sun, moon, _jsx("span", { className: "sr-only", "data-scheme-name": "dark", children: "Switch to dark theme" }), _jsx("span", { className: "sr-only", "data-scheme-name": "light", children: "Switch to light theme" })] })) }));
64
+ }
@@ -0,0 +1,22 @@
1
+ import { type HTMLAttributes, type ReactElement, type ReactNode, type Ref } from "react";
2
+ import type { Unstyled } from "./props.js";
3
+ /**
4
+ * The one content edge: every page's width and side padding. This file is the only place they are
5
+ * defined, so a header, a page and a footer inside a Container start at the same x.
6
+ */
7
+ export declare function Container({ as, ref, children, ...rest }: ContainerProps): ReactElement;
8
+ type ContainerProps = {
9
+ /**
10
+ * The element: `div`, `main`, `header`, `footer`, `section` or `nav`.
11
+ * @default div
12
+ */
13
+ as?: "div" | "main" | "header" | "footer" | "section" | "nav";
14
+ /** Reaches the rendered element, for a parent that measures or scrolls it. */
15
+ ref?: Ref<HTMLElement> | undefined;
16
+ children?: ReactNode;
17
+ } & Unstyled<Omit<HTMLAttributes<HTMLElement>, "children">>;
18
+ /** Container with the extra classes its own parts need (AppShell's padding): internal, not exported. */
19
+ export declare function ContainerFrame({ as: Tag, className, ref, children, ...rest }: ContainerProps & {
20
+ className?: string;
21
+ }): ReactElement;
22
+ export {};
@@ -0,0 +1,26 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useCallback, } from "react";
3
+ import { cx } from "./cx.js";
4
+ /**
5
+ * The one content edge: every page's width and side padding. This file is the only place they are
6
+ * defined, so a header, a page and a footer inside a Container start at the same x.
7
+ */
8
+ export function Container({ as, ref, children, ...rest }) {
9
+ return (_jsx(ContainerFrame, { ...rest, ...(as && { as }), ref: ref, children: children }));
10
+ }
11
+ // The one content edge: px-4 (px-6 from `sm`), or the safe-area inset where a notch or a rounded
12
+ // corner is wider (an app with `viewport-fit=cover`; the inset is 0 in an ordinary tab).
13
+ const SIDES = "mx-auto w-full max-w-6xl pl-[max(1rem,env(safe-area-inset-left))] pr-[max(1rem,env(safe-area-inset-right))] sm:pl-[max(1.5rem,env(safe-area-inset-left))] sm:pr-[max(1.5rem,env(safe-area-inset-right))]";
14
+ /** Container with the extra classes its own parts need (AppShell's padding): internal, not exported. */
15
+ export function ContainerFrame({ as: Tag = "div", className, ref, children, ...rest }) {
16
+ // The tag varies, so the element is handed over by a callback that takes any HTMLElement; a
17
+ // callback ref's cleanup is handed back to React.
18
+ const attach = useCallback((element) => {
19
+ if (typeof ref === "function")
20
+ return ref(element);
21
+ if (ref)
22
+ ref.current = element;
23
+ return undefined;
24
+ }, [ref]);
25
+ return (_jsx(Tag, { ...rest, ref: attach, className: cx(SIDES, className), children: children }));
26
+ }
@@ -0,0 +1,17 @@
1
+ import { type ComponentPropsWithoutRef, type ReactElement } from "react";
2
+ import type { Unstyled } from "./props.js";
3
+ /** Writes `text` to the clipboard and shows `copiedLabel` for two seconds, then `label` again. Defaults to `type="button"`. Its accessible name stays `label`; a polite status region beside it announces `copiedLabel` on each copy. A refused or missing clipboard leaves it on `label`. Every other button prop, `disabled` included, goes on the `<button>`. On a page rendered to static HTML without hydration, inline `copyScript` and the button works there too. */
4
+ export declare function CopyButton({ text, label, copiedLabel, onClick, ...rest }: {
5
+ /** What goes on the clipboard. */
6
+ text: string;
7
+ /**
8
+ * The button's text, and its accessible name.
9
+ * @default Copy
10
+ */
11
+ label?: string;
12
+ /**
13
+ * The text shown for two seconds once the copy has gone through, and announced.
14
+ * @default Copied
15
+ */
16
+ copiedLabel?: string;
17
+ } & Unstyled<Omit<ComponentPropsWithoutRef<"button">, "children">>): ReactElement;
@@ -0,0 +1,39 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useRef, useState, } from "react";
3
+ import { focusRing } from "./cx.js";
4
+ const BASE = `shrink-0 rounded px-1.5 py-0.5 font-sans text-xs text-slate-400 hover:bg-slate-100 disabled:pointer-events-none disabled:opacity-50 ${focusRing}`;
5
+ /** Both labels share one grid cell, centred, so the button is as wide as the longer and never resizes. */
6
+ const CELL = "col-start-1 row-start-1";
7
+ // The copied state is CSS, not a timer: a copy sets `data-copied` on the button, and for two seconds
8
+ // an animation hides `label` and shows `copiedLabel`; when it ends, the resting styles are back.
9
+ // `visibility` is discrete, so each keyframe holds one value for the whole run. A second copy starts
10
+ // the run again: React remounts both labels, `copyScript` re-sets the attribute after a reflow. The
11
+ // run's own end clears `data-copied`, so a button hidden and shown again later does not replay it.
12
+ const css = `[data-copied] [data-copy-idle]{animation:hc-copy-idle 2s}[data-copied] [data-copy-done]{animation:hc-copy-done 2s}@keyframes hc-copy-idle{from,to{visibility:hidden}}@keyframes hc-copy-done{from,to{visibility:visible}}`;
13
+ /** Writes `text` to the clipboard and shows `copiedLabel` for two seconds, then `label` again. Defaults to `type="button"`. Its accessible name stays `label`; a polite status region beside it announces `copiedLabel` on each copy. A refused or missing clipboard leaves it on `label`. Every other button prop, `disabled` included, goes on the `<button>`. On a page rendered to static HTML without hydration, inline `copyScript` and the button works there too. */
14
+ export function CopyButton({ text, label = "Copy", copiedLabel = "Copied", onClick, ...rest }) {
15
+ /** How many copies went through: the key that restarts the labels. */
16
+ const [copies, setCopies] = useState(0);
17
+ /** Set by a copy, cleared when the copied label's animation ends. */
18
+ const [copied, setCopied] = useState(false);
19
+ const status = useRef(null);
20
+ return (_jsxs(_Fragment, { children: [_jsx("style", { children: css }), _jsx("button", { type: "button", "aria-label": label, ...rest, "data-copy-text": text, "data-copy-copied": copiedLabel, "data-copied": copied ? "" : undefined,
21
+ // `copyScript` may have set `data-copied` before this button hydrated; React leaves it be.
22
+ suppressHydrationWarning: true, className: BASE, onClick: (event) => {
23
+ onClick?.(event);
24
+ // `copyScript` hears this same click on `document`. Whichever of the two runs first copies
25
+ // and flags the event, so the other skips it.
26
+ const native = event.nativeEvent;
27
+ if (native.copyHandled)
28
+ return;
29
+ native.copyHandled = true;
30
+ // The rejection is swallowed on purpose: a denied write is not an error the page can act on.
31
+ navigator.clipboard?.writeText(text).then(() => {
32
+ setCopies((n) => n + 1);
33
+ setCopied(true);
34
+ // A new text node each time, so a second copy is announced too. Set here, not
35
+ // rendered, as `copyScript` does, so a region it filled before hydration still matches.
36
+ status.current?.replaceChildren(copiedLabel);
37
+ }, () => { });
38
+ }, children: _jsxs("span", { className: "grid justify-items-center", onAnimationEnd: () => setCopied(false), children: [_jsx("span", { "data-copy-idle": "", className: CELL, children: label }), _jsx("span", { "data-copy-done": "", "aria-hidden": "true", className: `invisible ${CELL}`, children: copiedLabel })] }, copies) }), _jsx("span", { ref: status, role: "status", "data-copy-status": "", className: "sr-only", suppressHydrationWarning: true, children: "" })] }));
39
+ }
@@ -0,0 +1,9 @@
1
+ import type { ReactElement } from "react";
2
+ import type { Passthrough } from "./props.js";
3
+ /** One line of mono text in a box, with a `CopyButton`: a command or a token to paste elsewhere. `disabled` disables the button, e.g. until hydration. An `id`, `data-*` and `aria-*` go on the root `<div>`, so `data-testid` lands there; the `<code>` holds only `text`. */
4
+ export declare function CopyLine({ text, disabled, ...rest }: {
5
+ /** The line shown, and what the button copies. */
6
+ text: string;
7
+ /** Disables the copy button, e.g. until hydration. */
8
+ disabled?: boolean;
9
+ } & Passthrough): ReactElement;
@@ -0,0 +1,7 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { CopyButton } from "./CopyButton.js";
3
+ const BOX = "flex items-center justify-between gap-3 rounded-lg border border-slate-200 bg-white px-2.5 py-2 font-mono text-[12.5px] leading-normal text-slate-900";
4
+ /** One line of mono text in a box, with a `CopyButton`: a command or a token to paste elsewhere. `disabled` disables the button, e.g. until hydration. An `id`, `data-*` and `aria-*` go on the root `<div>`, so `data-testid` lands there; the `<code>` holds only `text`. */
5
+ export function CopyLine({ text, disabled, ...rest }) {
6
+ return (_jsxs("div", { ...rest, className: BOX, children: [_jsx("code", { className: "min-w-0 break-words", children: text }), _jsx(CopyButton, { text: text, disabled: disabled })] }));
7
+ }
@@ -0,0 +1,23 @@
1
+ import { type ReactElement } from "react";
2
+ import type { DateRangePreset } from "./DateRangePicker.js";
3
+ export declare const calendarIcon: import("react").JSX.Element;
4
+ /**
5
+ * ‹, a month dropdown, a year dropdown and ›: a birth date decades back is two picks away. It reads
6
+ * a one-date calendar's state, or a range calendar's when there is none.
7
+ */
8
+ /** The names of the calendar's month and year dropdowns, for an app in another language. */
9
+ export type CalendarLabels = {
10
+ monthLabel: string;
11
+ yearLabel: string;
12
+ };
13
+ /** The date picker's popover: header, a Monday-first month grid and a Clear footer. */
14
+ export declare function CalendarPopover({ container, labels, }: {
15
+ container: Element | undefined;
16
+ labels: CalendarLabels;
17
+ }): ReactElement;
18
+ /** The range picker's popover: the presets, if any, the header, one Monday-first month and Clear. */
19
+ export declare function RangeCalendarPopover({ container, presets, labels, }: {
20
+ container: Element | undefined;
21
+ presets: readonly DateRangePreset[] | undefined;
22
+ labels: CalendarLabels;
23
+ }): ReactElement;
@@ -0,0 +1,89 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { getLocalTimeZone, today } from "@internationalized/date";
3
+ import { useContext } from "react";
4
+ import { Button, Calendar, CalendarCell, CalendarGrid, CalendarGridBody, CalendarGridHeader, CalendarHeaderCell, CalendarStateContext, DatePickerStateContext, DateRangePickerStateContext, Dialog, Popover, RangeCalendar, RangeCalendarStateContext, } from "react-aria-components";
5
+ import { cx, focusRing } from "./cx.js";
6
+ import { Button as PresetButton } from "./Button.js";
7
+ import { MONTH_OPTIONS, iconButtonClass } from "./DateField.js";
8
+ import { Icon } from "./Icon.js";
9
+ export const calendarIcon = (_jsx(Icon, { children: _jsxs("svg", { viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", strokeWidth: "1.6", strokeLinecap: "round", children: [_jsx("rect", { x: "3", y: "4.5", width: "14", height: "12.5", rx: "2" }), _jsx("path", { d: "M3 8.5h14M7 2.5v4M13 2.5v4" })] }) }));
10
+ const chevron = (d) => (_jsx(Icon, { children: _jsx("svg", { viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", strokeWidth: "1.8", strokeLinecap: "round", strokeLinejoin: "round", children: _jsx("path", { d: d }) }) }));
11
+ const selectClass = `rounded-md border border-slate-300 bg-white py-1 pr-1 pl-2 text-sm text-slate-900 pointer-coarse:text-base transition hover:border-violet-400 ${focusRing}`;
12
+ function CalendarHeader({ monthLabel, yearLabel }) {
13
+ const single = useContext(CalendarStateContext);
14
+ const range = useContext(RangeCalendarStateContext);
15
+ const state = single ?? range;
16
+ if (!state)
17
+ return null;
18
+ const focused = state.focusedDate;
19
+ const now = today(getLocalTimeZone()).year;
20
+ const first = Math.min(state.minValue?.year ?? now - 100, focused.year);
21
+ const last = Math.max(state.maxValue?.year ?? now + 10, focused.year);
22
+ const years = Array.from({ length: last - first + 1 }, (_, i) => first + i);
23
+ return (_jsxs("div", { className: "flex items-center gap-1.5", children: [_jsx(Button, { slot: "previous", className: iconButtonClass, children: chevron("M12.5 15l-5-5 5-5") }), _jsx("select", { "aria-label": monthLabel, className: cx(selectClass, "flex-1"), value: focused.month, disabled: state.isDisabled, onChange: (event) => state.setFocusedDate(focused.set({ month: Number(event.target.value) })), children: MONTH_OPTIONS.map(({ month, name }) => (_jsx("option", { value: month, children: name }, month))) }), _jsx("select", { "aria-label": yearLabel, className: selectClass, value: focused.year, disabled: state.isDisabled, onChange: (event) => state.setFocusedDate(focused.set({ year: Number(event.target.value) })), children: years.map((year) => (_jsx("option", { value: year, children: year }, year))) }), _jsx(Button, { slot: "next", className: iconButtonClass, children: chevron("M7.5 5l5 5-5 5") })] }));
24
+ }
25
+ /** Clears the picker's value, a date or a range, and closes the popover. */
26
+ function ClearButton() {
27
+ const single = useContext(DatePickerStateContext);
28
+ const range = useContext(DateRangePickerStateContext);
29
+ const picker = single ?? range;
30
+ return (_jsx("button", { type: "button", className: `rounded-md px-2 py-1 text-sm font-medium text-violet-600 transition hover:bg-violet-50 ${focusRing}`, onClick: () => {
31
+ picker?.setValue(null);
32
+ picker?.close();
33
+ }, children: "Clear" }));
34
+ }
35
+ const cellClass = ({ isSelected, isOutsideMonth, isDisabled, isUnavailable, isInvalid, }) => {
36
+ let tone = "cursor-pointer text-slate-700 hover:bg-slate-100";
37
+ if (isSelected)
38
+ tone = isInvalid ? "bg-red-50 text-red-700" : "bg-violet-600 text-violet-50";
39
+ else if (isOutsideMonth || isDisabled || isUnavailable)
40
+ tone = "text-slate-300";
41
+ return cx("flex h-9 w-9 items-center justify-center rounded-lg text-sm tabular-nums", tone, focusRing);
42
+ };
43
+ /** The colour of a day in a range calendar: the ends filled, the days between a light band. */
44
+ function rangeTone(cell) {
45
+ if (cell.isOutsideMonth || cell.isDisabled || cell.isUnavailable)
46
+ return "text-slate-300";
47
+ if (!cell.isSelected)
48
+ return "cursor-pointer text-slate-700 hover:bg-slate-100";
49
+ if (cell.isInvalid)
50
+ return "bg-red-50 text-red-700";
51
+ if (cell.isSelectionStart || cell.isSelectionEnd)
52
+ return "bg-violet-600 text-violet-50";
53
+ return "bg-violet-50 text-violet-700";
54
+ }
55
+ /**
56
+ * A day in a range calendar. The selected days join into one band: square between the ends, rounded
57
+ * on the outer side of each end. Any other day is rounded like a `cellClass` day.
58
+ */
59
+ const rangeCellClass = (cell) => cx("flex h-9 w-9 items-center justify-center text-sm tabular-nums", rangeTone(cell), cell.isSelected && !cell.isOutsideMonth
60
+ ? cx(cell.isSelectionStart && "rounded-l-lg", cell.isSelectionEnd && "rounded-r-lg")
61
+ : "rounded-lg", focusRing);
62
+ /** The weekday row and the days of the month on show, in a `Calendar` or a `RangeCalendar`. */
63
+ function MonthGrid({ cellClass: dayClass, }) {
64
+ return (_jsxs(CalendarGrid, { weekdayStyle: "short", children: [_jsx(CalendarGridHeader, { children: (day) => (_jsx(CalendarHeaderCell, { className: "pb-1 text-xs font-medium text-slate-500", children: day })) }), _jsx(CalendarGridBody, { children: (date) => _jsx(CalendarCell, { date: date, className: dayClass }) })] }));
65
+ }
66
+ /**
67
+ * The popover's frame and dialog. `container` is the modal `<dialog>` the picker sits in, if any: a
68
+ * modal makes everything outside it inert and paints above the body, so the popover renders inside
69
+ * it (which also keeps the theme's scope class).
70
+ */
71
+ function PickerPopover({ container, children, }) {
72
+ return (_jsx(Popover, { ...(container ? { UNSTABLE_portalContainer: container } : {}), placement: "bottom start", className: "rounded-xl border border-slate-200 bg-white p-3 text-slate-900 shadow-lg", children: _jsxs(Dialog, { className: "flex flex-col gap-3 outline-none", children: [children, _jsx("div", { className: "flex justify-end border-t border-slate-200 pt-2", children: _jsx(ClearButton, {}) })] }) }));
73
+ }
74
+ /** The date picker's popover: header, a Monday-first month grid and a Clear footer. */
75
+ export function CalendarPopover({ container, labels, }) {
76
+ return (_jsx(PickerPopover, { container: container, children: _jsxs(Calendar, { firstDayOfWeek: "mon", className: "flex flex-col gap-3", children: [_jsx(CalendarHeader, { ...labels }), _jsx(MonthGrid, { cellClass: cellClass })] }) }));
77
+ }
78
+ /** A preset's button: sets the range, which reports it, and closes the popover. */
79
+ function PresetRow({ presets }) {
80
+ const picker = useContext(DateRangePickerStateContext);
81
+ return (_jsx("div", { className: "flex w-0 min-w-full flex-wrap gap-1.5", children: presets.map((preset) => (_jsx(PresetButton, { variant: "outline", size: "sm", onClick: () => {
82
+ picker?.setValue(preset.value);
83
+ picker?.close();
84
+ }, children: preset.label }, preset.label))) }));
85
+ }
86
+ /** The range picker's popover: the presets, if any, the header, one Monday-first month and Clear. */
87
+ export function RangeCalendarPopover({ container, presets, labels, }) {
88
+ return (_jsxs(PickerPopover, { container: container, children: [presets && presets.length > 0 ? _jsx(PresetRow, { presets: presets }) : null, _jsxs(RangeCalendar, { firstDayOfWeek: "mon", className: "flex flex-col gap-3", children: [_jsx(CalendarHeader, { ...labels }), _jsx(MonthGrid, { cellClass: rangeCellClass })] })] }));
89
+ }
@@ -0,0 +1,124 @@
1
+ import { type CalendarDate } from "@internationalized/date";
2
+ import { type ContextType, type ReactElement, type ReactNode } from "react";
3
+ import { type DateFieldProps as AriaDateFieldProps, DateFieldStateContext } from "react-aria-components";
4
+ import { type Passthrough } from "./props.js";
5
+ import { type LoadingProps } from "./skeleton.js";
6
+ import type { Size } from "./size.js";
7
+ /** Fixed, whatever the browser's locale: DD/MM/YYYY and Monday-first weeks. */
8
+ export declare const LOCALE = "en-GB";
9
+ export declare const MONTH_OPTIONS: {
10
+ month: number;
11
+ name: string;
12
+ }[];
13
+ type Segment = NonNullable<ContextType<typeof DateFieldStateContext>>["segments"][number];
14
+ /** The props of a plain `DateField`, without the calendar. */
15
+ export type FieldProps = {
16
+ /** The field's visible label, above it. Without one, name the field with `aria-label`. */
17
+ label?: ReactNode;
18
+ /** A muted line under the field that says more; an error replaces it. */
19
+ hint?: ReactNode;
20
+ /**
21
+ * Marks the field invalid and shows this in red with `role="alert"`, in place of the hint and of
22
+ * the built-in message (an impossible date, or one outside min/max). Like `Field`'s `error`.
23
+ */
24
+ error?: ReactNode;
25
+ /**
26
+ * The field's height and text, on the same scale as an `Input`: `sm` is `text-sm`, `md` `text-base`,
27
+ * `lg` `text-lg`, one step down under an `AppShell density="compact"`, and never under 16px on touch.
28
+ * @default md
29
+ */
30
+ size?: Size;
31
+ /** Disables the field: no typing, no calendar. */
32
+ disabled?: boolean | undefined;
33
+ /** Marks a date required: the field is `aria-required`, and an empty one is invalid. */
34
+ required?: boolean | undefined;
35
+ /** The date shown, controlled, with `onChange`; `null` is an empty field. */
36
+ value?: AriaDateFieldProps<CalendarDate>["value"];
37
+ /** The date it starts with, uncontrolled. */
38
+ defaultValue?: AriaDateFieldProps<CalendarDate>["defaultValue"];
39
+ /** Called with the new date, or `null` when the field is cleared or the date is incomplete. */
40
+ onChange?: AriaDateFieldProps<CalendarDate>["onChange"];
41
+ /** The earliest date allowed: an earlier one marks the field invalid with its own message. */
42
+ minValue?: AriaDateFieldProps<CalendarDate>["minValue"];
43
+ /** The latest date allowed: a later one marks the field invalid with its own message. */
44
+ maxValue?: AriaDateFieldProps<CalendarDate>["maxValue"];
45
+ /** Posts the date in a form as `YYYY-MM-DD` under this key, or an empty string. */
46
+ name?: AriaDateFieldProps<CalendarDate>["name"];
47
+ } & Passthrough;
48
+ /** The calendar's dropdown names, with their English defaults. */
49
+ type CalendarNames = {
50
+ /**
51
+ * The month dropdown's name, for an app in another language.
52
+ * @default Month
53
+ */
54
+ monthLabel?: string | undefined;
55
+ /**
56
+ * The year dropdown's name, for an app in another language.
57
+ * @default Year
58
+ */
59
+ yearLabel?: string | undefined;
60
+ };
61
+ export type DateFieldProps = FieldProps & LoadingProps & ({
62
+ /** Adds a calendar button that opens a month view in a popover; the field is a date picker. */
63
+ calendar?: false | undefined;
64
+ /** Only a `calendar` field takes `defaultOpen`. */
65
+ defaultOpen?: undefined;
66
+ /** Only a `calendar` field takes `monthLabel`. */
67
+ monthLabel?: undefined;
68
+ /** Only a `calendar` field takes `yearLabel`. */
69
+ yearLabel?: undefined;
70
+ } | ({
71
+ calendar: true;
72
+ /** Open the calendar on mount. */
73
+ defaultOpen?: boolean | undefined;
74
+ } & CalendarNames));
75
+ /** The react-aria flags for `disabled` and `required`, set only when true. */
76
+ export declare function fieldFlags(disabled: boolean | undefined, required: boolean | undefined): {
77
+ isDisabled?: true;
78
+ isRequired?: true;
79
+ };
80
+ /** What the segments show, as the day segment reports it to the field. */
81
+ export type Read = {
82
+ /** The date as `YYYY-MM-DD` once every segment is filled and the day exists, else `""`. */
83
+ typed: string;
84
+ /** "February 1990 has 28 days." when the day does not exist. */
85
+ impossible: string | null;
86
+ /** Some segments are filled and some are not. */
87
+ partial: boolean;
88
+ };
89
+ /** One segment. The day segment also reports what the segments show to the field. */
90
+ export declare function FieldSegment({ segment, onRead, }: {
91
+ segment: Segment;
92
+ onRead?: (read: Read) => void;
93
+ }): ReactElement;
94
+ export declare function frameClass({ isInvalid, isFocusWithin, isDisabled, }: {
95
+ isInvalid: boolean;
96
+ isFocusWithin: boolean;
97
+ isDisabled: boolean;
98
+ }): string;
99
+ /** The props that force a field invalid: an impossible date, or an `error` from outside. Spread onto the React Aria field after the rest. */
100
+ export declare function forcedInvalid({ impossible, error, }: {
101
+ impossible: string | null;
102
+ error: ReactNode;
103
+ }): {
104
+ isInvalid?: true;
105
+ };
106
+ /** The hint or the error line: the shared outside of every date field. */
107
+ export declare function Notes({ hint, error, impossible, isInvalid, }: {
108
+ hint: ReactNode;
109
+ error: ReactNode;
110
+ impossible: string | null;
111
+ isInvalid: boolean;
112
+ }): ReactElement;
113
+ export declare const labelClass = "text-sm font-medium text-slate-700";
114
+ /** A small icon button inside a date field or calendar, without its box size. */
115
+ export declare const iconButtonLook = "inline-flex shrink-0 items-center justify-center rounded-md text-slate-500 transition hover:bg-slate-100 disabled:opacity-50 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-violet-600";
116
+ export declare const iconButtonClass = "inline-flex shrink-0 items-center justify-center rounded-md text-slate-500 transition hover:bg-slate-100 disabled:opacity-50 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-violet-600 h-7 w-7";
117
+ /**
118
+ * A segmented DD / MM / YYYY date input. Values are `CalendarDate`s; `name` posts it as
119
+ * `YYYY-MM-DD`. `calendar` adds a calendar button that opens a month view in a popover, at the
120
+ * same height as the plain field; `defaultOpen` opens it on mount. While `loading` the label is
121
+ * drawn and the field is a bone of its height.
122
+ */
123
+ export declare function DateField({ calendar, defaultOpen, monthLabel, yearLabel, loading, loadingLabel, ...field }: DateFieldProps): ReactElement;
124
+ export {};