@lanfermann/ui 0.5.0 → 0.7.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 (186) hide show
  1. package/dist/components/accordion/accordion.d.ts +11 -3
  2. package/dist/components/accordion/accordion.js +15 -10
  3. package/dist/components/action-bar/action-bar.d.ts +60 -0
  4. package/dist/components/action-bar/action-bar.js +117 -0
  5. package/dist/components/alert/alert.d.ts +1 -1
  6. package/dist/components/alert/alert.js +3 -17
  7. package/dist/components/alert-dialog/alert-dialog.d.ts +1 -1
  8. package/dist/components/app-shell/app-shell.d.ts +33 -0
  9. package/dist/components/app-shell/app-shell.js +93 -0
  10. package/dist/components/attachment/attachment.d.ts +51 -0
  11. package/dist/components/attachment/attachment.js +255 -0
  12. package/dist/components/attachment/kinds.d.ts +7 -0
  13. package/dist/components/attachment/kinds.js +142 -0
  14. package/dist/components/avatar/avatar.d.ts +14 -4
  15. package/dist/components/avatar/avatar.js +57 -13
  16. package/dist/components/avatar-group/avatar-group.d.ts +33 -0
  17. package/dist/components/avatar-group/avatar-group.js +110 -0
  18. package/dist/components/avatar-group/people.d.ts +12 -0
  19. package/dist/components/avatar-group/people.js +24 -0
  20. package/dist/components/badge/badge.d.ts +9 -3
  21. package/dist/components/badge/badge.js +21 -6
  22. package/dist/components/banner/banner.d.ts +39 -0
  23. package/dist/components/banner/banner.js +149 -0
  24. package/dist/components/button-group/button-group-variants.d.ts +4 -3
  25. package/dist/components/button-group/button-group-variants.js +13 -12
  26. package/dist/components/button-group/button-group.d.ts +3 -3
  27. package/dist/components/button-group/button-group.js +3 -3
  28. package/dist/components/card/card.d.ts +20 -4
  29. package/dist/components/card/card.js +32 -6
  30. package/dist/components/checkbox-card/checkbox-card.d.ts +21 -0
  31. package/dist/components/checkbox-card/checkbox-card.js +50 -0
  32. package/dist/components/chip/chip-group.d.ts +15 -0
  33. package/dist/components/chip/chip-group.js +44 -0
  34. package/dist/components/chip/chip-variants.d.ts +6 -0
  35. package/dist/components/chip/chip-variants.js +28 -0
  36. package/dist/components/chip/chip.d.ts +39 -0
  37. package/dist/components/chip/chip.js +71 -0
  38. package/dist/components/code-block/code-copy.d.ts +3 -11
  39. package/dist/components/code-block/code-copy.js +15 -62
  40. package/dist/components/code-block/code-keys.js +10 -22
  41. package/dist/components/collapsible/collapsible.js +7 -3
  42. package/dist/components/combobox/combobox.d.ts +53 -3
  43. package/dist/components/combobox/combobox.js +204 -20
  44. package/dist/components/command/command.d.ts +131 -0
  45. package/dist/components/command/command.js +335 -0
  46. package/dist/components/consent/consent-card.js +365 -0
  47. package/dist/components/consent/consent-embed.d.ts +21 -0
  48. package/dist/components/consent/consent-embed.js +111 -0
  49. package/dist/components/consent/consent-labels.d.ts +70 -0
  50. package/dist/components/consent/consent-labels.js +61 -0
  51. package/dist/components/consent/consent-record.d.ts +95 -0
  52. package/dist/components/consent/consent-record.js +112 -0
  53. package/dist/components/consent/consent-store.d.ts +26 -0
  54. package/dist/components/consent/consent-store.js +240 -0
  55. package/dist/components/consent/consent.d.ts +86 -0
  56. package/dist/components/consent/consent.js +306 -0
  57. package/dist/components/container/container.d.ts +1 -1
  58. package/dist/components/context-menu/context-menu.d.ts +23 -0
  59. package/dist/components/context-menu/context-menu.js +50 -0
  60. package/dist/components/conversation/conversation.d.ts +45 -0
  61. package/dist/components/conversation/conversation.js +295 -0
  62. package/dist/components/conversation/stick.js +23 -0
  63. package/dist/components/copy-button/copy-button.d.ts +50 -0
  64. package/dist/components/copy-button/copy-button.js +65 -0
  65. package/dist/components/copy-page/copy-page.d.ts +4 -4
  66. package/dist/components/copy-page/copy-page.js +16 -36
  67. package/dist/components/copy-pill/copy-pill.js +1 -1
  68. package/dist/components/description-list/description-list.d.ts +32 -0
  69. package/dist/components/description-list/description-list.js +51 -0
  70. package/dist/components/empty/empty.d.ts +38 -0
  71. package/dist/components/empty/empty.js +57 -0
  72. package/dist/components/field/field.js +1 -1
  73. package/dist/components/file-upload/file-upload.d.ts +96 -0
  74. package/dist/components/file-upload/file-upload.js +347 -0
  75. package/dist/components/file-upload/files.d.ts +39 -0
  76. package/dist/components/file-upload/files.js +74 -0
  77. package/dist/components/grow/grow.d.ts +15 -3
  78. package/dist/components/grow/grow.js +24 -9
  79. package/dist/components/heading/heading.d.ts +1 -1
  80. package/dist/components/icon/icon.d.ts +1 -1
  81. package/dist/components/input/input.js +1 -1
  82. package/dist/components/menu/menu.d.ts +20 -8
  83. package/dist/components/menu/menu.js +51 -29
  84. package/dist/components/message/message.d.ts +81 -0
  85. package/dist/components/message/message.js +208 -0
  86. package/dist/components/navigation-menu/navigation-menu.d.ts +7 -1
  87. package/dist/components/navigation-menu/navigation-menu.js +11 -4
  88. package/dist/components/otp-field/otp-field.d.ts +37 -0
  89. package/dist/components/otp-field/otp-field.js +161 -0
  90. package/dist/components/pagination/pagination.d.ts +50 -0
  91. package/dist/components/pagination/pagination.js +188 -0
  92. package/dist/components/prompt-input/keys.js +15 -0
  93. package/dist/components/prompt-input/prompt-input.d.ts +89 -0
  94. package/dist/components/prompt-input/prompt-input.js +331 -0
  95. package/dist/components/radio-card/radio-card.d.ts +23 -0
  96. package/dist/components/radio-card/radio-card.js +49 -0
  97. package/dist/components/rolling-number/rolling-number.d.ts +30 -0
  98. package/dist/components/rolling-number/rolling-number.js +149 -0
  99. package/dist/components/seam/seam.d.ts +1 -1
  100. package/dist/components/secret-field/secret-field.d.ts +53 -0
  101. package/dist/components/secret-field/secret-field.js +121 -0
  102. package/dist/components/section/section.d.ts +1 -1
  103. package/dist/components/segmented-control/segmented-control.js +29 -16
  104. package/dist/components/select/select.d.ts +5 -4
  105. package/dist/components/select/select.js +16 -11
  106. package/dist/components/shortcut/shortcut.d.ts +46 -0
  107. package/dist/components/shortcut/shortcut.js +87 -0
  108. package/dist/components/sidebar/sidebar-context.js +16 -0
  109. package/dist/components/sidebar/sidebar.d.ts +161 -0
  110. package/dist/components/sidebar/sidebar.js +588 -0
  111. package/dist/components/site-header/site-header.js +1 -1
  112. package/dist/components/skeleton/loaded.d.ts +21 -0
  113. package/dist/components/skeleton/loaded.js +57 -0
  114. package/dist/components/skeleton/skeleton.d.ts +43 -0
  115. package/dist/components/skeleton/skeleton.js +48 -0
  116. package/dist/components/sources/source-list.d.ts +17 -0
  117. package/dist/components/sources/source-list.js +26 -0
  118. package/dist/components/sources/sources.d.ts +45 -0
  119. package/dist/components/sources/sources.js +167 -0
  120. package/dist/components/stat/stat.d.ts +59 -0
  121. package/dist/components/stat/stat.js +112 -0
  122. package/dist/components/steps/steps.d.ts +57 -0
  123. package/dist/components/steps/steps.js +134 -0
  124. package/dist/components/table/table.d.ts +18 -9
  125. package/dist/components/table/table.js +21 -13
  126. package/dist/components/text/text.d.ts +1 -1
  127. package/dist/components/theme-switch/theme-switch.js +1 -1
  128. package/dist/components/time-field/time-field.js +7 -6
  129. package/dist/components/timeline/timeline.d.ts +45 -0
  130. package/dist/components/timeline/timeline.js +86 -0
  131. package/dist/components/toast/toast.js +10 -26
  132. package/dist/components/toggle/toggle.d.ts +27 -0
  133. package/dist/components/toggle/toggle.js +61 -0
  134. package/dist/components/toggle-group/toggle-group.d.ts +27 -0
  135. package/dist/components/toggle-group/toggle-group.js +38 -0
  136. package/dist/components/toolbar/toolbar-context.js +12 -0
  137. package/dist/components/toolbar/toolbar.d.ts +52 -0
  138. package/dist/components/toolbar/toolbar.js +105 -0
  139. package/dist/components/trace/trace.d.ts +2 -1
  140. package/dist/components/trace/trace.js +15 -27
  141. package/dist/index.d.ts +46 -3
  142. package/dist/index.js +44 -3
  143. package/dist/internal/arriving-pieces.js +56 -0
  144. package/dist/internal/arriving.js +171 -0
  145. package/dist/internal/avatar-cut.d.ts +15 -0
  146. package/dist/internal/avatar-cut.js +83 -0
  147. package/dist/internal/choice-card.d.ts +15 -0
  148. package/dist/internal/choice-card.js +81 -0
  149. package/dist/internal/clipboard.js +37 -0
  150. package/dist/internal/copy.js +58 -0
  151. package/dist/internal/disclosure.js +15 -3
  152. package/dist/internal/field.js +24 -4
  153. package/dist/internal/glyphs.js +26 -1
  154. package/dist/internal/key-tip.js +18 -0
  155. package/dist/internal/list-mark.js +39 -0
  156. package/dist/internal/live-list.js +41 -0
  157. package/dist/internal/number-places.js +157 -0
  158. package/dist/internal/picker-sheet.js +1 -1
  159. package/dist/internal/presence-dot.js +24 -0
  160. package/dist/internal/presence.js +104 -0
  161. package/dist/internal/rail-mark.d.ts +3 -0
  162. package/dist/internal/rail-mark.js +33 -0
  163. package/dist/internal/rule.js +2 -1
  164. package/dist/internal/status-icon.js +22 -0
  165. package/dist/internal/tile.js +23 -0
  166. package/dist/internal/travelling-mark.js +204 -0
  167. package/dist/lib/cn.js +10 -0
  168. package/dist/lib/shortcut.d.ts +11 -0
  169. package/dist/lib/shortcut.js +165 -0
  170. package/package.json +1 -1
  171. package/src/styles/accordion.css +176 -0
  172. package/src/styles/action-bar.css +28 -0
  173. package/src/styles/assistant.css +83 -0
  174. package/src/styles/avatar.css +24 -0
  175. package/src/styles/consent.css +65 -0
  176. package/src/styles/copy.css +12 -11
  177. package/src/styles/depth.css +120 -4
  178. package/src/styles/marks.css +20 -2
  179. package/src/styles/motion.css +3 -0
  180. package/src/styles/rail.css +49 -0
  181. package/src/styles/rolling-number.css +94 -0
  182. package/src/styles/segmented.css +14 -7
  183. package/src/styles/steps.css +98 -0
  184. package/src/styles/timeline.css +48 -0
  185. package/src/styles/travel.css +36 -0
  186. package/src/styles.css +10 -0
