@slashsuite/ui-react 0.0.0-stage → 0.11.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (304) hide show
  1. package/LICENSE +21 -0
  2. package/MIGRATING.md +540 -0
  3. package/README.md +548 -2
  4. package/dist/AppShell.d.ts +127 -0
  5. package/dist/AppShell.js +119 -0
  6. package/dist/AppShellMenu.d.ts +26 -0
  7. package/dist/AppShellMenu.js +66 -0
  8. package/dist/Avatar.d.ts +75 -0
  9. package/dist/Avatar.js +95 -0
  10. package/dist/AvatarStack.d.ts +31 -0
  11. package/dist/AvatarStack.js +34 -0
  12. package/dist/Badge.d.ts +15 -0
  13. package/dist/Badge.js +15 -0
  14. package/dist/BottomSheet.d.ts +36 -0
  15. package/dist/BottomSheet.js +142 -0
  16. package/dist/Breadcrumbs.d.ts +27 -0
  17. package/dist/Breadcrumbs.js +29 -0
  18. package/dist/BulletList.d.ts +18 -0
  19. package/dist/BulletList.js +18 -0
  20. package/dist/Button.d.ts +121 -0
  21. package/dist/Button.js +182 -0
  22. package/dist/ButtonGroup.d.ts +15 -0
  23. package/dist/ButtonGroup.js +10 -0
  24. package/dist/Callout.d.ts +43 -0
  25. package/dist/Callout.js +45 -0
  26. package/dist/Card.d.ts +148 -0
  27. package/dist/Card.js +171 -0
  28. package/dist/CardBadge.d.ts +7 -0
  29. package/dist/CardBadge.js +12 -0
  30. package/dist/CardBody.d.ts +28 -0
  31. package/dist/CardBody.js +30 -0
  32. package/dist/CardGrid.d.ts +53 -0
  33. package/dist/CardGrid.js +52 -0
  34. package/dist/CardParts.d.ts +40 -0
  35. package/dist/CardParts.js +41 -0
  36. package/dist/ChatComposer.d.ts +35 -0
  37. package/dist/ChatComposer.js +50 -0
  38. package/dist/ChatMessage.d.ts +26 -0
  39. package/dist/ChatMessage.js +21 -0
  40. package/dist/ChatThread.d.ts +25 -0
  41. package/dist/ChatThread.js +60 -0
  42. package/dist/Checkbox.d.ts +42 -0
  43. package/dist/Checkbox.js +63 -0
  44. package/dist/Chevron.d.ts +5 -0
  45. package/dist/Chevron.js +6 -0
  46. package/dist/Cluster.d.ts +70 -0
  47. package/dist/Cluster.js +47 -0
  48. package/dist/Code.d.ts +6 -0
  49. package/dist/Code.js +5 -0
  50. package/dist/CodeBlock.d.ts +46 -0
  51. package/dist/CodeBlock.js +21 -0
  52. package/dist/CodeBody.d.ts +20 -0
  53. package/dist/CodeBody.js +38 -0
  54. package/dist/CodeExample.d.ts +25 -0
  55. package/dist/CodeExample.js +17 -0
  56. package/dist/CodeText.d.ts +11 -0
  57. package/dist/CodeText.js +64 -0
  58. package/dist/ColourSchemeToggle.d.ts +36 -0
  59. package/dist/ColourSchemeToggle.js +64 -0
  60. package/dist/Container.d.ts +22 -0
  61. package/dist/Container.js +26 -0
  62. package/dist/CopyButton.d.ts +17 -0
  63. package/dist/CopyButton.js +39 -0
  64. package/dist/CopyLine.d.ts +9 -0
  65. package/dist/CopyLine.js +7 -0
  66. package/dist/DateCalendar.d.ts +23 -0
  67. package/dist/DateCalendar.js +89 -0
  68. package/dist/DateField.d.ts +124 -0
  69. package/dist/DateField.js +111 -0
  70. package/dist/DateFieldCalendar.d.ts +24 -0
  71. package/dist/DateFieldCalendar.js +50 -0
  72. package/dist/DateRangePicker.d.ts +47 -0
  73. package/dist/DateRangePicker.js +44 -0
  74. package/dist/Dialog.d.ts +56 -0
  75. package/dist/Dialog.js +94 -0
  76. package/dist/Disclosure.d.ts +29 -0
  77. package/dist/Disclosure.js +23 -0
  78. package/dist/Divider.d.ts +4 -0
  79. package/dist/Divider.js +5 -0
  80. package/dist/DocsLayout.d.ts +69 -0
  81. package/dist/DocsLayout.js +64 -0
  82. package/dist/Drawer.d.ts +30 -0
  83. package/dist/Drawer.js +24 -0
  84. package/dist/EmptyState.d.ts +47 -0
  85. package/dist/EmptyState.js +34 -0
  86. package/dist/Field.d.ts +44 -0
  87. package/dist/Field.js +51 -0
  88. package/dist/FieldDialog.d.ts +26 -0
  89. package/dist/FieldDialog.js +31 -0
  90. package/dist/Fieldset.d.ts +21 -0
  91. package/dist/Fieldset.js +22 -0
  92. package/dist/FileDrop.d.ts +17 -0
  93. package/dist/FileDrop.js +14 -0
  94. package/dist/FormRow.d.ts +46 -0
  95. package/dist/FormRow.js +39 -0
  96. package/dist/Hero.d.ts +23 -0
  97. package/dist/Hero.js +28 -0
  98. package/dist/Icon.d.ts +40 -0
  99. package/dist/Icon.js +30 -0
  100. package/dist/IconButton.d.ts +72 -0
  101. package/dist/IconButton.js +65 -0
  102. package/dist/Image.d.ts +58 -0
  103. package/dist/Image.js +69 -0
  104. package/dist/InlineEdit.d.ts +22 -0
  105. package/dist/InlineEdit.js +60 -0
  106. package/dist/Input.d.ts +40 -0
  107. package/dist/Input.js +42 -0
  108. package/dist/InputShell.d.ts +24 -0
  109. package/dist/InputShell.js +40 -0
  110. package/dist/Kbd.d.ts +6 -0
  111. package/dist/Kbd.js +5 -0
  112. package/dist/KeyValueList.d.ts +34 -0
  113. package/dist/KeyValueList.js +35 -0
  114. package/dist/Lightbox.d.ts +45 -0
  115. package/dist/Lightbox.js +46 -0
  116. package/dist/ListRow.d.ts +26 -0
  117. package/dist/ListRow.js +151 -0
  118. package/dist/Markdown.d.ts +11 -0
  119. package/dist/Markdown.js +49 -0
  120. package/dist/MediaTile.d.ts +66 -0
  121. package/dist/MediaTile.js +50 -0
  122. package/dist/Menu.d.ts +64 -0
  123. package/dist/Menu.js +86 -0
  124. package/dist/MetaList.d.ts +23 -0
  125. package/dist/MetaList.js +20 -0
  126. package/dist/Morph.d.ts +41 -0
  127. package/dist/Morph.js +107 -0
  128. package/dist/NavigationProgress.d.ts +20 -0
  129. package/dist/NavigationProgress.js +26 -0
  130. package/dist/OutlineRegion.d.ts +60 -0
  131. package/dist/OutlineRegion.js +51 -0
  132. package/dist/PageFade.d.ts +30 -0
  133. package/dist/PageFade.js +46 -0
  134. package/dist/PageHeader.d.ts +26 -0
  135. package/dist/PageHeader.js +18 -0
  136. package/dist/PageLayouts.d.ts +100 -0
  137. package/dist/PageLayouts.js +78 -0
  138. package/dist/Pagination.d.ts +38 -0
  139. package/dist/Pagination.js +65 -0
  140. package/dist/Pill.d.ts +79 -0
  141. package/dist/Pill.js +121 -0
  142. package/dist/ProgressBar.d.ts +47 -0
  143. package/dist/ProgressBar.js +47 -0
  144. package/dist/RadioGroup.d.ts +55 -0
  145. package/dist/RadioGroup.js +53 -0
  146. package/dist/ScrollStrip.d.ts +21 -0
  147. package/dist/ScrollStrip.js +12 -0
  148. package/dist/SearchInput.d.ts +9 -0
  149. package/dist/SearchInput.js +55 -0
  150. package/dist/Section.d.ts +93 -0
  151. package/dist/Section.js +55 -0
  152. package/dist/SegmentedControl.d.ts +47 -0
  153. package/dist/SegmentedControl.js +78 -0
  154. package/dist/Select.d.ts +28 -0
  155. package/dist/Select.js +19 -0
  156. package/dist/Show.d.ts +33 -0
  157. package/dist/Show.js +27 -0
  158. package/dist/SideColumn.d.ts +50 -0
  159. package/dist/SideColumn.js +45 -0
  160. package/dist/SidebarLayout.d.ts +32 -0
  161. package/dist/SidebarLayout.js +77 -0
  162. package/dist/SiteFooter.d.ts +31 -0
  163. package/dist/SiteFooter.js +24 -0
  164. package/dist/SiteSearch.d.ts +40 -0
  165. package/dist/SiteSearch.js +150 -0
  166. package/dist/SortableList.d.ts +86 -0
  167. package/dist/SortableList.js +191 -0
  168. package/dist/SplitBar.d.ts +29 -0
  169. package/dist/SplitBar.js +22 -0
  170. package/dist/Stack.d.ts +114 -0
  171. package/dist/Stack.js +76 -0
  172. package/dist/StackedBar.d.ts +64 -0
  173. package/dist/StackedBar.js +58 -0
  174. package/dist/StatTile.d.ts +33 -0
  175. package/dist/StatTile.js +44 -0
  176. package/dist/StatusPages.d.ts +49 -0
  177. package/dist/StatusPages.js +63 -0
  178. package/dist/Steps.d.ts +29 -0
  179. package/dist/Steps.js +43 -0
  180. package/dist/StickyBar.d.ts +12 -0
  181. package/dist/StickyBar.js +10 -0
  182. package/dist/Switch.d.ts +56 -0
  183. package/dist/Switch.js +91 -0
  184. package/dist/Table.d.ts +92 -0
  185. package/dist/Table.js +92 -0
  186. package/dist/TableCells.d.ts +97 -0
  187. package/dist/TableCells.js +104 -0
  188. package/dist/TableEditCell.d.ts +31 -0
  189. package/dist/TableEditCell.js +17 -0
  190. package/dist/TableExpandCell.d.ts +25 -0
  191. package/dist/TableExpandCell.js +15 -0
  192. package/dist/Tabs.d.ts +38 -0
  193. package/dist/Tabs.js +46 -0
  194. package/dist/TextLink.d.ts +51 -0
  195. package/dist/TextLink.js +38 -0
  196. package/dist/Textarea.d.ts +11 -0
  197. package/dist/Textarea.js +11 -0
  198. package/dist/Timeline.d.ts +31 -0
  199. package/dist/Timeline.js +38 -0
  200. package/dist/ToastRegion.d.ts +44 -0
  201. package/dist/ToastRegion.js +37 -0
  202. package/dist/Tooltip.d.ts +46 -0
  203. package/dist/Tooltip.js +181 -0
  204. package/dist/TrendChart.d.ts +36 -0
  205. package/dist/TrendChart.js +58 -0
  206. package/dist/Video.d.ts +13 -0
  207. package/dist/Video.js +9 -0
  208. package/dist/blocked.d.ts +31 -0
  209. package/dist/blocked.js +31 -0
  210. package/dist/cardContext.d.ts +8 -0
  211. package/dist/cardContext.js +14 -0
  212. package/dist/cardWait.d.ts +13 -0
  213. package/dist/cardWait.js +16 -0
  214. package/dist/colourScheme.d.ts +22 -0
  215. package/dist/colourScheme.js +53 -0
  216. package/dist/control.d.ts +29 -0
  217. package/dist/control.js +37 -0
  218. package/dist/copyScript.d.ts +13 -0
  219. package/dist/copyScript.js +13 -0
  220. package/dist/cx.d.ts +19 -0
  221. package/dist/cx.js +21 -0
  222. package/dist/density.d.ts +38 -0
  223. package/dist/density.js +77 -0
  224. package/dist/emptySlot.d.ts +11 -0
  225. package/dist/emptySlot.js +16 -0
  226. package/dist/fieldControl.d.ts +23 -0
  227. package/dist/fieldControl.js +24 -0
  228. package/dist/fieldWait.d.ts +30 -0
  229. package/dist/fieldWait.js +27 -0
  230. package/dist/foldedColumn.d.ts +18 -0
  231. package/dist/foldedColumn.js +51 -0
  232. package/dist/headingLevel.d.ts +10 -0
  233. package/dist/headingLevel.js +18 -0
  234. package/dist/highlight.d.ts +18 -0
  235. package/dist/highlight.js +306 -0
  236. package/dist/highlightConsole.d.ts +9 -0
  237. package/dist/highlightConsole.js +42 -0
  238. package/dist/highlightHtml.d.ts +7 -0
  239. package/dist/highlightHtml.js +132 -0
  240. package/dist/highlightKit.d.ts +16 -0
  241. package/dist/highlightKit.js +23 -0
  242. package/dist/highlightYaml.d.ts +3 -0
  243. package/dist/highlightYaml.js +143 -0
  244. package/dist/icons.d.ts +16 -0
  245. package/dist/icons.js +108 -0
  246. package/dist/index.d.ts +99 -0
  247. package/dist/index.js +92 -0
  248. package/dist/isoDate.d.ts +5 -0
  249. package/dist/isoDate.js +16 -0
  250. package/dist/labelWords.d.ts +20 -0
  251. package/dist/labelWords.js +28 -0
  252. package/dist/layoutWait.d.ts +15 -0
  253. package/dist/layoutWait.js +18 -0
  254. package/dist/link.d.ts +82 -0
  255. package/dist/link.js +68 -0
  256. package/dist/listRowProps.d.ts +108 -0
  257. package/dist/listRowProps.js +1 -0
  258. package/dist/listRowWait.d.ts +6 -0
  259. package/dist/listRowWait.js +14 -0
  260. package/dist/modal.d.ts +25 -0
  261. package/dist/modal.js +61 -0
  262. package/dist/navFold.d.ts +15 -0
  263. package/dist/navFold.js +46 -0
  264. package/dist/pillTip.d.ts +8 -0
  265. package/dist/pillTip.js +25 -0
  266. package/dist/props.d.ts +26 -0
  267. package/dist/props.js +14 -0
  268. package/dist/scrollEdges.d.ts +12 -0
  269. package/dist/scrollEdges.js +40 -0
  270. package/dist/scrollStop.d.ts +32 -0
  271. package/dist/scrollStop.js +79 -0
  272. package/dist/sheetSnap.d.ts +27 -0
  273. package/dist/sheetSnap.js +45 -0
  274. package/dist/shownDate.d.ts +88 -0
  275. package/dist/shownDate.js +186 -0
  276. package/dist/size.d.ts +45 -0
  277. package/dist/size.js +12 -0
  278. package/dist/skeleton.d.ts +83 -0
  279. package/dist/skeleton.js +88 -0
  280. package/dist/stackGap.d.ts +9 -0
  281. package/dist/stackGap.js +16 -0
  282. package/dist/stickyColumn.d.ts +38 -0
  283. package/dist/stickyColumn.js +38 -0
  284. package/dist/switcher.d.ts +93 -0
  285. package/dist/switcher.js +78 -0
  286. package/dist/tableColumns.d.ts +31 -0
  287. package/dist/tableColumns.js +72 -0
  288. package/dist/tableEmpty.d.ts +15 -0
  289. package/dist/tableEmpty.js +26 -0
  290. package/dist/tableRow.d.ts +67 -0
  291. package/dist/tableRow.js +49 -0
  292. package/dist/tableSort.d.ts +22 -0
  293. package/dist/tableSort.js +19 -0
  294. package/dist/textBox.d.ts +10 -0
  295. package/dist/textBox.js +23 -0
  296. package/dist/tone.d.ts +11 -0
  297. package/dist/tone.js +1 -0
  298. package/dist/trend.d.ts +26 -0
  299. package/dist/trend.js +64 -0
  300. package/dist/typography.d.ts +203 -0
  301. package/dist/typography.js +242 -0
  302. package/dist/useImageFailed.d.ts +19 -0
  303. package/dist/useImageFailed.js +21 -0
  304. package/package.json +84 -4
