@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,255 @@
1
+ "use client";
2
+ import { Chip } from "../chip/chip.js";
3
+ import { chipRemoveKey } from "../chip/chip-variants.js";
4
+ import { formatFileSize } from "../file-upload/files.js";
5
+ import { Icon } from "../icon/icon.js";
6
+ import { Spinner } from "../spinner/spinner.js";
7
+ import { CloseGlyph } from "../../internal/glyphs.js";
8
+ import { cn } from "../../lib/cn.js";
9
+ import { fitName, kindOf, kindSymbols, kindSymbolsSmall, typeWord } from "./kinds.js";
10
+ import { jsx, jsxs } from "react/jsx-runtime";
11
+ import { createContext, useContext, useId, useLayoutEffect, useRef, useState } from "react";
12
+ import { Alert02Icon } from "@hugeicons/core-free-icons";
13
+ // src/components/attachment/attachment.tsx
14
+ /** Inside a prompt's row of attachments, they are chips unless they say otherwise. */
15
+ const AttachmentVariantContext = createContext("tile");
16
+ const defaultStatusLabels = {
17
+ uploading: "Wird hochgeladen",
18
+ done: "Hochgeladen",
19
+ error: "Fehlgeschlagen"
20
+ };
21
+ /** How many letters before the extension stay where a name is cut: „Angebot-Ko…bst.pdf“. */
22
+ const KEPT_LETTERS = 3;
23
+ /**
24
+ * A name too long for its place, cut in its middle with an ellipsis as a file manager cuts it:
25
+ * the extension and the last three letters before it stay (`fitName`), „Angebot-Ko…bst.pdf“.
26
+ * Chosen by Justin (2026-11-20) over a cut at the end of the name and over the fade before the
27
+ * extension, which "looks odd". The room is the width the whole name would take, or less where
28
+ * the chip runs out: an unseen copy of the whole name sets it, and the cut is worked out again
29
+ * when the room changes.
30
+ */
31
+ function FileName({ name, className }) {
32
+ const room = useRef(null);
33
+ const probe = useRef(null);
34
+ const [shown, setShown] = useState(name);
35
+ useLayoutEffect(() => {
36
+ const box = room.current;
37
+ const measuring = probe.current;
38
+ if (!box || !measuring) return;
39
+ let live = true;
40
+ let frame = 0;
41
+ const fit = () => {
42
+ const measure = (each) => {
43
+ measuring.textContent = each;
44
+ return measuring.offsetWidth;
45
+ };
46
+ const room = box.clientWidth;
47
+ setShown(measure(name) <= room ? name : fitName(name, room - 1, measure, KEPT_LETTERS));
48
+ };
49
+ fit();
50
+ const observer = new ResizeObserver(() => {
51
+ cancelAnimationFrame(frame);
52
+ frame = requestAnimationFrame(fit);
53
+ });
54
+ observer.observe(box);
55
+ document.fonts?.ready.then(() => live && fit());
56
+ return () => {
57
+ live = false;
58
+ cancelAnimationFrame(frame);
59
+ observer.disconnect();
60
+ };
61
+ }, [name]);
62
+ return /* @__PURE__ */ jsxs("span", {
63
+ ref: room,
64
+ "data-slot": "attachment-name",
65
+ className: cn("grid min-w-0 grid-cols-[minmax(0,max-content)]", className),
66
+ children: [
67
+ /* @__PURE__ */ jsx("span", {
68
+ "aria-hidden": true,
69
+ className: "col-start-1 row-start-1 overflow-hidden whitespace-nowrap",
70
+ children: shown
71
+ }),
72
+ /* @__PURE__ */ jsx("span", {
73
+ ref: probe,
74
+ "aria-hidden": true,
75
+ className: "invisible absolute whitespace-nowrap"
76
+ }),
77
+ /* @__PURE__ */ jsx("span", {
78
+ "aria-hidden": true,
79
+ className: "invisible col-start-1 row-start-1 h-0 overflow-hidden whitespace-nowrap",
80
+ children: name
81
+ }),
82
+ /* @__PURE__ */ jsx("span", {
83
+ className: "sr-only",
84
+ children: name
85
+ })
86
+ ]
87
+ });
88
+ }
89
+ /**
90
+ * A file attached to a prompt or shown in a message: a symbol for its kind, its name, its size,
91
+ * and a key that takes it away while it still can be. In a prompt it is a chip, a plug in the
92
+ * field; in a message a small flat tile, and a picture shows itself.
93
+ *
94
+ * While it uploads it carries the system's arc in place of its symbol; once it has arrived, the
95
+ * symbol comes back where the arc was. A failure is said in words („Fehlgeschlagen“, and in a
96
+ * tile why). The name is cut in its middle, so the end of it and the extension stay readable.
97
+ */
98
+ function Attachment({ name, size, type, src, status = "done", error, onRemove, removeLabel = "entfernen", href, variant: variantProp, chipVariant = "plug", statusLabels, locale = "de-DE", className, ...props }) {
99
+ const placed = useContext(AttachmentVariantContext);
100
+ const variant = variantProp ?? placed;
101
+ const labels = {
102
+ ...defaultStatusLabels,
103
+ ...statusLabels
104
+ };
105
+ const kind = kindOf({
106
+ name,
107
+ type
108
+ });
109
+ const picture = kind === "image" && src !== void 0;
110
+ const sizeWord = size === void 0 ? void 0 : formatFileSize(size, locale);
111
+ /** In front: the arc on the way, the danger symbol after a failure, else the kind. */
112
+ const mark = (small) => status === "uploading" ? /* @__PURE__ */ jsx(Spinner, {
113
+ size: small ? 12 : 16,
114
+ className: "text-fg"
115
+ }) : status === "error" ? /* @__PURE__ */ jsx(Icon, {
116
+ icon: Alert02Icon,
117
+ size: small ? 12 : 16,
118
+ className: "text-danger"
119
+ }) : /* @__PURE__ */ jsx(Icon, {
120
+ icon: small ? kindSymbolsSmall[kind] : kindSymbols[kind],
121
+ size: small ? 14 : 18,
122
+ className: "text-fg-muted transition-opacity spring-settle in-data-live:starting:opacity-0"
123
+ });
124
+ if (variant === "chip") return /* @__PURE__ */ jsx(Chip, {
125
+ "data-slot": "attachment",
126
+ "data-variant": "chip",
127
+ "data-status": status,
128
+ variant: chipVariant,
129
+ title: name,
130
+ onRemove,
131
+ removeLabel,
132
+ className: cn("max-w-64", className),
133
+ lead: /* @__PURE__ */ jsx("span", {
134
+ "data-slot": "attachment-mark",
135
+ "aria-hidden": true,
136
+ className: "-ml-0.5 flex size-3.5 shrink-0 items-center justify-center",
137
+ children: picture && status === "done" ? /* @__PURE__ */ jsx("img", {
138
+ src,
139
+ alt: "",
140
+ className: "size-4 max-w-none rounded-[3px] object-cover"
141
+ }) : mark(true)
142
+ }),
143
+ ...props,
144
+ children: /* @__PURE__ */ jsxs("span", {
145
+ className: "flex min-w-0 items-baseline gap-1.5",
146
+ children: [/* @__PURE__ */ jsx(FileName, { name }), status === "error" ? /* @__PURE__ */ jsx("span", {
147
+ className: "shrink-0 font-normal text-danger",
148
+ children: labels.error
149
+ }) : status === "uploading" ? /* @__PURE__ */ jsx("span", {
150
+ className: "sr-only",
151
+ children: labels.uploading
152
+ }) : sizeWord && /* @__PURE__ */ jsx("span", {
153
+ className: "shrink-0 font-normal text-fg-muted tabular-nums",
154
+ children: sizeWord
155
+ })]
156
+ })
157
+ });
158
+ return /* @__PURE__ */ jsx(AttachmentTile, {
159
+ name,
160
+ picture: picture ? src : void 0,
161
+ href,
162
+ onRemove,
163
+ removeLabel,
164
+ status,
165
+ className,
166
+ mark: mark(false),
167
+ meta: status === "uploading" ? labels.uploading : status === "error" ? /* @__PURE__ */ jsx("span", {
168
+ className: "text-danger",
169
+ children: error ?? labels.error
170
+ }) : [typeWord({
171
+ name,
172
+ type
173
+ }), sizeWord].filter(Boolean).join(" · "),
174
+ ...props
175
+ });
176
+ }
177
+ /** A file in a message: read, so flat; a picture as itself. */
178
+ function AttachmentTile({ name, picture, href, onRemove, removeLabel, status, mark, meta, className, ...props }) {
179
+ const nameId = useId();
180
+ const removeId = useId();
181
+ const Root = href ? "a" : "div";
182
+ const remove = onRemove && /* @__PURE__ */ jsx("button", {
183
+ type: "button",
184
+ id: removeId,
185
+ "data-slot": "attachment-remove",
186
+ "aria-label": removeLabel,
187
+ "aria-labelledby": `${nameId} ${removeId}`,
188
+ onClick: onRemove,
189
+ className: cn(chipRemoveKey, picture ? "absolute top-1.5 right-1.5 size-6 rounded-full bg-raised depth-plug text-fg" : "absolute right-2.5"),
190
+ children: /* @__PURE__ */ jsx(CloseGlyph, {
191
+ width: 8,
192
+ height: 8
193
+ })
194
+ });
195
+ if (picture) return /* @__PURE__ */ jsxs("div", {
196
+ "data-slot": "attachment",
197
+ "data-variant": "tile",
198
+ "data-status": status,
199
+ className: cn("relative inline-flex max-w-64", className),
200
+ ...props,
201
+ children: [/* @__PURE__ */ jsxs(Root, {
202
+ ...href ? { href } : {},
203
+ className: cn("relative block overflow-hidden rounded-lg", "after:pointer-events-none after:absolute after:inset-0 after:rounded-[inherit] after:inset-ring after:inset-ring-hairline", href && "focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-accent"),
204
+ children: [/* @__PURE__ */ jsx("img", {
205
+ id: nameId,
206
+ src: picture,
207
+ alt: name,
208
+ className: "block h-auto max-h-40 w-auto max-w-64 object-cover"
209
+ }), status !== "done" && /* @__PURE__ */ jsx("span", {
210
+ className: "absolute bottom-1.5 left-1.5 flex size-6 items-center justify-center rounded-full bg-raised depth-plug",
211
+ children: mark
212
+ })]
213
+ }), remove]
214
+ });
215
+ return /* @__PURE__ */ jsxs("div", {
216
+ "data-slot": "attachment",
217
+ "data-variant": "tile",
218
+ "data-status": status,
219
+ className: cn("relative flex w-64 max-w-full items-center", className),
220
+ ...props,
221
+ children: [/* @__PURE__ */ jsxs(Root, {
222
+ ...href ? { href } : {},
223
+ className: cn("flex min-w-0 flex-1 items-center gap-3 rounded-lg bg-surface p-2 inset-ring inset-ring-hairline forced-colors:inset-ring-[CanvasText]", remove ? "pr-10" : "pr-3", href && ["transition-colors spring-snap hover:bg-surface-quiet", "focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-accent"]),
224
+ children: [/* @__PURE__ */ jsx("span", {
225
+ "data-slot": "attachment-mark",
226
+ "aria-hidden": true,
227
+ className: "flex size-10 shrink-0 items-center justify-center rounded-md bg-surface-quiet",
228
+ children: mark
229
+ }), /* @__PURE__ */ jsxs("span", {
230
+ className: "flex min-w-0 flex-col",
231
+ children: [/* @__PURE__ */ jsx("span", {
232
+ id: nameId,
233
+ className: "min-w-0 text-sm font-medium text-fg",
234
+ children: /* @__PURE__ */ jsx(FileName, { name })
235
+ }), /* @__PURE__ */ jsx("span", {
236
+ "data-slot": "attachment-meta",
237
+ className: cn("text-sm text-fg-muted tabular-nums", status === "error" ? "line-clamp-3" : "truncate"),
238
+ children: meta
239
+ })]
240
+ })]
241
+ }), remove]
242
+ });
243
+ }
244
+ /**
245
+ * The files of a message, side by side, wrapping: at the start of an answer, at the right above
246
+ * the person's words. Put `Attachment`s inside.
247
+ */
248
+ function MessageAttachments({ className, ...props }) {
249
+ return /* @__PURE__ */ jsx("div", {
250
+ "data-slot": "message-attachments",
251
+ className: cn("flex flex-wrap items-end gap-2 *:shrink-0 in-data-[from=user]:justify-end", className),
252
+ ...props
253
+ });
254
+ }
255
+ export { Attachment, AttachmentVariantContext, MessageAttachments };
@@ -0,0 +1,7 @@
1
+ import "../icon/icon.js";
2
+ export type FileKind = "pdf" | "image" | "sheet" | "csv" | "document" | "archive" | "audio" | "video" | "file";
3
+ /** The kind of a file: its MIME type decides, and its extension where the type says too little. */
4
+ export declare function kindOf({ name, type }: {
5
+ name: string;
6
+ type?: string;
7
+ }): FileKind;
@@ -0,0 +1,142 @@
1
+ import { Csv01Icon, Doc01Icon, File01Icon, FileArchiveIcon, FileAudioIcon, FileEmpty02Icon, FileImageIcon, FilePenLineIcon, FileSpreadsheetIcon, FileTextIcon, FileVideoIcon, Image01Icon, Pdf01Icon, Xls01Icon, Zip01Icon } from "@hugeicons/core-free-icons";
2
+ // src/components/attachment/kinds.ts
3
+ /**
4
+ * What kind of file an attachment is, from its MIME type or else its name: the symbol it
5
+ * carries and the word that names it. Plain functions, so they can be tested and used anywhere.
6
+ */
7
+ /** The symbol of a kind at a tile's size (18px), where the letters of a type stay readable. */
8
+ const kindSymbols = {
9
+ pdf: Pdf01Icon,
10
+ image: Image01Icon,
11
+ sheet: Xls01Icon,
12
+ csv: Csv01Icon,
13
+ document: Doc01Icon,
14
+ archive: Zip01Icon,
15
+ audio: FileAudioIcon,
16
+ video: FileVideoIcon,
17
+ file: File01Icon
18
+ };
19
+ /**
20
+ * The symbol of a kind in a chip (14px): a sheet with what it holds, without letters. At 14px
21
+ * the stroke is pinned to 1.5px, and the letters of „PDF“ or „XLS“ ran together into blots
22
+ * (Justin, 2026-11-20: "the icons look too thick, they kinda explode"). The extension stands in
23
+ * the name beside it anyway.
24
+ */
25
+ const kindSymbolsSmall = {
26
+ pdf: FileTextIcon,
27
+ image: FileImageIcon,
28
+ sheet: FileSpreadsheetIcon,
29
+ csv: FileSpreadsheetIcon,
30
+ document: FilePenLineIcon,
31
+ archive: FileArchiveIcon,
32
+ audio: FileAudioIcon,
33
+ video: FileVideoIcon,
34
+ file: FileEmpty02Icon
35
+ };
36
+ /** The word for a kind where the name has no extension to show. */
37
+ const kindWords = {
38
+ pdf: "PDF",
39
+ image: "Bild",
40
+ sheet: "Tabelle",
41
+ csv: "CSV",
42
+ document: "Dokument",
43
+ archive: "Archiv",
44
+ audio: "Audio",
45
+ video: "Video",
46
+ file: "Datei"
47
+ };
48
+ const byExtension = {
49
+ pdf: "pdf",
50
+ png: "image",
51
+ jpg: "image",
52
+ jpeg: "image",
53
+ gif: "image",
54
+ webp: "image",
55
+ avif: "image",
56
+ heic: "image",
57
+ svg: "image",
58
+ xls: "sheet",
59
+ xlsx: "sheet",
60
+ numbers: "sheet",
61
+ ods: "sheet",
62
+ csv: "csv",
63
+ doc: "document",
64
+ docx: "document",
65
+ pages: "document",
66
+ odt: "document",
67
+ rtf: "document",
68
+ txt: "document",
69
+ md: "document",
70
+ zip: "archive",
71
+ rar: "archive",
72
+ "7z": "archive",
73
+ gz: "archive",
74
+ tar: "archive",
75
+ mp3: "audio",
76
+ m4a: "audio",
77
+ wav: "audio",
78
+ mp4: "video",
79
+ mov: "video",
80
+ webm: "video"
81
+ };
82
+ /** The extension of a file name, lower case, without its dot: `pdf`. Empty if it has none. */
83
+ function extensionOf(name) {
84
+ const dot = name.lastIndexOf(".");
85
+ return dot > 0 && dot < name.length - 1 ? name.slice(dot + 1).toLowerCase() : "";
86
+ }
87
+ /** A name in the two parts that are drawn apart: what may be cut, and the end that stays. */
88
+ function splitName(name) {
89
+ const extension = extensionOf(name);
90
+ if (!extension || extension.length > 5) return {
91
+ stem: name,
92
+ end: ""
93
+ };
94
+ return {
95
+ stem: name.slice(0, -(extension.length + 1)),
96
+ end: `.${name.slice(-extension.length)}`
97
+ };
98
+ }
99
+ /**
100
+ * A file name shortened to fit `width`, cut with an ellipsis the way a file manager cuts it:
101
+ * the extension always stays, and so do the last `keep` letters before it, so „Angebot-
102
+ * Kornprobst.pdf“ becomes „Angebot-Ko…bst.pdf“. `measure` gives the drawn width of a text in
103
+ * the name's own font. The cut is exact, so no gap is left before what stays (a CSS ellipsis
104
+ * leaves up to a letter's room). A name that fits is returned as it is.
105
+ */
106
+ function fitName(name, width, measure, keep = 3) {
107
+ if (measure(name) <= width) return name;
108
+ const { stem, end } = splitName(name);
109
+ for (let tail = Math.min(keep, Math.max(0, stem.length - 1)); tail >= 0; tail--) {
110
+ const after = `…${stem.slice(stem.length - tail)}${end}`;
111
+ const room = stem.length - tail;
112
+ let low = 0;
113
+ let high = room;
114
+ while (low < high) {
115
+ const mid = Math.ceil((low + high) / 2);
116
+ if (measure(stem.slice(0, mid) + after) <= width) low = mid;
117
+ else high = mid - 1;
118
+ }
119
+ if (low > 0) return stem.slice(0, low).trimEnd() + after;
120
+ }
121
+ return `…${end}`;
122
+ }
123
+ /** The kind of a file: its MIME type decides, and its extension where the type says too little. */
124
+ function kindOf({ name, type = "" }) {
125
+ const mime = type.toLowerCase();
126
+ if (mime === "application/pdf") return "pdf";
127
+ if (mime.startsWith("image/")) return "image";
128
+ if (mime.startsWith("audio/")) return "audio";
129
+ if (mime.startsWith("video/")) return "video";
130
+ if (mime === "text/csv") return "csv";
131
+ if (mime.includes("spreadsheet") || mime.includes("excel")) return "sheet";
132
+ if (mime.includes("wordprocessing") || mime === "application/msword") return "document";
133
+ if (mime.includes("zip") || mime.includes("compressed")) return "archive";
134
+ return byExtension[extensionOf(name)] ?? (mime.startsWith("text/") ? "document" : "file");
135
+ }
136
+ /** The word under a file's name: its extension as it is written (`PDF`), or its kind's word. */
137
+ function typeWord(file) {
138
+ const extension = extensionOf(file.name);
139
+ if (extension && extension.length <= 5) return extension.toUpperCase();
140
+ return kindWords[kindOf(file)];
141
+ }
142
+ export { extensionOf, fitName, kindOf, kindSymbols, kindSymbolsSmall, kindWords, splitName, typeWord };
@@ -1,14 +1,24 @@
1
+ import { Presence } from "../avatar-group/people.js";
1
2
  import { VariantProps } from "class-variance-authority";