@@ -0,0 +1,295 @@
1
+ "use client";
2
+ import { Button } from "../button/button.js";
3
+ import { Icon } from "../icon/icon.js";
4
+ import { useScrollEdges } from "../scroll-fade/use-scroll-edges.js";
5
+ import { useLive } from "../../internal/presence.js";
6
+ import { cn } from "../../lib/cn.js";
7
+ import { atRest, springForce, stepSpring } from "../../motion/spring-step.js";
8
+ import { springs } from "../../motion/springs.js";
9
+ import { aboveFoot, footOf, glideFrom, movesUp } from "./stick.js";
10
+ import { jsx, jsxs } from "react/jsx-runtime";
11
+ import { createContext, useCallback, useContext, useLayoutEffect, useMemo, useRef, useState } from "react";
12
+ import { ArrowDown01Icon } from "@hugeicons/core-free-icons";
13
+ // src/components/conversation/conversation.tsx
14
+ const ConversationContext = createContext(null);
15
+ /** The conversation around a part, if there is one. */
16
+ function useConversation() {
17
+ return useContext(ConversationContext);
18
+ }
19
+ const SharedContext = createContext(null);
20
+ /**
21
+ * A conversation with an assistant: the messages in a scroller that keeps to its foot while an
22
+ * answer is written, and the key that leads back there. Put a `ConversationContent` inside with
23
+ * the `Message`s, and a `ConversationLatest` after it. Give the conversation its height (`h-full`
24
+ * in a column, `flex-1`); the prompt stands below it, outside.
25
+ *
26
+ * At the foot, what joins is followed: the view glides down with the answer as it grows. The
27
+ * reader who scrolls up, presses a scroll key or opens a fold inside an answer is left where
28
+ * they are, and the key „Neueste“ appears; it leads back and keeps to the foot again, and so
29
+ * does sending a prompt. A finished answer is announced once, not word by word.
30
+ */
31
+ function Conversation({ className, children, ...props }) {
32
+ const engine = useRef(null);
33
+ const [away, setAway] = useState(false);
34
+ const [said, setSaid] = useState("");
35
+ const live = useLive();
36
+ const api = useMemo(() => ({
37
+ toLatest: () => engine.current?.toLatest(false),
38
+ announce: setSaid,
39
+ live
40
+ }), [live]);
41
+ const register = useCallback((next) => {
42
+ engine.current = next;
43
+ return () => {
44
+ if (engine.current === next) engine.current = null;
45
+ };
46
+ }, []);
47
+ const shared = useMemo(() => ({
48
+ register,
49
+ engine,
50
+ away,
51
+ setAway
52
+ }), [register, away]);
53
+ return /* @__PURE__ */ jsx(ConversationContext, {
54
+ value: api,
55
+ children: /* @__PURE__ */ jsx(SharedContext, {
56
+ value: shared,
57
+ children: /* @__PURE__ */ jsxs("div", {
58
+ "data-slot": "conversation",
59
+ className: cn("relative flex min-h-0 flex-col", "rounded-sm has-[[data-slot=conversation-scroller]:focus-visible]:outline-2 has-[[data-slot=conversation-scroller]:focus-visible]:outline-offset-2 has-[[data-slot=conversation-scroller]:focus-visible]:outline-accent", className),
60
+ ...props,
61
+ children: [children, /* @__PURE__ */ jsx("div", {
62
+ "data-slot": "conversation-announcer",
63
+ role: "status",
64
+ className: "sr-only",
65
+ children: said
66
+ })]
67
+ })
68
+ })
69
+ });
70
+ }
71
+ /**
72
+ * The messages, in a box that scrolls. `className` lays out what it holds (the column's width,
73
+ * its padding, the room between messages); the box itself fills the conversation.
74
+ */
75
+ function ConversationContent({ label = "Unterhaltung", className, children, ...props }) {
76
+ const shared = useContext(SharedContext);
77
+ const scroller = useRef(null);
78
+ const content = useRef(null);
79
+ const live = useLive();
80
+ useScrollEdges(scroller, "y");
81
+ const report = shared?.setAway;
82
+ const register = shared?.register;
83
+ useLayoutEffect(() => {
84
+ const box = scroller.current;
85
+ const inner = content.current;
86
+ if (!box || !inner) return;
87
+ const reduced = window.matchMedia("(prefers-reduced-motion: reduce)");
88
+ const force = springForce(springs.settle);
89
+ const setAway = (away) => report?.(away);
90
+ /** Whether the view keeps to the foot as what it holds grows. */
91
+ let following = true;
92
+ let frame = 0;
93
+ let moving = null;
94
+ let lastFrame = 0;
95
+ /** Where the view was last put by this code, so the scroll it causes is not the reader's. */
96
+ let written = NaN;
97
+ /** A finger is on the screen: nothing is written under it. */
98
+ let touching = false;
99
+ const write = (top) => {
100
+ box.scrollTop = top;
101
+ written = box.scrollTop;
102
+ };
103
+ const stop = () => {
104
+ cancelAnimationFrame(frame);
105
+ frame = 0;
106
+ moving = null;
107
+ };
108
+ const step = (now) => {
109
+ frame = 0;
110
+ if (!following || touching) {
111
+ moving = null;
112
+ return;
113
+ }
114
+ const goal = footOf(box);
115
+ const seconds = lastFrame ? (now - lastFrame) / 1e3 : 1 / 60;
116
+ lastFrame = now;
117
+ moving = stepSpring(moving ?? {
118
+ value: box.scrollTop,
119
+ velocity: 0
120
+ }, goal, force, seconds);
121
+ if (atRest(moving, goal, .5)) {
122
+ write(goal);
123
+ moving = null;
124
+ return;
125
+ }
126
+ write(moving.value);
127
+ frame = requestAnimationFrame(step);
128
+ };
129
+ /** Follows the foot on `settle`, from where the view is or already moves. */
130
+ const glide = () => {
131
+ if (!following || touching) return;
132
+ if (reduced.matches) {
133
+ write(footOf(box));
134
+ return;
135
+ }
136
+ if (frame || aboveFoot(box) < .5) return;
137
+ lastFrame = 0;
138
+ frame = requestAnimationFrame(step);
139
+ };
140
+ /**
141
+ * While the view keeps to the foot, the browser must not anchor it to a line further up
142
+ * (it would move the view when something above changes size, and that move would read as
143
+ * the reader's). Left alone, the reader keeps the browser's anchoring: what they read stays
144
+ * put when an answer above opens a fold.
145
+ */
146
+ const keep = (next) => {
147
+ following = next;
148
+ box.style.overflowAnchor = next ? "none" : "";
149
+ };
150
+ const leave = () => {
151
+ if (!following) return;
152
+ keep(false);
153
+ stop();
154
+ setAway(aboveFoot(box) > 4);
155
+ };
156
+ keep(true);
157
+ write(footOf(box));
158
+ const onScroll = () => {
159
+ if (Math.abs(box.scrollTop - written) < 1) return;
160
+ written = NaN;
161
+ if (aboveFoot(box) <= 4) {
162
+ if (!following) {
163
+ keep(true);
164
+ setAway(false);
165
+ }
166
+ return;
167
+ }
168
+ if (following) {
169
+ keep(false);
170
+ stop();
171
+ }
172
+ setAway(true);
173
+ };
174
+ const onWheel = (event) => {
175
+ if (event.deltaY < 0) leave();
176
+ };
177
+ const onKeyDown = (event) => {
178
+ if (event.target.closest("input, textarea, select, [contenteditable='true']")) return;
179
+ if (movesUp(event)) leave();
180
+ };
181
+ const onTouchStart = () => {
182
+ touching = true;
183
+ stop();
184
+ };
185
+ const onTouchEnd = () => {
186
+ touching = false;
187
+ glide();
188
+ };
189
+ const onClick = (event) => {
190
+ if (event.target.closest("[aria-expanded=\"false\"], summary")) leave();
191
+ };
192
+ let opened = false;
193
+ const grown = new ResizeObserver(() => {
194
+ if (!opened) {
195
+ opened = true;
196
+ if (following) write(footOf(box));
197
+ return;
198
+ }
199
+ if (following) glide();
200
+ else setAway(aboveFoot(box) > 4);
201
+ });
202
+ grown.observe(inner);
203
+ const resized = new ResizeObserver(() => {
204
+ if (following && !touching) {
205
+ stop();
206
+ write(footOf(box));
207
+ }
208
+ });
209
+ resized.observe(box);
210
+ box.addEventListener("scroll", onScroll, { passive: true });
211
+ box.addEventListener("wheel", onWheel, { passive: true });
212
+ box.addEventListener("keydown", onKeyDown);
213
+ box.addEventListener("touchstart", onTouchStart, { passive: true });
214
+ box.addEventListener("touchend", onTouchEnd);
215
+ box.addEventListener("touchcancel", onTouchEnd);
216
+ inner.addEventListener("click", onClick, { capture: true });
217
+ const unregister = register?.({ toLatest: (focus) => {
218
+ keep(true);
219
+ setAway(false);
220
+ if (focus) box.focus({ preventScroll: true });
221
+ if (reduced.matches) {
222
+ write(footOf(box));
223
+ return;
224
+ }
225
+ const from = glideFrom(box);
226
+ if (Math.abs(from - box.scrollTop) >= 1) {
227
+ stop();
228
+ write(from);
229
+ }
230
+ glide();
231
+ } });
232
+ return () => {
233
+ unregister?.();
234
+ stop();
235
+ grown.disconnect();
236
+ resized.disconnect();
237
+ box.removeEventListener("scroll", onScroll);
238
+ box.removeEventListener("wheel", onWheel);
239
+ box.removeEventListener("keydown", onKeyDown);
240
+ box.removeEventListener("touchstart", onTouchStart);
241
+ box.removeEventListener("touchend", onTouchEnd);
242
+ box.removeEventListener("touchcancel", onTouchEnd);
243
+ inner.removeEventListener("click", onClick, { capture: true });
244
+ };
245
+ }, [report, register]);
246
+ return /* @__PURE__ */ jsx("div", {
247
+ ref: scroller,
248
+ "data-slot": "conversation-scroller",
249
+ "data-scroll-fade": "y",
250
+ "data-fade-edges": shared?.away ? void 0 : "start",
251
+ role: "region",
252
+ "aria-label": label,
253
+ tabIndex: 0,
254
+ className: "min-h-0 flex-1 overflow-y-auto overscroll-contain focus-visible:outline-hidden",
255
+ children: /* @__PURE__ */ jsx("div", {
256
+ ref: content,
257
+ "data-slot": "conversation-content",
258
+ "data-live": live ? "" : void 0,
259
+ className: cn("flex flex-col gap-8", className),
260
+ ...props,
261
+ children
262
+ })
263
+ });
264
+ }
265
+ /**
266
+ * The key that leads back to the newest message. It stands centred above the conversation's
267
+ * foot and only while the reader has left it: it rises in on `settle` and leaves by fading.
268
+ * Pressed, the view glides back down (from far up it jumps closer first), keeps to the foot
269
+ * again, and the keyboard focus goes to the conversation.
270
+ */
271
+ function ConversationLatest({ label = "Neueste", className, ...props }) {
272
+ const shared = useContext(SharedContext);
273
+ const shown = shared?.away ?? false;
274
+ return /* @__PURE__ */ jsx("div", {
275
+ "data-slot": "conversation-latest-place",
276
+ className: "pointer-events-none absolute inset-x-0 bottom-3 flex justify-center",
277
+ children: /* @__PURE__ */ jsx("span", {
278
+ "data-slot": "conversation-latest",
279
+ "data-shown": shown ? "" : void 0,
280
+ inert: !shown,
281
+ className: cn("pointer-events-auto", className),
282
+ ...props,
283
+ children: /* @__PURE__ */ jsxs(Button, {
284
+ size: "sm",
285
+ variant: "secondary",
286
+ onClick: () => shared?.engine.current?.toLatest(true),
287
+ children: [/* @__PURE__ */ jsx(Icon, {
288
+ icon: ArrowDown01Icon,
289
+ size: 14
290
+ }), label]
291
+ })
292
+ })
293
+ });
294
+ }
295
+ export { Conversation, ConversationContent, ConversationLatest, useConversation };
@@ -0,0 +1,23 @@
1
+ // src/components/conversation/stick.ts
2
+ /** How far the view stands above the foot of what it holds, in px. Never below nothing. */
3
+ function aboveFoot({ scrollTop, scrollHeight, clientHeight }) {
4
+ return Math.max(0, scrollHeight - clientHeight - scrollTop);
5
+ }
6
+ /** Where the view stands at the foot. */
7
+ function footOf({ scrollHeight, clientHeight }) {
8
+ return Math.max(0, scrollHeight - clientHeight);
9
+ }
10
+ /** Keys that move a scrolling box up, read where the keyboard is not in a text field. */
11
+ function movesUp(event) {
12
+ return event.key === "ArrowUp" || event.key === "PageUp" || event.key === "Home" || event.key === " " && event.shiftKey;
13
+ }
14
+ /**
15
+ * Where a way back to the foot starts gliding. A long way is not glided all the way: from more
16
+ * than three screens up the view jumps to one screen above the foot and glides the rest, so the
17
+ * reader sees the motion without waiting for it.
18
+ */
19
+ function glideFrom(box) {
20
+ if (aboveFoot(box) <= box.clientHeight * 3) return box.scrollTop;
21
+ return footOf(box) - box.clientHeight;
22
+ }
23
+ export { aboveFoot, footOf, glideFrom, movesUp };
@@ -0,0 +1,50 @@
1
+ import { ButtonProps } from "../button/button.js";
2
+ import { ComponentProps, ReactNode, RefObject } from "react";
3
+ /** The words of a key that copies. */
4
+ export type CopyButtonLabels = {
5
+ /** The key's name and its tooltip: worded like a button ("Schlüssel kopieren"). */
6
+ copyLabel?: string;
7
+ /** The tooltip once the text is on the clipboard. */
8
+ copiedLabel?: string;
9
+ /** Read out once the text is on the clipboard: a full sentence. */
10
+ copiedMessage?: string;
11
+ /** The tooltip when the clipboard refused. */
12
+ failedLabel?: string;
13
+ /** Read out when the clipboard refused: a full sentence that says what to do now. */
14
+ failedMessage?: string;
15
+ };
16
+ export type CopyButtonProps = Omit<ComponentProps<"span">, "children"> & CopyButtonLabels & {
17
+ /**
18
+ * What goes on the clipboard: the text, or a function that gives it. The function may
19
+ * return a promise (a secret fetched on demand); it is called inside the press.
20
+ */
21
+ text: string | (() => string | Promise<string>);
22
+ /**
23
+ * The element that shows the text. When the browser refuses the clipboard it is selected
24
+ * instead, so ⌘C still works: a field's text, or everything inside any other element.
25
+ */
26
+ selectTarget?: RefObject<HTMLElement | null>;
27
+ /** Called once the text has reached the clipboard. */
28
+ onCopied?: () => void;
29
+ size?: "sm" | "md" | "lg";
30
+ /** `quiet` (the default) beside what it copies; `secondary` where it stands on its own. */
31
+ variant?: ButtonProps["variant"];
32
+ disabled?: boolean;
33
+ /**
34
+ * Words beside the symbol ("Link kopieren"). Without them it is a square key with a
35
+ * tooltip.
36
+ */
37
+ children?: ReactNode;
38
+ };
39
+ /**
40
+ * A key that copies: an API key, an address, an invitation link, a sentence. The copy symbol
41
+ * shrinks away and a tick is drawn in its place, the tooltip says that it worked, and a screen
42
+ * reader hears it once. After a moment the symbol seats back. No word appears beside the key
43
+ * and there is no toast.
44
+ *
45
+ * When the browser refuses the clipboard (a page without HTTPS, a missing permission), the
46
+ * `selectTarget` is selected instead and the key says so. Name the key after what it copies
47
+ * (`copyLabel`), not after the mechanism. `className` goes to the box around the key, for its
48
+ * place in a row.
49
+ */
50
+ export declare function CopyButton({ text, selectTarget, onCopied, size, variant, disabled, copyLabel, copiedLabel, copiedMessage, failedLabel, failedMessage, className, children, ...props }: CopyButtonProps): import("react").JSX.Element;
@@ -0,0 +1,65 @@
1
+ "use client";
2
+ import { Button } from "../button/button.js";
3
+ import { Tooltip, TooltipContent, TooltipTrigger } from "../tooltip/tooltip.js";
4
+ import { CopyMarks, useCopy } from "../../internal/copy.js";
5
+ import { cn } from "../../lib/cn.js";
6
+ import { jsx, jsxs } from "react/jsx-runtime";
7
+ // src/components/copy-button/copy-button.tsx
8
+ const symbolSize = {
9
+ sm: 14,
10
+ md: 16,
11
+ lg: 18
12
+ };
13
+ /**
14
+ * A key that copies: an API key, an address, an invitation link, a sentence. The copy symbol
15
+ * shrinks away and a tick is drawn in its place, the tooltip says that it worked, and a screen
16
+ * reader hears it once. After a moment the symbol seats back. No word appears beside the key
17
+ * and there is no toast.
18
+ *
19
+ * When the browser refuses the clipboard (a page without HTTPS, a missing permission), the
20
+ * `selectTarget` is selected instead and the key says so. Name the key after what it copies
21
+ * (`copyLabel`), not after the mechanism. `className` goes to the box around the key, for its
22
+ * place in a row.
23
+ */
24
+ function CopyButton({ text, selectTarget, onCopied, size = "md", variant = "quiet", disabled, copyLabel = "Kopieren", copiedLabel = "Kopiert", copiedMessage = "In die Zwischenablage kopiert.", failedLabel = selectTarget ? "Markiert" : "Nicht kopiert", failedMessage = selectTarget ? "Nicht kopiert. Der Text ist markiert und kann mit ⌘C kopiert werden." : "Nicht kopiert. Der Browser hat den Zugriff auf die Zwischenablage abgelehnt.", className, children, ...props }) {
25
+ const { state, copy } = useCopy({
26
+ text,
27
+ selectTarget,
28
+ onCopied
29
+ });
30
+ const marks = /* @__PURE__ */ jsx(CopyMarks, {
31
+ copied: state === "copied",
32
+ size: symbolSize[size]
33
+ });
34
+ const word = state === "failed" ? failedLabel : copiedLabel;
35
+ return /* @__PURE__ */ jsxs("span", {
36
+ "data-slot": "copy-button",
37
+ "data-state": state,
38
+ className: cn("relative inline-flex items-center", className),
39
+ ...props,
40
+ children: [children === void 0 ? /* @__PURE__ */ jsxs(Tooltip, { children: [/* @__PURE__ */ jsx(TooltipTrigger, {
41
+ closeOnClick: false,
42
+ render: /* @__PURE__ */ jsx(Button, {
43
+ iconOnly: true,
44
+ size,
45
+ variant,
46
+ disabled,
47
+ "aria-label": copyLabel,
48
+ onClick: () => void copy(),
49
+ className: variant === "quiet" ? "text-fg-muted hover:text-fg" : void 0,
50
+ children: marks
51
+ })
52
+ }), /* @__PURE__ */ jsx(TooltipContent, { children: state === "idle" ? copyLabel : word })] }) : /* @__PURE__ */ jsxs(Button, {
53
+ size,
54
+ variant,
55
+ disabled,
56
+ onClick: () => void copy(),
57
+ children: [marks, children]
58
+ }), /* @__PURE__ */ jsx("span", {
59
+ role: "status",
60
+ className: "sr-only",
61
+ children: state === "copied" ? copiedMessage : state === "failed" ? failedMessage : ""
62
+ })]
63
+ });
64
+ }
65
+ export { CopyButton };
@@ -27,10 +27,10 @@ export type CopyPageProps = Omit<ComponentProps<"div">, "children" | "aria-label
27
27
  * menu repeats it with a line on what it is, and opens the Markdown in a new tab. Put it at the
