@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,38 @@
1
+ import { ComponentProps } from "react";
2
+ export type EmptyProps = ComponentProps<"div"> & {
3
+ /**
4
+ * `page` (the default): the whole content of a page or a large panel. `inline`: inside
5
+ * something else, a table without rows, a card, a list in a sheet.
6
+ */
7
+ size?: "page" | "inline";
8
+ };
9
+ /**
10
+ * What stands where a list, a table or a page has nothing in it yet. It is read, so it is flat.
11
+ * Put an `EmptyMedia` with a symbol, an `EmptyTitle`, an `EmptyText` and the first step in
12
+ * `EmptyActions` inside.
13
+ *
14
+ * The title is the fact, said to the reader ("Sie haben noch kein Angebot geschrieben."). The
15
+ * text says what will appear here, and when. The button is the first step, the thing and then
16
+ * the action ("Erstes Angebot schreiben"). A search that finds nothing is a different case: one
17
+ * sentence that names the kind of thing that was looked for, and no button.
18
+ */
19
+ export declare function Empty({ size, className, ...props }: EmptyProps): import("react").JSX.Element;
20
+ export type EmptyMediaProps = ComponentProps<"div"> & {
21
+ /**
22
+ * `tile` (the default): the symbol stands in a small plate with a hairline. `bare`: the
23
+ * symbol alone.
24
+ */
25
+ variant?: "tile" | "bare";
26
+ };
27
+ /** The symbol above the title: an `Icon` at 20px (18px in an inline one). It is decoration. */
28
+ export declare function EmptyMedia({ variant, className, ...props }: EmptyMediaProps): import("react").JSX.Element;
29
+ export type EmptyTitleProps = ComponentProps<"h2"> & {
30
+ /** The heading level it has in the page's outline. */
31
+ level?: 2 | 3 | 4;
32
+ };
33
+ /** The fact, as a sentence with its full stop. */
34
+ export declare function EmptyTitle({ level, className, ...props }: EmptyTitleProps): import("react").JSX.Element;
35
+ /** What will appear here, and when: one or two sentences. */
36
+ export declare function EmptyText({ className, ...props }: ComponentProps<"p">): import("react").JSX.Element;
37
+ /** The first step, as a `Button`; a second, quieter way beside it at most. */
38
+ export declare function EmptyActions({ className, ...props }: ComponentProps<"div">): import("react").JSX.Element;
@@ -0,0 +1,57 @@
1
+ import { cn } from "../../lib/cn.js";
2
+ import { jsx } from "react/jsx-runtime";
3
+ // src/components/empty/empty.tsx
4
+ /**
5
+ * What stands where a list, a table or a page has nothing in it yet. It is read, so it is flat.
6
+ * Put an `EmptyMedia` with a symbol, an `EmptyTitle`, an `EmptyText` and the first step in
7
+ * `EmptyActions` inside.
8
+ *
9
+ * The title is the fact, said to the reader ("Sie haben noch kein Angebot geschrieben."). The
10
+ * text says what will appear here, and when. The button is the first step, the thing and then
11
+ * the action ("Erstes Angebot schreiben"). A search that finds nothing is a different case: one
12
+ * sentence that names the kind of thing that was looked for, and no button.
13
+ */
14
+ function Empty({ size = "page", className, ...props }) {
15
+ return /* @__PURE__ */ jsx("div", {
16
+ "data-slot": "empty",
17
+ "data-size": size,
18
+ className: cn("group/empty mx-auto flex w-full max-w-sm flex-col items-center text-center", size === "page" ? "gap-2 py-16" : "gap-1.5 py-8", className),
19
+ ...props
20
+ });
21
+ }
22
+ /** The symbol above the title: an `Icon` at 20px (18px in an inline one). It is decoration. */
23
+ function EmptyMedia({ variant = "tile", className, ...props }) {
24
+ return /* @__PURE__ */ jsx("div", {
25
+ "data-slot": "empty-media",
26
+ "data-variant": variant,
27
+ "aria-hidden": true,
28
+ className: cn("mb-2 flex shrink-0 items-center justify-center text-fg-muted", variant === "tile" && "size-10 rounded-lg bg-surface inset-ring inset-ring-hairline group-data-[size=inline]/empty:size-9 group-data-[size=inline]/empty:rounded-md forced-colors:inset-ring-[CanvasText]", className),
29
+ ...props
30
+ });
31
+ }
32
+ /** The fact, as a sentence with its full stop. */
33
+ function EmptyTitle({ level = 2, className, ...props }) {
34
+ const Tag = `h${level}`;
35
+ return /* @__PURE__ */ jsx(Tag, {
36
+ "data-slot": "empty-title",
37
+ className: cn("leading-snug font-semibold text-balance text-fg", "text-lg group-data-[size=inline]/empty:text-control group-data-[size=inline]/empty:font-medium", className),
38
+ ...props
39
+ });
40
+ }
41
+ /** What will appear here, and when: one or two sentences. */
42
+ function EmptyText({ className, ...props }) {
43
+ return /* @__PURE__ */ jsx("p", {
44
+ "data-slot": "empty-text",
45
+ className: cn("text-pretty text-fg-muted", "text-control group-data-[size=inline]/empty:text-sm", className),
46
+ ...props
47
+ });
48
+ }
49
+ /** The first step, as a `Button`; a second, quieter way beside it at most. */
50
+ function EmptyActions({ className, ...props }) {
51
+ return /* @__PURE__ */ jsx("div", {
52
+ "data-slot": "empty-actions",
53
+ className: cn("mt-4 flex flex-wrap items-center justify-center gap-2 group-data-[size=inline]/empty:mt-3", className),
54
+ ...props
55
+ });
56
+ }
57
+ export { Empty, EmptyActions, EmptyMedia, EmptyText, EmptyTitle };
@@ -3,8 +3,8 @@ import { Icon } from "../icon/icon.js";
3
3
  import { FieldActionsContext, FieldDisabledContext } from "../../internal/field-context.js";