2
3
  import { Avatar as Avatar$1 } from "@base-ui/react/avatar";
3
4
  declare const avatarVariants: (props?: ({
4
5
  size?: "sm" | "md" | "lg" | "xl" | null | undefined;
5
6
  } & import("class-variance-authority/types").ClassProp) | undefined) => string;
6
- export type AvatarProps = Avatar$1.Root.Props & VariantProps<typeof avatarVariants>;
7
+ export type AvatarProps = Avatar$1.Root.Props & VariantProps<typeof avatarVariants> & {
8
+ /**
9
+ * Whether the person is there: a dot on the edge at the bottom end, cut out of the avatar
10
+ * with a gap, so it reads on every ground. It is said in words as well (`presenceLabel`).
11
+ */
12
+ presence?: Presence;
13
+ /** The word assistive tech hears for the presence. „Online“, „Abwesend“, „Offline“. */
14
+ presenceLabel?: string;
15
+ };
7
16
  /**
8
- * A person or a business, as a rounded square. Put an `AvatarImage` and an `AvatarFallback` with
9
- * one or two initials inside; the initials show until the picture has loaded, or if there is none.
17
+ * A person or a business, as a circle. Put an `AvatarImage` and an `AvatarFallback` with one or
18
+ * two initials inside; the initials show until the picture has loaded, or if there is none.
19
+ * Several people at once are an `AvatarGroup`.
10
20
  */
