@lanfermann/ui 0.5.0 → 0.6.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 (165) hide show
  1. package/dist/components/action-bar/action-bar.d.ts +59 -0
  2. package/dist/components/action-bar/action-bar.js +116 -0
  3. package/dist/components/alert/alert.d.ts +1 -1
  4. package/dist/components/alert/alert.js +3 -17
  5. package/dist/components/alert-dialog/alert-dialog.d.ts +1 -1
  6. package/dist/components/app-shell/app-shell.d.ts +33 -0
  7. package/dist/components/app-shell/app-shell.js +93 -0
  8. package/dist/components/attachment/attachment.d.ts +46 -0
  9. package/dist/components/attachment/attachment.js +222 -0
  10. package/dist/components/attachment/kinds.d.ts +7 -0
  11. package/dist/components/attachment/kinds.js +100 -0
  12. package/dist/components/avatar/avatar.d.ts +14 -4
  13. package/dist/components/avatar/avatar.js +57 -13
  14. package/dist/components/avatar-group/avatar-group.d.ts +33 -0
  15. package/dist/components/avatar-group/avatar-group.js +110 -0
  16. package/dist/components/avatar-group/people.d.ts +12 -0
  17. package/dist/components/avatar-group/people.js +24 -0
  18. package/dist/components/badge/badge.d.ts +9 -3
  19. package/dist/components/badge/badge.js +21 -6
  20. package/dist/components/banner/banner.d.ts +39 -0
  21. package/dist/components/banner/banner.js +149 -0
  22. package/dist/components/card/card.d.ts +11 -3
  23. package/dist/components/card/card.js +18 -4
  24. package/dist/components/checkbox-card/checkbox-card.d.ts +21 -0
  25. package/dist/components/checkbox-card/checkbox-card.js +49 -0
  26. package/dist/components/chip/chip-group.d.ts +15 -0
  27. package/dist/components/chip/chip-group.js +44 -0
  28. package/dist/components/chip/chip-variants.d.ts +6 -0
  29. package/dist/components/chip/chip-variants.js +28 -0
  30. package/dist/components/chip/chip.d.ts +39 -0
  31. package/dist/components/chip/chip.js +71 -0
  32. package/dist/components/code-block/code-copy.d.ts +3 -11
  33. package/dist/components/code-block/code-copy.js +15 -62
  34. package/dist/components/code-block/code-keys.js +10 -22
  35. package/dist/components/combobox/combobox.d.ts +50 -2
  36. package/dist/components/combobox/combobox.js +178 -9
  37. package/dist/components/command/command.d.ts +131 -0
  38. package/dist/components/command/command.js +335 -0
  39. package/dist/components/consent/consent-card.js +365 -0
  40. package/dist/components/consent/consent-embed.d.ts +21 -0
  41. package/dist/components/consent/consent-embed.js +111 -0
  42. package/dist/components/consent/consent-labels.d.ts +70 -0
  43. package/dist/components/consent/consent-labels.js +61 -0
  44. package/dist/components/consent/consent-record.d.ts +95 -0
  45. package/dist/components/consent/consent-record.js +112 -0
  46. package/dist/components/consent/consent-store.d.ts +26 -0
  47. package/dist/components/consent/consent-store.js +240 -0
  48. package/dist/components/consent/consent.d.ts +86 -0
  49. package/dist/components/consent/consent.js +306 -0
  50. package/dist/components/container/container.d.ts +1 -1
  51. package/dist/components/context-menu/context-menu.d.ts +23 -0
  52. package/dist/components/context-menu/context-menu.js +50 -0
  53. package/dist/components/conversation/conversation.d.ts +45 -0
  54. package/dist/components/conversation/conversation.js +295 -0
  55. package/dist/components/conversation/stick.js +23 -0
  56. package/dist/components/copy-button/copy-button.d.ts +50 -0
  57. package/dist/components/copy-button/copy-button.js +65 -0
  58. package/dist/components/copy-page/copy-page.js +7 -17
  59. package/dist/components/copy-pill/copy-pill.js +1 -1
  60. package/dist/components/description-list/description-list.d.ts +32 -0
  61. package/dist/components/description-list/description-list.js +51 -0
  62. package/dist/components/empty/empty.d.ts +38 -0
  63. package/dist/components/empty/empty.js +57 -0
  64. package/dist/components/field/field.js +1 -1
  65. package/dist/components/file-upload/file-upload.d.ts +96 -0
  66. package/dist/components/file-upload/file-upload.js +347 -0
  67. package/dist/components/file-upload/files.d.ts +39 -0
  68. package/dist/components/file-upload/files.js +74 -0
  69. package/dist/components/grow/grow.d.ts +15 -3
  70. package/dist/components/grow/grow.js +24 -9
  71. package/dist/components/heading/heading.d.ts +1 -1
  72. package/dist/components/icon/icon.d.ts +1 -1
  73. package/dist/components/input/input.js +1 -1
  74. package/dist/components/message/message.d.ts +73 -0
  75. package/dist/components/message/message.js +196 -0
  76. package/dist/components/otp-field/otp-field.d.ts +37 -0
  77. package/dist/components/otp-field/otp-field.js +126 -0
  78. package/dist/components/pagination/pagination.d.ts +50 -0
  79. package/dist/components/pagination/pagination.js +188 -0
  80. package/dist/components/prompt-input/keys.js +15 -0
  81. package/dist/components/prompt-input/prompt-input.d.ts +89 -0
  82. package/dist/components/prompt-input/prompt-input.js +331 -0
  83. package/dist/components/radio-card/radio-card.d.ts +23 -0
  84. package/dist/components/radio-card/radio-card.js +48 -0
  85. package/dist/components/rolling-number/rolling-number.d.ts +30 -0
  86. package/dist/components/rolling-number/rolling-number.js +149 -0
  87. package/dist/components/seam/seam.d.ts +1 -1
  88. package/dist/components/secret-field/secret-field.d.ts +53 -0
  89. package/dist/components/secret-field/secret-field.js +121 -0
  90. package/dist/components/section/section.d.ts +1 -1
  91. package/dist/components/select/select.d.ts +1 -1
  92. package/dist/components/select/select.js +1 -1
  93. package/dist/components/shortcut/shortcut.d.ts +46 -0
  94. package/dist/components/shortcut/shortcut.js +87 -0
  95. package/dist/components/sidebar/sidebar-context.js +16 -0
  96. package/dist/components/sidebar/sidebar.d.ts +161 -0
  97. package/dist/components/sidebar/sidebar.js +588 -0
  98. package/dist/components/site-header/site-header.js +1 -1
  99. package/dist/components/skeleton/loaded.d.ts +21 -0
  100. package/dist/components/skeleton/loaded.js +57 -0
  101. package/dist/components/skeleton/skeleton.d.ts +43 -0
  102. package/dist/components/skeleton/skeleton.js +48 -0
  103. package/dist/components/sources/source-list.d.ts +17 -0
  104. package/dist/components/sources/source-list.js +26 -0
  105. package/dist/components/sources/sources.d.ts +45 -0
  106. package/dist/components/sources/sources.js +167 -0
  107. package/dist/components/stat/stat.d.ts +57 -0
  108. package/dist/components/stat/stat.js +110 -0
  109. package/dist/components/steps/steps.d.ts +57 -0
  110. package/dist/components/steps/steps.js +131 -0
  111. package/dist/components/table/table.d.ts +18 -9
  112. package/dist/components/table/table.js +21 -13
  113. package/dist/components/text/text.d.ts +1 -1
  114. package/dist/components/theme-switch/theme-switch.js +1 -1
  115. package/dist/components/time-field/time-field.js +1 -1
  116. package/dist/components/timeline/timeline.d.ts +45 -0
  117. package/dist/components/timeline/timeline.js +86 -0
  118. package/dist/components/toast/toast.js +10 -26
  119. package/dist/components/toggle/toggle.d.ts +24 -0
  120. package/dist/components/toggle/toggle.js +53 -0
  121. package/dist/components/toggle-group/toggle-group.d.ts +27 -0
  122. package/dist/components/toggle-group/toggle-group.js +38 -0
  123. package/dist/components/toolbar/toolbar-context.js +12 -0
  124. package/dist/components/toolbar/toolbar.d.ts +45 -0
  125. package/dist/components/toolbar/toolbar.js +92 -0
  126. package/dist/components/trace/trace.d.ts +2 -1
  127. package/dist/components/trace/trace.js +14 -26
  128. package/dist/index.d.ts +46 -3
  129. package/dist/index.js +44 -3
  130. package/dist/internal/arriving-pieces.js +56 -0
  131. package/dist/internal/arriving.js +171 -0
  132. package/dist/internal/avatar-cut.d.ts +15 -0
  133. package/dist/internal/avatar-cut.js +83 -0
  134. package/dist/internal/choice-card.d.ts +15 -0
  135. package/dist/internal/choice-card.js +65 -0
  136. package/dist/internal/clipboard.js +37 -0
  137. package/dist/internal/copy.js +58 -0
  138. package/dist/internal/field.js +24 -4
  139. package/dist/internal/glyphs.js +26 -1
  140. package/dist/internal/live-list.js +41 -0
  141. package/dist/internal/number-places.js +156 -0
  142. package/dist/internal/picker-sheet.js +1 -1
  143. package/dist/internal/presence-dot.js +24 -0
  144. package/dist/internal/presence.js +104 -0
  145. package/dist/internal/rail-mark.d.ts +3 -0
  146. package/dist/internal/rail-mark.js +33 -0
  147. package/dist/internal/status-icon.js +22 -0
  148. package/dist/internal/travelling-mark.js +204 -0
  149. package/dist/lib/cn.js +4 -0
  150. package/dist/lib/shortcut.d.ts +11 -0
  151. package/dist/lib/shortcut.js +165 -0
  152. package/package.json +1 -1
  153. package/src/styles/action-bar.css +28 -0
  154. package/src/styles/assistant.css +83 -0
  155. package/src/styles/avatar.css +24 -0
  156. package/src/styles/consent.css +65 -0
  157. package/src/styles/copy.css +12 -11
  158. package/src/styles/depth.css +46 -2
  159. package/src/styles/marks.css +20 -2
  160. package/src/styles/rail.css +49 -0
  161. package/src/styles/rolling-number.css +94 -0
  162. package/src/styles/steps.css +98 -0
  163. package/src/styles/timeline.css +48 -0
  164. package/src/styles/travel.css +36 -0
  165. package/src/styles.css +9 -0
