{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"dashboard-sidebar","type":"registry:block","title":"Dashboard sidebar","description":"Grouped pages with counts, a section that opens, a plan card and the account menu; collapses to a rail of icons.","dependencies":["lucide-react"],"registryDependencies":["https://dashral.com/r/utils.json","https://dashral.com/r/lib-use-indicator.json","https://dashral.com/r/avatar.json","https://dashral.com/r/button.json","https://dashral.com/r/dropdown-menu.json","https://dashral.com/r/progress.json","https://dashral.com/r/sheet.json","https://dashral.com/r/tooltip.json"],"files":[{"path":"registry/dashral/blocks/dashboard-sidebar.tsx","type":"registry:file","target":"components/dashral/blocks/dashboard-sidebar.tsx","content":"\"use client\"\n\nimport { useState } from \"react\"\nimport {\n  BarChart3,\n  ChevronDown,\n  ChevronsUpDown,\n  CreditCard,\n  FileText,\n  Inbox,\n  LayoutDashboard,\n  LogOut,\n  Menu,\n  Package,\n  PanelLeftClose,\n  PanelLeftOpen,\n  X,\n  Settings,\n  ShoppingCart,\n  Sparkles,\n  User,\n  Users,\n} from \"lucide-react\"\nimport { Avatar } from \"../avatar\"\nimport { Button } from \"../button\"\nimport { DropdownMenu } from \"../dropdown-menu\"\nimport { Progress } from \"../progress\"\nimport { Sheet, SheetClose } from \"../sheet\"\nimport { Tooltip } from \"../tooltip\"\nimport { indicatorMotion, useIndicator } from \"../lib/use-indicator\"\nimport { cn } from \"../lib/utils\"\n\n/** A page in the sidebar, with a count, or a section that opens to its children. Pages are named by their label. */\nexport type SidebarItem = { label: string; icon: React.ReactNode; count?: number; children?: string[] }\nexport type SidebarGroup = { label: string; items: SidebarItem[] }\n/** What the account menu asks for. */\nexport type AccountAction = \"profile\" | \"billing\" | \"settings\" | \"sign-out\"\n/** Everything the sidebar shows besides where you are. */\ntype Config = {\n  groups: SidebarGroup[]\n  brand: { name: string; plan?: string; mark?: string }\n  user: { name: string; email: string; src?: string }\n  /** The card above the account: a line, a meter and a button; null hides it. */\n  promo: { title: string; value: number; action: string; onAction?: () => void } | null\n  onAccount?: (action: AccountAction) => void\n}\n\nconst sampleGroups: SidebarGroup[] = [\n  {\n    label: \"Overview\",\n    items: [\n      { label: \"Dashboard\", icon: <LayoutDashboard /> },\n      { label: \"Inbox\", icon: <Inbox />, count: 4 },\n      { label: \"Reports\", icon: <BarChart3 />, children: [\"Sales\", \"Traffic\", \"Cohorts\"] },\n    ],\n  },\n  {\n    label: \"Store\",\n    items: [\n      { label: \"Orders\", icon: <ShoppingCart />, count: 12 },\n      { label: \"Products\", icon: <Package /> },\n      { label: \"Customers\", icon: <Users /> },\n      { label: \"Invoices\", icon: <FileText /> },\n    ],\n  },\n]\n\n/**\n * A dashboard's sidebar: the product, grouped pages with counts, a section that opens (Reports), a plan card and the\n * account menu. It collapses to a rail of icons with their names in tooltips, and on phones becomes a top bar whose\n * menu opens in a sheet. Every part comes from props: your pages (the one you're on controllable, `onNavigate` to go\n * there), brand, user and promo card.\n */\nexport function DashboardSidebar({\n  groups = sampleGroups,\n  current: currentProp,\n  onNavigate,\n  brand = { name: \"Acme Inc.\", plan: \"Team plan\" },\n  user = { name: \"Olivia Martin\", email: \"olivia@acme.com\", src: \"https://randomuser.me/api/portraits/women/44.jpg\" },\n  promo = { title: \"7 of 10 seats used\", value: 70, action: \"Upgrade to Business\" },\n  onAccount,\n}: {\n  groups?: SidebarGroup[]\n  /** The page you're on, by label (the sidebar keeps it without it). */\n  current?: string\n  onNavigate?: (page: string) => void\n  brand?: Config[\"brand\"]\n  user?: Config[\"user\"]\n  promo?: Config[\"promo\"]\n  onAccount?: Config[\"onAccount\"]\n}) {\n  const config: Config = { groups, brand, user, promo, onAccount }\n  const [collapsed, setCollapsed] = useState(false)\n  const [ownCurrent, setOwnCurrent] = useState(groups[0]?.items[0]?.label ?? \"\")\n  const current = currentProp ?? ownCurrent\n  const setCurrent = (page: string) => {\n    setOwnCurrent(page)\n    onNavigate?.(page)\n  }\n  const [open, setOpen] = useState<string[]>(() => groups.flatMap((g) => g.items.filter((i) => i.children).map((i) => i.label)).slice(0, 1))\n  const [sheet, setSheet] = useState(false)\n\n  return (\n    <>\n      {/* Phones: a top bar, and the same menu in a sheet. */}\n      <div className=\"flex h-14 items-center gap-3 border-b bg-sidebar px-4 md:hidden\">\n        <Button variant=\"ghost\" size=\"icon\" aria-label=\"Open the menu\" onClick={() => setSheet(true)}>\n          <Menu />\n        </Button>\n        <Brand brand={brand} />\n      </div>\n      <Sheet open={sheet} onOpenChange={setSheet} side=\"left\" title=\"Menu\" padding=\"none\" showCloseButton={false} className=\"w-72 bg-sidebar\" classNames={{ header: \"sr-only\" }}>\n        <SidebarBody\n          config={config}\n          inSheet\n          collapsed={false}\n          current={current}\n          open={open}\n          onOpen={setOpen}\n          onPick={(page) => {\n            setCurrent(page)\n            setSheet(false)\n          }}\n        />\n      </Sheet>\n\n      <aside\n        aria-label=\"Sidebar\"\n        className={cn(\n          \"sticky top-0 hidden h-svh shrink-0 border-e bg-sidebar transition-[width] duration-(--duration-standard) ease-standard motion-reduce:transition-none md:block\",\n          collapsed ? \"w-16\" : \"w-64\"\n        )}\n      >\n        <SidebarBody config={config} collapsed={collapsed} onToggle={() => setCollapsed(!collapsed)} current={current} open={open} onOpen={setOpen} onPick={setCurrent} />\n      </aside>\n    </>\n  )\n}\n\nfunction Brand({ brand, compact = false }: { brand: Config[\"brand\"]; compact?: boolean }) {\n  return (\n    <span className=\"flex min-w-0 items-center gap-2.5\">\n      <span aria-hidden className=\"flex size-8 shrink-0 items-center justify-center rounded-lg bg-primary text-sm font-bold text-primary-foreground\">\n        {brand.mark ?? brand.name[0]}\n      </span>\n      {!compact && (\n        <span className=\"grid min-w-0\">\n          <span className=\"truncate text-sm font-semibold\">{brand.name}</span>\n          {brand.plan && <span className=\"truncate text-xs text-muted-foreground\">{brand.plan}</span>}\n        </span>\n      )}\n    </span>\n  )\n}\n\nfunction SidebarBody({\n  config: { groups, brand, user, promo, onAccount },\n  inSheet = false,\n  collapsed,\n  onToggle,\n  current,\n  open,\n  onOpen,\n  onPick,\n}: {\n  config: Config\n  /** In the phone sheet: a close button where the collapse button would be. */\n  inSheet?: boolean\n  collapsed: boolean\n  onToggle?: () => void\n  current: string\n  open: string[]\n  onOpen: (open: string[]) => void\n  onPick: (page: string) => void\n}) {\n  // One highlight behind the current page, sliding to the next one you open.\n  const [navRef, highlight] = useIndicator<HTMLElement>(\"[aria-current=page]\")\n  const row =\n    \"relative flex h-9 w-full items-center gap-3 rounded-md text-sm outline-none transition-colors focus-visible:ring-2 focus-visible:ring-ring/50 [&>svg]:size-4 [&>svg]:shrink-0\"\n\n  return (\n    <div className=\"flex h-full flex-col\">\n      <div className={cn(\"flex h-16 shrink-0 items-center gap-2 px-4\", collapsed && \"justify-center px-0\")}>\n        {collapsed ? (\n          <Tooltip content=\"Expand sidebar\" side=\"right\">\n            <button type=\"button\" aria-label=\"Expand sidebar\" onClick={onToggle} className=\"group relative rounded-lg outline-none focus-visible:ring-2 focus-visible:ring-ring/50\">\n              <Brand brand={brand} compact />\n              <span aria-hidden className=\"absolute inset-0 hidden items-center justify-center rounded-lg bg-sidebar-accent text-foreground group-hover:flex [&>svg]:size-4\">\n                <PanelLeftOpen />\n              </span>\n            </button>\n          </Tooltip>\n        ) : (\n          <>\n            <Brand brand={brand} />\n            {inSheet && (\n              <SheetClose asChild>\n                <Button variant=\"ghost\" size=\"icon-sm\" aria-label=\"Close the menu\" className=\"ms-auto text-muted-foreground\">\n                  <X />\n                </Button>\n              </SheetClose>\n            )}\n            {onToggle && (\n              <Button variant=\"ghost\" size=\"icon-sm\" aria-label=\"Collapse sidebar\" onClick={onToggle} className=\"ms-auto text-muted-foreground\">\n                <PanelLeftClose />\n              </Button>\n            )}\n          </>\n        )}\n      </div>\n\n      <nav ref={navRef} aria-label=\"Main\" className=\"relative min-h-0 flex-1 overflow-y-auto px-3 pb-3\">\n        {highlight && (\n          <span\n            aria-hidden\n            className={cn(indicatorMotion, \"rounded-md bg-sidebar-accent\")}\n            style={{ translate: `${highlight.x}px ${highlight.y}px`, width: highlight.width, height: highlight.height }}\n          />\n        )}\n        {groups.map((group, g) => (\n          <div key={group.label} className={cn(g > 0 && \"mt-5\")}>\n            {collapsed ? (\n              g > 0 && <span aria-hidden className=\"mx-auto mb-3 block h-px w-6 bg-border\" />\n            ) : (\n              <p className=\"mb-1 px-3 text-xs font-medium text-muted-foreground\">{group.label}</p>\n            )}\n            <ul className=\"grid gap-0.5\">\n              {group.items.map((item) => {\n                const here = current === item.label || item.children?.includes(current)\n                const expanded = open.includes(item.label)\n\n                if (collapsed) {\n                  const icon = (\n                    <button\n                      type=\"button\"\n                      aria-label={item.count ? `${item.label}, ${item.count}` : item.label}\n                      aria-current={here ? \"page\" : undefined}\n                      onClick={() => !item.children && onPick(item.label)}\n                      className={cn(row, \"justify-center\", here ? \"text-foreground\" : \"text-muted-foreground hover:bg-sidebar-accent/60 hover:text-foreground\")}\n                    >\n                      {item.icon}\n                      {item.count && <span aria-hidden className=\"absolute end-1.5 top-1.5 size-1.5 rounded-full bg-primary\" />}\n                    </button>\n                  )\n                  return (\n                    <li key={item.label}>\n                      {item.children ? (\n                        // A section opens to the side when the rail is collapsed.\n                        <DropdownMenu\n                          side=\"right\"\n                          align=\"start\"\n                          className=\"w-44\"\n                          trigger={icon}\n                          items={[{ type: \"label\", label: item.label }, ...item.children.map((child) => ({ label: child, onSelect: () => onPick(child) }))]}\n                        />\n                      ) : (\n                        <Tooltip content={item.count ? `${item.label} · ${item.count}` : item.label} side=\"right\">\n                          {icon}\n                        </Tooltip>\n                      )}\n                    </li>\n                  )\n                }\n\n                return (\n                  <li key={item.label}>\n                    <button\n                      type=\"button\"\n                      aria-current={!item.children && here ? \"page\" : undefined}\n                      aria-expanded={item.children ? expanded : undefined}\n                      onClick={() => (item.children ? onOpen(expanded ? open.filter((o) => o !== item.label) : [...open, item.label]) : onPick(item.label))}\n                      className={cn(row, \"px-3\", here ? \"font-medium text-foreground\" : \"text-muted-foreground hover:bg-sidebar-accent/60 hover:text-foreground\")}\n                    >\n                      {item.icon}\n                      <span className=\"flex-1 truncate text-start\">{item.label}</span>\n                      {item.count && <span className=\"rounded-full bg-primary/12 px-1.5 text-[11px] font-medium text-primary-text tabular-nums\">{item.count}</span>}\n                      {item.children && (\n                        <ChevronDown aria-hidden className={cn(\"size-4 text-muted-foreground transition-transform duration-(--duration-standard) ease-standard\", !expanded && \"-rotate-90 rtl:rotate-90\")} />\n                      )}\n                    </button>\n                    {item.children && (\n                      <div\n                        inert={!expanded || undefined}\n                        className=\"grid transition-[grid-template-rows] duration-(--duration-standard) ease-standard motion-reduce:transition-none\"\n                        style={{ gridTemplateRows: expanded ? \"1fr\" : \"0fr\" }}\n                      >\n                        <ul className=\"ms-5 min-h-0 overflow-hidden border-s ps-2\">\n                          {item.children.map((child) => (\n                            <li key={child} className=\"pt-0.5\">\n                              <button\n                                type=\"button\"\n                                aria-current={current === child ? \"page\" : undefined}\n                                onClick={() => onPick(child)}\n                                className={cn(row, \"h-8 px-3\", current === child ? \"font-medium text-foreground\" : \"text-muted-foreground hover:bg-sidebar-accent/60 hover:text-foreground\")}\n                              >\n                                {child}\n                              </button>\n                            </li>\n                          ))}\n                        </ul>\n                      </div>\n                    )}\n                  </li>\n                )\n              })}\n            </ul>\n          </div>\n        ))}\n      </nav>\n\n      <div className={cn(\"grid shrink-0 gap-3 border-t p-3\", collapsed && \"justify-center\")}>\n        {!collapsed && promo && (\n          <div className=\"rounded-lg border bg-card p-3\">\n            <p className=\"flex items-center gap-1.5 text-sm font-medium\">\n              <Sparkles className=\"size-4 text-primary-text\" aria-hidden /> {promo.title}\n            </p>\n            <Progress value={promo.value} className=\"mt-2 h-1.5\" aria-label={promo.title} />\n            <Button size=\"sm\" className=\"mt-3 w-full\" onClick={promo.onAction}>\n              {promo.action}\n            </Button>\n          </div>\n        )}\n        <DropdownMenu\n          side={collapsed ? \"right\" : \"top\"}\n          align={collapsed ? \"end\" : \"start\"}\n          className=\"w-56\"\n          trigger={\n            <button\n              type=\"button\"\n              aria-label={`Account menu for ${user.name}`}\n              className={cn(\"flex items-center gap-3 rounded-md p-1.5 text-start outline-none transition-colors hover:bg-sidebar-accent/60 focus-visible:ring-2 focus-visible:ring-ring/50 data-[state=open]:bg-sidebar-accent\", !collapsed && \"w-full\")}\n            >\n              <Avatar src={user.src} name={user.name} alt=\"\" size=\"md\" />\n              {!collapsed && (\n                <>\n                  <span className=\"grid min-w-0 flex-1\">\n                    <span className=\"truncate text-sm font-medium\">{user.name}</span>\n                    <span className=\"truncate text-xs text-muted-foreground\">{user.email}</span>\n                  </span>\n                  <ChevronsUpDown className=\"size-4 shrink-0 text-muted-foreground\" aria-hidden />\n                </>\n              )}\n            </button>\n          }\n          items={[\n            { label: \"Profile\", icon: <User />, onSelect: () => onAccount?.(\"profile\") },\n            { label: \"Billing\", icon: <CreditCard />, onSelect: () => onAccount?.(\"billing\") },\n            { label: \"Settings\", icon: <Settings />, onSelect: () => onAccount?.(\"settings\") },\n            { type: \"separator\" },\n            { label: \"Sign out\", icon: <LogOut />, color: \"destructive\", onSelect: () => onAccount?.(\"sign-out\") },\n          ]}\n        />\n      </div>\n    </div>\n  )\n}\n"}],"cssVars":{"theme":{"color-primary-text":"var(--primary-text, var(--primary))","ease-standard":"var(--ease-standard)","ease-enter":"var(--ease-enter)","ease-exit":"var(--ease-exit)","ease-spring":"var(--ease-spring)"},"light":{"duration-fast":"160ms","duration-standard":"240ms","duration-considered":"480ms","ease-standard":"cubic-bezier(0.2, 0, 0, 1)","ease-enter":"cubic-bezier(0, 0, 0, 1)","ease-exit":"cubic-bezier(0.3, 0, 1, 1)","ease-spring":"linear(0, 0.071 4%, 0.234 8%, 0.433 12%, 0.626 17%, 0.791 21%, 0.917 25%, 1.004 29%, 1.055 33%, 1.079 38%, 1.083 42%, 1.075 46%, 1.06 50%, 1.043 54%, 1.027 58%, 1.015 62%, 1.005 67%, 0.998 71%, 0.995 75%, 0.993 79%, 0.993 83%, 0.994 88%, 0.995 92%, 0.997 96%, 1)"},"dark":{}}}