28
28
  * end of the row above the page's title.
29
29
  *
30
- * It is a `ButtonGroup`, named by its `label`: one part with two keys, so it moves as one: under the pointer the whole fitting lifts,
31
- * and the key under it takes the hover wash. Pressed, the fitting goes down and drops its
32
- * ambient shadow, and only the pressed key takes the inner shade, so it rocks on that key and the
33
- * other keeps its gloss. A copy is confirmed in the key, as in a code block: the copy symbol
30
+ * It is a `ButtonGroup`, named by its `label`: one part with two keys. Under the pointer the whole
31
+ * fitting lifts and the key under it takes the hover wash; a press moves only the pressed key,
32
+ * which takes the inner shade and goes down while the fitting and the other key stay where they
33
+ * are. A copy is confirmed in the key, as in a code block: the copy symbol
34
34
  * shrinks away and the tick draws itself, short leg first, then fades where it stands while the
35
35
  * symbol seats back. There is no toast; a screen reader hears one sentence.
36
36
  *
@@ -4,25 +4,26 @@ import { ButtonGroup } from "../button-group/button-group.js";
4
4
  import { Icon } from "../icon/icon.js";
5
5
  import { MenuContent, MenuItem, MenuLinkItem } from "../menu/menu.js";
6
6
  import { ActionArrow } from "../../internal/arrow.js";