11
- export declare function Avatar({ className, size, ...props }: AvatarProps): import("react").JSX.Element;
21
+ export declare function Avatar({ className, size, presence, presenceLabel, style, ...props }: AvatarProps): import("react").JSX.Element;
12
22
  export declare function AvatarImage({ className, alt, ...props }: Avatar$1.Image.Props): import("react").JSX.Element;
13
23
  export declare function AvatarFallback({ className, ...props }: Avatar$1.Fallback.Props): import("react").JSX.Element;
14
24
  export {};
@@ -1,27 +1,71 @@
1
1
  "use client";
2
+ import { defaultPresenceLabels } from "../avatar-group/people.js";
3
+ import { avatarGeometry, cutMask } from "../../internal/avatar-cut.js";
4
+ import { PresenceDot } from "../../internal/presence-dot.js";
2
5
  import { mergeClassName } from "../../lib/cn.js";
3
- import { jsx } from "react/jsx-runtime";
6
+ import { jsx, jsxs } from "react/jsx-runtime";
4
7
  import { cva } from "class-variance-authority";
5
8
  import { Avatar as Avatar$1 } from "@base-ui/react/avatar";
6
9
  // src/components/avatar/avatar.tsx
7
- const avatarVariants = cva("relative inline-flex shrink-0 items-center justify-center overflow-hidden bg-fg font-semibold text-ground select-none forced-colors:outline", {
10
+ const avatarVariants = cva("relative inline-flex shrink-0 items-center justify-center overflow-hidden rounded-full bg-fg font-semibold text-ground select-none forced-colors:outline", {
8
11
  variants: { size: {
9
- sm: "size-6 rounded-xs text-xs",
10
- md: "size-7 rounded-sm text-xs",
11
- lg: "size-9 rounded-md text-sm",
12
- xl: "size-12 rounded-lg text-base"
12
+ sm: "size-6 text-[0.625rem]",
13
+ md: "size-7 text-xs",
14
+ lg: "size-9 text-sm",
15
+ xl: "size-12 text-base"
13
16
  } },
14
17
  defaultVariants: { size: "md" }
15
18
  });
16
19
  /**
17
- * A person or a business, as a rounded square. Put an `AvatarImage` and an `AvatarFallback` with
18
- * one or two initials inside; the initials show until the picture has loaded, or if there is none.
20
+ * A person or a business, as a circle. Put an `AvatarImage` and an `AvatarFallback` with one or
21
+ * two initials inside; the initials show until the picture has loaded, or if there is none.
22
+ * Several people at once are an `AvatarGroup`.
19
23
  */
20
- function Avatar({ className, size, ...props }) {
21
- return /* @__PURE__ */ jsx(Avatar$1.Root, {
22
- "data-slot": "avatar",
23
- className: mergeClassName(avatarVariants({ size }), className),
24
- ...props
24
+ function Avatar({ className, size, presence, presenceLabel, style, ...props }) {
25
+ const root = (cut, cutRtl) => {
26
+ const vars = {
27
+ "--avatar-cut": cut,
28
+ "--avatar-cut-rtl": cutRtl
29
+ };
30
+ return /* @__PURE__ */ jsx(Avatar$1.Root, {
31
+ "data-slot": "avatar",
32
+ "data-cut": cut ? "" : void 0,
33
+ style: !cut ? style : typeof style === "function" ? (state) => ({
34
+ ...vars,
35
+ ...style(state)
36
+ }) : {
37
+ ...vars,
38
+ ...style
39
+ },
40
+ className: mergeClassName(avatarVariants({ size }), className),
41
+ ...props
42
+ });
43
+ };
44
+ if (!presence) return root();
45
+ const geometry = avatarGeometry[size ?? "md"];
46
+ const cut = {
47
+ size: geometry.size,
48
+ gap: 2,
49
+ dot: geometry.dot
50
+ };
51
+ return /* @__PURE__ */ jsxs("span", {
52
+ "data-slot": "avatar-place",
53
+ className: "relative inline-flex shrink-0",
54
+ children: [
55
+ root(cutMask(cut), cutMask({
56
+ ...cut,
57
+ rtl: true
58
+ })),
59
+ /* @__PURE__ */ jsx(PresenceDot, {
60
+ slot: "avatar-presence",
61
+ presence,
62
+ diameter: geometry.dot
63
+ }),
64
+ /* @__PURE__ */ jsx("span", {
65
+ className: "sr-only",
66
+ children: presenceLabel ?? defaultPresenceLabels[presence]
67
+ })
68
+ ]
25
69
  });
26
70
  }
27
71
  function AvatarImage({ className, alt = "", ...props }) {
@@ -0,0 +1,33 @@
1
+ import { AvatarSize } from "../../internal/avatar-cut.js";
2
+ import { AvatarPerson, Presence } from "./people.js";
3
+ import { ComponentProps } from "react";
4
+ export type AvatarGroupProps = Omit<ComponentProps<"div">, "children"> & {
5
+ /** Everyone, in the order of importance: the first stands in front. */
6
+ people: readonly AvatarPerson[];
7
+ /**
8
+ * How many tiles the stack has room for, the „+3“ tile included. Default 4: three people
9
+ * and the rest as a number.
10
+ */
11
+ max?: number;
12
+ size?: AvatarSize;
13
+ /**
14
+ * What the group is, before the names, for assistive tech: „Bearbeitet von“. The names follow
15
+ * it; without it they stand alone.
16
+ */
17
+ label?: string;
18
+ presenceLabels?: Partial<Record<Presence, string>>;
19
+ /** The language the names are joined in: „Anna, Jonas und Lena“. */
20
+ locale?: Intl.LocalesArgument;
21
+ };
22
+ /**
23
+ * Several people at once, as one stack of overlapping `Avatar`s: who is in a team, who works on
24
+ * a record, who has seen it. The first stands in front. Between two the gap is cut out of the
25
+ * one underneath, following the one in front at a constant distance, so the stack is right on
26
+ * every ground, on a washed table row and over a picture. More people than fit become a „+3“
27
+ * tile of the same shape.
28
+ *
29
+ * Each avatar names itself in a tooltip under the pointer (one tooltip, which moves along the
30
+ * stack without waiting again), the „+3“ tile names the rest, and assistive tech hears the whole
31
+ * group as one sentence. A presence dot carries its words in both.
32
+ */
33
+ export declare function AvatarGroup({ people, max, size, label, presenceLabels, locale, className, style, ...props }: AvatarGroupProps): import("react").JSX.Element;
@@ -0,0 +1,110 @@
1
+ "use client";
2
+ import { Avatar, AvatarFallback, AvatarImage } from "../avatar/avatar.js";
3
+ import { Tooltip, TooltipContent, TooltipTrigger } from "../tooltip/tooltip.js";
4
+ import { avatarGeometry, avatarOverlap, cutMask } from "../../internal/avatar-cut.js";
5
+ import { PresenceDot } from "../../internal/presence-dot.js";
6
+ import { cn } from "../../lib/cn.js";
7
+ import { defaultPresenceLabels, initialsOf, listOf, personLabel } from "./people.js";
8
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
9
+ import "react";
10
+ // src/components/avatar-group/avatar-group.tsx
11
+ /**
12
+ * Several people at once, as one stack of overlapping `Avatar`s: who is in a team, who works on
13
+ * a record, who has seen it. The first stands in front. Between two the gap is cut out of the
14
+ * one underneath, following the one in front at a constant distance, so the stack is right on
15
+ * every ground, on a washed table row and over a picture. More people than fit become a „+3“
16
+ * tile of the same shape.
17
+ *
18
+ * Each avatar names itself in a tooltip under the pointer (one tooltip, which moves along the
19
+ * stack without waiting again), the „+3“ tile names the rest, and assistive tech hears the whole
20
+ * group as one sentence. A presence dot carries its words in both.
21
+ */
22
+ function AvatarGroup({ people, max = 4, size = "md", label, presenceLabels, locale = "de-DE", className, style, ...props }) {
23
+ const words = {
24
+ ...defaultPresenceLabels,
25
+ ...presenceLabels
26
+ };
27
+ const room = Math.max(1, max);
28
+ const front = people.length > room ? people.slice(0, room - 1) : people;
29
+ const rest = people.slice(front.length);
30
+ const geometry = avatarGeometry[size];
31
+ const gap = 2;
32
+ const over = avatarOverlap[size];
33
+ const step = geometry.size - over;
34
+ /**
35
+ * The mask of a tile: cut by the one in front (and by its dot, which stands half outside it,
36
+ * over this one), and around its own dot.
37
+ */
38
+ const cut = (index, dot) => {
39
+ const before = index > 0 ? front[index - 1] : void 0;
40
+ const options = {
41
+ size: geometry.size,
42
+ gap,
43
+ step: index > 0 ? step : void 0,
44
+ dot: dot ? geometry.dot : void 0,
45
+ frontDot: before?.presence ? geometry.dot : void 0
46
+ };
47
+ const mask = cutMask(options);
48
+ if (!mask) return void 0;
49
+ return {
50
+ "data-cut": "",
51
+ style: {
52
+ "--avatar-cut": mask,
53
+ "--avatar-cut-rtl": cutMask({
54
+ ...options,
55
+ rtl: true
56
+ })
57
+ }
58
+ };
59
+ };
60
+ const everyone = listOf(people.map((person) => personLabel(person, words)), locale);
61
+ const centred = (first) => first ? void 0 : "ps-(--avatar-hidden)";
62
+ const tiles = front.map((person, index) => ({
63
+ key: `${index}:${person.name}`,
64
+ tip: personLabel(person, words),
65
+ content: /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs(Avatar, {
66
+ size,
67
+ ...cut(index, person.presence !== void 0),
68
+ children: [person.src && /* @__PURE__ */ jsx(AvatarImage, { src: person.src }), /* @__PURE__ */ jsx(AvatarFallback, {
69
+ className: centred(index === 0),
70
+ children: person.initials ?? initialsOf(person.name)
71
+ })]
72
+ }), person.presence && /* @__PURE__ */ jsx(PresenceDot, {
73
+ slot: "avatar-group-presence",
74
+ presence: person.presence,
75
+ diameter: geometry.dot
76
+ })] })
77
+ }));
78
+ if (rest.length > 0) tiles.push({
79
+ key: "rest",
80
+ tip: listOf(rest.map((person) => personLabel(person, words)), locale),
81
+ content: /* @__PURE__ */ jsxs("span", {
82
+ "data-slot": "avatar-group-more",
83
+ ...cut(tiles.length, false),
84
+ className: cn("inline-flex shrink-0 items-center justify-center rounded-full bg-trough font-semibold text-fg tabular-nums select-none forced-colors:outline", centred(tiles.length === 0), size === "sm" && "size-6 text-[0.625rem]", size === "md" && "size-7 text-xs", size === "lg" && "size-9 text-sm", size === "xl" && "size-12 text-base"),
85
+ children: ["+", rest.length]
86
+ })
87
+ });
88
+ return /* @__PURE__ */ jsx("div", {
89
+ role: "img",
90
+ "aria-label": label ? `${label}: ${everyone}` : everyone,
91
+ "data-slot": "avatar-group",
92
+ "data-size": size,
93
+ style: {
94
+ "--avatar-step": `${-over / 16}rem`,
95
+ "--avatar-hidden": `${(over + gap) / 16}rem`,
96
+ ...style
97
+ },
98
+ className: cn("isolate inline-flex items-center", className),
99
+ ...props,
100
+ children: /* @__PURE__ */ jsx(Tooltip, { children: ({ payload }) => /* @__PURE__ */ jsxs(Fragment, { children: [tiles.map((tile, index) => /* @__PURE__ */ jsx(TooltipTrigger, {
101
+ payload: tile.tip,
102
+ render: /* @__PURE__ */ jsx("span", {}),
103
+ "data-slot": "avatar-group-item",
104
+ style: { zIndex: tiles.length - index },
105
+ className: "relative inline-flex shrink-0 not-first:ms-(--avatar-step)",
106
+ children: tile.content
107
+ }, tile.key)), /* @__PURE__ */ jsx(TooltipContent, { children: payload })] }) })
108
+ });
109
+ }
110
+ export { AvatarGroup };
@@ -0,0 +1,12 @@
1
+ /** Whether a person is there: shown as a dot on their avatar, and always said in words. */
2
+ export type Presence = "online" | "away" | "offline";
3
+ /** One person in an `AvatarGroup`. */
4
+ export type AvatarPerson = {
5
+ /** The full name, as the tooltip and assistive tech say it. */
6
+ name: string;
7
+ /** A picture; the initials show until it has loaded, or if there is none. */
8
+ src?: string;
9
+ /** One or two letters; by default the first letters of the first and the last name. */
10
+ initials?: string;
11
+ presence?: Presence;
12
+ };