asta-ui 0.9.6 → 0.9.7

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.
@@ -0,0 +1,388 @@
1
+ "use client";
2
+ import {
3
+ Avatar
4
+ } from "./chunk-6RA7LJ3K.js";
5
+
6
+ // components/kit/sidebar.tsx
7
+ import { useEffect, useLayoutEffect, useRef, useState } from "react";
8
+ import { jsx, jsxs } from "react/jsx-runtime";
9
+ var cx = (...c) => c.filter(Boolean).join(" ");
10
+ var EASE = "ease-[cubic-bezier(.16,1,.3,1)]";
11
+ var RING = "shadow-[inset_0_0_0_1px_color-mix(in_srgb,var(--ink)_10%,transparent)]";
12
+ var HOVER = "hover:bg-[color-mix(in_srgb,var(--ink)_4%,transparent)]";
13
+ var ON = "bg-[color-mix(in_srgb,var(--ink)_6%,transparent)]";
14
+ var Icon = ({ d, className = "" }) => /* @__PURE__ */ jsx("svg", { viewBox: "0 0 16 16", className: cx("h-4 w-4", className), fill: "none", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": true, children: /* @__PURE__ */ jsx("path", { d }) });
15
+ function Logo({ w, size = "sm" }) {
16
+ return /* @__PURE__ */ jsx(
17
+ "span",
18
+ {
19
+ "aria-hidden": true,
20
+ className: cx(
21
+ "flex shrink-0 items-center justify-center overflow-hidden bg-brand font-semibold text-paper [&>*]:h-full [&>*]:w-full",
22
+ size === "sm" ? "h-5 w-5 rounded-[5px] text-[11px]" : "h-7 w-7 rounded-[7px] text-[12.5px]"
23
+ ),
24
+ children: w.logo ?? w.name.charAt(0)
25
+ }
26
+ );
27
+ }
28
+ function Label({ hidden, children, className }) {
29
+ return /* @__PURE__ */ jsx(
30
+ "span",
31
+ {
32
+ className: cx(
33
+ "min-w-0 flex-1 overflow-hidden whitespace-nowrap text-left transition-[opacity,transform] duration-300",
34
+ EASE,
35
+ hidden ? "pointer-events-none -translate-x-1 opacity-0" : "translate-x-0 opacity-100 delay-75",
36
+ className
37
+ ),
38
+ children
39
+ }
40
+ );
41
+ }
42
+ function Tip({ children }) {
43
+ return /* @__PURE__ */ jsx(
44
+ "span",
45
+ {
46
+ "aria-hidden": true,
47
+ className: cx(
48
+ "pointer-events-none absolute left-[calc(100%+10px)] top-1/2 z-20 -translate-x-1 -translate-y-1/2 whitespace-nowrap rounded-md bg-ink px-2 py-1 text-[12px] text-paper opacity-0 transition-[opacity,translate] duration-200",
49
+ "group-hover/item:translate-x-0 group-hover/item:opacity-100 group-focus-visible/item:translate-x-0 group-focus-visible/item:opacity-100",
50
+ EASE
51
+ ),
52
+ children
53
+ }
54
+ );
55
+ }
56
+ var itemCls = "group/item relative flex h-9 w-full items-center rounded-lg text-[14px] outline-none transition-colors duration-200 focus-visible:ring-2 focus-visible:ring-brand/50";
57
+ function Row({ it, on, collapsed, onClick, flat }) {
58
+ return /* @__PURE__ */ jsxs(
59
+ "button",
60
+ {
61
+ type: "button",
62
+ "data-sb-id": flat ? void 0 : it.id,
63
+ "aria-current": on ? "page" : void 0,
64
+ "aria-label": collapsed ? it.label : void 0,
65
+ onClick,
66
+ className: cx(itemCls, on ? cx("text-ink", flat && ON) : cx("text-ink-2 hover:text-ink", HOVER)),
67
+ children: [
68
+ /* @__PURE__ */ jsxs("span", { className: cx("relative flex w-10 shrink-0 justify-center transition-colors duration-200 [&_svg]:h-[18px] [&_svg]:w-[18px]", on ? "text-ink" : "text-mute group-hover/item:text-ink"), children: [
69
+ it.icon,
70
+ !!it.badge && /* @__PURE__ */ jsx(
71
+ "span",
72
+ {
73
+ className: cx(
74
+ "absolute right-2 top-0 h-1.5 w-1.5 rounded-full bg-brand shadow-[0_0_0_2px_var(--paper-2)] transition-[opacity,transform] duration-300",
75
+ EASE,
76
+ collapsed ? "scale-100 opacity-100" : "scale-50 opacity-0"
77
+ )
78
+ }
79
+ )
80
+ ] }),
81
+ /* @__PURE__ */ jsx(Label, { hidden: collapsed, className: "relative", children: it.label }),
82
+ !!it.badge && /* @__PURE__ */ jsx(
83
+ "span",
84
+ {
85
+ className: cx(
86
+ "relative mr-2 rounded-md bg-[color-mix(in_srgb,var(--ink)_6%,transparent)] px-1.5 text-[11.5px] tabular-nums leading-5 text-mute transition-opacity duration-300",
87
+ collapsed ? "opacity-0" : "opacity-100"
88
+ ),
89
+ children: it.badge
90
+ }
91
+ ),
92
+ collapsed && /* @__PURE__ */ jsx(Tip, { children: it.label })
93
+ ]
94
+ }
95
+ );
96
+ }
97
+ function Sidebar({
98
+ brand,
99
+ groups,
100
+ footer = [],
101
+ promo,
102
+ cta,
103
+ workspaces = [],
104
+ defaultWorkspace,
105
+ onWorkspaceChange,
106
+ active: activeProp,
107
+ defaultActive,
108
+ onNavigate,
109
+ collapsed: collapsedProp,
110
+ defaultCollapsed = false,
111
+ onCollapsedChange,
112
+ user,
113
+ className
114
+ }) {
115
+ const [activeState, setActive] = useState(defaultActive ?? groups[0]?.items[0]?.id ?? "");
116
+ const [collapsedState, setCollapsed] = useState(defaultCollapsed);
117
+ const [workspace, setWorkspace] = useState(defaultWorkspace ?? workspaces[0]?.id);
118
+ const [menu, setMenu] = useState(false);
119
+ const [promoOpen, setPromoOpen] = useState(true);
120
+ const active = activeProp ?? activeState;
121
+ const collapsed = collapsedProp ?? collapsedState;
122
+ const current = workspaces.find((w) => w.id === workspace) ?? workspaces[0];
123
+ const nav = useRef(null);
124
+ const indicator = useRef(null);
125
+ const placed = useRef(false);
126
+ const switcher = useRef(null);
127
+ const trigger = useRef(null);
128
+ useLayoutEffect(() => {
129
+ const ind = indicator.current;
130
+ const el = nav.current?.querySelector(`[data-sb-id="${CSS.escape(active)}"]`);
131
+ if (!ind) return;
132
+ if (!el) {
133
+ ind.style.opacity = "0";
134
+ return;
135
+ }
136
+ if (!placed.current) ind.style.transition = "none";
137
+ ind.style.transform = `translateY(${el.offsetTop}px)`;
138
+ ind.style.opacity = "1";
139
+ if (!placed.current) {
140
+ void ind.offsetHeight;
141
+ ind.style.transition = "";
142
+ placed.current = true;
143
+ }
144
+ }, [active]);
145
+ useEffect(() => {
146
+ if (!menu) return;
147
+ switcher.current?.querySelector("[role=menuitemradio][aria-checked=true]")?.focus();
148
+ const down = (e) => {
149
+ if (!switcher.current?.contains(e.target)) setMenu(false);
150
+ };
151
+ document.addEventListener("pointerdown", down);
152
+ return () => document.removeEventListener("pointerdown", down);
153
+ }, [menu]);
154
+ const navigate = (id) => {
155
+ setActive(id);
156
+ onNavigate?.(id);
157
+ };
158
+ const toggle = () => {
159
+ setCollapsed(!collapsed);
160
+ onCollapsedChange?.(!collapsed);
161
+ };
162
+ const pick = (id) => {
163
+ setWorkspace(id);
164
+ onWorkspaceChange?.(id);
165
+ setMenu(false);
166
+ trigger.current?.focus();
167
+ };
168
+ const rove = (e, selector, root) => {
169
+ const els = [...root?.querySelectorAll(selector) ?? []];
170
+ const i = els.indexOf(document.activeElement);
171
+ const next = { ArrowDown: i + 1, ArrowUp: i - 1, Home: 0, End: els.length - 1 }[e.key];
172
+ if (next === void 0 || !els.length) return;
173
+ e.preventDefault();
174
+ els[(next + els.length) % els.length]?.focus();
175
+ };
176
+ return /* @__PURE__ */ jsxs(
177
+ "aside",
178
+ {
179
+ "aria-label": "Sidebar",
180
+ "data-collapsed": collapsed || void 0,
181
+ className: cx(
182
+ "relative flex h-full shrink-0 flex-col bg-paper-2 px-3 py-3 shadow-[inset_-1px_0_0_color-mix(in_srgb,var(--ink)_8%,transparent)] transition-[width] duration-500",
183
+ EASE,
184
+ collapsed ? "w-16" : "w-[248px]",
185
+ className
186
+ ),
187
+ children: [
188
+ /* @__PURE__ */ jsx("style", { href: "asta-sidebar", precedence: "asta", children: `
189
+ @keyframes kit-sb-pop { from { opacity: 0; transform: translateY(4px) scale(.98); } to { opacity: 1; transform: none; } }
190
+ @keyframes kit-sb-fade { from { opacity: 0; } to { opacity: 1; } }
191
+ @media (prefers-reduced-motion: reduce) { .kit-sb, .kit-sb * { animation: none !important; transition-duration: 0s !important; } }
192
+ ` }),
193
+ /* @__PURE__ */ jsxs("div", { className: "kit-sb flex min-h-0 flex-1 flex-col", children: [
194
+ /* @__PURE__ */ jsxs("div", { className: "flex h-11 shrink-0 items-center", children: [
195
+ /* @__PURE__ */ jsx(Label, { hidden: collapsed, className: "pl-3 text-[19px] font-semibold tracking-[-0.03em] text-ink", children: brand ?? current?.name }),
196
+ /* @__PURE__ */ jsxs(
197
+ "button",
198
+ {
199
+ type: "button",
200
+ "aria-pressed": collapsed,
201
+ "aria-label": collapsed ? "Expand sidebar" : "Collapse sidebar",
202
+ onClick: toggle,
203
+ className: cx(
204
+ "group/item relative flex h-9 w-10 shrink-0 items-center justify-center rounded-lg text-mute outline-none transition-colors duration-200 hover:text-ink focus-visible:ring-2 focus-visible:ring-brand/50",
205
+ HOVER
206
+ ),
207
+ children: [
208
+ /* @__PURE__ */ jsx(Icon, { d: "M2.5 3.5h11v9h-11zM6 3.5v9M10.5 6.5 9 8l1.5 1.5", className: cx("transition-transform duration-500", EASE, collapsed && "-scale-x-100") }),
209
+ collapsed && /* @__PURE__ */ jsx(Tip, { children: "Expand" })
210
+ ]
211
+ }
212
+ )
213
+ ] }),
214
+ /* @__PURE__ */ jsx(
215
+ "nav",
216
+ {
217
+ "aria-label": "Main",
218
+ className: cx("-mx-1 mt-3 min-h-0 flex-1 px-1 [scrollbar-width:none]", collapsed ? "overflow-visible" : "overflow-y-auto overscroll-contain [mask-image:linear-gradient(to_bottom,black_calc(100%-20px),transparent)]"),
219
+ onKeyDown: (e) => rove(e, "[data-sb-id]", nav.current),
220
+ children: /* @__PURE__ */ jsxs("div", { ref: nav, className: "relative pb-2", children: [
221
+ /* @__PURE__ */ jsx(
222
+ "span",
223
+ {
224
+ ref: indicator,
225
+ "aria-hidden": true,
226
+ className: cx("absolute inset-x-0 top-0 h-9 rounded-lg opacity-0 transition-[transform,opacity] duration-500", ON, EASE)
227
+ }
228
+ ),
229
+ groups.map((g, gi) => /* @__PURE__ */ jsxs("div", { className: cx(gi > 0 && "mt-5"), children: [
230
+ g.label && /* @__PURE__ */ jsxs("div", { className: "relative flex h-8 items-center px-3", "aria-hidden": collapsed || void 0, children: [
231
+ /* @__PURE__ */ jsx("span", { className: cx("text-[13px] text-mute transition-opacity duration-300", collapsed ? "opacity-0" : "opacity-100"), children: g.label }),
232
+ /* @__PURE__ */ jsx(
233
+ "span",
234
+ {
235
+ className: cx(
236
+ "absolute left-1/2 h-px w-3 -translate-x-1/2 bg-[color-mix(in_srgb,var(--ink)_14%,transparent)] transition-opacity duration-300",
237
+ collapsed ? "opacity-100" : "opacity-0"
238
+ )
239
+ }
240
+ )
241
+ ] }),
242
+ /* @__PURE__ */ jsx("ul", { className: "flex flex-col gap-0.5", children: g.items.map((it) => /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx(Row, { it, on: it.id === active, collapsed, onClick: () => navigate(it.id) }) }, it.id)) })
243
+ ] }, g.label ?? gi))
244
+ ] })
245
+ }
246
+ ),
247
+ promo && promoOpen && !collapsed && /* @__PURE__ */ jsxs(
248
+ "div",
249
+ {
250
+ className: cx("group/promo relative mt-3 min-w-[222px] shrink-0 rounded-xl bg-paper p-4", RING, promo.onClick && "transition-colors hover:bg-[color-mix(in_srgb,var(--ink)_2%,var(--paper))]"),
251
+ style: { animation: "kit-sb-fade .3s .25s cubic-bezier(.16,1,.3,1) both" },
252
+ children: [
253
+ promo.icon && /* @__PURE__ */ jsx("span", { className: "mb-3 flex h-8 w-8 items-center justify-center rounded-full bg-paper-2 text-mute [&_svg]:h-4 [&_svg]:w-4", children: promo.icon }),
254
+ promo.onClick ? /* @__PURE__ */ jsx("button", { type: "button", onClick: promo.onClick, className: "block text-left text-[14px] font-medium text-ink outline-none after:absolute after:inset-0 after:rounded-xl focus-visible:after:ring-2 focus-visible:after:ring-brand/50", children: promo.title }) : /* @__PURE__ */ jsx("p", { className: "text-[14px] font-medium text-ink", children: promo.title }),
255
+ promo.text && /* @__PURE__ */ jsx("p", { className: "mt-1 text-[13px] leading-snug text-mute", children: promo.text }),
256
+ promo.onDismiss && /* @__PURE__ */ jsx(
257
+ "button",
258
+ {
259
+ type: "button",
260
+ "aria-label": `Dismiss ${promo.title}`,
261
+ onClick: () => {
262
+ setPromoOpen(false);
263
+ promo.onDismiss?.();
264
+ },
265
+ className: "absolute right-2 top-2 z-10 flex h-7 w-7 items-center justify-center rounded-md text-mute outline-none transition-colors hover:bg-paper-2 hover:text-ink focus-visible:ring-2 focus-visible:ring-brand/50",
266
+ children: /* @__PURE__ */ jsx(Icon, { d: "M4.5 4.5l7 7M11.5 4.5l-7 7", className: "h-3.5 w-3.5" })
267
+ }
268
+ )
269
+ ]
270
+ }
271
+ ),
272
+ footer.length > 0 && /* @__PURE__ */ jsx("ul", { className: "mt-2 flex shrink-0 flex-col gap-0.5", children: footer.map((it) => /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx(Row, { it, on: it.id === active, collapsed, onClick: () => navigate(it.id), flat: true }) }, it.id)) }),
273
+ cta && /* @__PURE__ */ jsxs(
274
+ "button",
275
+ {
276
+ type: "button",
277
+ onClick: cta.onClick,
278
+ "aria-label": collapsed ? cta.label : void 0,
279
+ className: cx(itemCls, "mt-2 h-10 shrink-0 overflow-visible bg-paper font-medium text-ink", RING, "hover:bg-[color-mix(in_srgb,var(--ink)_3%,var(--paper))]"),
280
+ children: [
281
+ /* @__PURE__ */ jsx(
282
+ "span",
283
+ {
284
+ "aria-hidden": true,
285
+ className: cx(
286
+ "pointer-events-none absolute inset-y-0 right-0 w-3/5 rounded-r-lg bg-[repeating-linear-gradient(-45deg,color-mix(in_srgb,var(--ink)_9%,transparent)_0_1px,transparent_1px_6px)] [mask-image:linear-gradient(to_right,transparent,black)] transition-opacity duration-300",
287
+ collapsed ? "opacity-0" : "opacity-100"
288
+ )
289
+ }
290
+ ),
291
+ /* @__PURE__ */ jsx("span", { className: "relative flex w-10 shrink-0 justify-center", children: /* @__PURE__ */ jsx("span", { className: "flex h-5 w-5 items-center justify-center rounded-full bg-ink text-paper [&_svg]:h-3 [&_svg]:w-3", children: cta.icon ?? /* @__PURE__ */ jsx(Icon, { d: "M9 1.5 3.5 9H8l-1 5.5L12.5 7H8z" }) }) }),
292
+ /* @__PURE__ */ jsx(Label, { hidden: collapsed, className: "relative", children: /* @__PURE__ */ jsx("span", { className: "block text-center", children: cta.label }) }),
293
+ !collapsed && /* @__PURE__ */ jsx("span", { "aria-hidden": true, className: "w-10 shrink-0" }),
294
+ collapsed && /* @__PURE__ */ jsx(Tip, { children: cta.label })
295
+ ]
296
+ }
297
+ ),
298
+ current && /* @__PURE__ */ jsxs("div", { ref: switcher, className: "relative mt-2 shrink-0", children: [
299
+ /* @__PURE__ */ jsxs(
300
+ "button",
301
+ {
302
+ ref: trigger,
303
+ type: "button",
304
+ "aria-haspopup": "menu",
305
+ "aria-expanded": menu,
306
+ "aria-label": collapsed ? `Workspace: ${current.name}` : void 0,
307
+ onClick: () => setMenu((v) => !v),
308
+ onKeyDown: (e) => {
309
+ if (e.key === "ArrowUp" && !menu) {
310
+ e.preventDefault();
311
+ setMenu(true);
312
+ }
313
+ },
314
+ className: cx(itemCls, "h-10 text-ink", HOVER, "aria-expanded:bg-[color-mix(in_srgb,var(--ink)_5%,transparent)]"),
315
+ children: [
316
+ /* @__PURE__ */ jsx("span", { className: "flex w-10 shrink-0 justify-center", children: /* @__PURE__ */ jsx(Logo, { w: current }) }),
317
+ /* @__PURE__ */ jsx(Label, { hidden: collapsed, className: "truncate", children: current.name }),
318
+ /* @__PURE__ */ jsx(
319
+ Icon,
320
+ {
321
+ d: "m5.5 6 2.5-2.5L10.5 6M5.5 10l2.5 2.5 2.5-2.5",
322
+ className: cx("mr-2 shrink-0 text-mute transition-opacity duration-300", collapsed ? "opacity-0" : "opacity-100")
323
+ }
324
+ ),
325
+ collapsed && /* @__PURE__ */ jsx(Tip, { children: current.name })
326
+ ]
327
+ }
328
+ ),
329
+ menu && /* @__PURE__ */ jsxs(
330
+ "div",
331
+ {
332
+ role: "menu",
333
+ "aria-label": "Switch workspace",
334
+ onKeyDown: (e) => {
335
+ if (e.key === "Escape" || e.key === "Tab") {
336
+ if (e.key === "Escape") e.preventDefault();
337
+ setMenu(false);
338
+ trigger.current?.focus();
339
+ } else rove(e, "[role=menuitemradio]", e.currentTarget);
340
+ },
341
+ className: "absolute bottom-[calc(100%+6px)] left-0 z-30 w-[232px] origin-bottom-left rounded-xl bg-paper p-1.5 shadow-[inset_0_0_0_1px_color-mix(in_srgb,var(--ink)_10%,transparent),0_16px_36px_-14px_rgb(0_0_0/0.3)]",
342
+ style: { animation: "kit-sb-pop .28s cubic-bezier(.16,1,.3,1) both" },
343
+ children: [
344
+ /* @__PURE__ */ jsx("p", { className: "px-2 pb-1.5 pt-1 text-[11.5px] text-mute", children: "Workspaces" }),
345
+ workspaces.map((w) => {
346
+ const on = w.id === current.id;
347
+ return /* @__PURE__ */ jsxs(
348
+ "button",
349
+ {
350
+ type: "button",
351
+ role: "menuitemradio",
352
+ "aria-checked": on,
353
+ onClick: () => pick(w.id),
354
+ className: "flex w-full items-center gap-2.5 rounded-lg px-2 py-1.5 text-left outline-none transition-colors hover:bg-paper-2 focus-visible:bg-paper-2",
355
+ children: [
356
+ /* @__PURE__ */ jsx(Logo, { w, size: "md" }),
357
+ /* @__PURE__ */ jsxs("span", { className: "flex min-w-0 flex-1 flex-col leading-tight", children: [
358
+ /* @__PURE__ */ jsx("span", { className: "truncate text-[13.5px] text-ink", children: w.name }),
359
+ w.plan && /* @__PURE__ */ jsx("span", { className: "truncate text-[11.5px] text-mute", children: w.plan })
360
+ ] }),
361
+ on && /* @__PURE__ */ jsx(Icon, { d: "M3.5 8.5l3 3 6-7", className: "shrink-0 text-brand" })
362
+ ]
363
+ },
364
+ w.id
365
+ );
366
+ })
367
+ ]
368
+ }
369
+ )
370
+ ] }),
371
+ user && /* @__PURE__ */ jsxs("div", { className: "mt-2 flex h-12 shrink-0 items-center rounded-lg", children: [
372
+ /* @__PURE__ */ jsx("span", { className: "flex w-10 shrink-0 justify-center", children: /* @__PURE__ */ jsx(Avatar, { name: user.name, src: user.src, size: "sm" }) }),
373
+ /* @__PURE__ */ jsxs(Label, { hidden: collapsed, className: "flex flex-col pl-1 leading-tight", children: [
374
+ /* @__PURE__ */ jsx("span", { className: "truncate text-[13px] font-medium text-ink", children: user.name }),
375
+ /* @__PURE__ */ jsx("span", { className: "truncate text-[11.5px] text-mute", children: user.email })
376
+ ] })
377
+ ] })
378
+ ] })
379
+ ]
380
+ }
381
+ );
382
+ }
383
+ var sidebar_default = Sidebar;
384
+
385
+ export {
386
+ Sidebar,
387
+ sidebar_default
388
+ };