@@ -0,0 +1,588 @@
1
+ "use client";
2
+ import { Button } from "../button/button.js";
3
+ import { Drawer, DrawerClose, DrawerContent, DrawerTitle } from "../drawer/drawer.js";
4
+ import { Icon } from "../icon/icon.js";
5
+ import { Menu, MenuContent, MenuTrigger } from "../menu/menu.js";
6
+ import { ScrollFade } from "../scroll-fade/scroll-fade.js";
7
+ import { Shortcut } from "../shortcut/shortcut.js";
8
+ import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "../tooltip/tooltip.js";
9
+ import { disclosureChevron, disclosurePanel } from "../../internal/disclosure.js";
10
+ import { ChevronRightGlyph } from "../../internal/glyphs.js";
11
+ import { renderAs } from "../../internal/render-as.js";
12
+ import { useTravellingMark } from "../../internal/travelling-mark.js";
13
+ import { cn } from "../../lib/cn.js";
14
+ import { SidebarStateContext, useWideWindow } from "./sidebar-context.js";
15
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
16
+ import { createContext, useContext, useEffect, useId, useMemo, useRef, useState } from "react";
17
+ import { Collapsible } from "@base-ui/react/collapsible";
18
+ // src/components/sidebar/sidebar.tsx
19
+ const SidebarLayoutContext = createContext({
20
+ rail: false,
21
+ label: ""
22
+ });
23
+ const focusRing = "focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-accent";
24
+ /**
25
+ * The lengths every part is cut from.
26
+ *
27
+ * --sidebar-width the open sidebar
28
+ * --sidebar-rail the collapsed one: a row's height, and the gutter to both sides
29
+ * --sidebar-pad what a row keeps to the left of its symbol, so that a 16px symbol stands
30
+ * in the middle of a row that is as wide as it is tall
31
+ * --sidebar-row the width a row's content is laid out at, whatever the row's own width
32
+ * --sidebar-current the tint of the current entry, taken away once the travelling tint has
33
+ * taken over (and given back inside a group that is folding)
34
+ */
35
+ const lengths = [
36
+ "[--sidebar-width:15rem]",
37
+ "[--sidebar-rail:calc(var(--control-md)+1rem)]",
38
+ "[--sidebar-pad:calc((var(--control-md)-1rem)/2)]",
39
+ "[--sidebar-row:calc(var(--sidebar-width)-1rem-1px)]",
40
+ "[--sidebar-current:var(--lf-tint)]"
41
+ ].join(" ");
42
+ /**
43
+ * The navigation of an app, beside its pages: the places one works in, in groups, each with a
44
+ * symbol. It is read and it leads somewhere, so it is flat: no shadow, a hairline to the page.
45
+ * The page one is on stands on the tint, and the tint travels there when the page changes; on a
46
+ * subpage it goes down to the subpage. By default it stands on the page's ground; `bg-well` as
47
+ * its class makes it a plate of its own beside the page.
48
+ *
49
+ * Put a `SidebarHeader`, a `SidebarContent` with the entries and a `SidebarFooter` inside, and
50
+ * the sidebar inside an `AppShell`. The shell keeps whether it is open; a `SidebarTrigger`
51
+ * anywhere in the shell collapses it, and so does ⌘B. Collapsed, the symbols stay where they
52
+ * are and what stands to their right leaves. On a narrow window the same sidebar comes in from
53
+ * the left as a drawer that can be swiped back.
54
+ *
55
+ * Word an entry as the place, a noun of one or two words ("Angebote", "Einstellungen"). An
56
+ * entry that does something instead of leading somewhere belongs in a menu or the page.
57
+ */
58
+ function Sidebar({ "aria-label": label, collapse = "rail", className, children, ...props }) {
59
+ const state = useContext(SidebarStateContext);
60
+ const box = useRef(null);
61
+ const open = state?.open ?? true;
62
+ const rail = !open && collapse === "rail";
63
+ const gone = !open && collapse === "hidden";
64
+ useEffect(() => {
65
+ const sidebar = box.current;
66
+ if (!gone || !sidebar?.contains(document.activeElement)) return;
67
+ sidebar.closest("[data-slot=\"app-shell\"]")?.querySelector("[data-slot=\"sidebar-trigger\"]")?.focus();
68
+ }, [gone]);
69
+ const layout = useMemo(() => ({
70
+ rail,
71
+ label
72
+ }), [rail, label]);
73
+ const closeDrawer = state?.setDrawerOpen;
74
+ const drawerLayout = useMemo(() => ({
75
+ rail: false,
76
+ label,
77
+ onNavigate: () => closeDrawer?.(false)
78
+ }), [label, closeDrawer]);
79
+ return /* @__PURE__ */ jsxs(TooltipProvider, { children: [/* @__PURE__ */ jsx(SidebarLayoutContext, {
80
+ value: layout,
81
+ children: /* @__PURE__ */ jsx("div", {
82
+ ref: box,
83
+ id: state?.id,
84
+ "data-slot": "sidebar",
85
+ "data-state": open ? "expanded" : "collapsed",
86
+ "data-collapse": collapse,
87
+ "data-rail": rail ? "" : void 0,
88
+ inert: gone,
89
+ className: cn(lengths, "sticky top-0 z-10 h-dvh shrink-0 justify-end self-start overflow-hidden border-r border-hairline bg-ground text-control", "w-(--sidebar-width) transition-[width,border-color] spring-settle", "data-rail:w-(--sidebar-rail)", "data-[collapse=hidden]:data-[state=collapsed]:w-0 data-[collapse=hidden]:data-[state=collapsed]:border-transparent", state ? "hidden md:flex" : "flex", className),
90
+ ...props,
91
+ children: /* @__PURE__ */ jsx("div", {
92
+ "data-slot": "sidebar-inner",
93
+ className: cn("flex min-h-0 flex-col", collapse === "hidden" ? "w-[calc(var(--sidebar-width)-1px)] shrink-0" : "w-full"),
94
+ children
95
+ })
96
+ })
97
+ }), state ? /* @__PURE__ */ jsx(Drawer, {
98
+ side: "left",
99
+ open: state.drawerOpen,
100
+ onOpenChange: state.setDrawerOpen,
101
+ children: /* @__PURE__ */ jsxs(DrawerContent, {
102
+ hideClose: true,
103
+ className: "w-[calc(18rem+var(--bleed))] rounded-r-xl py-0 pr-0 pl-(--bleed)",
104
+ children: [
105
+ /* @__PURE__ */ jsx(DrawerTitle, {
106
+ className: "sr-only",
107
+ children: label
108
+ }),
109
+ /* @__PURE__ */ jsx(SidebarLayoutContext, {
110
+ value: drawerLayout,
111
+ children: /* @__PURE__ */ jsx("div", {
112
+ "data-slot": "sidebar",
113
+ "data-drawer": "",
114
+ className: cn(lengths, "flex min-h-0 flex-1 flex-col text-control [--sidebar-row:calc(var(--sidebar-width)-1rem)] [--sidebar-width:18rem]"),
115
+ children
116
+ })
117
+ }),
118
+ /* @__PURE__ */ jsx(DrawerClose, {
119
+ className: "sr-only",
120
+ children: "Schließen"
121
+ })
122
+ ]
123
+ })
124
+ }) : null] });
125
+ }
126
+ /** What stands above the entries and stays there: the workspace, the product's mark. */
127
+ function SidebarHeader({ className, ...props }) {
128
+ return /* @__PURE__ */ jsx("div", {
129
+ "data-slot": "sidebar-header",
130
+ className: cn("flex h-12 shrink-0 items-center px-2", className),
131
+ ...props
132
+ });
133
+ }
134
+ /** What stands below the entries and stays there: the person who is signed in. */
135
+ function SidebarFooter({ className, ...props }) {
136
+ return /* @__PURE__ */ jsx("div", {
137
+ "data-slot": "sidebar-footer",
138
+ className: cn("flex shrink-0 flex-col gap-0.5 p-2", className),
139
+ ...props
140
+ });
141
+ }
142
+ /**
143
+ * The entries: `SidebarGroup`s, or `SidebarItem`s without a group. It is the navigation, named
144
+ * by the sidebar's `aria-label`, and it scrolls inside itself when the entries do not fit,
145
+ * fading at the end that has more.
146
+ */
147
+ function SidebarContent({ className, children, ...props }) {
148
+ const { label } = useContext(SidebarLayoutContext);
149
+ const list = useRef(null);
150
+ const mark = useRef(null);
151
+ useTravellingMark(list, mark, {
152
+ current: ":is([data-slot=\"sidebar-item\"], [data-slot=\"sidebar-sub-item\"], [data-slot=\"sidebar-menu\"])[data-current]",
153
+ attribute: "data-current",
154
+ still: "data-folding",
155
+ folds: "[data-slot=\"sidebar-sub\"]"
156
+ });
157
+ return /* @__PURE__ */ jsx("nav", {
158
+ "data-slot": "sidebar-content",
159
+ "aria-label": label,
160
+ className: cn("flex min-h-0 flex-1 flex-col", className),
161
+ ...props,
162
+ children: /* @__PURE__ */ jsx(ScrollFade, {
163
+ axis: "y",
164
+ className: "min-h-0 flex-1 [scrollbar-width:none] overscroll-contain px-2 py-2",
165
+ children: /* @__PURE__ */ jsxs("ul", {
166
+ ref: list,
167
+ "data-slot": "sidebar-list",
168
+ className: "relative isolate flex flex-col gap-4 data-placed:[--sidebar-current:transparent]",
169
+ children: [children, /* @__PURE__ */ jsx("li", {
170
+ ref: mark,
171
+ "aria-hidden": true,
172
+ role: "presentation",
173
+ "data-slot": "sidebar-mark",
174
+ className: "travels -z-10 rounded-md bg-tint"
175
+ })]
176
+ })
177
+ })
178
+ });
179
+ }
180
+ /** Text that leaves when the sidebar collapses to its rail, and comes back with it. */
181
+ const leaves = "transition-opacity spring-settle in-data-rail:opacity-0 in-data-rail:spring-leave";
182
+ const groupTitle = [
183
+ "relative flex h-7 w-full shrink-0 items-center overflow-hidden rounded-md text-left text-sm text-fg-muted",
184
+ "after:absolute after:top-1/2 after:left-(--sidebar-pad) after:h-px after:w-4 after:bg-hairline after:opacity-0 after:transition-opacity after:spring-leave",
185
+ "in-data-rail:after:opacity-100 in-data-rail:after:delay-150 in-data-rail:after:spring-settle"
186
+ ].join(" ");
187
+ const groupTitleStrip = cn("flex w-(--sidebar-row) shrink-0 items-center gap-2 px-(--sidebar-pad) whitespace-nowrap", leaves);
188
+ const groupList = "flex flex-col gap-0.5";
189
+ /**
190
+ * Entries that belong together, under their name. Without a `title` they simply stand apart
191
+ * from the group before. A group that is `collapsible` folds under its name; use it for a
192
+ * group that is long and not needed every day, and leave the main one alone.
193
+ */
194
+ function SidebarGroup({ title, collapsible = false, open, defaultOpen = true, onOpenChange, className, children, ...props }) {
195
+ const id = useId();
196
+ const { rail } = useContext(SidebarLayoutContext);
197
+ const [folding, setFolding] = useState(false);
198
+ const rest = useRef(void 0);
199
+ useEffect(() => () => clearTimeout(rest.current), []);
200
+ if (!collapsible || title === void 0) return /* @__PURE__ */ jsxs("li", {
201
+ "data-slot": "sidebar-group",
202
+ className: cn("flex flex-col gap-0.5", className),
203
+ ...props,
204
+ children: [title !== void 0 && /* @__PURE__ */ jsx("p", {
205
+ id,
206
+ "data-slot": "sidebar-group-title",
207
+ className: groupTitle,
208
+ children: /* @__PURE__ */ jsx("span", {
209
+ className: groupTitleStrip,
210
+ children: title
211
+ })
212
+ }), /* @__PURE__ */ jsx("ul", {
213
+ "aria-labelledby": title !== void 0 ? id : void 0,
214
+ className: groupList,
215
+ children
216
+ })]
217
+ });
218
+ const settled = () => {
219
+ clearTimeout(rest.current);
220
+ setFolding(false);
221
+ };
222
+ return /* @__PURE__ */ jsxs(Collapsible.Root, {
223
+ render: /* @__PURE__ */ jsx("li", { ...props }),
224
+ "data-slot": "sidebar-group",
225
+ "data-folding": folding ? "" : void 0,
226
+ open,
227
+ defaultOpen,
228
+ disabled: rail,
229
+ onOpenChange: (next) => {
230
+ onOpenChange?.(next);
231
+ setFolding(true);
232
+ clearTimeout(rest.current);
233
+ rest.current = setTimeout(settled, 900);
234
+ },
235
+ className: cn("flex flex-col gap-0.5 data-folding:[--sidebar-current:var(--lf-tint)]", className),
236
+ children: [/* @__PURE__ */ jsx(Collapsible.Trigger, {
237
+ id,
238
+ "data-slot": "sidebar-group-title",
239
+ className: cn(groupTitle, "group select-none hover:text-fg", focusRing),
240
+ children: /* @__PURE__ */ jsxs("span", {
241
+ className: groupTitleStrip,
242
+ children: [title, /* @__PURE__ */ jsx(ChevronRightGlyph, {
243
+ width: 10,
244
+ height: 10,
245
+ className: cn(disclosureChevron, "ml-auto group-data-panel-open:rotate-90")
246
+ })]
247
+ })
248
+ }), /* @__PURE__ */ jsx(Collapsible.Panel, {
249
+ "data-slot": "sidebar-group-panel",
250
+ onTransitionEnd: (event) => {
251
+ if (event.target === event.currentTarget && event.propertyName === "height") settled();
252
+ },
253
+ className: cn("-m-1 h-(--collapsible-panel-height) p-1", disclosurePanel),
254
+ children: /* @__PURE__ */ jsx("ul", {
255
+ "aria-labelledby": id,
256
+ className: groupList,
257
+ children
258
+ })
259
+ })]
260
+ });
261
+ }
262
+ /**
263
+ * A row. It is as wide as the sidebar lets it be, and it clips: what it holds is laid out at
264
+ * the sidebar's full width and never reflows. So when the sidebar collapses, the symbol stays
265
+ * exactly where it is and the row's edge takes away what stands to its right.
266
+ */
267
+ const row = [
268
+ "group/row relative flex h-(--control-md) w-full shrink-0 items-center overflow-hidden rounded-md text-left text-control text-fg-body select-none",
269
+ "not-data-current:hover:bg-hover hover:text-fg data-popup-open:text-fg not-data-current:data-popup-open:bg-hover",
270
+ "data-current:bg-(--sidebar-current) data-current:font-medium data-current:text-fg",
271
+ "data-within:text-fg",
272
+ "forced-colors:data-current:outline forced-colors:data-current:-outline-offset-1",
273
+ focusRing
274
+ ].join(" ");
275
+ const rowStrip = "flex w-(--sidebar-row) shrink-0 items-center gap-2.5 px-(--sidebar-pad)";
276
+ const rowStripMedia = "gap-1.5 px-[calc((var(--control-md)-1.5rem)/2)]";
277
+ const rowLabel = cn("min-w-0 flex-1 truncate", leaves);
278
+ const rowDetail = cn("flex shrink-0 items-center text-sm text-fg-muted tabular-nums", leaves);
279
+ /**
280
+ * The symbol answers the hand. Under the pointer it darkens, from muted to the text colour, and
281
+ * that is all most symbols do. Under a press it dips and, let go, seats back with the small
282
+ * bounce a button has (`seat`). A symbol that has a motion of its own in it (a gear turns, a
283
+ * sheet is picked up) may show it under the pointer: `iconMotion`. The motions are transforms,
284
+ * and none of them runs under reduced motion.
285
+ */
286
+ const rowSymbol = [
287
+ "text-fg-muted transition-[color,scale,rotate] spring-seat",
288
+ "group-hover/row:text-fg group-hover/row:spring-snap group-data-popup-open/row:text-fg",
289
+ "group-data-current/row:text-fg group-data-within/row:text-fg group-aria-[current=page]/row:text-fg",
290
+ "motion-safe:group-active/row:scale-90 group-active/row:spring-snap"
291
+ ].join(" ");
292
+ /** What the symbol does under the pointer, besides darkening. */
293
+ const symbolMotion = {
294
+ /** Nothing. The default: a symbol is not sized up just so that something happens. */
295
+ none: "",
296
+ /** It turns by a sixth: for what turns, a gear, a wheel, something that reloads. */
297
+ turn: "motion-safe:group-hover/row:rotate-60",
298
+ /** It leans, the way a sheet is picked up by its corner: for a page, a note, a letter. */
299
+ tilt: "motion-safe:group-hover/row:-rotate-8"
300
+ };
301
+ /** Two chevrons that part a little: the row opens a menu. */
302
+ function UnfoldGlyph() {
303
+ const part = "transition-[translate] spring-seat group-hover/row:spring-snap";
304
+ return /* @__PURE__ */ jsxs("svg", {
305
+ "data-slot": "glyph",
306
+ width: "12",
307
+ height: "12",
308
+ viewBox: "0 0 12 12",
309
+ fill: "none",
310
+ stroke: "currentColor",
311
+ strokeWidth: "1.5",
312
+ strokeLinecap: "round",
313
+ strokeLinejoin: "round",
314
+ "aria-hidden": true,
315
+ className: "shrink-0 overflow-visible",
316
+ children: [/* @__PURE__ */ jsx("path", {
317
+ d: "M3.5 4.5 6 2l2.5 2.5",
318
+ className: cn(part, "motion-safe:group-hover/row:-translate-y-px motion-safe:group-data-popup-open/row:-translate-y-px")
319
+ }), /* @__PURE__ */ jsx("path", {
320
+ d: "M3.5 7.5 6 10l2.5-2.5",
321
+ className: cn(part, "motion-safe:group-hover/row:translate-y-px motion-safe:group-data-popup-open/row:translate-y-px")
322
+ })]
323
+ });
324
+ }
325
+ /**
326
+ * One chevron that points to where the menu opens: beside the sidebar. It leans there by a
327
+ * pixel under the pointer and while the menu is open. In the drawer the menu opens below.
328
+ */
329
+ function AsideGlyph() {
330
+ return /* @__PURE__ */ jsx(ChevronRightGlyph, { className: cn("shrink-0 transition-[translate] spring-seat group-hover/row:spring-snap in-data-drawer:rotate-90", "motion-safe:group-hover/row:translate-x-px motion-safe:group-data-popup-open/row:translate-x-px", "motion-safe:in-data-drawer:group-hover/row:translate-x-0 motion-safe:in-data-drawer:group-hover/row:translate-y-px", "motion-safe:in-data-drawer:group-data-popup-open/row:translate-x-0 motion-safe:in-data-drawer:group-data-popup-open/row:translate-y-px") });
331
+ }
332
+ function RowContent({ icon, iconMotion = "none", media, detail, children }) {
333
+ return /* @__PURE__ */ jsxs("span", {
334
+ className: cn(rowStrip, media !== void 0 && rowStripMedia),
335
+ children: [
336
+ media !== void 0 ? /* @__PURE__ */ jsx("span", {
337
+ "data-slot": "sidebar-media",
338
+ className: "flex size-6 shrink-0 items-center justify-center transition-[scale] spring-seat group-active/row:spring-snap motion-safe:group-active/row:scale-92",
339
+ children: media
340
+ }) : icon ? /* @__PURE__ */ jsx(Icon, {
341
+ icon,
342
+ size: 16,
343
+ className: cn(rowSymbol, symbolMotion[iconMotion])
344
+ }) : null,
345
+ /* @__PURE__ */ jsx("span", {
346
+ "data-slot": "sidebar-label",
347
+ className: rowLabel,
348
+ children
349
+ }),
350
+ detail !== void 0 && /* @__PURE__ */ jsx("span", {
351
+ "data-slot": "sidebar-detail",
352
+ className: rowDetail,
353
+ children: detail
354
+ })
355
+ ]
356
+ });
357
+ }
358
+ /**
359
+ * One place of the app: a symbol and its name. For a router's link, pass it as `render`. On
360
+ * the rail the name is a tooltip beside the symbol.
361
+ */
362
+ function SidebarItem({ icon, iconMotion, media, detail, current = false, sub, open = false, render, className, children, onClick, ...props }) {
363
+ const { rail, onNavigate } = useContext(SidebarLayoutContext);
364
+ const unfolded = (current || open) && !rail;
365
+ const within = open && !current;
366
+ const tinted = current || within && rail;
367
+ const link = renderAs("a", render, {
368
+ ...props,
369
+ "data-slot": "sidebar-item",
370
+ "aria-current": current ? "page" : void 0,
371
+ "data-current": tinted ? "" : void 0,
372
+ "data-within": within ? "" : void 0,
373
+ onClick: (event) => {
374
+ onClick?.(event);
375
+ onNavigate?.();
376
+ },
377
+ className: cn(row, className),
378
+ children: /* @__PURE__ */ jsx(RowContent, {
379
+ icon,
380
+ iconMotion,
381
+ media,
382
+ detail,
383
+ children
384
+ })
385
+ });
386
+ return /* @__PURE__ */ jsxs("li", {
387
+ "data-slot": "sidebar-entry",
388
+ className: "flex flex-col",
389
+ children: [/* @__PURE__ */ jsxs(Tooltip, {
390
+ disabled: !rail,
391
+ children: [/* @__PURE__ */ jsx(TooltipTrigger, { render: link }), /* @__PURE__ */ jsx(TooltipContent, {
392
+ side: "right",
393
+ sideOffset: 14,
394
+ children
395
+ })]
396
+ }), sub ? /* @__PURE__ */ jsx("div", {
397
+ "data-slot": "sidebar-sub",
398
+ "data-open": unfolded ? "" : void 0,
399
+ inert: !unfolded,
400
+ className: cn("grid grid-rows-[0fr] overflow-hidden opacity-0 transition-[grid-template-rows,opacity,visibility] spring-leave", "invisible data-open:visible data-open:grid-rows-[1fr] data-open:opacity-100 data-open:spring-settle", "-mx-1 px-1"),
401
+ children: /* @__PURE__ */ jsx("div", {
402
+ className: "min-h-0",
403
+ children: /* @__PURE__ */ jsx("div", {
404
+ className: "pt-1 pb-1.5",
405
+ children: /* @__PURE__ */ jsx("ul", {
406
+ className: "ml-[calc(var(--sidebar-pad)+0.5rem-0.5px)] flex w-[calc(var(--sidebar-row)-var(--sidebar-pad)-0.5rem+0.5px)] flex-col gap-0.5 border-l border-hairline",
407
+ children: sub
408
+ })
409
+ })
410
+ })
411
+ }) : null]
412
+ });
413
+ }
414
+ /**
415
+ * The tint's own shape on a subpage, set in from the hairline. The hairline stands on a half
416
+ * pixel (the middle of the symbol above); the half pixel here puts the shape back on whole
417
+ * ones, where the travelling tint is measured, and its name on the line of the names above.
418
+ */
419
+ const subItemShape = ["ml-[7.5px] rounded-md pl-2.5 not-aria-[current=page]:hover:bg-hover data-current:bg-(--sidebar-current)", "forced-colors:aria-[current=page]:outline forced-colors:aria-[current=page]:-outline-offset-1"].join(" ");
420
+ /**
421
+ * A subpage under an entry, with a 14px symbol if the subpages have them (all of them, or none:
422
+ * the names should start on one line). The one being worked on stands on the tint, which comes
423
+ * down to it from the page above; that page stays in the text colour, so the part of the app
424
+ * one is in can still be told.
425
+ */
426
+ function SidebarSubItem({ icon, iconMotion = "none", current = false, render, className, onClick, children, ...props }) {
427
+ const { rail, onNavigate } = useContext(SidebarLayoutContext);
428
+ const link = renderAs("a", render, {
429
+ ...props,
430
+ "data-slot": "sidebar-sub-item",
431
+ "aria-current": current ? "page" : void 0,
432
+ "data-current": current && !rail ? "" : void 0,
433
+ onClick: (event) => {
434
+ onClick?.(event);
435
+ onNavigate?.();
436
+ },
437
+ className: cn("group/row flex min-h-7 items-center gap-2 py-0.5 pr-2 text-sm text-fg-muted select-none hover:text-fg", "aria-[current=page]:font-medium aria-[current=page]:text-fg", subItemShape, focusRing, className),
438
+ children: /* @__PURE__ */ jsxs(Fragment, { children: [icon ? /* @__PURE__ */ jsx(Icon, {
439
+ icon,
440
+ size: 14,
441
+ className: cn(rowSymbol, symbolMotion[iconMotion])
442
+ }) : null, /* @__PURE__ */ jsx("span", {
443
+ "data-slot": "sidebar-label",
444
+ className: "min-w-0 flex-1 truncate",
445
+ children
446
+ })] })
447
+ });
448
+ return /* @__PURE__ */ jsx("li", {
449
+ "data-slot": "sidebar-sub-entry",
450
+ children: link
451
+ });
452
+ }
453
+ /**
454
+ * An entry that opens a menu beside the sidebar instead of leading somewhere: the places that
455
+ * are needed now and then and would make the list too long ("Mehr"). A chevron at its end
456
+ * points to where the menu opens. On the rail the menu opens from the symbol alone, and in the
457
+ * drawer of a narrow window it opens below the entry.
458
+ *
459
+ * Name it as what the menu holds, a noun, and put the places inside as `items`. What is needed
460
+ * every day stays in the list as a `SidebarItem`.
461
+ */
462
+ function SidebarMenu({ icon, iconMotion, media, items, current = false, open, defaultOpen = false, onOpenChange, modal, render, className, children, ...props }) {
463
+ const { rail, onNavigate } = useContext(SidebarLayoutContext);
464
+ const drawer = onNavigate !== void 0;
465
+ const [unfolded, setUnfolded] = useState(defaultOpen);
466
+ const shown = open ?? unfolded;
467
+ const trigger = renderAs("button", render, {
468
+ type: "button",
469
+ ...props,
470
+ "data-slot": "sidebar-menu",
471
+ "aria-current": current ? "true" : void 0,
472
+ "data-current": current ? "" : void 0,
473
+ className: cn(row, className),
474
+ children: /* @__PURE__ */ jsx(RowContent, {
475
+ icon,
476
+ iconMotion,
477
+ media,
478
+ detail: /* @__PURE__ */ jsx(AsideGlyph, {}),
479
+ children
480
+ })
481
+ });
482
+ return /* @__PURE__ */ jsx("li", {
483
+ "data-slot": "sidebar-entry",
484
+ className: "flex flex-col",
485
+ children: /* @__PURE__ */ jsxs(Menu, {
486
+ open,
487
+ defaultOpen,
488
+ modal,
489
+ onOpenChange: (next, details) => {
490
+ setUnfolded(next);
491
+ onOpenChange?.(next, details);
492
+ },
493
+ children: [/* @__PURE__ */ jsxs(Tooltip, {
494
+ disabled: !rail || shown,
495
+ children: [/* @__PURE__ */ jsx(TooltipTrigger, { render: /* @__PURE__ */ jsx(MenuTrigger, { render: trigger }) }), /* @__PURE__ */ jsx(TooltipContent, {
496
+ side: "right",
497
+ sideOffset: 14,
498
+ children
499
+ })]
500
+ }), /* @__PURE__ */ jsx(MenuContent, {
501
+ side: drawer ? "bottom" : "right",
502
+ align: "start",
503
+ sideOffset: drawer ? 4 : 14,
504
+ alignOffset: drawer ? 0 : -4,
505
+ onClick: () => onNavigate?.(),
506
+ children: items
507
+ })]
508
+ })
509
+ });
510
+ }
511
+ /**
512
+ * A row that is pressed instead of leading somewhere, for the header and the footer: the
513
+ * workspace or the person, as the trigger of a `Menu`
514
+ * (`<MenuTrigger render={<SidebarButton menu media={…}>…</SidebarButton>} />`). Not for the
515
+ * list of places: those are `SidebarItem`s.
516
+ */
517
+ function SidebarButton({ icon, iconMotion, media, detail, menu = false, render, className, children, ...props }) {
518
+ return renderAs("button", render, {
519
+ type: "button",
520
+ ...props,
521
+ "data-slot": "sidebar-button",
522
+ className: cn(row, className),
523
+ children: /* @__PURE__ */ jsx(RowContent, {
524
+ icon,
525
+ iconMotion,
526
+ media,
527
+ detail: menu ? /* @__PURE__ */ jsx(UnfoldGlyph, {}) : detail,
528
+ children
529
+ })
530
+ });
531
+ }
532
+ /** A window with its side panel. The dividing line steps aside while the sidebar is collapsed. */
533
+ function SidebarGlyph() {
534
+ return /* @__PURE__ */ jsxs("svg", {
535
+ "data-slot": "glyph",
536
+ width: "16",
537
+ height: "16",
538
+ viewBox: "0 0 16 16",
539
+ fill: "none",
540
+ stroke: "currentColor",
541
+ strokeWidth: "1.5",
542
+ strokeLinecap: "round",
543
+ strokeLinejoin: "round",
544
+ "aria-hidden": true,
545
+ className: "shrink-0",
546
+ children: [/* @__PURE__ */ jsx("rect", {
547
+ x: "1.75",
548
+ y: "2.75",
549
+ width: "12.5",
550
+ height: "10.5",
551
+ rx: "2.5"
552
+ }), /* @__PURE__ */ jsx("path", {
553
+ d: "M6.25 3v10",
554
+ className: "transition-[translate] spring-seat group-aria-[expanded=false]/trigger:-translate-x-[1.5px]"
555
+ })]
556
+ });
557
+ }
558
+ /**
559
+ * The button that collapses and expands the sidebar, usually the first thing in the page's bar.
560
+ * On a narrow window it opens the sidebar as a drawer. Its tooltip names the shortcut.
561
+ */
562
+ function SidebarTrigger({ "aria-label": label = "Seitenleiste", className, onClick, ...props }) {
563
+ const state = useContext(SidebarStateContext);
564
+ const wide = useWideWindow();
565
+ const expanded = state ? wide ? state.open : state.drawerOpen : true;
566
+ return /* @__PURE__ */ jsxs(Tooltip, { children: [/* @__PURE__ */ jsx(TooltipTrigger, {
567
+ render: /* @__PURE__ */ jsx(Button, {
568
+ variant: "quiet",
569
+ ...props,
570
+ iconOnly: true,
571
+ "aria-label": label,
572
+ "aria-expanded": expanded,
573
+ "aria-controls": wide ? state?.id : void 0,
574
+ "data-slot": "sidebar-trigger",
575
+ className: cn("group/trigger text-fg-muted hover:text-fg", className),
576
+ onClick: (event) => {
577
+ onClick?.(event);
578
+ state?.toggle();
579
+ }
580
+ }),
581
+ children: /* @__PURE__ */ jsx(SidebarGlyph, {})
582
+ }), /* @__PURE__ */ jsxs(TooltipContent, {
583
+ side: "bottom",
584
+ className: "flex items-center gap-2",
585
+ children: [label, state?.shortcut ? /* @__PURE__ */ jsx(Shortcut, { keys: state.shortcut }) : null]
586
+ })] });
587
+ }
588
+ export { Sidebar, SidebarButton, SidebarContent, SidebarFooter, SidebarGroup, SidebarHeader, SidebarItem, SidebarMenu, SidebarSubItem, SidebarTrigger };
@@ -5,8 +5,8 @@ import { Icon } from "../icon/icon.js";
5
5
  import { useScrollEdges } from "../scroll-fade/use-scroll-edges.js";
