{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"workspace-sidebar","type":"registry:block","title":"Workspace sidebar","description":"A workspace switcher, search, inbox, and Favorites and Projects that fold away; each project opens to its views.","dependencies":["lucide-react"],"registryDependencies":["https://dashral.com/r/utils.json","https://dashral.com/r/lib-use-indicator.json","https://dashral.com/r/button.json","https://dashral.com/r/command.json","https://dashral.com/r/dropdown-menu.json","https://dashral.com/r/sheet.json"],"files":[{"path":"registry/dashral/blocks/workspace-sidebar.tsx","type":"registry:file","target":"components/dashral/blocks/workspace-sidebar.tsx","content":"\"use client\"\n\nimport { useState } from \"react\"\nimport { ChevronDown, ChevronsUpDown, CircleHelp, Columns3, FileText, Inbox, ListTodo, Menu, Plus, Search, SquarePen, Star, UserPlus, X } from \"lucide-react\"\nimport { Button } from \"../button\"\nimport { CommandDialog } from \"../command\"\nimport { DropdownMenu } from \"../dropdown-menu\"\nimport { Sheet, SheetClose } from \"../sheet\"\nimport { indicatorMotion, useIndicator } from \"../lib/use-indicator\"\nimport { cn } from \"../lib/utils\"\n\n/** A workspace in the switcher; `tile` is the classes of its letter tile. */\nexport type Workspace = { id: string; name: string; initials?: string; tile?: string }\n/** A project; `color` is the class of its square. */\nexport type WorkspaceProject = { id: string; name: string; color: string }\nexport type WorkspaceView = { id: string; label: string; icon: React.ReactNode }\n/** A starred page: `to` is where it goes, a page id like the sidebar's own (\"q4/board\"). */\nexport type WorkspaceFavorite = { to: string; label: string }\n/** The buttons that don't navigate. */\nexport type WorkspaceAction = \"new-issue\" | \"create-workspace\" | \"invite\" | \"help\"\n\nconst sampleWorkspaces: Workspace[] = [\n  { id: \"acme\", name: \"Acme Inc.\", initials: \"A\", tile: \"bg-primary text-primary-foreground\" },\n  { id: \"nusantara\", name: \"PT Nusantara\", initials: \"N\", tile: \"bg-success text-success-foreground\" },\n]\nconst sampleProjects: WorkspaceProject[] = [\n  { id: \"web\", name: \"Website\", color: \"bg-info\" },\n  { id: \"mobile\", name: \"Mobile app\", color: \"bg-highlight\" },\n  { id: \"q4\", name: \"Q4 launch\", color: \"bg-warning\" },\n]\nconst sampleFavorites: WorkspaceFavorite[] = [\n  { to: \"q4/board\", label: \"Q4 launch board\" },\n  { to: \"web/docs\", label: \"Website specs\" },\n]\nconst colors = [\"bg-info\", \"bg-highlight\", \"bg-success\", \"bg-warning\", \"bg-destructive\"]\nconst sampleViews: WorkspaceView[] = [\n  { id: \"issues\", label: \"Issues\", icon: <ListTodo /> },\n  { id: \"board\", label: \"Board\", icon: <Columns3 /> },\n  { id: \"docs\", label: \"Docs\", icon: <FileText /> },\n]\n\n/** A titled part of the sidebar that folds away, its height easing open and closed. */\nfunction Section({\n  label,\n  expanded,\n  onToggle,\n  action,\n  children,\n}: {\n  label: string\n  expanded: boolean\n  onToggle: () => void\n  action?: React.ReactNode\n  children: React.ReactNode\n}) {\n  return (\n    <div className=\"mt-4\">\n      <div className=\"group flex items-center\">\n        <button\n          type=\"button\"\n          aria-expanded={expanded}\n          onClick={onToggle}\n          className=\"flex h-7 flex-1 items-center gap-1 rounded-md px-2 text-xs font-medium text-muted-foreground outline-none hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring/50\"\n        >\n          {label}\n          <ChevronDown aria-hidden className={cn(\"size-3 transition-transform duration-(--duration-standard) ease-standard\", !expanded && \"-rotate-90 rtl:rotate-90\")} />\n        </button>\n        {action}\n      </div>\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=\"grid min-h-0 gap-0.5 overflow-hidden\">{children}</ul>\n      </div>\n    </div>\n  )\n}\n\n/**\n * A project tool's sidebar, like Linear's or Notion's: the workspace switcher and new-item button, search, your inbox\n * and issues, then Favorites and Projects that fold away. Each project opens to its views, and + adds one. Replace\n * your workspaces, projects, views and favorites through props. Pages are ids: \"inbox\", \"mine\" and \"<project>/<view>\";\n * the one you're on is controllable, with `onNavigate`. + calls `onAddProject`, which may return the stored project.\n */\nexport function WorkspaceSidebar({\n  workspaces = sampleWorkspaces,\n  workspace: workspaceProp,\n  onWorkspaceChange,\n  projects: projectsProp = sampleProjects,\n  views = sampleViews,\n  favorites = sampleFavorites,\n  inbox = 4,\n  current: currentProp,\n  onNavigate,\n  onAddProject,\n  onAction,\n}: {\n  workspaces?: Workspace[]\n  /** The workspace you're in, by id (the sidebar keeps it without it). */\n  workspace?: string\n  onWorkspaceChange?: (id: string) => void\n  projects?: WorkspaceProject[]\n  /** The views every project opens to. */\n  views?: WorkspaceView[]\n  favorites?: WorkspaceFavorite[]\n  /** The count beside Inbox; 0 hides it. */\n  inbox?: number\n  current?: string\n  onNavigate?: (page: string) => void\n  /** Called with the new project; return the one you stored (its real id) or throw to take it back. */\n  onAddProject?: (project: WorkspaceProject) => WorkspaceProject | void | Promise<WorkspaceProject | void>\n  onAction?: (action: WorkspaceAction) => void\n}) {\n  const [ownWorkspace, setOwnWorkspace] = useState(workspaces[0]?.id ?? \"\")\n  const workspace = workspaceProp ?? ownWorkspace\n  const setWorkspace = (id: string) => {\n    setOwnWorkspace(id)\n    onWorkspaceChange?.(id)\n  }\n  // Your projects, re-read when you pass new ones.\n  const [projects, setProjects] = useState(projectsProp)\n  const [lastProjects, setLastProjects] = useState(projectsProp)\n  if (projectsProp !== lastProjects) {\n    setLastProjects(projectsProp)\n    setProjects(projectsProp)\n  }\n  const first = projects[0] ? `${projects[0].id}/${views[1]?.id ?? views[0]?.id}` : \"inbox\"\n  const [ownCurrent, setOwnCurrent] = useState(first)\n  const current = currentProp ?? ownCurrent\n  const [open, setOpen] = useState<string[]>([\"favorites\", \"projects\", first.split(\"/\")[0]!])\n  const [search, setSearch] = useState(false)\n  const [navRef, highlight] = useIndicator<HTMLElement>(\"[aria-current=page]\")\n  const active = workspaces.find((w) => w.id === workspace) ?? workspaces[0] ?? { id: \"\", name: \"\" }\n  const tile = (w: Workspace) => w.tile ?? \"bg-primary text-primary-foreground\"\n\n  const toggle = (id: string) => setOpen(open.includes(id) ? open.filter((o) => o !== id) : [...open, id])\n  const row =\n    \"relative flex h-8 w-full items-center gap-2.5 rounded-md px-2 text-sm text-muted-foreground outline-none transition-colors hover:bg-sidebar-accent/60 hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring/50 aria-[current=page]:text-foreground aria-[current=page]:font-medium [&>svg]:size-4 [&>svg]:shrink-0\"\n  const link = (id: string, label: string, icon: React.ReactNode, extra?: React.ReactNode) => (\n    <button type=\"button\" aria-current={current === id ? \"page\" : undefined} onClick={() => pick(id)} className={row}>\n      {icon}\n      <span className=\"flex-1 truncate text-start\">{label}</span>\n      {extra}\n    </button>\n  )\n\n  const [sheet, setSheet] = useState(false)\n  const pick = (id: string) => {\n    setOwnCurrent(id)\n    onNavigate?.(id)\n    setSheet(false)\n  }\n\n  async function addProject() {\n    const draft = { id: `p${Date.now()}`, name: \"Untitled project\", color: colors[projects.length % colors.length]! }\n    const before = projects\n    setProjects([...projects, draft])\n    setOpen([...open, \"projects\", draft.id])\n    try {\n      const stored = (await onAddProject?.(draft)) || draft\n      if (stored !== draft) setProjects((list) => list.map((p) => (p.id === draft.id ? stored : p)))\n      setOpen((list) => [...list, stored.id])\n      pick(`${stored.id}/${views[0]?.id}`)\n    } catch {\n      setProjects(before)\n    }\n  }\n\n  // In the sheet, its close button sits in the top row with the others (the sheet's own would cover New issue).\n  const body = (inSheet: boolean) => (\n    <>\n      <div className=\"flex items-center gap-1 p-3 pb-2\">\n        <DropdownMenu\n          align=\"start\"\n          className=\"w-56\"\n          trigger={\n            <button\n              type=\"button\"\n              className=\"flex min-w-0 flex-1 items-center gap-2 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\"\n            >\n              <span aria-hidden className={cn(\"flex size-6 shrink-0 items-center justify-center rounded-md text-xs font-bold\", tile(active))}>\n                {active.initials ?? active.name[0]}\n              </span>\n              <span className=\"truncate text-sm font-semibold\">{active.name}</span>\n              <ChevronsUpDown className=\"ms-auto size-3.5 shrink-0 text-muted-foreground\" aria-hidden />\n            </button>\n          }\n          items={[\n            {\n              type: \"radio\",\n              value: workspace,\n              onValueChange: setWorkspace,\n              options: workspaces.map((w) => ({\n                value: w.id,\n                label: w.name,\n                icon: (\n                  <span aria-hidden className={cn(\"flex size-5 items-center justify-center rounded-[calc(var(--radius)*2/7)] text-[10px] font-bold\", tile(w))}>\n                    {w.initials ?? w.name[0]}\n                  </span>\n                ),\n              })),\n            },\n            { type: \"separator\" },\n            { label: \"Create workspace\", icon: <Plus />, onSelect: () => onAction?.(\"create-workspace\") },\n          ]}\n        />\n        <Button variant=\"ghost\" size=\"icon-sm\" aria-label=\"New issue\" onClick={() => onAction?.(\"new-issue\")} className=\"text-muted-foreground\">\n          <SquarePen />\n        </Button>\n        {inSheet && (\n          <SheetClose asChild>\n            <Button variant=\"ghost\" size=\"icon-sm\" aria-label=\"Close the menu\" className=\"text-muted-foreground\">\n              <X />\n            </Button>\n          </SheetClose>\n        )}\n      </div>\n\n      <nav ref={navRef} aria-label=\"Workspace\" 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        <ul className=\"grid gap-0.5\">\n          <li>\n            <button type=\"button\" onClick={() => setSearch(true)} className={row}>\n              <Search />\n              <span className=\"flex-1 text-start\">Search</span>\n            </button>\n          </li>\n          <li>{link(\"inbox\", \"Inbox\", <Inbox />, inbox > 0 && <span className=\"text-xs text-muted-foreground tabular-nums\">{inbox}</span>)}</li>\n          <li>{link(\"mine\", \"My issues\", <ListTodo />)}</li>\n        </ul>\n\n        {favorites.length > 0 && (\n          <Section label=\"Favorites\" expanded={open.includes(\"favorites\")} onToggle={() => toggle(\"favorites\")}>\n            {favorites.map((f) => (\n              <li key={f.to}>{link(f.to, f.label, <Star className=\"fill-warning text-warning\" />)}</li>\n            ))}\n          </Section>\n        )}\n\n        <Section\n          label=\"Projects\"\n          expanded={open.includes(\"projects\")}\n          onToggle={() => toggle(\"projects\")}\n          action={\n            <Button variant=\"ghost\" size=\"icon-sm\" aria-label=\"New project\" onClick={addProject} className=\"size-7 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100 focus-visible:opacity-100 pointer-coarse:opacity-100\">\n              <Plus />\n            </Button>\n          }\n        >\n          {projects.map((project) => {\n            const expanded = open.includes(project.id)\n            return (\n              <li key={project.id}>\n                <button type=\"button\" aria-expanded={expanded} onClick={() => toggle(project.id)} className={cn(row, current.startsWith(`${project.id}/`) && !expanded && \"text-foreground\")}>\n                  <span aria-hidden className={cn(\"size-2.5 shrink-0 rounded-[3px]\", project.color)} />\n                  <span className=\"flex-1 truncate text-start\">{project.name}</span>\n                  <ChevronDown aria-hidden className={cn(\"size-3.5 transition-transform duration-(--duration-standard) ease-standard\", !expanded && \"-rotate-90 rtl:rotate-90\")} />\n                </button>\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-3 grid min-h-0 overflow-hidden border-s ps-2\">\n                    {views.map((view) => (\n                      // The space sits on each row, so a closed list has no height at all (no stub of its line).\n                      <li key={view.id} className=\"pt-0.5\">\n                        {link(`${project.id}/${view.id}`, view.label, view.icon)}\n                      </li>\n                    ))}\n                  </ul>\n                </div>\n              </li>\n            )\n          })}\n        </Section>\n      </nav>\n\n      <div className=\"grid gap-0.5 border-t p-3\">\n        <button type=\"button\" onClick={() => onAction?.(\"invite\")} className={row}>\n          <UserPlus />\n          Invite people\n        </button>\n        <button type=\"button\" onClick={() => onAction?.(\"help\")} className={row}>\n          <CircleHelp />\n          Help and support\n        </button>\n      </div>\n\n      <CommandDialog\n        open={search}\n        onOpenChange={setSearch}\n        placeholder=\"Search projects and views…\"\n        groups={[\n          {\n            heading: \"Projects\",\n            items: projects.flatMap((project) =>\n              views.map((view) => ({\n                label: `${project.name} · ${view.label}`,\n                icon: view.icon,\n                onSelect: () => {\n                  setOpen([...new Set([...open, \"projects\", project.id])])\n                  pick(`${project.id}/${view.id}`)\n                  setSearch(false)\n                },\n              }))\n            ),\n          },\n        ]}\n      />\n    </>\n  )\n\n  return (\n    <>\n      {/* Phones: a top bar, and the same sidebar 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        <span className=\"truncate text-sm font-semibold\">{active.name}</span>\n      </div>\n      <Sheet\n        open={sheet}\n        onOpenChange={setSheet}\n        side=\"left\"\n        title=\"Menu\"\n        padding=\"none\"\n        showCloseButton={false}\n        className=\"w-72 bg-sidebar\"\n        classNames={{ header: \"sr-only\", body: \"flex flex-col\" }}\n      >\n        {sheet && body(true)}\n      </Sheet>\n      <aside aria-label=\"Sidebar\" className=\"sticky top-0 hidden h-svh w-64 shrink-0 flex-col border-e bg-sidebar md:flex\">\n        {!sheet && body(false)}\n      </aside>\n    </>\n  )\n}\n"}],"cssVars":{"theme":{"color-info":"var(--info)","color-info-foreground":"var(--info-foreground)","color-info-text":"var(--info-text)","color-success":"var(--success)","color-success-foreground":"var(--success-foreground)","color-success-text":"var(--success-text)","color-warning":"var(--warning)","color-warning-foreground":"var(--warning-foreground)","color-warning-text":"var(--warning-text)","color-highlight":"var(--highlight)","color-highlight-foreground":"var(--highlight-foreground)","color-highlight-text":"var(--highlight-text)","ease-standard":"var(--ease-standard)","ease-enter":"var(--ease-enter)","ease-exit":"var(--ease-exit)","ease-spring":"var(--ease-spring)"},"light":{"info":"oklch(0.5 0.134 242.749)","info-foreground":"oklch(0.985 0 0)","info-text":"oklch(0.443 0.11 240.79)","success":"oklch(0.508 0.118 165.612)","success-foreground":"oklch(0.985 0 0)","success-text":"oklch(0.432 0.095 166.913)","warning":"#f59200","warning-foreground":"oklch(0.3 0.07 60)","warning-text":"#964e00","highlight":"#b8008c","highlight-foreground":"oklch(0.985 0 0)","highlight-text":"#a3007b","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":{"info":"oklch(0.685 0.169 237.323)","info-foreground":"oklch(0.2 0 0)","info-text":"oklch(0.746 0.16 232.661)","success":"oklch(0.696 0.17 162.48)","success-foreground":"oklch(0.2 0.04 160)","success-text":"oklch(0.765 0.177 163.223)","warning":"#f59200","warning-foreground":"oklch(0.25 0.06 60)","warning-text":"#ffba42","highlight":"#ff2ecf","highlight-foreground":"oklch(0.2 0 0)","highlight-text":"#ff75df"}}}