@@ -0,0 +1,35 @@
1
+ import { type ReactElement } from "react";
2
+ import type { Passthrough } from "./props.js";
3
+ /**
4
+ * The box a message is typed into, with its button beside it. It keeps its own text. Enter sends
5
+ * the trimmed text and clears the box; Shift+Enter is a newline; empty or whitespace-only text does
6
+ * not send. While `busy` a reply is on its way: the button is Stop, Enter does not send, and typing
7
+ * carries on with the text kept for the next send.
8
+ */
9
+ export declare function ChatComposer({ label, placeholder, disabled, busy, onSend, onStop, sendLabel, stopLabel, ...rest }: {
10
+ /** The box's name for assistive tech; it is not drawn. */
11
+ label: string;
12
+ /** The hint inside the empty box. */
13
+ placeholder?: string | undefined;
14
+ /** Disables the box and the button. For a chat that cannot take a message at all, not for a reply in flight: that is `busy`. */
15
+ disabled?: boolean | undefined;
16
+ /**
17
+ * A reply is on its way: the button is Stop and Enter does not send. With no `onStop`, the button
18
+ * stays a disabled Send and no Stop is drawn.
19
+ */
20
+ busy?: boolean | undefined;
21
+ /** Called with the trimmed text. */
22
+ onSend: (text: string) => void;
23
+ /** Called when the reader presses Stop. */
24
+ onStop?: (() => void) | undefined;
25
+ /**
26
+ * The button's word, for sending.
27
+ * @default Send
28
+ */
29
+ sendLabel?: string | undefined;
30
+ /**
31
+ * The button's word, while `busy`.
32
+ * @default Stop
33
+ */
34
+ stopLabel?: string | undefined;
35
+ } & Passthrough): ReactElement;
@@ -0,0 +1,50 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useId, useRef, useState, } from "react";
3
+ import { Button } from "./Button.js";
4
+ import { Cluster, ClusterGrow } from "./Cluster.js";
5
+ import { Field } from "./Field.js";
6
+ import { Textarea } from "./Textarea.js";
7
+ /**
8
+ * An IME is still composing. Safari ends the composition before the Enter's keydown, so there
9
+ * `isComposing` is already false and only the 229 keyCode tells the commit from a real Enter.
10
+ */
11
+ function isComposing({ nativeEvent }) {
12
+ return nativeEvent.isComposing || nativeEvent.keyCode === 229;
13
+ }
14
+ /**
15
+ * The box a message is typed into, with its button beside it. It keeps its own text. Enter sends
16
+ * the trimmed text and clears the box; Shift+Enter is a newline; empty or whitespace-only text does
17
+ * not send. While `busy` a reply is on its way: the button is Stop, Enter does not send, and typing
18
+ * carries on with the text kept for the next send.
19
+ */
20
+ export function ChatComposer({ label, placeholder, disabled = false, busy = false, onSend, onStop, sendLabel = "Send", stopLabel = "Stop", ...rest }) {
21
+ const id = useId();
22
+ const box = useRef(null);
23
+ const [text, setText] = useState("");
24
+ const trimmed = text.trim();
25
+ const stop = busy && onStop !== undefined;
26
+ const send = () => {
27
+ if (busy || trimmed === "")
28
+ return;
29
+ onSend(trimmed);
30
+ setText("");
31
+ };
32
+ const onKeyDown = (event) => {
33
+ if (event.key !== "Enter" || event.shiftKey || isComposing(event))
34
+ return;
35
+ event.preventDefault();
36
+ send();
37
+ };
38
+ // One submit button that is Send or Stop, so it is the same element across the swap and keeps its
39
+ // focus. Send goes back to the box: the empty box has just disabled the button under the focus.
40
+ const onSubmit = (event) => {
41
+ event.preventDefault();
42
+ if (busy) {
43
+ onStop?.();
44
+ return;
45
+ }
46
+ send();
47
+ box.current?.focus();
48
+ };
49
+ return (_jsx("form", { ...rest, onSubmit: onSubmit, children: _jsxs(Cluster, { align: "end", gap: "sm", children: [_jsx(ClusterGrow, { children: _jsx(Field, { label: label, htmlFor: id, labelHidden: true, children: _jsx(Textarea, { ref: box, id: id, rows: 2, value: text, placeholder: placeholder, disabled: disabled, onChange: (event) => setText(event.target.value), onKeyDown: onKeyDown }) }) }), _jsx(Button, { type: "submit", variant: stop ? "outline" : "primary", disabled: disabled || (busy ? !stop : trimmed === ""), children: stop ? stopLabel : sendLabel })] }) }));
50
+ }
@@ -0,0 +1,26 @@
1
+ import type { ReactElement, ReactNode } from "react";
2
+ import type { Passthrough } from "./props.js";
3
+ /**
4
+ * One message in a chat: a bubble on the sender's side, with an optional line above it and a row of
5
+ * actions under it. `children` is the body as the caller wants it (plain text, which keeps its line
6
+ * breaks, a `Markdown`, an `Image`). `streaming` marks a reply still arriving; with no children it
7
+ * draws the caret alone, the pending state.
8
+ */
9
+ export declare function ChatMessage({ role, author, meta, actions, streaming, children, ...rest }: {
10
+ /** Whose side it sits on: `user` on the right on the inset fill, `assistant` on the left on the surface. */
11
+ role: "user" | "assistant";
12
+ /** Who sent it, read first by a screen reader and drawn nowhere: alignment alone tells a screen reader nothing. Show a sender with `meta`. */
13
+ author: string;
14
+ /** A small line above the bubble: a sender and a time, already formatted. */
15
+ meta?: ReactNode;
16
+ /** A row under the bubble on the message's own side: copy, retry, a row of reaction `Pill`s. */
17
+ actions?: ReactNode;
18
+ /**
19
+ * The reply is still arriving: sets `aria-busy` and draws a caret after the body, which pulses
20
+ * unless the reader asks for reduced motion.
21
+ * @default false
22
+ */
23
+ streaming?: boolean | undefined;
24
+ /** The body. It may be empty while `streaming`. */
25
+ children?: ReactNode;
26
+ } & Passthrough): ReactElement;
@@ -0,0 +1,21 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { cx } from "./cx.js";
3
+ const BUBBLE = "max-w-[90%] rounded-xl px-3 py-2 text-sm text-slate-900";
4
+ const ROLE = {
5
+ user: { side: "items-end", row: "justify-end", bubble: "bg-slate-100" },
6
+ assistant: {
7
+ side: "items-start",
8
+ row: "justify-start",
9
+ bubble: "border border-slate-200 bg-white",
10
+ },
11
+ };
12
+ /**
13
+ * One message in a chat: a bubble on the sender's side, with an optional line above it and a row of
14
+ * actions under it. `children` is the body as the caller wants it (plain text, which keeps its line
15
+ * breaks, a `Markdown`, an `Image`). `streaming` marks a reply still arriving; with no children it
16
+ * draws the caret alone, the pending state.
17
+ */
18
+ export function ChatMessage({ role, author, meta, actions, streaming = false, children, ...rest }) {
19
+ const look = ROLE[role];
20
+ return (_jsxs("article", { ...rest, "aria-busy": streaming || undefined, className: cx("flex w-full min-w-0 flex-col gap-1", look.side), children: [_jsx("span", { className: "sr-only", children: author }), meta && _jsx("div", { className: "text-xs text-slate-500", children: meta }), _jsxs("div", { className: cx(BUBBLE, look.bubble, "wrap-anywhere whitespace-pre-wrap"), children: [children, streaming && (_jsx("span", { "aria-hidden": "true", className: "text-slate-400 motion-safe:animate-pulse", children: "\u258D" }))] }), actions && (_jsx("div", { className: cx("flex flex-wrap items-center gap-1", look.row), children: actions }))] }));
21
+ }
@@ -0,0 +1,25 @@
1
+ import { type ReactElement, type ReactNode } from "react";
2
+ import type { Passthrough } from "./props.js";
3
+ /** Whether a box scrolled this far is at its bottom, give or take `BOTTOM_SLACK`. */
4
+ export declare function isAtBottom(scrollTop: number, clientHeight: number, scrollHeight: number): boolean;
5
+ /**
6
+ * The scrolling box of a chat: its children are the messages, tool cards and anything else, a gap
7
+ * apart. It follows the newest content unless the reader has scrolled up. It is a named region and
8
+ * a tab stop, so a keyboard can scroll it. It is deliberately not a live region, which would read
9
+ * every streamed token aloud: set `announce` when a message is finished.
10
+ */
11
+ export declare function ChatThread({ label, height, empty, announce, children, ...rest }: {
12
+ /** Names the region. */
13
+ label: string;
14
+ /**
15
+ * The tallest it gets before it scrolls: `sm` 20rem, `md` 28rem, `lg` 40rem. `fill` takes the
16
+ * height of a parent that sets one.
17
+ * @default md
18
+ */
19
+ height?: "sm" | "md" | "lg" | "fill" | undefined;
20
+ /** Drawn instead when there are no children: an `EmptyState`. */
21
+ empty?: ReactNode;
22
+ /** Text a screen reader reads out politely when it changes. Set it when a message is finished, not on each token. */
23
+ announce?: string | undefined;
24
+ children?: ReactNode;
25
+ } & Passthrough): ReactElement;
@@ -0,0 +1,60 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Children, useLayoutEffect, useRef } from "react";
3
+ import { cx, focusRing, themedScrollbar } from "./cx.js";
4
+ import { EmptySlot } from "./emptySlot.js";
5
+ const HEIGHT = {
6
+ sm: "max-h-80",
7
+ md: "max-h-[28rem]",
8
+ lg: "max-h-[40rem]",
9
+ fill: "h-full min-h-0",
10
+ };
11
+ /** How far above the very bottom, in pixels, still counts as reading the latest message. */
12
+ const BOTTOM_SLACK = 32;
13
+ /** Whether a box scrolled this far is at its bottom, give or take `BOTTOM_SLACK`. */
14
+ export function isAtBottom(scrollTop, clientHeight, scrollHeight) {
15
+ return scrollHeight - scrollTop - clientHeight <= BOTTOM_SLACK;
16
+ }
17
+ /**
18
+ * Starts the box at the bottom and keeps it there as the content grows, until the reader scrolls
19
+ * up; scrolling back to the bottom re-arms it. The box is watched as well as the content: a box
20
+ * that gets shorter (a phone's keyboard opening under `fill`) has moved the bottom out of view too.
21
+ */
22
+ function useStickToBottom() {
23
+ const box = useRef(null);
24
+ const content = useRef(null);
25
+ const following = useRef(true);
26
+ useLayoutEffect(() => {
27
+ const scroller = box.current;
28
+ if (!scroller || !content.current)
29
+ return undefined;
30
+ const follow = () => {
31
+ if (following.current)
32
+ scroller.scrollTop = scroller.scrollHeight;
33
+ };
34
+ follow();
35
+ // jsdom (a consumer's own tests) has no ResizeObserver.
36
+ if (typeof ResizeObserver === "undefined")
37
+ return undefined;
38
+ const observer = new ResizeObserver(follow);
39
+ observer.observe(content.current);
40
+ observer.observe(scroller);
41
+ return () => observer.disconnect();
42
+ }, []);
43
+ const onScroll = () => {
44
+ const scroller = box.current;
45
+ if (!scroller)
46
+ return;
47
+ following.current = isAtBottom(scroller.scrollTop, scroller.clientHeight, scroller.scrollHeight);
48
+ };
49
+ return { box, content, onScroll };
50
+ }
51
+ /**
52
+ * The scrolling box of a chat: its children are the messages, tool cards and anything else, a gap
53
+ * apart. It follows the newest content unless the reader has scrolled up. It is a named region and
54
+ * a tab stop, so a keyboard can scroll it. It is deliberately not a live region, which would read
55
+ * every streamed token aloud: set `announce` when a message is finished.
56
+ */
57
+ export function ChatThread({ label, height = "md", empty, announce, children, ...rest }) {
58
+ const { box, content, onScroll } = useStickToBottom();
59
+ return (_jsxs(_Fragment, { children: [_jsx("div", { "aria-live": "polite", className: "sr-only", children: announce }), _jsx("div", { ...rest, ref: box, role: "region", "aria-label": label, tabIndex: 0, onScroll: onScroll, className: cx("overflow-y-auto rounded-lg", HEIGHT[height], themedScrollbar, focusRing), children: _jsx("div", { ref: content, className: "flex flex-col gap-3 text-slate-900", children: Children.toArray(children).length === 0 ? (_jsx(EmptySlot, { size: "md", children: empty })) : (children) }) })] }));
60
+ }
@@ -0,0 +1,42 @@
1
+ import type { ComponentPropsWithoutRef, ReactElement, ReactNode, Ref } from "react";
2
+ import type { Unstyled } from "./props.js";
3
+ import type { Size } from "./size.js";
4
+ import { type LoadingProps } from "./skeleton.js";
5
+ /** The props of a `Checkbox`. */
6
+ type CheckboxProps = {
7
+ /** The text beside the box. Leave it out for a bare box (a table cell) and name it with `aria-label`. */
8
+ label?: ReactNode;
9
+ /** A muted line under the label that says more. It is the box's `aria-describedby`. */
10
+ hint?: ReactNode;
11
+ /** Replaces the hint with a red line (`role="alert"`) and makes the box `aria-invalid`. */
12
+ error?: ReactNode;
13
+ /**
14
+ * The label's text size and the box with it.
15
+ * @default md
16
+ */
17
+ size?: Size | undefined;
18
+ /** Called with the new checked state when the person ticks or clears the box. */
19
+ onChange?: ((checked: boolean) => void) | undefined;
20
+ /**
21
+ * Why the box cannot be changed: it dims and is blocked (`aria-disabled`; a click and Space
22
+ * change nothing) while it stays in the tab order, and the reason is its tooltip on hover,
23
+ * keyboard focus and a tap, read out as its description.
24
+ */
25
+ disabledReason?: string | undefined;
26
+ /** The `<input>`, for focus control. */
27
+ ref?: Ref<HTMLInputElement> | undefined;
28
+ } & Unstyled<Omit<ComponentPropsWithoutRef<"input">, "type" | "size" | "width" | "onChange">>;
29
+ /**
30
+ * A checkbox with its label. It is a real `<input type="checkbox">`, drawn by the library (an
31
+ * empty outlined box, then a filled accent one with a check mark) so it reads the same in every
32
+ * theme and browser. Every prop but the label goes on the input, and `ref` reaches it.
33
+ * `size="sm"` is `text-xs` and a smaller box, for a dense row; `size="lg"` is `text-base` and a
34
+ * larger box. Leave `label` out for a bare box in a table cell, and name it with `aria-label`. The
35
+ * box sits on the label's first line, so a label that wraps reads from the box. `hint` is a muted
36
+ * line under the label that says more, like a `Field`'s; `error` replaces it with a red line
37
+ * (`role="alert"`) and makes the box `aria-invalid`. The note is the box's `aria-describedby`.
38
+ * `onChange` gets the new checked state; take `checked` with it, or `defaultChecked` alone.
39
+ * While `loading` the label is drawn and the box is a bone of its size.
40
+ */
41
+ export declare function Checkbox({ loading, loadingLabel, ...props }: CheckboxProps & LoadingProps): ReactElement;
42
+ export {};
@@ -0,0 +1,63 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { cx, focusRing } from "./cx.js";
3
+ import { useNote, Words } from "./labelWords.js";
4
+ import { WaitingChoice } from "./fieldWait.js";
5
+ import { useLoading } from "./skeleton.js";
6
+ import { useBlocked } from "./blocked.js";
7
+ /** The label's gap and text, the box, and the box's drop onto the label's first line, by `size`. */
8
+ const SIZE = {
9
+ sm: { label: "gap-1.5 text-xs", box: "h-3.5 w-3.5", start: "mt-px" },
10
+ md: { label: "gap-2 text-sm", box: "h-4 w-4", start: "mt-0.5" },
11
+ lg: { label: "gap-2.5 text-base", box: "h-5 w-5", start: "mt-0.5" },
12
+ };
13
+ /** The tick: shown over the box when it is checked. */
14
+ function Tick({ size, onFirstLine }) {
15
+ /* The checked box: a filled accent square at the input's own place (an absolutely
16
+ positioned flex child sits where the first flex item would, so it needs no insets), shown
17
+ by the label's `:has(:checked)` so an uncontrolled Checkbox changes with no re-render.
18
+ Inside a Card or table row the input is lifted to `z-10` by `liftInteractive` (cx.ts), and
19
+ it comes later in the DOM, so the tick ranks `z-20` there to paint over it. Scoped to the
20
+ `isolate` ancestor like the Input icon (InputShell.tsx), so it never outranks a sticky bar. */
21
+ return (_jsx("span", { "aria-hidden": "true", className: cx(SIZE[size].box, onFirstLine && SIZE[size].start, "pointer-events-none invisible absolute in-[.isolate]:z-20 block rounded border border-violet-600 bg-violet-600 text-violet-50 group-has-checked/checkbox:visible"), children: _jsx("svg", { viewBox: "0 0 16 16", fill: "none", className: "h-full w-full", children: _jsx("path", { d: "M4 8.5l2.5 2.5L12 5.5", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }) }) }));
22
+ }
23
+ /**
24
+ * A checkbox with its label. It is a real `<input type="checkbox">`, drawn by the library (an
25
+ * empty outlined box, then a filled accent one with a check mark) so it reads the same in every
26
+ * theme and browser. Every prop but the label goes on the input, and `ref` reaches it.
27
+ * `size="sm"` is `text-xs` and a smaller box, for a dense row; `size="lg"` is `text-base` and a
28
+ * larger box. Leave `label` out for a bare box in a table cell, and name it with `aria-label`. The
29
+ * box sits on the label's first line, so a label that wraps reads from the box. `hint` is a muted
30
+ * line under the label that says more, like a `Field`'s; `error` replaces it with a red line
31
+ * (`role="alert"`) and makes the box `aria-invalid`. The note is the box's `aria-describedby`.
32
+ * `onChange` gets the new checked state; take `checked` with it, or `defaultChecked` alone.
33
+ * While `loading` the label is drawn and the box is a bone of its size.
34
+ */
35
+ export function Checkbox({ loading, loadingLabel, ...props }) {
36
+ if (useLoading(loading).loading) {
37
+ const size = props.size ?? "md";
38
+ return (_jsx(WaitingChoice, { own: loading, loadingLabel: loadingLabel, label: props.label, look: SIZE[size].label, shape: cx(SIZE[size].box, props.label != null && SIZE[size].start, "rounded"), attrs: props }));
39
+ }
40
+ return _jsx(ShownCheckbox, { ...props });
41
+ }
42
+ /** A checkbox with its box drawn. */
43
+ function ShownCheckbox({ label, hint, error, size = "md", onChange, disabledReason, "aria-describedby": describedBy, ...rest }) {
44
+ const { noteId, describedIds, invalid } = useNote(hint, error, describedBy);
45
+ const { props: guard, tooltip, blocked, } = useBlocked(disabledReason, {
46
+ ...rest,
47
+ "aria-describedby": describedIds || undefined,
48
+ });
49
+ return (_jsxs(_Fragment, { children: [_jsxs("label", { className: cx(
50
+ // Faded and default-cursor unless the box is enabled. Written as `has-enabled` so the
51
+ // label carries no `disabled` class text: the disabled state belongs on the input. A
52
+ // blocked box is enabled (it keeps its focus) and fades as a disabled one does.
53
+ "group/checkbox inline-flex items-start text-slate-700", blocked
54
+ ? "cursor-not-allowed opacity-50"
55
+ : "cursor-default opacity-50 has-enabled:cursor-pointer has-enabled:opacity-100", SIZE[size].label), children: [_jsx(Tick, { size: size, onFirstLine: label != null }), _jsx("input", { type: "checkbox", className: cx(SIZE[size].box, "shrink-0", label != null && SIZE[size].start, "appearance-none rounded border border-slate-300 bg-white hover:border-violet-400", focusRing), ...(invalid ? { "aria-invalid": true } : {}), ...rest, ...guard, ...(onChange
56
+ ? {
57
+ onChange: (event) => {
58
+ if (!blocked)
59
+ onChange(event.target.checked);
60
+ },
61
+ }
62
+ : {}) }), _jsx(Words, { label: label, hint: hint, error: error, id: noteId })] }), tooltip] }));
63
+ }
@@ -0,0 +1,5 @@
1
+ import type { ReactElement } from "react";
2
+ /** The right-pointing chevron of a collapsible header; it turns down when `open`. */
3
+ export declare function Chevron({ open }: {
4
+ open: boolean;
5
+ }): ReactElement;
@@ -0,0 +1,6 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { cx } from "./cx.js";
3
+ /** The right-pointing chevron of a collapsible header; it turns down when `open`. */
4
+ export function Chevron({ open }) {
5
+ return (_jsx("svg", { "aria-hidden": "true", viewBox: "0 0 20 20", fill: "currentColor", className: cx("h-4 w-4 shrink-0 text-slate-400", open && "rotate-90"), children: _jsx("path", { fillRule: "evenodd", d: "M7.2 4.8a.75.75 0 0 1 1.06 0l4.7 4.67a.75.75 0 0 1 0 1.06l-4.7 4.67a.75.75 0 1 1-1.06-1.06L11.37 10 7.2 5.86a.75.75 0 0 1 0-1.06Z", clipRule: "evenodd" }) }));
6
+ }
@@ -0,0 +1,70 @@
1
+ import type { ReactElement, ReactNode } from "react";
2
+ import type { Passthrough } from "./props.js";
3
+ import { type StackGap } from "./Stack.js";
4
+ /** The first three steps of `Stack`'s scale: `xs` between items in a line, `sm` inside a group, `md` between blocks. */
5
+ export type ClusterGap = Extract<StackGap, "xs" | "sm" | "md">;
6
+ /** Where a `Cluster`'s items sit across the row: `center`, `baseline` for mixed text sizes, `start` or `end`. */
7
+ export type ClusterAlign = "center" | "baseline" | "start" | "end";
8
+ /** Where a `Cluster`'s items sit along the row: `start`, `end`, or `between` to spread them to both ends. */
9
+ export type ClusterJustify = "start" | "between" | "end";
10
+ /**
11
+ * A horizontal row of items a fixed `gap` apart (`sm` by default): the row counterpart of `Stack`. `align` is the
12
+ * cross axis (`center` default, `baseline` for mixed text sizes, `start`, `end`) and `justify` the
13
+ * main one (`start` default, `between` to push the first and last items to the two ends, `end`).
14
+ * The items flow onto further lines when the row runs out of room; `wrap={false}` keeps them on one
15
+ * line.
16
+ *
17
+ * Put one `ClusterGrow` around the item that takes the room left over, an input beside its
18
+ * buttons, say. An empty `ClusterGrow` is a spacer that pushes what follows it to the end.
19
+ * `ButtonGroup` is the row for buttons; use `Cluster` for any other row. `as="span"` is for a row
20
+ * inside phrasing content, such as a `PageHeader` description (a `<p>`): its items must be phrasing
21
+ * content too, so no `ClusterGrow`. `as="ul"` or `as="ol"` is a wrapping list with no markers
22
+ * (tags, chips): as in a `Stack` list the Cluster does not wrap its children, so each child is an
23
+ * `<li>` the caller writes, and a `ClusterGrow` (a `div`) does not belong in it.
24
+ */
25
+ export declare function Cluster({ as: Tag, gap, align, justify, wrap, children, ...rest }: {
26
+ /**
27
+ * The element: `div`, `span` for a row inside a `<p>` or other phrasing content, or `ul` or `ol`
28
+ * for a list (no markers; each child is an `<li>`).
29
+ *
30
+ * In a `span` the items must be phrasing content, so no `ClusterGrow`.
31
+ * @default div
32
+ */
33
+ as?: "div" | "span" | "ul" | "ol" | undefined;
34
+ /**
35
+ * The space between items: the first steps of the gap scale. Its default is one of those the
36
+ * `Size` type lists as not `md`.
37
+ * @default sm
38
+ */
39
+ gap?: ClusterGap | undefined;
40
+ /**
41
+ * The cross axis: `center`, `baseline` (for mixed text sizes), `start` or `end`.
42
+ * @default center
43
+ */
44
+ align?: ClusterAlign | undefined;
45
+ /**
46
+ * The main axis: `start`, `between` (the first and last items at the two ends) or `end`.
47
+ * @default start
48
+ */
49
+ justify?: ClusterJustify | undefined;
50
+ /**
51
+ * Let the items flow onto further lines when the row runs out of room. `false` keeps them on one line.
52
+ * @default true
53
+ */
54
+ wrap?: boolean | undefined;
55
+ children?: ReactNode;
56
+ } & Passthrough): ReactElement;
57
+ /** The narrowest a `ClusterGrow` gets before the row wraps: `sm` or `md`. */
58
+ export type ClusterGrowMinWidth = "sm" | "md";
59
+ /**
60
+ * The one child of a `Cluster` (or of a `Stack` with `rowFrom`) that grows to the room left in the
61
+ * row. By default it can shrink to nothing (`min-w-0`), so the items beside it stay on the line and
62
+ * a long value truncates instead of pushing them out. With `minWidth` it instead keeps that width
63
+ * (`sm` 12rem, `md` 17rem) and, in a `Cluster` with `wrap`, drops onto the next line when the room
64
+ * left is narrower, rather than being squashed. Empty, it is a spacer.
65
+ */
66
+ export declare function ClusterGrow({ minWidth, children, ...rest }: {
67
+ /** The narrowest it gets: `sm` 12rem or `md` 17rem. In a `Cluster` with `wrap` it wraps under the other items below this width. Left out, it shrinks to nothing. */
68
+ minWidth?: ClusterGrowMinWidth | undefined;
69
+ children?: ReactNode;
70
+ } & Passthrough): ReactElement;
@@ -0,0 +1,47 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { cx } from "./cx.js";
3
+ import { STACK_GAP } from "./Stack.js";
4
+ const ALIGN = {
5
+ center: "items-center",
6
+ baseline: "items-baseline",
7
+ start: "items-start",
8
+ end: "items-end",
9
+ };
10
+ const JUSTIFY = {
11
+ start: "justify-start",
12
+ between: "justify-between",
13
+ end: "justify-end",
14
+ };
15
+ /**
16
+ * A horizontal row of items a fixed `gap` apart (`sm` by default): the row counterpart of `Stack`. `align` is the
17
+ * cross axis (`center` default, `baseline` for mixed text sizes, `start`, `end`) and `justify` the
18
+ * main one (`start` default, `between` to push the first and last items to the two ends, `end`).
19
+ * The items flow onto further lines when the row runs out of room; `wrap={false}` keeps them on one
20
+ * line.
21
+ *
22
+ * Put one `ClusterGrow` around the item that takes the room left over, an input beside its
23
+ * buttons, say. An empty `ClusterGrow` is a spacer that pushes what follows it to the end.
24
+ * `ButtonGroup` is the row for buttons; use `Cluster` for any other row. `as="span"` is for a row
25
+ * inside phrasing content, such as a `PageHeader` description (a `<p>`): its items must be phrasing
26
+ * content too, so no `ClusterGrow`. `as="ul"` or `as="ol"` is a wrapping list with no markers
27
+ * (tags, chips): as in a `Stack` list the Cluster does not wrap its children, so each child is an
28
+ * `<li>` the caller writes, and a `ClusterGrow` (a `div`) does not belong in it.
29
+ */
30
+ export function Cluster({ as: Tag = "div", gap = "sm", align = "center", justify = "start", wrap = true, children, ...rest }) {
31
+ return (_jsx(Tag, { ...rest, className: cx("flex", (Tag === "ul" || Tag === "ol") && "list-none", STACK_GAP[gap], ALIGN[align], JUSTIFY[justify], wrap && "flex-wrap"), children: children }));
32
+ }
33
+ /** The narrowest a `ClusterGrow` gets before it wraps under, the same two steps as `CardGrid`'s `minWidth`. */
34
+ const GROW_MIN_WIDTH = {
35
+ sm: "min-w-0 flex-[1_1_12rem]",
36
+ md: "min-w-0 flex-[1_1_17rem]",
37
+ };
38
+ /**
39
+ * The one child of a `Cluster` (or of a `Stack` with `rowFrom`) that grows to the room left in the
40
+ * row. By default it can shrink to nothing (`min-w-0`), so the items beside it stay on the line and
41
+ * a long value truncates instead of pushing them out. With `minWidth` it instead keeps that width
42
+ * (`sm` 12rem, `md` 17rem) and, in a `Cluster` with `wrap`, drops onto the next line when the room
43
+ * left is narrower, rather than being squashed. Empty, it is a spacer.
44
+ */
45
+ export function ClusterGrow({ minWidth, children, ...rest }) {
46
+ return (_jsx("div", { ...rest, className: minWidth ? GROW_MIN_WIDTH[minWidth] : "min-w-0 flex-1", children: children }));
47
+ }
package/dist/Code.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ import type { ReactElement, ReactNode } from "react";
2
+ import type { Passthrough } from "./props.js";
3
+ /** Inline code: mono, on a subtle inset background. It takes the surrounding text colour and size (a touch smaller, for the mono face). */
4
+ export declare function Code({ children, ...rest }: {
5
+ children: ReactNode;
6
+ } & Passthrough): ReactElement;
package/dist/Code.js ADDED
@@ -0,0 +1,5 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ /** Inline code: mono, on a subtle inset background. It takes the surrounding text colour and size (a touch smaller, for the mono face). */
3
+ export function Code({ children, ...rest }) {
4
+ return (_jsx("code", { ...rest, className: "rounded bg-slate-100 px-1 py-0.5 font-mono text-[0.9em]", children: children }));
5
+ }
@@ -0,0 +1,46 @@
1
+ import { type ComponentPropsWithoutRef, type ReactElement } from "react";
2
+ import type { CodeLanguage } from "./highlight.js";
3
+ import type { Unstyled } from "./props.js";
4
+ /** Exactly one of `children` (a string, newlines kept) or `lines` (one array entry per line). */
5
+ type CodeBlockSource = {
6
+ children: string;
7
+ /** The code as one array entry per line, in place of `children`. */
8
+ lines?: never;
9
+ } | {
10
+ /** The code as one array entry per line, in place of `children`. */
11
+ lines: string[];
12
+ children?: never;
13
+ };
14
+ /**
15
+ * A block of code: mono, in a bordered inset box. No client JS unless `copy` adds a copy button
16
+ * beside the code, which copies it exactly as given. `language` colours
17
+ * it: `tsx`, `ts`, `js`, `json`, `bash`, `console`, `css`, `html` or `yaml`. `console` is a shell
18
+ * session: a line starting with `$ ` is a command (coloured as bash, its `$ ` dimmed and not
19
+ * selectable) and any other line is output; with `copy` only the commands are copied, without the
20
+ * `$ `. `label` names the language or file (`bash`, `css`) in a caption above the code. `text` (the
21
+ * default) leaves the code in one colour, for a block that is not a language. Give the text as `children` or as `lines`. Long lines wrap, so
22
+ * nothing is cut off and a command stays one copyable line; `overflow="scroll"` keeps lines whole
23
+ * and scrolls them sideways under a thin themed scrollbar, for code whose layout matters. With
24
+ * `overflow="scroll"`, a strip wider than its box is a tab stop named by `label`, else "Code". Every
25
+ * other figure prop goes on the root `<figure>`. For one short line to copy, `CopyLine` is the
26
+ * smaller box.
27
+ */
28
+ export declare function CodeBlock({ label, language, overflow, copy, children, lines, ...rest }: {
29
+ /** A caption above the code naming its language or file (`bash`, `theme.css`). */
30
+ label?: string;
31
+ /** What the code is written in; `text` (the default) colours nothing. */
32
+ language?: CodeLanguage;
33
+ /**
34
+ * What a line longer than the box does: `wrap` onto the next line (the default, nothing is cut
35
+ * off), or `scroll` sideways inside the box.
36
+ * @default wrap
37
+ */
38
+ overflow?: "wrap" | "scroll";
39
+ /**
40
+ * A copy button beside the code, which copies it exactly as given (a `console` block copies only
41
+ * its commands). On a page rendered to static HTML without hydration, inline `copyScript` and it works there too.
42
+ * @default false
43
+ */
44
+ copy?: boolean;
45
+ } & CodeBlockSource & Unstyled<Omit<ComponentPropsWithoutRef<"figure">, "children">>): ReactElement;
46
+ export {};
@@ -0,0 +1,21 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useId } from "react";
3
+ import { CodeBody } from "./CodeBody.js";
4
+ /**
5
+ * A block of code: mono, in a bordered inset box. No client JS unless `copy` adds a copy button
6
+ * beside the code, which copies it exactly as given. `language` colours
7
+ * it: `tsx`, `ts`, `js`, `json`, `bash`, `console`, `css`, `html` or `yaml`. `console` is a shell
8
+ * session: a line starting with `$ ` is a command (coloured as bash, its `$ ` dimmed and not
9
+ * selectable) and any other line is output; with `copy` only the commands are copied, without the
10
+ * `$ `. `label` names the language or file (`bash`, `css`) in a caption above the code. `text` (the
11
+ * default) leaves the code in one colour, for a block that is not a language. Give the text as `children` or as `lines`. Long lines wrap, so
12
+ * nothing is cut off and a command stays one copyable line; `overflow="scroll"` keeps lines whole
13
+ * and scrolls them sideways under a thin themed scrollbar, for code whose layout matters. With
14
+ * `overflow="scroll"`, a strip wider than its box is a tab stop named by `label`, else "Code". Every
15
+ * other figure prop goes on the root `<figure>`. For one short line to copy, `CopyLine` is the
16
+ * smaller box.
17
+ */
18
+ export function CodeBlock({ label, language = "text", overflow = "wrap", copy = false, children, lines, ...rest }) {
19
+ const captionId = useId();
20
+ return (_jsxs("figure", { ...rest, className: "overflow-hidden rounded-lg border border-slate-200 bg-slate-50 font-mono text-[12.5px] leading-normal text-slate-900", children: [label && (_jsx("figcaption", { id: captionId, className: "border-b border-slate-200 px-3 py-1.5 text-xs text-slate-500", children: label })), _jsx(CodeBody, { code: lines ? lines.join("\n") : children, language: language, wrap: overflow === "wrap", copy: copy, labelledBy: label ? captionId : undefined })] }));
21
+ }
@@ -0,0 +1,20 @@
1
+ import type { ReactElement } from "react";
2
+ import { type CodeLanguage } from "./highlight.js";
3
+ /**
4
+ * The code of a `CodeBlock` or a `CodeExample`: the `<pre>` and, with `copy`, a `CopyButton` beside
5
+ * it that copies `code` exactly as given (wrapping is CSS, so it adds no characters), except in a
6
+ * `console` block, where it copies only the commands (see `consoleCommands`). `wrap` wraps
7
+ * long lines at whitespace only (a flag with hyphens stays whole; a word wider than the box still
8
+ * breaks inside itself); without it they scroll sideways under a themed thin scrollbar. The button's column has
9
+ * a fixed width, so "copy" turning into "copied" never rewraps the code beside it. The button needs
10
+ * client JS, which is why it is opt-in: a page rendered to static HTML needs `copyScript` inlined
11
+ * or the button is dead.
12
+ */
13
+ export declare function CodeBody({ code, language, wrap, copy, labelledBy, }: {
14
+ code: string;
15
+ language: CodeLanguage;
16
+ wrap: boolean;
17
+ copy: boolean;
18
+ /** The id of the element that names the strip when it takes the stop; with none it is named "Code". */
19
+ labelledBy?: string | undefined;
20
+ }): ReactElement;
@@ -0,0 +1,38 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { CodeText } from "./CodeText.js";
3
+ import { CopyButton } from "./CopyButton.js";
4
+ import { cx, themedScrollbar } from "./cx.js";
5
+ import { consoleCommands } from "./highlight.js";
6
+ import { scrollStopProps, useScrollStop } from "./scrollStop.js";
7
+ /**
8
+ * The strip's focus ring, drawn inside it: the frame around the code clips anything outside the
9
+ * strip. `focusRing` with `-outline-offset-2` added would not do, since `outline-offset-2` comes
10
+ * later in the CSS and wins.
11
+ */
12
+ const INSET_RING = "focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-violet-600";
13
+ /** Whether a strip that scrolls sideways takes its tab stop: always, until it has been measured. */
14
+ function takesStop(measured, stop) {
15
+ return measured ? stop : true;
16
+ }
17
+ /**
18
+ * The code of a `CodeBlock` or a `CodeExample`: the `<pre>` and, with `copy`, a `CopyButton` beside
19
+ * it that copies `code` exactly as given (wrapping is CSS, so it adds no characters), except in a
20
+ * `console` block, where it copies only the commands (see `consoleCommands`). `wrap` wraps
21
+ * long lines at whitespace only (a flag with hyphens stays whole; a word wider than the box still
22
+ * breaks inside itself); without it they scroll sideways under a themed thin scrollbar. The button's column has
23
+ * a fixed width, so "copy" turning into "copied" never rewraps the code beside it. The button needs
24
+ * client JS, which is why it is opt-in: a page rendered to static HTML needs `copyScript` inlined
25
+ * or the button is dead.
26
+ */
27
+ export function CodeBody({ code, language, wrap, copy, labelledBy, }) {
28
+ // A strip that scrolls sideways holds no link or button, so when it overflows it takes a tab
29
+ // stop of its own, or the keyboard could never scroll it (axe's scrollable-region-focusable).
30
+ // Until it has been measured it takes the stop anyway: a page rendered to HTML and never
31
+ // hydrated is never measured and still needs the stop. Once measured, a strip that fits drops it.
32
+ const { attach, stop, measured } = useScrollStop("x");
33
+ const tabStop = !wrap && takesStop(measured, stop);
34
+ // The ring stays INSET_RING: scrollStopProps' own ring is drawn outside the box, which the strip's
35
+ // overflow-hidden frame would clip.
36
+ const { props: stopProps } = scrollStopProps(tabStop, labelledBy !== undefined ? { labelledBy } : { label: "Code" });
37
+ return (_jsxs("div", { className: cx("flex items-start", copy && "gap-1 pr-1.5"), children: [_jsx("div", { ref: wrap ? undefined : attach, ...stopProps, className: cx("min-w-0 flex-1", !wrap && `overflow-x-auto ${themedScrollbar}`, tabStop && INSET_RING), children: _jsx("pre", { className: cx("px-3 py-2.5 font-mono text-[12.5px] leading-normal text-slate-900", wrap ? "break-words whitespace-pre-wrap" : "w-max min-w-full whitespace-pre"), children: _jsx(CodeText, { code: code, language: language, breakAtSpaces: wrap }) }) }), copy && (_jsx("div", { className: "flex w-14 shrink-0 justify-end pt-2", children: _jsx(CopyButton, { text: language === "console" ? consoleCommands(code) : code }) }))] }));
38
+ }