Sidebar
An app sidebar with groups and a workspace menu.
Installation
Run the CLI
Run
pnpm dlx asta-ui@latest initonce, then this. The file lands incomponents/astabyte/, installsradix-ui@base-ui/reactand the colour tokens go into your CSS. This is the Radix build. Drop --radix for Base UI.This is the Base UI build, the default. Want Radix? Add --radix.$ pnpm dlx asta-ui@latest add sidebar --radixOr install the package
Don’t want the file? Import from
asta-uiasta-ui/baseand update withpnpm update asta-ui. Add the stylesheet once. More.$ pnpm add asta-ui radix-ui @base-ui/reactimport { Sidebar } from "asta-ui";import { Sidebar } from "asta-ui/base";Or copy it by hand
Install
radix-ui@base-ui/react, then copy these files. Keep the paths, or fix the@/imports. Then add the tokens fromglobals.css."use client"; import { useEffect, useLayoutEffect, useRef, useState, type KeyboardEvent, type ReactNode } from "react"; import { Avatar } from "@/components/kit/avatar"; const cx = (...c: (string | false | null | undefined)[]) => c.filter(Boolean).join(" "); const EASE = "ease-[cubic-bezier(.16,1,.3,1)]"; const RING = "shadow-[inset_0_0_0_1px_color-mix(in_srgb,var(--color-ink)_10%,transparent)]"; const HOVER = "hover:bg-[color-mix(in_srgb,var(--color-ink)_4%,transparent)]"; const ON = "bg-[color-mix(in_srgb,var(--color-ink)_6%,transparent)]"; export interface SidebarItem { id: string; label: string; icon: ReactNode; /** Small count on the right. In the icon rail it becomes a dot. */ badge?: number; } export interface SidebarGroup { label?: string; items: SidebarItem[]; } export interface SidebarWorkspace { id: string; name: string; plan?: string; /** Square logo. Leave it out and the first letter is used. */ logo?: ReactNode; } export interface SidebarPromo { title: string; text?: string; icon?: ReactNode; onClick?: () => void; /** Shows a close button. The card hides itself and this is called. */ onDismiss?: () => void; } export interface SidebarProps { /** Wordmark at the top. Defaults to the current workspace name. */ brand?: ReactNode; groups: SidebarGroup[]; /** Links pinned to the bottom, under the promo card. */ footer?: SidebarItem[]; promo?: SidebarPromo; /** The striped button near the bottom, for an upgrade or a plan. */ cta?: { label: string; icon?: ReactNode; onClick?: () => void }; /** Workspace switcher at the very bottom. The menu opens upward. */ workspaces?: SidebarWorkspace[]; defaultWorkspace?: string; onWorkspaceChange?: (id: string) => void; /** Controlled active item. Leave it out and the sidebar tracks clicks itself. */ active?: string; defaultActive?: string; onNavigate?: (id: string) => void; collapsed?: boolean; defaultCollapsed?: boolean; onCollapsedChange?: (collapsed: boolean) => void; user?: { name: string; email: string; src?: string }; className?: string; } const Icon = ({ d, className = "" }: { d: string; className?: string }) => ( <svg viewBox="0 0 24 24" className={cx("h-4 w-4", className)} fill="none" stroke="currentColor" strokeWidth="2.25" strokeLinecap="round" strokeLinejoin="round" aria-hidden> <path d={d} /> </svg> ); function Logo({ w, size = "sm" }: { w: SidebarWorkspace; size?: "sm" | "md" }) { return ( <span aria-hidden className={cx( "flex shrink-0 items-center justify-center overflow-hidden bg-brand font-semibold text-paper [&>*]:h-full [&>*]:w-full", size === "sm" ? "h-5 w-5 rounded-[5px] text-[11px]" : "h-7 w-7 rounded-[7px] text-[12.5px]", )} > {w.logo ?? w.name.charAt(0)} </span> ); } /** Label that fades and slides a touch when the sidebar folds to the rail. */ function Label({ hidden, children, className }: { hidden: boolean; children: ReactNode; className?: string }) { return ( <span className={cx( "min-w-0 flex-1 overflow-hidden whitespace-nowrap text-left transition-[opacity,transform] duration-300", EASE, hidden ? "pointer-events-none -translate-x-1 opacity-0" : "translate-x-0 opacity-100 delay-75", className, )} > {children} </span> ); } /** Tooltip shown next to rail items, on hover and keyboard focus. */ function Tip({ children }: { children: ReactNode }) { return ( <span aria-hidden className={cx( "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", "group-hover/item:translate-x-0 group-hover/item:opacity-100 group-focus-visible/item:translate-x-0 group-focus-visible/item:opacity-100", EASE, )} > {children} </span> ); } const 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"; function Row({ it, on, collapsed, onClick, flat }: { it: SidebarItem; on: boolean; collapsed: boolean; onClick: () => void; flat?: boolean }) { return ( <button type="button" data-sb-id={flat ? undefined : it.id} aria-current={on ? "page" : undefined} aria-label={collapsed ? it.label : undefined} onClick={onClick} className={cx(itemCls, on ? cx("text-ink", flat && ON) : cx("text-ink-2 hover:text-ink", HOVER))} > <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")}> {it.icon} {!!it.badge && ( <span className={cx( "absolute right-2 top-0 h-1.5 w-1.5 rounded-full bg-brand shadow-[0_0_0_2px_var(--color-paper-2)] transition-[opacity,transform] duration-300", EASE, collapsed ? "scale-100 opacity-100" : "scale-50 opacity-0", )} /> )} </span> <Label hidden={collapsed} className="relative"> {it.label} </Label> {!!it.badge && ( <span className={cx( "relative mr-2 rounded-md bg-[color-mix(in_srgb,var(--color-ink)_6%,transparent)] px-1.5 text-[11.5px] tabular-nums leading-5 text-mute transition-opacity duration-300", collapsed ? "opacity-0" : "opacity-100", )} > {it.badge} </span> )} {collapsed && <Tip>{it.label}</Tip>} </button> ); } /** * App sidebar: a wordmark, grouped navigation with a sliding grey pill, then a promo card, footer * links, a striped call to action and the workspace switcher at the bottom. It folds to a 64px icon * rail where labels fade out and tooltips take over. Arrow keys move between items. */ export function Sidebar({ brand, groups, footer = [], promo, cta, workspaces = [], defaultWorkspace, onWorkspaceChange, active: activeProp, defaultActive, onNavigate, collapsed: collapsedProp, defaultCollapsed = false, onCollapsedChange, user, className, }: SidebarProps) { const [activeState, setActive] = useState(defaultActive ?? groups[0]?.items[0]?.id ?? ""); const [collapsedState, setCollapsed] = useState(defaultCollapsed); const [workspace, setWorkspace] = useState(defaultWorkspace ?? workspaces[0]?.id); const [menu, setMenu] = useState(false); const [promoOpen, setPromoOpen] = useState(true); const active = activeProp ?? activeState; const collapsed = collapsedProp ?? collapsedState; const current = workspaces.find((w) => w.id === workspace) ?? workspaces[0]; const nav = useRef<HTMLDivElement>(null); const indicator = useRef<HTMLSpanElement>(null); const placed = useRef(false); const switcher = useRef<HTMLDivElement>(null); const trigger = useRef<HTMLButtonElement>(null); // Slide the pill under the active item. Rows keep their height when folded, so only `active` matters. useLayoutEffect(() => { const ind = indicator.current; const el = nav.current?.querySelector<HTMLElement>(`[data-sb-id="${CSS.escape(active)}"]`); if (!ind) return; if (!el) { ind.style.opacity = "0"; return; } if (!placed.current) ind.style.transition = "none"; ind.style.transform = `translateY(${el.offsetTop}px)`; ind.style.opacity = "1"; if (!placed.current) { void ind.offsetHeight; ind.style.transition = ""; placed.current = true; } }, [active]); // Workspace menu: focus the current workspace on open, close on outside click. useEffect(() => { if (!menu) return; switcher.current?.querySelector<HTMLElement>("[role=menuitemradio][aria-checked=true]")?.focus(); const down = (e: PointerEvent) => { if (!switcher.current?.contains(e.target as Node)) setMenu(false); }; document.addEventListener("pointerdown", down); return () => document.removeEventListener("pointerdown", down); }, [menu]); const navigate = (id: string) => { setActive(id); onNavigate?.(id); }; const toggle = () => { setCollapsed(!collapsed); onCollapsedChange?.(!collapsed); }; const pick = (id: string) => { setWorkspace(id); onWorkspaceChange?.(id); setMenu(false); trigger.current?.focus(); }; // Roving focus with arrows inside a list of elements. const rove = (e: KeyboardEvent, selector: string, root: HTMLElement | null) => { const els = [...(root?.querySelectorAll<HTMLElement>(selector) ?? [])]; const i = els.indexOf(document.activeElement as HTMLElement); const next = { ArrowDown: i + 1, ArrowUp: i - 1, Home: 0, End: els.length - 1 }[e.key]; if (next === undefined || !els.length) return; e.preventDefault(); els[(next + els.length) % els.length]?.focus(); }; return ( <aside aria-label="Sidebar" data-collapsed={collapsed || undefined} className={cx( // perf-ok: the width glide is deliberate. It runs once per click, and the page beside the sidebar has to follow it; a transform would leave a gap or overlap the content. "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(--color-ink)_8%,transparent)] transition-[width] duration-500", EASE, collapsed ? "w-16" : "w-[248px]", className, )} > <style href="asta-sidebar" precedence="asta">{` @keyframes kit-sb-pop { from { opacity: 0; transform: translateY(4px) scale(.98); } to { opacity: 1; transform: none; } } @keyframes kit-sb-fade { from { opacity: 0; } to { opacity: 1; } } @media (prefers-reduced-motion: reduce) { .kit-sb, .kit-sb * { animation: none !important; transition-duration: 0s !important; } } `}</style> <div className="kit-sb flex min-h-0 flex-1 flex-col"> {/* Wordmark + fold */} <div className="flex h-11 shrink-0 items-center"> <Label hidden={collapsed} className="pl-3 text-[19px] font-semibold tracking-[-0.03em] text-ink"> {brand ?? current?.name} </Label> <button type="button" aria-pressed={collapsed} aria-label={collapsed ? "Expand sidebar" : "Collapse sidebar"} onClick={toggle} className={cx( "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", HOVER, )} > <Icon d="M5.5 4.5h13a2 2 0 0 1 2 2v11a2 2 0 0 1-2 2h-13a2 2 0 0 1-2-2v-11a2 2 0 0 1 2-2ZM9.5 4.5v15M15.5 10l-2 2 2 2" className={cx("transition-transform duration-500", EASE, collapsed && "-scale-x-100")} /> {collapsed && <Tip>Expand</Tip>} </button> </div> {/* Navigation */} <nav aria-label="Main" 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)]")} onKeyDown={(e) => rove(e, "[data-sb-id]", nav.current)} > <div ref={nav} className="relative pb-2"> <span ref={indicator} aria-hidden className={cx("absolute inset-x-0 top-0 h-9 rounded-lg opacity-0 transition-[transform,opacity] duration-500", ON, EASE)} /> {groups.map((g, gi) => ( <div key={g.label ?? gi} className={cx(gi > 0 && "mt-5")}> {g.label && ( <div className="relative flex h-8 items-center px-3" aria-hidden={collapsed || undefined}> <span className={cx("text-[13px] text-mute transition-opacity duration-300", collapsed ? "opacity-0" : "opacity-100")}>{g.label}</span> <span className={cx( "absolute left-1/2 h-px w-3 -translate-x-1/2 bg-[color-mix(in_srgb,var(--color-ink)_14%,transparent)] transition-opacity duration-300", collapsed ? "opacity-100" : "opacity-0", )} /> </div> )} <ul className="flex flex-col gap-0.5"> {g.items.map((it) => ( <li key={it.id}> <Row it={it} on={it.id === active} collapsed={collapsed} onClick={() => navigate(it.id)} /> </li> ))} </ul> </div> ))} </div> </nav> {/* Promo card: gone on the rail, fades back in once the column has room again. */} {promo && promoOpen && !collapsed && ( <div 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(--color-ink)_2%,var(--color-paper))]")} style={{ animation: "kit-sb-fade .3s .25s cubic-bezier(.16,1,.3,1) both" }} > {promo.icon && <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">{promo.icon}</span>} {promo.onClick ? ( <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"> {promo.title} </button> ) : ( <p className="text-[14px] font-medium text-ink">{promo.title}</p> )} {promo.text && <p className="mt-1 text-[13px] leading-snug text-mute">{promo.text}</p>} {promo.onDismiss && ( <button type="button" aria-label={`Dismiss ${promo.title}`} onClick={() => { setPromoOpen(false); promo.onDismiss?.(); }} 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" > <Icon d="M6 6l12 12M18 6 6 18" className="h-3.5 w-3.5" /> </button> )} </div> )} {/* Footer links */} {footer.length > 0 && ( <ul className="mt-2 flex shrink-0 flex-col gap-0.5"> {footer.map((it) => ( <li key={it.id}> <Row it={it} on={it.id === active} collapsed={collapsed} onClick={() => navigate(it.id)} flat /> </li> ))} </ul> )} {/* Call to action: outlined, with a hatched tail. */} {cta && ( <button type="button" onClick={cta.onClick} aria-label={collapsed ? cta.label : undefined} 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(--color-ink)_3%,var(--color-paper))]")} > <span aria-hidden className={cx( "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(--color-ink)_9%,transparent)_0_1px,transparent_1px_6px)] [mask-image:linear-gradient(to_right,transparent,black)] transition-opacity duration-300", collapsed ? "opacity-0" : "opacity-100", )} /> <span className="relative flex w-10 shrink-0 justify-center"> <span className="flex h-5 w-5 items-center justify-center rounded-full bg-ink text-paper [&_svg]:h-3 [&_svg]:w-3"> {cta.icon ?? <Icon d="M13.5 3 5.5 13.5h6L10.5 21l8-10.5h-6Z" />} </span> </span> <Label hidden={collapsed} className="relative"> <span className="block text-center">{cta.label}</span> </Label> {!collapsed && <span aria-hidden className="w-10 shrink-0" />} {collapsed && <Tip>{cta.label}</Tip>} </button> )} {/* Workspace switcher */} {current && ( <div ref={switcher} className="relative mt-2 shrink-0"> <button ref={trigger} type="button" aria-haspopup="menu" aria-expanded={menu} aria-label={collapsed ? `Workspace: ${current.name}` : undefined} onClick={() => setMenu((v) => !v)} onKeyDown={(e) => { if (e.key === "ArrowUp" && !menu) { e.preventDefault(); setMenu(true); } }} className={cx(itemCls, "h-10 text-ink", HOVER, "aria-expanded:bg-[color-mix(in_srgb,var(--color-ink)_5%,transparent)]")} > <span className="flex w-10 shrink-0 justify-center"> <Logo w={current} /> </span> <Label hidden={collapsed} className="truncate"> {current.name} </Label> <Icon d="M8 9l4-4 4 4M8 15l4 4 4-4" className={cx("mr-2 shrink-0 text-mute transition-opacity duration-300", collapsed ? "opacity-0" : "opacity-100")} /> {collapsed && <Tip>{current.name}</Tip>} </button> {menu && ( <div role="menu" aria-label="Switch workspace" onKeyDown={(e) => { if (e.key === "Escape" || e.key === "Tab") { if (e.key === "Escape") e.preventDefault(); setMenu(false); trigger.current?.focus(); } else rove(e, "[role=menuitemradio]", e.currentTarget); }} 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(--color-ink)_10%,transparent),0_16px_36px_-14px_rgb(0_0_0/0.3)]" style={{ animation: "kit-sb-pop .28s cubic-bezier(.16,1,.3,1) both" }} > <p className="px-2 pb-1.5 pt-1 text-[11.5px] text-mute">Workspaces</p> {workspaces.map((w) => { const on = w.id === current.id; return ( <button key={w.id} type="button" role="menuitemradio" aria-checked={on} onClick={() => pick(w.id)} 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" > <Logo w={w} size="md" /> <span className="flex min-w-0 flex-1 flex-col leading-tight"> <span className="truncate text-[13.5px] text-ink">{w.name}</span> {w.plan && <span className="truncate text-[11.5px] text-mute">{w.plan}</span>} </span> {on && <Icon d="M5 12.5l4.5 4.5L19 7.5" className="shrink-0 text-brand" />} </button> ); })} </div> )} </div> )} {user && ( <div className="mt-2 flex h-12 shrink-0 items-center rounded-lg"> <span className="flex w-10 shrink-0 justify-center"> <Avatar name={user.name} src={user.src} size="sm" /> </span> <Label hidden={collapsed} className="flex flex-col pl-1 leading-tight"> <span className="truncate text-[13px] font-medium text-ink">{user.name}</span> <span className="truncate text-[11.5px] text-mute">{user.email}</span> </Label> </div> )} </div> </aside> ); } export default Sidebar;"use client"; import { useEffect, useLayoutEffect, useRef, useState, type KeyboardEvent, type ReactNode } from "react"; import { Avatar } from "@/components/kit/base/avatar"; const cx = (...c: (string | false | null | undefined)[]) => c.filter(Boolean).join(" "); const EASE = "ease-[cubic-bezier(.16,1,.3,1)]"; const RING = "shadow-[inset_0_0_0_1px_color-mix(in_srgb,var(--color-ink)_10%,transparent)]"; const HOVER = "hover:bg-[color-mix(in_srgb,var(--color-ink)_4%,transparent)]"; const ON = "bg-[color-mix(in_srgb,var(--color-ink)_6%,transparent)]"; export interface SidebarItem { id: string; label: string; icon: ReactNode; /** Small count on the right. In the icon rail it becomes a dot. */ badge?: number; } export interface SidebarGroup { label?: string; items: SidebarItem[]; } export interface SidebarWorkspace { id: string; name: string; plan?: string; /** Square logo. Leave it out and the first letter is used. */ logo?: ReactNode; } export interface SidebarPromo { title: string; text?: string; icon?: ReactNode; onClick?: () => void; /** Shows a close button. The card hides itself and this is called. */ onDismiss?: () => void; } export interface SidebarProps { /** Wordmark at the top. Defaults to the current workspace name. */ brand?: ReactNode; groups: SidebarGroup[]; /** Links pinned to the bottom, under the promo card. */ footer?: SidebarItem[]; promo?: SidebarPromo; /** The striped button near the bottom, for an upgrade or a plan. */ cta?: { label: string; icon?: ReactNode; onClick?: () => void }; /** Workspace switcher at the very bottom. The menu opens upward. */ workspaces?: SidebarWorkspace[]; defaultWorkspace?: string; onWorkspaceChange?: (id: string) => void; /** Controlled active item. Leave it out and the sidebar tracks clicks itself. */ active?: string; defaultActive?: string; onNavigate?: (id: string) => void; collapsed?: boolean; defaultCollapsed?: boolean; onCollapsedChange?: (collapsed: boolean) => void; user?: { name: string; email: string; src?: string }; className?: string; } const Icon = ({ d, className = "" }: { d: string; className?: string }) => ( <svg viewBox="0 0 24 24" className={cx("h-4 w-4", className)} fill="none" stroke="currentColor" strokeWidth="2.25" strokeLinecap="round" strokeLinejoin="round" aria-hidden> <path d={d} /> </svg> ); function Logo({ w, size = "sm" }: { w: SidebarWorkspace; size?: "sm" | "md" }) { return ( <span aria-hidden className={cx( "flex shrink-0 items-center justify-center overflow-hidden bg-brand font-semibold text-paper [&>*]:h-full [&>*]:w-full", size === "sm" ? "h-5 w-5 rounded-[5px] text-[11px]" : "h-7 w-7 rounded-[7px] text-[12.5px]", )} > {w.logo ?? w.name.charAt(0)} </span> ); } /** Label that fades and slides a touch when the sidebar folds to the rail. */ function Label({ hidden, children, className }: { hidden: boolean; children: ReactNode; className?: string }) { return ( <span className={cx( "min-w-0 flex-1 overflow-hidden whitespace-nowrap text-left transition-[opacity,transform] duration-300", EASE, hidden ? "pointer-events-none -translate-x-1 opacity-0" : "translate-x-0 opacity-100 delay-75", className, )} > {children} </span> ); } /** Tooltip shown next to rail items, on hover and keyboard focus. */ function Tip({ children }: { children: ReactNode }) { return ( <span aria-hidden className={cx( "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", "group-hover/item:translate-x-0 group-hover/item:opacity-100 group-focus-visible/item:translate-x-0 group-focus-visible/item:opacity-100", EASE, )} > {children} </span> ); } const 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"; function Row({ it, on, collapsed, onClick, flat }: { it: SidebarItem; on: boolean; collapsed: boolean; onClick: () => void; flat?: boolean }) { return ( <button type="button" data-sb-id={flat ? undefined : it.id} aria-current={on ? "page" : undefined} aria-label={collapsed ? it.label : undefined} onClick={onClick} className={cx(itemCls, on ? cx("text-ink", flat && ON) : cx("text-ink-2 hover:text-ink", HOVER))} > <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")}> {it.icon} {!!it.badge && ( <span className={cx( "absolute right-2 top-0 h-1.5 w-1.5 rounded-full bg-brand shadow-[0_0_0_2px_var(--color-paper-2)] transition-[opacity,transform] duration-300", EASE, collapsed ? "scale-100 opacity-100" : "scale-50 opacity-0", )} /> )} </span> <Label hidden={collapsed} className="relative"> {it.label} </Label> {!!it.badge && ( <span className={cx( "relative mr-2 rounded-md bg-[color-mix(in_srgb,var(--color-ink)_6%,transparent)] px-1.5 text-[11.5px] tabular-nums leading-5 text-mute transition-opacity duration-300", collapsed ? "opacity-0" : "opacity-100", )} > {it.badge} </span> )} {collapsed && <Tip>{it.label}</Tip>} </button> ); } /** * App sidebar: a wordmark, grouped navigation with a sliding grey pill, then a promo card, footer * links, a striped call to action and the workspace switcher at the bottom. It folds to a 64px icon * rail where labels fade out and tooltips take over. Arrow keys move between items. */ export function Sidebar({ brand, groups, footer = [], promo, cta, workspaces = [], defaultWorkspace, onWorkspaceChange, active: activeProp, defaultActive, onNavigate, collapsed: collapsedProp, defaultCollapsed = false, onCollapsedChange, user, className, }: SidebarProps) { const [activeState, setActive] = useState(defaultActive ?? groups[0]?.items[0]?.id ?? ""); const [collapsedState, setCollapsed] = useState(defaultCollapsed); const [workspace, setWorkspace] = useState(defaultWorkspace ?? workspaces[0]?.id); const [menu, setMenu] = useState(false); const [promoOpen, setPromoOpen] = useState(true); const active = activeProp ?? activeState; const collapsed = collapsedProp ?? collapsedState; const current = workspaces.find((w) => w.id === workspace) ?? workspaces[0]; const nav = useRef<HTMLDivElement>(null); const indicator = useRef<HTMLSpanElement>(null); const placed = useRef(false); const switcher = useRef<HTMLDivElement>(null); const trigger = useRef<HTMLButtonElement>(null); // Slide the pill under the active item. Rows keep their height when folded, so only `active` matters. useLayoutEffect(() => { const ind = indicator.current; const el = nav.current?.querySelector<HTMLElement>(`[data-sb-id="${CSS.escape(active)}"]`); if (!ind) return; if (!el) { ind.style.opacity = "0"; return; } if (!placed.current) ind.style.transition = "none"; ind.style.transform = `translateY(${el.offsetTop}px)`; ind.style.opacity = "1"; if (!placed.current) { void ind.offsetHeight; ind.style.transition = ""; placed.current = true; } }, [active]); // Workspace menu: focus the current workspace on open, close on outside click. useEffect(() => { if (!menu) return; switcher.current?.querySelector<HTMLElement>("[role=menuitemradio][aria-checked=true]")?.focus(); const down = (e: PointerEvent) => { if (!switcher.current?.contains(e.target as Node)) setMenu(false); }; document.addEventListener("pointerdown", down); return () => document.removeEventListener("pointerdown", down); }, [menu]); const navigate = (id: string) => { setActive(id); onNavigate?.(id); }; const toggle = () => { setCollapsed(!collapsed); onCollapsedChange?.(!collapsed); }; const pick = (id: string) => { setWorkspace(id); onWorkspaceChange?.(id); setMenu(false); trigger.current?.focus(); }; // Roving focus with arrows inside a list of elements. const rove = (e: KeyboardEvent, selector: string, root: HTMLElement | null) => { const els = [...(root?.querySelectorAll<HTMLElement>(selector) ?? [])]; const i = els.indexOf(document.activeElement as HTMLElement); const next = { ArrowDown: i + 1, ArrowUp: i - 1, Home: 0, End: els.length - 1 }[e.key]; if (next === undefined || !els.length) return; e.preventDefault(); els[(next + els.length) % els.length]?.focus(); }; return ( <aside aria-label="Sidebar" data-collapsed={collapsed || undefined} className={cx( // perf-ok: the width glide is deliberate. It runs once per click, and the page beside the sidebar has to follow it; a transform would leave a gap or overlap the content. "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(--color-ink)_8%,transparent)] transition-[width] duration-500", EASE, collapsed ? "w-16" : "w-[248px]", className, )} > <style href="asta-sidebar" precedence="asta">{` @keyframes kit-sb-pop { from { opacity: 0; transform: translateY(4px) scale(.98); } to { opacity: 1; transform: none; } } @keyframes kit-sb-fade { from { opacity: 0; } to { opacity: 1; } } @media (prefers-reduced-motion: reduce) { .kit-sb, .kit-sb * { animation: none !important; transition-duration: 0s !important; } } `}</style> <div className="kit-sb flex min-h-0 flex-1 flex-col"> {/* Wordmark + fold */} <div className="flex h-11 shrink-0 items-center"> <Label hidden={collapsed} className="pl-3 text-[19px] font-semibold tracking-[-0.03em] text-ink"> {brand ?? current?.name} </Label> <button type="button" aria-pressed={collapsed} aria-label={collapsed ? "Expand sidebar" : "Collapse sidebar"} onClick={toggle} className={cx( "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", HOVER, )} > <Icon d="M5.5 4.5h13a2 2 0 0 1 2 2v11a2 2 0 0 1-2 2h-13a2 2 0 0 1-2-2v-11a2 2 0 0 1 2-2ZM9.5 4.5v15M15.5 10l-2 2 2 2" className={cx("transition-transform duration-500", EASE, collapsed && "-scale-x-100")} /> {collapsed && <Tip>Expand</Tip>} </button> </div> {/* Navigation */} <nav aria-label="Main" 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)]")} onKeyDown={(e) => rove(e, "[data-sb-id]", nav.current)} > <div ref={nav} className="relative pb-2"> <span ref={indicator} aria-hidden className={cx("absolute inset-x-0 top-0 h-9 rounded-lg opacity-0 transition-[transform,opacity] duration-500", ON, EASE)} /> {groups.map((g, gi) => ( <div key={g.label ?? gi} className={cx(gi > 0 && "mt-5")}> {g.label && ( <div className="relative flex h-8 items-center px-3" aria-hidden={collapsed || undefined}> <span className={cx("text-[13px] text-mute transition-opacity duration-300", collapsed ? "opacity-0" : "opacity-100")}>{g.label}</span> <span className={cx( "absolute left-1/2 h-px w-3 -translate-x-1/2 bg-[color-mix(in_srgb,var(--color-ink)_14%,transparent)] transition-opacity duration-300", collapsed ? "opacity-100" : "opacity-0", )} /> </div> )} <ul className="flex flex-col gap-0.5"> {g.items.map((it) => ( <li key={it.id}> <Row it={it} on={it.id === active} collapsed={collapsed} onClick={() => navigate(it.id)} /> </li> ))} </ul> </div> ))} </div> </nav> {/* Promo card: gone on the rail, fades back in once the column has room again. */} {promo && promoOpen && !collapsed && ( <div 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(--color-ink)_2%,var(--color-paper))]")} style={{ animation: "kit-sb-fade .3s .25s cubic-bezier(.16,1,.3,1) both" }} > {promo.icon && <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">{promo.icon}</span>} {promo.onClick ? ( <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"> {promo.title} </button> ) : ( <p className="text-[14px] font-medium text-ink">{promo.title}</p> )} {promo.text && <p className="mt-1 text-[13px] leading-snug text-mute">{promo.text}</p>} {promo.onDismiss && ( <button type="button" aria-label={`Dismiss ${promo.title}`} onClick={() => { setPromoOpen(false); promo.onDismiss?.(); }} 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" > <Icon d="M6 6l12 12M18 6 6 18" className="h-3.5 w-3.5" /> </button> )} </div> )} {/* Footer links */} {footer.length > 0 && ( <ul className="mt-2 flex shrink-0 flex-col gap-0.5"> {footer.map((it) => ( <li key={it.id}> <Row it={it} on={it.id === active} collapsed={collapsed} onClick={() => navigate(it.id)} flat /> </li> ))} </ul> )} {/* Call to action: outlined, with a hatched tail. */} {cta && ( <button type="button" onClick={cta.onClick} aria-label={collapsed ? cta.label : undefined} 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(--color-ink)_3%,var(--color-paper))]")} > <span aria-hidden className={cx( "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(--color-ink)_9%,transparent)_0_1px,transparent_1px_6px)] [mask-image:linear-gradient(to_right,transparent,black)] transition-opacity duration-300", collapsed ? "opacity-0" : "opacity-100", )} /> <span className="relative flex w-10 shrink-0 justify-center"> <span className="flex h-5 w-5 items-center justify-center rounded-full bg-ink text-paper [&_svg]:h-3 [&_svg]:w-3"> {cta.icon ?? <Icon d="M13.5 3 5.5 13.5h6L10.5 21l8-10.5h-6Z" />} </span> </span> <Label hidden={collapsed} className="relative"> <span className="block text-center">{cta.label}</span> </Label> {!collapsed && <span aria-hidden className="w-10 shrink-0" />} {collapsed && <Tip>{cta.label}</Tip>} </button> )} {/* Workspace switcher */} {current && ( <div ref={switcher} className="relative mt-2 shrink-0"> <button ref={trigger} type="button" aria-haspopup="menu" aria-expanded={menu} aria-label={collapsed ? `Workspace: ${current.name}` : undefined} onClick={() => setMenu((v) => !v)} onKeyDown={(e) => { if (e.key === "ArrowUp" && !menu) { e.preventDefault(); setMenu(true); } }} className={cx(itemCls, "h-10 text-ink", HOVER, "aria-expanded:bg-[color-mix(in_srgb,var(--color-ink)_5%,transparent)]")} > <span className="flex w-10 shrink-0 justify-center"> <Logo w={current} /> </span> <Label hidden={collapsed} className="truncate"> {current.name} </Label> <Icon d="M8 9l4-4 4 4M8 15l4 4 4-4" className={cx("mr-2 shrink-0 text-mute transition-opacity duration-300", collapsed ? "opacity-0" : "opacity-100")} /> {collapsed && <Tip>{current.name}</Tip>} </button> {menu && ( <div role="menu" aria-label="Switch workspace" onKeyDown={(e) => { if (e.key === "Escape" || e.key === "Tab") { if (e.key === "Escape") e.preventDefault(); setMenu(false); trigger.current?.focus(); } else rove(e, "[role=menuitemradio]", e.currentTarget); }} 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(--color-ink)_10%,transparent),0_16px_36px_-14px_rgb(0_0_0/0.3)]" style={{ animation: "kit-sb-pop .28s cubic-bezier(.16,1,.3,1) both" }} > <p className="px-2 pb-1.5 pt-1 text-[11.5px] text-mute">Workspaces</p> {workspaces.map((w) => { const on = w.id === current.id; return ( <button key={w.id} type="button" role="menuitemradio" aria-checked={on} onClick={() => pick(w.id)} 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" > <Logo w={w} size="md" /> <span className="flex min-w-0 flex-1 flex-col leading-tight"> <span className="truncate text-[13.5px] text-ink">{w.name}</span> {w.plan && <span className="truncate text-[11.5px] text-mute">{w.plan}</span>} </span> {on && <Icon d="M5 12.5l4.5 4.5L19 7.5" className="shrink-0 text-brand" />} </button> ); })} </div> )} </div> )} {user && ( <div className="mt-2 flex h-12 shrink-0 items-center rounded-lg"> <span className="flex w-10 shrink-0 justify-center"> <Avatar name={user.name} src={user.src} size="sm" /> </span> <Label hidden={collapsed} className="flex flex-col pl-1 leading-tight"> <span className="truncate text-[13px] font-medium text-ink">{user.name}</span> <span className="truncate text-[11.5px] text-mute">{user.email}</span> </Label> </div> )} </div> </aside> ); } export default Sidebar;Or ask your AI agent
Paste this into Claude Code, Cursor, Codex, v0 or Lovable. Fill in the last line. More in Prompts.
Add the Astabyte UI Sidebar component to my project. An app sidebar with groups and a workspace menu. It includes: wordmark, groups, sliding pill, promo card, upgrade button, workspace switcher, icon rail. Install it (Radix build): ```sh pnpm dlx asta-ui@latest add sidebar --radix ``` Or with the shadcn CLI: ```sh pnpm dlx shadcn@latest add https://ui.astabyte.com/r/sidebar.json ``` If the project isn't set up yet, run `pnpm dlx asta-ui@latest init --radix` first: it runs `shadcn init` when needed and adds the @astabyte registry (Next.js, Vite, React Router, Astro, TanStack Start; Tailwind CSS v4). Import it like this: ```tsx import { Sidebar, type SidebarGroup, type SidebarItem } from "@/components/astabyte/sidebar"; ``` Usage example and props: https://ui.astabyte.com/sidebar Full catalogue for context: https://ui.astabyte.com/llms.txt Rules: - Keep the colour tokens (paper, paper-2, ink, ink-2, mute, brand). Don't restyle with hard-coded colours; rebrand by changing the token values in the CSS. - Keep the motion as it is: transform and opacity only, and the prefers-reduced-motion fallback. - Keep keyboard, focus and ARIA behaviour (interactive pieces are built on Radix primitives from the radix-ui package). - Stay on Radix: install other Astabyte UI components with `--radix` so the project uses one primitive library. - Use fake data and fake brand names in examples. Use it to: [describe where it goes and what it should do]Add the Astabyte UI Sidebar component to my project. An app sidebar with groups and a workspace menu. It includes: wordmark, groups, sliding pill, promo card, upgrade button, workspace switcher, icon rail. Install it (Base UI build): ```sh pnpm dlx asta-ui@latest add sidebar ``` Or with the shadcn CLI: ```sh pnpm dlx shadcn@latest add https://ui.astabyte.com/r/base/sidebar.json ``` If the project isn't set up yet, run `pnpm dlx asta-ui@latest init` first: it runs `shadcn init` when needed and adds the @astabyte registry (Next.js, Vite, React Router, Astro, TanStack Start; Tailwind CSS v4). Import it like this: ```tsx import { Sidebar, type SidebarGroup, type SidebarItem } from "@/components/astabyte/sidebar"; ``` Usage example and props: https://ui.astabyte.com/sidebar Full catalogue for context: https://ui.astabyte.com/llms.txt Rules: - Keep the colour tokens (paper, paper-2, ink, ink-2, mute, brand). Don't restyle with hard-coded colours; rebrand by changing the token values in the CSS. - Keep the motion as it is: transform and opacity only, and the prefers-reduced-motion fallback. - Keep keyboard, focus and ARIA behaviour (interactive pieces are built on Base UI primitives from the @base-ui/react package). - Stay on Base UI: install other Astabyte UI components without `--radix` so the project uses one primitive library. - Use fake data and fake brand names in examples. Use it to: [describe where it goes and what it should do]Or use plain HTML + CSS
Not on React? Use it from Django, Rails, Laravel, Go
html/template, htmx or a static page. Loadasta.cssandasta.jsonce (thehead.htmltab), then paste the markup. Theui.astabyte.com/cdnlink is temporary: pin a version from jsDelivr for production. More in HTML + CSS.<!-- Needs asta.js: the collapse toggle (data-collapsed), the active indicator and the workspace menu are scripted. --> <div style="display:flex;height:520px;width:100%;overflow:hidden;border-radius:12px;background:var(--paper)"> <aside aria-label="Sidebar" data-asta-sidebar data-auto-rail class="asta-sidebar"> <div class="asta-sidebar-ws" data-asta-dropdown data-asta-ws> <button type="button" class="asta-sidebar-item asta-sidebar-ws-trigger" data-asta-dropdown-trigger aria-haspopup="menu" aria-expanded="false"> <span class="asta-sidebar-slot"><span data-ws-logo-out aria-hidden="true" class="asta-sidebar-ws-logo">A</span></span> <span class="asta-sidebar-label asta-sidebar-ws-text"><span data-ws-name-out class="asta-sidebar-ws-name">Astabyte</span><span data-ws-plan-out class="asta-sidebar-ws-plan">Pro plan</span></span> <svg class="asta-sidebar-ws-chevron" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m5.5 6 2.5-2.5L10.5 6M5.5 10l2.5 2.5 2.5-2.5"/></svg> <span aria-hidden="true" data-ws-name-out class="asta-sidebar-tip">Astabyte</span> </button> <div role="menu" popover="manual" tabindex="-1" data-asta-mpanel aria-label="Switch workspace" class="asta-float asta-dropdown-panel asta-sidebar-ws-panel"> <p class="asta-sidebar-ws-heading">Workspaces</p> <button type="button" role="menuitemradio" tabindex="-1" aria-checked="true" data-group="workspace" data-value="studio" data-ws-name="Astabyte" data-ws-plan="Pro plan" class="asta-sidebar-ws-option"><span aria-hidden="true" class="asta-sidebar-ws-option-logo">A</span><span class="asta-sidebar-ws-option-text"><span>Astabyte</span><span>Pro plan</span></span><svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M3.5 8.5l3 3 6-7"/></svg></button> <button type="button" role="menuitemradio" tabindex="-1" aria-checked="false" data-group="workspace" data-value="labs" data-ws-name="Astabyte Labs" data-ws-plan="Free" class="asta-sidebar-ws-option"><span aria-hidden="true" class="asta-sidebar-ws-option-logo">A</span><span class="asta-sidebar-ws-option-text"><span>Astabyte Labs</span><span>Free</span></span><svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M3.5 8.5l3 3 6-7"/></svg></button> </div> </div> <nav aria-label="Main" data-asta-sidebar-nav class="asta-sidebar-nav"><div> <span data-asta-sidebar-indicator aria-hidden="true" class="asta-sidebar-indicator"></span> <div class="asta-sidebar-group"><ul> <li><button type="button" data-asta-sidebar-item="home" class="asta-sidebar-link"><span class="asta-sidebar-icon"><svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"><path d="M2.5 7 8 2.5 13.5 7v6.5h-11z"/></svg></span><span class="asta-sidebar-label">Home</span><span aria-hidden="true" class="asta-sidebar-tip">Home</span></button></li> <li><button type="button" data-asta-sidebar-item="inbox" aria-current="page" class="asta-sidebar-link"><span class="asta-sidebar-icon"><svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"><path d="M2.5 9.5h3l1 1.5h3l1-1.5h3M2.5 9.5 4 3.5h8l1.5 6v3h-11z"/></svg><span aria-hidden="true" class="asta-sidebar-dot"></span></span><span class="asta-sidebar-label">Inbox</span><span class="asta-sidebar-badge">4</span><span aria-hidden="true" class="asta-sidebar-tip">Inbox</span></button></li> <li><button type="button" data-asta-sidebar-item="search" class="asta-sidebar-link"><span class="asta-sidebar-icon"><svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"><path d="M7 2.5a4.5 4.5 0 1 0 0 9 4.5 4.5 0 0 0 0-9zM10.5 10.5 13.5 13.5"/></svg></span><span class="asta-sidebar-label">Search</span><span aria-hidden="true" class="asta-sidebar-tip">Search</span></button></li> </ul></div> <div class="asta-sidebar-group"><div class="asta-sidebar-group-label"><span>Workspace</span><span aria-hidden="true"></span></div><ul> <li><button type="button" data-asta-sidebar-item="reports" class="asta-sidebar-link"><span class="asta-sidebar-icon"><svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"><path d="M3 13V8M8 13V3M13 13V6"/></svg></span><span class="asta-sidebar-label">Reports</span><span aria-hidden="true" class="asta-sidebar-tip">Reports</span></button></li> <li><button type="button" data-asta-sidebar-item="settings" class="asta-sidebar-link"><span class="asta-sidebar-icon"><svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"><path d="M8 5.5a2.5 2.5 0 1 0 0 5 2.5 2.5 0 0 0 0-5zM8 1.5v2M8 12.5v2M1.5 8h2M12.5 8h2"/></svg></span><span class="asta-sidebar-label">Settings</span><span aria-hidden="true" class="asta-sidebar-tip">Settings</span></button></li> </ul></div> </div></nav> <button type="button" data-asta-sidebar-toggle aria-pressed="false" aria-label="Collapse sidebar" class="asta-sidebar-item asta-sidebar-toggle"><span class="asta-sidebar-slot"><svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M2.5 3.5h11v9h-11zM6 3.5v9M10.5 6.5 9 8l1.5 1.5"/></svg></span><span class="asta-sidebar-label">Collapse</span><span aria-hidden="true" class="asta-sidebar-tip">Expand</span></button> <div class="asta-sidebar-user"><span class="asta-sidebar-slot"><span class="asta-avatar asta-avatar-sm" role="img" aria-label="Sam Rivera"><span class="asta-avatar-face">SR</span></span></span><span class="asta-sidebar-label asta-sidebar-user-text"><span>Sam Rivera</span><span>[email protected]</span></span></div> </aside> <div style="flex:1;padding:24px;font-size:14px;color:var(--mute)">Content</div> </div>
Usage
The demo above, as code.
"use client";
import { useState } from "react";
import { Sidebar, type SidebarGroup, type SidebarItem } from "@/components/astabyte/sidebar";
const icon = (d: string) => (
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.1" strokeLinecap="round" strokeLinejoin="round" aria-hidden>
<path d={d} />
</svg>
);
const GROUPS: SidebarGroup[] = [
{
items: [
{ id: "home", label: "Home", icon: icon("M4 10.5 12 4l8 6.5M6 9v10.5h12V9M10 19.5v-5h4v5") },
{ id: "projects", label: "Projects", icon: icon("M3.5 7A1.5 1.5 0 0 1 5 5.5h4.5l2 2.5H19a1.5 1.5 0 0 1 1.5 1.5v8A1.5 1.5 0 0 1 19 19H5a1.5 1.5 0 0 1-1.5-1.5Z") },
{ id: "studio", label: "Studio", icon: icon("M5 6h8.5a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-8.5a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2ZM15.5 10.5l5.5-3.5v10l-5.5-3.5") },
{ id: "flows", label: "Flows", icon: icon("M5 3.5h4a1.5 1.5 0 0 1 1.5 1.5v4a1.5 1.5 0 0 1-1.5 1.5h-4a1.5 1.5 0 0 1-1.5-1.5v-4a1.5 1.5 0 0 1 1.5-1.5ZM15 13.5h4a1.5 1.5 0 0 1 1.5 1.5v4a1.5 1.5 0 0 1-1.5 1.5h-4a1.5 1.5 0 0 1-1.5-1.5v-4a1.5 1.5 0 0 1 1.5-1.5ZM7 10.5V14a2.5 2.5 0 0 0 2.5 2.5h4") },
{ id: "assets", label: "Assets", icon: icon("M12 4l8.5 4.5L12 13 3.5 8.5ZM3.5 12.5l8.5 4.5 8.5-4.5M3.5 16.5l8.5 4.5 8.5-4.5"), badge: 3 },
],
},
{
label: "Pinned",
items: [
{ id: "image", label: "Image editor", icon: icon("M5.5 4.5h13a2 2 0 0 1 2 2v11a2 2 0 0 1-2 2h-13a2 2 0 0 1-2-2v-11a2 2 0 0 1 2-2ZM7.25 9.5a1.75 1.75 0 1 0 3.5 0a1.75 1.75 0 1 0-3.5 0M4 17l5-5 4 4 2.5-2.5 4.5 4.5") },
{ id: "video", label: "Video", icon: icon("M5 6h8.5a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-8.5a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2ZM15.5 10.5l5.5-3.5v10l-5.5-3.5") },
{ id: "voice", label: "Voice", icon: icon("M12 3.5h0a3 3 0 0 1 3 3v5a3 3 0 0 1-3 3h0a3 3 0 0 1-3-3v-5a3 3 0 0 1 3-3ZM5.5 11.5a6.5 6.5 0 0 0 13 0M12 18v2.5") },
{ id: "captions", label: "Captions", icon: icon("M5.5 4.5h13a2 2 0 0 1 2 2v11a2 2 0 0 1-2 2h-13a2 2 0 0 1-2-2v-11a2 2 0 0 1 2-2ZM7 12.5h3M13 12.5h4M7 15.5h6M16 15.5h1") },
{ id: "more", label: "More tools", icon: icon("M4.5 12a1 1 0 1 0 2 0a1 1 0 1 0-2 0M11 12a1 1 0 1 0 2 0a1 1 0 1 0-2 0M17.5 12a1 1 0 1 0 2 0a1 1 0 1 0-2 0") },
],
},
];
const FOOTER: SidebarItem[] = [{ id: "api", label: "MCP and API", icon: icon("M5.5 4.5h13a2 2 0 0 1 2 2v11a2 2 0 0 1-2 2h-13a2 2 0 0 1-2-2v-11a2 2 0 0 1 2-2ZM7.5 9.5l3 2.5-3 2.5M12.5 15h4") }];
export default function SidebarDemo() {
const [page, setPage] = useState("studio");
const title = [...GROUPS.flatMap((g) => g.items), ...FOOTER].find((i) => i.id === page)?.label;
return (
<div className="flex min-h-[820px] w-full items-center justify-center p-3 sm:p-6">
{/* A small app frame: the sidebar on the left, a mock page on the right. */}
<div className="flex h-[820px] w-full max-w-[860px] overflow-hidden rounded-xl bg-paper shadow-[inset_0_0_0_1px_color-mix(in_srgb,var(--color-ink)_12%,transparent),0_24px_60px_-30px_rgb(0_0_0/0.35)]">
<Sidebar
brand="Astabyte"
groups={GROUPS}
footer={FOOTER}
active={page}
onNavigate={setPage}
promo={{
title: "Invite your team",
text: "Bring people in to edit and share projects together.",
icon: icon("M20.5 3.5 10 14M20.5 3.5l-6.5 17-4-6.5-6.5-4Z"),
onClick: () => setPage("home"),
onDismiss: () => {},
}}
cta={{ label: "Upgrade" }}
workspaces={[
{ id: "studio", name: "Astabyte Studio", plan: "Team plan" },
{ id: "personal", name: "Personal", plan: "Pro plan" },
{ id: "labs", name: "Astabyte Labs", plan: "Free" },
]}
/>
<main className="min-w-0 flex-1 p-6 max-sm:hidden">
<p className="text-[12px] text-mute">Astabyte Studio</p>
<h3 className="mt-1 text-[20px] font-medium tracking-[-0.02em] text-ink">{title}</h3>
<div className="mt-6 grid gap-3 sm:grid-cols-3">
{Array.from({ length: 3 }, (_, i) => (
<div key={i} className="h-24 rounded-[10px] bg-paper-2" />
))}
</div>
<div className="mt-3 h-40 rounded-[10px] bg-paper-2" />
</main>
</div>
</div>
);
}