7
+ import { writeClipboard } from "../../internal/clipboard.js";
8
+ import { COPY_SHOWN_MS } from "../../internal/copy.js";
7
9
  import { ChevronDownGlyph, TickGlyph } from "../../internal/glyphs.js";
10
+ import { Tile } from "../../internal/tile.js";
8
11
  import { cn } from "../../lib/cn.js";
9
12
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
10
- import { Copy01Icon } from "@hugeicons/core-free-icons";
11
13
  import { useEffect, useRef, useState } from "react";
14
+ import { Copy01Icon } from "@hugeicons/core-free-icons";
12
15
  import { Menu } from "@base-ui/react/menu";
13
16
  // src/components/copy-page/copy-page.tsx
14
- /** How long a copy stays confirmed before the symbol comes back, in ms (as in a code block). */
15
- const CONFIRM_MS = 1600;
16
17
  /**
17
18
  * Hands a docs page on as Markdown: one raised fitting split in two, the copy and the menu. The
18
19
  * copy fetches the page's Markdown and puts it on the clipboard, for a model or an agent; the
19
20
  * menu repeats it with a line on what it is, and opens the Markdown in a new tab. Put it at the
20
21
  * end of the row above the page's title.
21
22
  *
22
- * It is a `ButtonGroup`, named by its `label`: one part with two keys, so it moves as one: under the pointer the whole fitting lifts,
23
- * and the key under it takes the hover wash. Pressed, the fitting goes down and drops its
24
- * ambient shadow, and only the pressed key takes the inner shade, so it rocks on that key and the
25
- * other keeps its gloss. A copy is confirmed in the key, as in a code block: the copy symbol
23
+ * It is a `ButtonGroup`, named by its `label`: one part with two keys. Under the pointer the whole
24
+ * fitting lifts and the key under it takes the hover wash; a press moves only the pressed key,
25
+ * which takes the inner shade and goes down while the fitting and the other key stay where they
26
+ * are. A copy is confirmed in the key, as in a code block: the copy symbol
26
27
  * shrinks away and the tick draws itself, short leg first, then fades where it stands while the
27
28
  * symbol seats back. There is no toast; a screen reader hears one sentence.
28
29
  *
@@ -50,26 +51,16 @@ function CopyPage({ href, label, description, viewLabel, viewDescription, moreLa
50
51
  const settle = (next) => {
51
52
  clearTimeout(timer.current);
52
53
  setState(next);
53
- timer.current = setTimeout(() => setState("idle"), CONFIRM_MS);
54
+ timer.current = setTimeout(() => setState("idle"), COPY_SHOWN_MS);
54
55
  };
55
56
  async function copy() {
56
- const text = load();
57
57
  try {
58
- if (typeof ClipboardItem !== "undefined" && navigator.clipboard?.write) {
59
- const blob = text.then((body) => new Blob([body], { type: "text/plain" }));
60
- await navigator.clipboard.write([new ClipboardItem({ "text/plain": blob })]);
61
- } else await navigator.clipboard.writeText(await text);
58
+ await writeClipboard(load());
62
59
  settle("copied");
63
60
  onCopied?.();
64
61
  } catch {
65
- try {
66
- await navigator.clipboard.writeText(await text);
67
- settle("copied");
68
- onCopied?.();
69
- } catch {
70
- markdown.current = void 0;
71
- settle("failed");
72
- }
62
+ markdown.current = void 0;
63
+ settle("failed");
73
64
  }
74
65
  }
75
66
  const isCopied = state === "copied";
@@ -129,10 +120,7 @@ function CopyPage({ href, label, description, viewLabel, viewDescription, moreLa
129
120
  children: [/* @__PURE__ */ jsxs(MenuItem, {
130
121
  onClick: () => void copy(),
131
122
  className: row,
132
- children: [/* @__PURE__ */ jsx(Tile, { children: /* @__PURE__ */ jsx(Icon, {
133
- icon: Copy01Icon,
134
- size: 16
135
- }) }), /* @__PURE__ */ jsx(RowText, {
123
+ children: [/* @__PURE__ */ jsx(Tile, { icon: Copy01Icon }), /* @__PURE__ */ jsx(RowText, {
136
124
  title: label,
137
125
  description
138
126
  })]
@@ -162,14 +150,6 @@ function CopyPage({ href, label, description, viewLabel, viewDescription, moreLa
162
150
  }
163
151
  /** A row of the menu: a tile, then two lines. It keeps the list's instant highlight. */
164
152
  const row = "group/row items-center gap-3 px-2 py-2";
165
- function Tile({ children }) {
166
- return /* @__PURE__ */ jsx("span", {
167
- "aria-hidden": true,
168
- "data-slot": "copy-page-tile",
169
- className: "flex size-8 shrink-0 items-center justify-center rounded-md bg-surface text-fg-muted inset-ring inset-ring-hairline group-data-highlighted/row:text-fg forced-colors:inset-ring-[CanvasText]",
170
- children
171
- });
172
- }
173
153
  function RowText({ title, description }) {
174
154
  return /* @__PURE__ */ jsxs("span", {
175
155
  className: "flex min-w-0 flex-col gap-0.5",
@@ -186,12 +166,12 @@ function RowText({ title, description }) {
186
166
  function MarkdownGlyph(props) {
187
167
  return /* @__PURE__ */ jsxs("svg", {
188
168
  "aria-hidden": true,
189
- width: 16,
190
- height: 16,
169
+ width: 18,
170
+ height: 18,
191
171
  viewBox: "0 0 24 24",
192
172
  fill: "none",
193
173
  stroke: "currentColor",
194
- strokeWidth: 1.5,
174
+ strokeWidth: 2,
195
175
  strokeLinecap: "round",
196
176
  strokeLinejoin: "round",
197
177
  ...props,
@@ -7,8 +7,8 @@ import { cn } from "../../lib/cn.js";
7
7
  import { restingMotion, trackMotion } from "../../motion/inertia.js";
8
8
  import { springs } from "../../motion/springs.js";
9
9
  import { jsx, jsxs } from "react/jsx-runtime";
10
- import { Copy01Icon } from "@hugeicons/core-free-icons";
11
10
  import { Children, useEffect, useId, useLayoutEffect, useRef, useState } from "react";
11
+ import { Copy01Icon } from "@hugeicons/core-free-icons";
12
12
  // src/components/copy-pill/copy-pill.tsx
13
13
  /** How long a copy stays confirmed, in ms. */
14
14
  const CONFIRM_MS = 2e3;
@@ -0,0 +1,32 @@
1
+ import { ComponentProps, ReactNode } from "react";
2
+ export type DescriptionListProps = ComponentProps<"dl"> & {
3
+ /**
4
+ * Whether the 2px rule opens the list. It does on a page; inside a `Card`, whose edge already
5
+ * opens it, leave it out.
6
+ */
7
+ rule?: boolean;
8
+ };
9
+ /**
10
+ * The facts of one record: customer, number, valid until, total. A real `<dl>`: each
11
+ * `DescriptionTerm` is followed by its `DescriptionDetails`. The label stands muted in a column of
12
+ * its own and the value beside it; hairlines divide the rows, and the 2px rule opens the list.
13
+ * On a phone the value goes under its label.
14
+ *
15
+ * Digits are tabular only where they form a column down the list (amounts under each other):
16
+ * give those details `tabular-nums`. The column of labels is 12rem; set `--dl-term` to change
17
+ * it. For the parameters of an API in the docs, use `ParameterList`.
18
+ *
19
+ * Server-safe.
20
+ */
21
+ export declare function DescriptionList({ rule, className, ...props }: DescriptionListProps): import("react").JSX.Element;
22
+ /** What the value is: „Kunde“, „Gültig bis“. A few words, no colon. */
23
+ export declare function DescriptionTerm({ className, ...props }: ComponentProps<"dt">): import("react").JSX.Element;
24
+ export type DescriptionDetailsProps = ComponentProps<"dd"> & {
25
+ /**
26
+ * Something to do with the value, at the end of its row: a `CopyButton` for a number someone
27
+ * will paste elsewhere, a link to the record.
28
+ */
29
+ action?: ReactNode;
30
+ };
31
+ /** The value. It may wrap; a long one (an IBAN, an address) breaks where it must. */
32
+ export declare function DescriptionDetails({ action, className, children, ...props }: DescriptionDetailsProps): import("react").JSX.Element;
@@ -0,0 +1,51 @@
1
+ import { ruleTop } from "../../internal/rule.js";
2
+ import { cn } from "../../lib/cn.js";
3
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
4
+ // src/components/description-list/description-list.tsx
5
+ /**
6
+ * The facts of one record: customer, number, valid until, total. A real `<dl>`: each
7
+ * `DescriptionTerm` is followed by its `DescriptionDetails`. The label stands muted in a column of
8
+ * its own and the value beside it; hairlines divide the rows, and the 2px rule opens the list.
9
+ * On a phone the value goes under its label.
10
+ *
11
+ * Digits are tabular only where they form a column down the list (amounts under each other):
12
+ * give those details `tabular-nums`. The column of labels is 12rem; set `--dl-term` to change
13
+ * it. For the parameters of an API in the docs, use `ParameterList`.
14
+ *
15
+ * Server-safe.
16
+ */
17
+ function DescriptionList({ rule = true, className, ...props }) {
18
+ return /* @__PURE__ */ jsx("div", {
19
+ "data-slot": "description-list-frame",
20
+ className: "@container/dl",
21
+ children: /* @__PURE__ */ jsx("dl", {
22
+ "data-slot": "description-list",
23
+ className: cn("grid text-control @sm/dl:grid-cols-[minmax(0,var(--dl-term,12rem))_minmax(0,1fr)]", "[&>:last-child]:border-b-0 @sm/dl:[&>:nth-last-child(-n+2)]:border-b-0", rule && ruleTop, className),
24
+ ...props
25
+ })
26
+ });
27
+ }
28
+ /** What the value is: „Kunde“, „Gültig bis“. A few words, no colon. */
29
+ function DescriptionTerm({ className, ...props }) {
30
+ return /* @__PURE__ */ jsx("dt", {
31
+ "data-slot": "description-term",
32
+ className: cn("min-w-0 pt-3 text-fg-muted @sm/dl:border-b @sm/dl:border-hairline @sm/dl:py-3 @sm/dl:pr-6", className),
33
+ ...props
34
+ });
35
+ }
36
+ /** The value. It may wrap; a long one (an IBAN, an address) breaks where it must. */
37
+ function DescriptionDetails({ action, className, children, ...props }) {
38
+ return /* @__PURE__ */ jsx("dd", {
39
+ "data-slot": "description-details",
40
+ className: cn("min-w-0 border-b border-hairline pt-0.5 pb-3 break-words text-fg @sm/dl:py-3", action !== void 0 && "flex items-start justify-between gap-3", className),
41
+ ...props,
42
+ children: action !== void 0 ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("div", {
43
+ className: "min-w-0",
44
+ children
45
+ }), /* @__PURE__ */ jsx("div", {
46
+ className: "-my-1 shrink-0",
47
+ children: action
48
+ })] }) : children
49
+ });
50
+ }
51
+ export { DescriptionDetails, DescriptionList, DescriptionTerm };