6
6
  import { cn } from "../../lib/cn.js";
7
7
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
8
- import { Cancel01Icon, Menu01Icon } from "@hugeicons/core-free-icons";
9
8
  import { createContext, useCallback, useContext, useId, useRef, useState } from "react";
9
+ import { Cancel01Icon, Menu01Icon } from "@hugeicons/core-free-icons";
10
10
  import { Dialog } from "@base-ui/react/dialog";
11
11
  import { useRender } from "@base-ui/react/use-render";
12
12
  // src/components/site-header/site-header.tsx
@@ -0,0 +1,21 @@
1
+ import { ComponentProps, ReactNode } from "react";
2
+ export type LoadedProps = Omit<ComponentProps<"div">, "children"> & {
3
+ /** The content is there. */
4
+ ready: boolean;
5
+ /** What stands in for the content until then: a `SkeletonGroup` in the content's shape. */
6
+ skeleton: ReactNode;
7
+ /** The content. It is not rendered before it is `ready`. */
8
+ children: ReactNode;
9
+ };
10
+ /**
11
+ * Content that may still be on its way, with the skeleton that stands in for it. It keeps the
12
+ * two from flickering:
13
+ *
14
+ * an answer within a fifth of a second the skeleton never shows, the content is simply there
15
+ * an answer after that the skeleton has shown itself, so it stays for a
16
+ * moment longer, and the content fades in over it
17
+ *
18
+ * Where the framework holds content back itself (a `Suspense` boundary), a `SkeletonGroup`
19
+ * alone is the fallback and this is not needed.
20
+ */
21
+ export declare function Loaded({ ready, skeleton, className, children, ...props }: LoadedProps): string | number | bigint | boolean | import("react").JSX.Element | Iterable<ReactNode> | Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | null | undefined;
@@ -0,0 +1,57 @@
1
+ "use client";
2
+ import { cn } from "../../lib/cn.js";
3
+ import { jsx } from "react/jsx-runtime";
4
+ import { useEffect, useRef, useState } from "react";
5
+ // src/components/skeleton/loaded.tsx
6
+ /** How long a `SkeletonGroup` waits before it shows itself. The same number as its class. */
7
+ const SHOW_AFTER_MS = 200;
8
+ /** How long a skeleton that has shown itself stays at least, so it does not flicker. */
9
+ const STAY_MS = 350;
10
+ /**
11
+ * Content that may still be on its way, with the skeleton that stands in for it. It keeps the
12
+ * two from flickering:
13
+ *
14
+ * an answer within a fifth of a second the skeleton never shows, the content is simply there
15
+ * an answer after that the skeleton has shown itself, so it stays for a
16
+ * moment longer, and the content fades in over it
17
+ *
18
+ * Where the framework holds content back itself (a `Suspense` boundary), a `SkeletonGroup`
19
+ * alone is the fallback and this is not needed.
20
+ */
21
+ function Loaded({ ready, skeleton, className, children, ...props }) {
22
+ const [showing, setShowing] = useState(ready ? "content" : "skeleton");
23
+ const [arrived, setArrived] = useState(false);
24
+ const seenAt = useRef(null);
25
+ const [wasReady, setWasReady] = useState(ready);
26
+ if (ready !== wasReady) {
27
+ setWasReady(ready);
28
+ if (!ready) setShowing("skeleton");
29
+ }
30
+ useEffect(() => {
31
+ if (ready) return;
32
+ seenAt.current = null;
33
+ const timer = setTimeout(() => {
34
+ seenAt.current = performance.now();
35
+ }, SHOW_AFTER_MS);
36
+ return () => clearTimeout(timer);
37
+ }, [ready]);
38
+ useEffect(() => {
39
+ if (!ready || showing === "content") return;
40
+ const seen = seenAt.current;
41
+ const wait = seen === null ? 0 : Math.max(0, STAY_MS - (performance.now() - seen));
42
+ const timer = setTimeout(() => {
43
+ setArrived(seen !== null);
44
+ setShowing("content");
45
+ }, wait);
46
+ return () => clearTimeout(timer);
47
+ }, [ready, showing]);
48
+ if (showing === "skeleton") return skeleton;
49
+ return /* @__PURE__ */ jsx("div", {
50
+ "data-slot": "loaded",
51
+ "data-arrived": arrived ? "" : void 0,
52
+ className: cn("transition-opacity spring-settle data-arrived:starting:opacity-0", className),
53
+ ...props,
54
+ children
55
+ });
56
+ }
57
+ export { Loaded };