4
4
  import { mergeClassName } from "../../lib/cn.js";
5
5
  import { jsx, jsxs } from "react/jsx-runtime";
6
- import { AlertCircleIcon } from "@hugeicons/core-free-icons";
7
6
  import { useRef } from "react";
7
+ import { AlertCircleIcon } from "@hugeicons/core-free-icons";
8
8
  import { Field as Field$1 } from "@base-ui/react/field";
9
9
  // src/components/field/field.tsx
10
10
  /**
@@ -0,0 +1,96 @@
1
+ import { IconSvgElement } from "../icon/icon.js";
2
+ import { FileRejection, FileRules } from "./files.js";
3
+ import { ComponentProps, ReactNode } from "react";
4
+ export type FileUploadProps = Omit<ComponentProps<"div">, "onChange"> & FileRules & {
5
+ /**
6
+ * Called with the files that were dropped, pasted or chosen and that fit the rules. Start
7
+ * their upload here and show each as a `FileUploadItem`.
8
+ */
9
+ onFilesAdded: (files: File[]) => void;
10
+ /** Called with the files that were not taken, each with its reason. Say so in words. */
11
+ onReject?: (rejected: FileRejection[]) => void;
12
+ /** Nothing can be added right now. */
13
+ disabled?: boolean;
14
+ /** The name the chosen files are submitted under, if the field is part of a plain form. */
15
+ name?: string;
16
+ };
17
+ /**
18
+ * Takes files: a zone to drop them on, a button that opens the system's dialog, and a list of
19
+ * what was added with the state of each. It does not upload anything. It reports the files
20
+ * (`onFilesAdded`) and shows the progress the caller gives it; sending, resuming and checking
21
+ * them is the caller's work.
22
+ *
23
+ * Put a `FileUploadZone` inside and, under it, a `FileUploadList` of `FileUploadItem`s. A real
24
+ * file input stands behind the button, so it works from the keyboard and with assistive tech,
25
+ * and a file pasted while the focus is in the zone is taken as well. `accept` and `maxSize`
26
+ * are checked here for every way in; what does not fit comes back through `onReject`.
27
+ */
28
+ export declare function FileUpload({ accept, maxSize, multiple, onFilesAdded, onReject, disabled, name, className, children, ...props }: FileUploadProps): import("react").JSX.Element;
29
+ export type FileUploadZoneProps = Omit<ComponentProps<"div">, "title"> & {
30
+ /** What to do, as a short line: "Dateien hierher ziehen". */
31
+ title?: ReactNode;
32
+ /** The same line while a file hangs over the zone. */
33
+ dropTitle?: ReactNode;
34
+ /** What is taken: the kinds and the largest size ("PDF oder Bild, höchstens 10 MB"). */
35
+ description?: ReactNode;
36
+ /** The words on the button that opens the system's dialog. */
37
+ buttonLabel?: ReactNode;
38
+ /**
39
+ * `tile` (the default): a symbol in a small tile above the words. `plain`: the words and the
40
+ * button alone, for a lower zone: one of several in a form, or in a narrow card.
41
+ */
42
+ variant?: "tile" | "plain";
43
+ /** The symbol in the tile. */
44
+ icon?: IconSvgElement;
45
+ };
46
+ /**
47
+ * Where files are dropped. It is a socket, cut like a field: white, with a hairline edge. While
48
+ * a file hangs over it, it takes the field's halo, the sign that it will take what is let go.
49
+ * There is no dashed border. Its button opens the system's file dialog.
50
+ */
51
+ export declare function FileUploadZone({ title, dropTitle, description, buttonLabel, variant, icon, className, ...props }: FileUploadZoneProps): import("react").JSX.Element;
52
+ export type FileUploadListProps = ComponentProps<"ul">;
53
+ /**
54
+ * The files that were added, one row each, under the zone. A row that joins opens its place and
55
+ * fades in, and what stands below is pushed; one that is removed fades and its place folds shut.
56
+ * The rows that are there when the list first shows stand still.
57
+ *
58
+ * Keep it in the upload while there are no files: an empty list takes no room, the first file
59
+ * opens it like any other, and a screen reader hears it join (a live region has to be there
60
+ * before what it announces). Name it (`aria-label`: "Dateien") and give each `FileUploadItem` a
61
+ * `key` that stays its own.
62
+ */
63
+ export declare function FileUploadList({ className, children, ...props }: FileUploadListProps): import("react").JSX.Element;
64
+ /** Where a file stands: not begun, on its way, arrived, or failed. */
65
+ export type FileUploadStatus = "waiting" | "uploading" | "done" | "error";
66
+ export type FileUploadItemProps = Omit<ComponentProps<"div">, "children"> & {
67
+ /** The file's name, with its ending. */
68
+ name: string;
69
+ /** Its size in bytes. */
70
+ size: number;
71
+ /** Where it stands. Arrived unless said otherwise. */
72
+ status?: FileUploadStatus;
73
+ /** How much has arrived, from 0 to 1, while it is `uploading`. Without it the bar runs through. */
74
+ progress?: number;
75
+ /** Why it failed, as a sentence: "Die Verbindung wurde unterbrochen." */
76
+ error?: ReactNode;
77
+ /** With it a failed file offers to try once more. */
78
+ onRetry?: () => void;
79
+ /** With it the row carries a key that takes the file out of the list (and stops its upload). */
80
+ onRemove?: () => void;
81
+ /** The words on the key that tries again. */
82
+ retryLabel?: ReactNode;
83
+ /** The verb of the key that removes the file. The file's name is said before it. */
84
+ removeLabel?: string;
85
+ /** What each state is called for assistive tech, where the mark alone would say it. */
86
+ statusLabels?: Partial<Record<FileUploadStatus, string>>;
87
+ /** The locale the sizes are written in. */
88
+ locale?: string;
89
+ };
90
+ /**
91
+ * One file: the system's mark in front (the open ring waits, the arc works, the disc is done),
92
+ * its name, its size in tabular digits, and under the name a thin bar while it is on its way.
93
+ * The bar folds away once the file has arrived, and the mark closes where the arc was. A file
94
+ * that failed says so in words, with the danger symbol and a key that tries again.
95
+ */
96
+ export declare function FileUploadItem({ name, size, status, progress, error, onRetry, onRemove, retryLabel, removeLabel, statusLabels, locale, className, ...props }: FileUploadItemProps): import("react").JSX.Element;
@@ -0,0 +1,347 @@
1
+ "use client";
2
+ import { Button } from "../button/button.js";
3
+ import { Icon } from "../icon/icon.js";
4
+ import { Progress, ProgressTrack } from "../progress/progress.js";
5
+ import { Spinner } from "../spinner/spinner.js";
6
+ import { CloseGlyph } from "../../internal/glyphs.js";
7
+ import { placeProps, useLive, usePresence } from "../../internal/presence.js";
8
+ import { cn } from "../../lib/cn.js";
9
+ import { formatFileProgress, formatFileSize, sortFiles } from "./files.js";
10
+ import { jsx, jsxs } from "react/jsx-runtime";
11
+ import { Children, createContext, isValidElement, useContext, useMemo, useRef, useState } from "react";
12
+ import { Alert02Icon, Upload04Icon } from "@hugeicons/core-free-icons";
13
+ // src/components/file-upload/file-upload.tsx
14
+ const FileUploadContext = createContext({
15
+ open: () => {},
16
+ add: () => {},
17
+ disabled: false,
18
+ live: false
19
+ });
20
+ /**
21
+ * Takes files: a zone to drop them on, a button that opens the system's dialog, and a list of
22
+ * what was added with the state of each. It does not upload anything. It reports the files
23
+ * (`onFilesAdded`) and shows the progress the caller gives it; sending, resuming and checking
24
+ * them is the caller's work.
25
+ *
26
+ * Put a `FileUploadZone` inside and, under it, a `FileUploadList` of `FileUploadItem`s. A real
27
+ * file input stands behind the button, so it works from the keyboard and with assistive tech,
28
+ * and a file pasted while the focus is in the zone is taken as well. `accept` and `maxSize`
29
+ * are checked here for every way in; what does not fit comes back through `onReject`.
30
+ */
31
+ function FileUpload({ accept, maxSize, multiple = false, onFilesAdded, onReject, disabled = false, name, className, children, ...props }) {
32
+ const input = useRef(null);
33
+ const live = useLive();
34
+ const context = useMemo(() => ({
35
+ disabled,
36
+ live,
37
+ open: () => input.current?.click(),
38
+ add: (files) => {
39
+ if (disabled || files.length === 0) return;
40
+ const { accepted, rejected } = sortFiles(files, {
41
+ accept,
42
+ maxSize,
43
+ multiple
44
+ });
45
+ if (accepted.length > 0) onFilesAdded(accepted);
46
+ if (rejected.length > 0) onReject?.(rejected);
47
+ }
48
+ }), [
49
+ accept,
50
+ maxSize,
51
+ multiple,
52
+ disabled,
53
+ live,
54
+ onFilesAdded,
55
+ onReject
56
+ ]);
57
+ return /* @__PURE__ */ jsx(FileUploadContext, {
58
+ value: context,
59
+ children: /* @__PURE__ */ jsxs("div", {
60
+ "data-slot": "file-upload",
61
+ "data-live": live ? "" : void 0,
62
+ className: cn("flex flex-col gap-3", className),
63
+ ...props,
64
+ children: [/* @__PURE__ */ jsx("input", {
65
+ ref: input,
66
+ type: "file",
67
+ hidden: true,
68
+ tabIndex: -1,
69
+ name,
70
+ accept,
71
+ multiple,
72
+ disabled,
73
+ "data-slot": "file-upload-input",
74
+ onChange: (event) => {
75
+ context.add([...event.currentTarget.files ?? []]);
76
+ if (!name) event.currentTarget.value = "";
77
+ }
78
+ }), children]
79
+ })
80
+ });
81
+ }
82
+ /** Whether what is being dragged is files, and not a piece of text or a link. */
83
+ const carriesFiles = (event) => event.dataTransfer.types.includes("Files");
84
+ /**
85
+ * Where files are dropped. It is a socket, cut like a field: white, with a hairline edge. While
86
+ * a file hangs over it, it takes the field's halo, the sign that it will take what is let go.
87
+ * There is no dashed border. Its button opens the system's file dialog.
88
+ */
89
+ function FileUploadZone({ title = "Dateien hierher ziehen", dropTitle = "Loslassen, um sie hinzuzufügen", description, buttonLabel = "Dateien auswählen", variant = "tile", icon = Upload04Icon, className, ...props }) {
90
+ const { open, add, disabled } = useContext(FileUploadContext);
91
+ const depth = useRef(0);
92
+ const [over, setOver] = useState(false);
93
+ const rest = () => {
94
+ depth.current = 0;
95
+ setOver(false);
96
+ };
97
+ return /* @__PURE__ */ jsxs("div", {
98
+ "data-slot": "file-upload-zone",
99
+ "data-variant": variant,
100
+ "data-dragging": over ? "" : void 0,
101
+ "data-disabled": disabled ? "" : void 0,
102
+ className: cn("group/zone flex flex-col items-center gap-1 rounded-xl bg-surface px-6 py-6 text-center depth-field", "transition-[box-shadow,background-color] spring-snap data-dragging:depth-field-focus", "data-disabled:bg-disabled data-disabled:depth-flat", className),
103
+ onDragEnter: (event) => {
104
+ if (disabled || !carriesFiles(event)) return;
105
+ event.preventDefault();
106
+ depth.current += 1;
107
+ setOver(true);
108
+ },
109
+ onDragOver: (event) => {
110
+ if (!disabled && carriesFiles(event)) event.preventDefault();
111
+ },
112
+ onDragLeave: (event) => {
113
+ if (disabled || !carriesFiles(event)) return;
114
+ depth.current = Math.max(0, depth.current - 1);
115
+ if (depth.current === 0) setOver(false);
116
+ },
117
+ onDrop: (event) => {
118
+ if (disabled || !carriesFiles(event)) return;
119
+ event.preventDefault();
120
+ rest();
121
+ add([...event.dataTransfer.files]);
122
+ },
123
+ onPaste: (event) => {
124
+ const files = [...event.clipboardData.files];
125
+ if (files.length === 0) return;
126
+ event.preventDefault();
127
+ add(files);
128
+ },
129
+ ...props,
130
+ children: [
131
+ variant === "tile" && /* @__PURE__ */ jsx("span", {
132
+ "aria-hidden": true,
133
+ "data-slot": "file-upload-tile",
134
+ className: "mb-2 flex size-10 items-center justify-center rounded-lg bg-surface-quiet text-fg-muted inset-ring inset-ring-hairline group-data-disabled/zone:text-on-disabled forced-colors:inset-ring-[CanvasText]",
135
+ children: /* @__PURE__ */ jsx(Icon, {
136
+ icon,
137
+ size: 18,
138
+ className: "transition-[translate,color] spring-seat group-data-dragging/zone:-translate-y-0.5 group-data-dragging/zone:text-accent"
139
+ })
140
+ }),
141
+ /* @__PURE__ */ jsx("p", {
142
+ "data-slot": "file-upload-title",
143
+ className: "text-control font-medium text-fg group-data-disabled/zone:text-on-disabled",
144
+ children: over ? dropTitle : title
145
+ }),
146
+ description !== void 0 && /* @__PURE__ */ jsx("p", {
147
+ "data-slot": "file-upload-description",
148
+ className: "text-sm text-pretty text-fg-muted group-data-disabled/zone:text-on-disabled",
149
+ children: description
150
+ }),
151
+ /* @__PURE__ */ jsx(Button, {
152
+ size: "sm",
153
+ disabled,
154
+ onClick: open,
155
+ className: "mt-3",
156
+ children: buttonLabel
157
+ })
158
+ ]
159
+ });
160
+ }
161
+ const keyOf = (element) => element.key ?? "";
162
+ /**
163
+ * A row's place in the list. It opens from nothing when a file joins and folds shut when one is
164
+ * removed, so the rows below glide. Every change of height in the list is one of these folds,
165
+ * or the fold of a bar or an error inside a row: each eases by itself and the list adds them
166
+ * up, so a file that arrives while another is removed does not make the list chase its own
167
+ * height. The place clips only up and down: the focus ring of a key stays whole.
168
+ */
169
+ const placeOfFile = [
170
+ "group/place grid grid-rows-[1fr] overflow-y-clip transition-[grid-template-rows] spring-settle",
171
+ "in-data-live:starting:grid-rows-[0fr]",
172
+ "data-leaving:grid-rows-[0fr] data-leaving:delay-[120ms]"
173
+ ].join(" ");
174
+ /**
175
+ * The files that were added, one row each, under the zone. A row that joins opens its place and
176
+ * fades in, and what stands below is pushed; one that is removed fades and its place folds shut.
177
+ * The rows that are there when the list first shows stand still.
178
+ *
179
+ * Keep it in the upload while there are no files: an empty list takes no room, the first file
180
+ * opens it like any other, and a screen reader hears it join (a live region has to be there
181
+ * before what it announces). Name it (`aria-label`: "Dateien") and give each `FileUploadItem` a
182
+ * `key` that stays its own.
183
+ */
184
+ function FileUploadList({ className, children, ...props }) {
185
+ const { live: uploadLive } = useContext(FileUploadContext);
186
+ const live = useLive() || uploadLive;
187
+ const box = useRef(null);
188
+ const files = useMemo(() => Children.toArray(children).filter(isValidElement), [children]);
189
+ const { places, left } = usePresence(files, keyOf, box);
190
+ const empty = places.every((place) => place.leaving);
191
+ return /* @__PURE__ */ jsx("ul", {
192
+ ref: box,
193
+ "data-slot": "file-upload-list",
194
+ "data-live": live ? "" : void 0,
195
+ "data-empty": empty ? "" : void 0,
196
+ "aria-live": "polite",
197
+ "aria-relevant": "additions",
198
+ className: cn("flex flex-col empty:hidden", "transition-[margin-top] spring-settle data-empty:-mt-3 in-data-live:starting:-mt-3", className),
199
+ ...props,
200
+ children: places.map((place) => /* @__PURE__ */ jsx("li", {
201
+ "data-slot": "file-upload-place",
202
+ ...placeProps(place, left),
203
+ className: placeOfFile,
204
+ children: /* @__PURE__ */ jsx("div", {
205
+ className: "min-h-0 border-t border-hairline group-first/place:border-t-0",
206
+ children: place.item
207
+ })
208
+ }, place.key))
209
+ });
210
+ }
211
+ const statusWords = {
212
+ waiting: "Wartet",
213
+ uploading: "Wird hochgeladen",
214
+ done: "Hochgeladen",
215
+ error: "Fehlgeschlagen"
216
+ };
217
+ /** The key of the row beside this one, the next if there is one, that can take the focus. */
218
+ function keyBeside(key) {
219
+ const place = key.closest("[data-slot=\"file-upload-place\"]");
220
+ const find = (step) => {
221
+ for (let other = place?.[step]; other; other = other[step]) {
222
+ const found = other.matches("[data-leaving]") ? null : other.querySelector("[data-slot=\"file-upload-remove\"]");
223
+ if (found) return found;
224
+ }
225
+ return null;
226
+ };
227
+ return find("nextElementSibling") ?? find("previousElementSibling");
228
+ }
229
+ /**
230
+ * A line under a file's name (its bar, or why it failed) that opens and folds. Opening, its
231
+ * place opens first and the line fades in behind; folding, the line fades out on `leave` first
232
+ * and its place folds after, so it is never cut through while it can still be read.
233
+ */
234
+ const lineOpen = "grid grid-rows-[1fr] [transition:grid-template-rows_var(--transition-duration-spring-settle)_var(--ease-spring-settle),opacity_var(--transition-duration-spring-settle)_var(--ease-spring-settle)_80ms]";
235
+ const lineShut = "grid grid-rows-[0fr] opacity-0 [transition:opacity_var(--transition-duration-spring-leave)_var(--ease-spring-leave),grid-template-rows_var(--transition-duration-spring-settle)_var(--ease-spring-settle)_100ms]";
236
+ /** The bar of a file that arrived: seen full for a moment (its fill glides there), then gone. */
237
+ const lineShutLater = "grid grid-rows-[0fr] opacity-0 [transition:opacity_var(--transition-duration-spring-leave)_var(--ease-spring-leave)_200ms,grid-template-rows_var(--transition-duration-spring-settle)_var(--ease-spring-settle)_300ms]";
238
+ /**
239
+ * One file: the system's mark in front (the open ring waits, the arc works, the disc is done),
240
+ * its name, its size in tabular digits, and under the name a thin bar while it is on its way.
241
+ * The bar folds away once the file has arrived, and the mark closes where the arc was. A file
242
+ * that failed says so in words, with the danger symbol and a key that tries again.
243
+ */
244
+ function FileUploadItem({ name, size, status = "done", progress, error, onRetry, onRemove, retryLabel = "Noch einmal versuchen", removeLabel = "entfernen", statusLabels, locale = "de-DE", className, ...props }) {
245
+ const fraction = Math.min(1, Math.max(0, progress ?? 0));
246
+ const failed = status === "error";
247
+ const [said, setSaid] = useState({
248
+ error,
249
+ retry: onRetry !== void 0
250
+ });
251
+ if (failed && (said.error !== error || said.retry !== (onRetry !== void 0))) setSaid({
252
+ error,
253
+ retry: onRetry !== void 0
254
+ });
255
+ return /* @__PURE__ */ jsxs("div", {
256
+ "data-slot": "file-upload-item",
257
+ "data-status": status,
258
+ className: cn("group/file flex gap-2.5 py-2.5 text-control", "transition-[opacity,translate] spring-settle in-data-live:starting:translate-y-(--motion-enter-offset) in-data-live:starting:opacity-0", "in-data-leaving:opacity-0 in-data-leaving:spring-leave", className),
259
+ ...props,
260
+ children: [
261
+ /* @__PURE__ */ jsx("span", {
262
+ "aria-hidden": true,
263
+ "data-slot": "file-upload-mark",
264
+ className: "flex h-[1.3125rem] w-4 shrink-0 items-center justify-center",
265
+ children: status === "uploading" ? /* @__PURE__ */ jsx(Spinner, {
266
+ size: 14,
267
+ className: "text-fg"
268
+ }) : status === "error" ? /* @__PURE__ */ jsx(Icon, {
269
+ icon: Alert02Icon,
270
+ size: 14,
271
+ className: "text-danger"
272
+ }) : /* @__PURE__ */ jsx("span", { className: cn("mark", status === "done" && "mark-on in-data-live:mark-closes") })
273
+ }),
274
+ /* @__PURE__ */ jsxs("div", {
275
+ className: "flex min-w-0 flex-1 flex-col",
276
+ children: [
277
+ /* @__PURE__ */ jsxs("div", {
278
+ className: "flex items-baseline gap-3",
279
+ children: [/* @__PURE__ */ jsxs("span", {
280
+ "data-slot": "file-upload-name",
281
+ className: "min-w-0 truncate text-fg",
282
+ children: [/* @__PURE__ */ jsxs("span", {
283
+ className: "sr-only",
284
+ children: [statusLabels?.[status] ?? statusWords[status], ": "]
285
+ }), name]
286
+ }), /* @__PURE__ */ jsx("span", {
287
+ "data-slot": "file-upload-size",
288
+ className: "ml-auto shrink-0 text-sm whitespace-nowrap text-fg-muted tabular-nums",
289
+ children: status === "uploading" && progress !== void 0 ? formatFileProgress(fraction * size, size, locale) : formatFileSize(size, locale)
290
+ })]
291
+ }),
292
+ /* @__PURE__ */ jsx("div", {
293
+ "data-slot": "file-upload-progress",
294
+ "aria-hidden": status === "uploading" ? void 0 : true,
295
+ className: status === "uploading" ? lineOpen : status === "done" ? lineShutLater : lineShut,
296
+ children: /* @__PURE__ */ jsx("div", {
297
+ className: "min-h-0 overflow-hidden",
298
+ children: /* @__PURE__ */ jsx(Progress, {
299
+ "aria-label": name,
300
+ value: status === "uploading" ? progress === void 0 ? null : fraction * 100 : status === "done" ? 100 : fraction * 100,
301
+ className: "pt-1.5 pb-0.5",
302
+ children: /* @__PURE__ */ jsx(ProgressTrack, { className: "h-1" })
303
+ })
304
+ })
305
+ }),
306
+ /* @__PURE__ */ jsx("div", {
307
+ "data-slot": "file-upload-error-fold",
308
+ "aria-hidden": failed ? void 0 : true,
309
+ inert: !failed,
310
+ className: cn("-my-1", failed ? lineOpen : lineShut),
311
+ children: /* @__PURE__ */ jsx("div", {
312
+ className: "min-h-0 overflow-y-clip py-1",
313
+ children: (said.error !== void 0 || said.retry) && /* @__PURE__ */ jsxs("div", {
314
+ "data-slot": "file-upload-error",
315
+ className: "flex flex-wrap items-center gap-x-2 text-sm font-semibold text-danger",
316
+ children: [said.error !== void 0 && /* @__PURE__ */ jsx("span", { children: said.error }), said.retry && /* @__PURE__ */ jsx("button", {
317
+ type: "button",
318
+ "data-slot": "file-upload-retry",
319
+ onClick: onRetry,
320
+ className: "touch-target relative rounded-xs font-medium text-fg underline decoration-1 underline-offset-[0.25em] focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-accent",
321
+ children: retryLabel
322
+ })]
323
+ })
324
+ })
325
+ })
326
+ ]
327
+ }),
328
+ onRemove && /* @__PURE__ */ jsx(Button, {
329
+ iconOnly: true,
330
+ size: "sm",
331
+ variant: "quiet",
332
+ "aria-label": `${name} ${removeLabel}`,
333
+ "data-slot": "file-upload-remove",
334
+ onClick: (event) => {
335
+ if (event.currentTarget === document.activeElement) keyBeside(event.currentTarget)?.focus();
336
+ onRemove();
337
+ },
338
+ className: "-my-[2.5px] shrink-0 text-fg-muted hover:text-fg",
339
+ children: /* @__PURE__ */ jsx(CloseGlyph, {
340
+ width: 10,
341
+ height: 10
342
+ })
343
+ })
344
+ ]
345
+ });
346
+ }
347
+ export { FileUpload, FileUploadItem, FileUploadList, FileUploadZone };
@@ -0,0 +1,39 @@
1
+ /**
2
+ * What a `FileUpload` works out without a browser: which files it takes, and how a size reads.
3
+ * Plain functions, so they can be tested and used on a server.
4
+ */
5
+ /** Why a file was not taken. */
6
+ export type FileRejection = {
7
+ file: File;
8
+ /** `type`: not one of the kinds asked for. `size`: over the limit. `count`: one too many. */
9
+ reason: "type" | "size" | "count";
10
+ };
11
+ export type FileRules = {
12
+ /** As on an `<input type="file">`: `.pdf`, `image/*`, `application/pdf`, comma-separated. */
13
+ accept?: string;
14
+ /** The largest size a file may have, in bytes. */
15
+ maxSize?: number;
16
+ /** Whether more than one file may be taken at once. */
17
+ multiple?: boolean;
18
+ };
19
+ /** Whether a file is one of the kinds an `accept` string asks for. No `accept` takes every file. */
20
+ export declare function acceptsFile(file: Pick<File, "name" | "type">, accept?: string): boolean;
21
+ /**
22
+ * Sorts dropped, pasted or chosen files into those that are taken and those that are not, each
23
+ * with its reason. Without `multiple` the first file that fits is taken and the others are one
24
+ * too many.
25
+ */
26
+ export declare function sortFiles(files: readonly File[], { accept, maxSize, multiple }: FileRules): {
27
+ accepted: File[];
28
+ rejected: FileRejection[];
29
+ };
30
+ /**
31
+ * A size the way a file manager writes it, in powers of 1000 and with the locale's decimal
32
+ * comma: "842 KB", "2,4 MB".
33
+ */
34
+ export declare function formatFileSize(bytes: number, locale?: string): string;
35
+ /**
36
+ * How much of a file has arrived, both numbers in the unit of the whole: "1,2 von 2,4 MB". The
37
+ * word between them is the caller's, for another language.
38
+ */
39
+ export declare function formatFileProgress(loaded: number, total: number, locale?: string, of?: string): string;
@@ -0,0 +1,74 @@
1
+ // src/components/file-upload/files.ts
2
+ /** Whether a file is one of the kinds an `accept` string asks for. No `accept` takes every file. */
3
+ function acceptsFile(file, accept) {
4
+ const kinds = (accept ?? "").split(",").map((kind) => kind.trim().toLowerCase()).filter(Boolean);
5
+ if (kinds.length === 0) return true;
6
+ const name = file.name.toLowerCase();
7
+ const type = file.type.toLowerCase();
8
+ return kinds.some((kind) => {
9
+ if (kind.startsWith(".")) return name.endsWith(kind);
10
+ if (kind.endsWith("/*")) return type.startsWith(kind.slice(0, -1));
11
+ return type === kind;
12
+ });
13
+ }
14
+ /**
15
+ * Sorts dropped, pasted or chosen files into those that are taken and those that are not, each
16
+ * with its reason. Without `multiple` the first file that fits is taken and the others are one
17
+ * too many.
18
+ */
19
+ function sortFiles(files, { accept, maxSize, multiple = false }) {
20
+ const accepted = [];
21
+ const rejected = [];
22
+ for (const file of files) if (!acceptsFile(file, accept)) rejected.push({
23
+ file,
24
+ reason: "type"
25
+ });
26
+ else if (maxSize !== void 0 && file.size > maxSize) rejected.push({
27
+ file,
28
+ reason: "size"
29
+ });
30
+ else if (!multiple && accepted.length > 0) rejected.push({
31
+ file,
32
+ reason: "count"
33
+ });
34
+ else accepted.push(file);
35
+ return {
36
+ accepted,
37
+ rejected
38
+ };
39
+ }
40
+ const UNITS = [
41
+ "B",
42
+ "KB",
43
+ "MB",
44
+ "GB",
45
+ "TB"
46
+ ];
47
+ /** The unit a number of bytes reads best in, as a power of 1000: 2 400 000 is counted in MB. */
48
+ function unitOf(bytes) {
49
+ return Math.min(UNITS.length - 1, bytes < 1 ? 0 : Math.floor(Math.log10(bytes) / 3));
50
+ }
51
+ function inUnit(bytes, unit, locale) {
52
+ const digits = unit < 2 ? 0 : 1;
53
+ return new Intl.NumberFormat(locale, {
54
+ minimumFractionDigits: digits,
55
+ maximumFractionDigits: digits
56
+ }).format(bytes / 1e3 ** unit);
57
+ }
58
+ /**
59
+ * A size the way a file manager writes it, in powers of 1000 and with the locale's decimal
60
+ * comma: "842 KB", "2,4 MB".
61
+ */
62
+ function formatFileSize(bytes, locale = "de-DE") {
63
+ const unit = unitOf(bytes);
64
+ return `${inUnit(bytes, unit, locale)} ${UNITS[unit]}`;
65
+ }
66
+ /**
67
+ * How much of a file has arrived, both numbers in the unit of the whole: "1,2 von 2,4 MB". The
68
+ * word between them is the caller's, for another language.
69
+ */
70
+ function formatFileProgress(loaded, total, locale = "de-DE", of = "von") {
71
+ const unit = unitOf(total);
72
+ return `${inUnit(Math.min(loaded, total), unit, locale)} ${of} ${inUnit(total, unit, locale)} ${UNITS[unit]}`;
73
+ }
74
+ export { acceptsFile, formatFileProgress, formatFileSize, sortFiles };