{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"workspace-header","type":"registry:block","title":"Workspace header","description":"A workspace switcher, the section's tabs underneath, and help, notifications and the account menu.","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/badge.json","https://dashral.com/r/button.json","https://dashral.com/r/dropdown-menu.json","https://dashral.com/r/tooltip.json"],"files":[{"path":"registry/dashral/blocks/workspace-header.tsx","type":"registry:file","target":"components/dashral/blocks/workspace-header.tsx","content":"\"use client\"\n\nimport { useState } from \"react\"\nimport { Bell, ChevronsUpDown, CircleHelp, CreditCard, LogOut, MessageSquare, Plus, Settings, User } from \"lucide-react\"\nimport { Avatar } from \"../avatar\"\nimport { Badge } from \"../badge\"\nimport { Button } from \"../button\"\nimport { DropdownMenu } from \"../dropdown-menu\"\nimport { Tooltip } from \"../tooltip\"\nimport { indicatorMotion, useIndicator } from \"../lib/use-indicator\"\nimport { cn } from \"../lib/utils\"\n\nexport type Workspace = { id: string; name: string; plan?: string; /** Its tile's color class, e.g. \"bg-primary\". */ color: string }\nexport type Project = { id: string; name: string; /** Its status dot's color class, e.g. \"bg-success\". */ status: string }\nexport type Section = { label: string; href?: string }\n/** What the account menu and the workspace and project menus can ask for. */\nexport type HeaderAction = \"create-workspace\" | \"workspace-settings\" | \"new-project\" | \"feedback\" | \"help\" | \"notifications\" | \"profile\" | \"billing\" | \"sign-out\"\n\nconst sampleWorkspaces: Workspace[] = [\n  { id: \"acme\", name: \"Acme Inc\", plan: \"Team\", color: \"bg-primary\" },\n  { id: \"marketing\", name: \"Acme Marketing\", plan: \"Pro\", color: \"bg-highlight\" },\n  { id: \"personal\", name: \"Olivia's projects\", plan: \"Free\", color: \"bg-success\" },\n]\n\nconst sampleProjects: Project[] = [\n  { id: \"website\", name: \"Website\", status: \"bg-success\" },\n  { id: \"mobile\", name: \"Mobile app\", status: \"bg-warning\" },\n  { id: \"api\", name: \"Public API\", status: \"bg-success\" },\n]\n\nconst sampleSections: Section[] = [\"Overview\", \"Analytics\", \"Customers\", \"Reports\", \"Settings\"].map((label) => ({ label }))\n\n/** A workspace's initial on its own color. */\nfunction WorkspaceTile({ name, color, className }: { name: string; color: string; className?: string }) {\n  return (\n    <span aria-hidden className={cn(\"grid size-6 shrink-0 place-items-center rounded-md text-xs font-semibold text-white\", color, className)}>\n      {name[0]}\n    </span>\n  )\n}\n\n/**\n * Two rows: the workspace and project switchers with help, notifications and the account menu on top, and the\n * section's tabs underneath, with an underline that slides to the one you pick. Every part comes from props: what's\n * picked can be controlled, and every menu item and button tells `onAction`.\n */\nexport function WorkspaceHeader({\n  workspaces = sampleWorkspaces,\n  workspace: workspaceProp,\n  onWorkspaceChange,\n  projects = sampleProjects,\n  project: projectProp,\n  onProjectChange,\n  sections = sampleSections,\n  section: sectionProp,\n  onSectionChange,\n  user = { name: \"Olivia Martin\", email: \"olivia@acme.com\", src: \"https://randomuser.me/api/portraits/women/44.jpg\" },\n  notifications = 2,\n  onAction,\n}: {\n  workspaces?: Workspace[]\n  /** The workspace picked, by id (the header keeps it without it). */\n  workspace?: string\n  onWorkspaceChange?: (id: string) => void\n  /** The projects in it; none hides the project switcher. */\n  projects?: Project[]\n  project?: string\n  onProjectChange?: (id: string) => void\n  /** The tabs underneath: links (href), or picked in place (onSectionChange); none hides the row. */\n  sections?: Section[]\n  section?: string\n  onSectionChange?: (label: string) => void\n  user?: { name: string; email: string; src?: string }\n  /** Unread notifications: a dot on the bell when there are any. */\n  notifications?: number\n  onAction?: (action: HeaderAction) => void\n}) {\n  const [ownWorkspace, setOwnWorkspace] = useState(workspaces[0]?.id ?? \"\")\n  const [ownProject, setOwnProject] = useState(projects[0]?.id ?? \"\")\n  const [ownSection, setOwnSection] = useState(sections[0]?.label ?? \"\")\n  const workspaceId = workspaceProp ?? ownWorkspace\n  const projectId = projectProp ?? ownProject\n  const section = sectionProp ?? ownSection\n  const setWorkspaceId = (id: string) => {\n    setOwnWorkspace(id)\n    onWorkspaceChange?.(id)\n  }\n  const setProjectId = (id: string) => {\n    setOwnProject(id)\n    onProjectChange?.(id)\n  }\n  const [navRef, underline] = useIndicator<HTMLElement>(\"[aria-current=page]\")\n  const workspace = workspaces.find((w) => w.id === workspaceId) ?? workspaces[0]!\n  const project = projects.find((p) => p.id === projectId) ?? projects[0]\n\n  return (\n    <header className=\"sticky top-0 z-30 border-b bg-background/85 backdrop-blur-md\">\n      <div className=\"flex h-14 items-center gap-2 px-4 sm:px-6\">\n        <DropdownMenu\n          align=\"start\"\n          className=\"w-64\"\n          trigger={\n            <Button variant=\"ghost\" className=\"-ms-2 gap-2 px-2\">\n              <WorkspaceTile name={workspace.name} color={workspace.color} />\n              <span className=\"max-w-32 truncate font-medium sm:max-w-none\">{workspace.name}</span>\n              {workspace.plan && (\n                <Badge variant=\"soft\" color=\"neutral\" className=\"hidden rounded-[calc(var(--radius)*11/14)] px-1.5 py-px text-[10px] sm:inline-flex\">\n                  {workspace.plan}\n                </Badge>\n              )}\n              <ChevronsUpDown className=\"text-muted-foreground\" aria-hidden />\n            </Button>\n          }\n          items={[\n            { type: \"label\", label: \"Workspaces\" },\n            {\n              type: \"radio\",\n              value: workspaceId,\n              onValueChange: setWorkspaceId,\n              options: workspaces.map((w) => ({\n                value: w.id,\n                label: (\n                  <span className=\"flex flex-1 items-center gap-2\">\n                    {w.name}\n                    <span className=\"ms-auto text-xs text-muted-foreground\">{w.plan}</span>\n                  </span>\n                ),\n                icon: <WorkspaceTile name={w.name} color={w.color} className=\"size-5 text-[10px]\" />,\n              })),\n            },\n            { type: \"separator\" },\n            { label: \"Create a workspace\", icon: <Plus />, onSelect: () => onAction?.(\"create-workspace\") },\n            { label: \"Workspace settings\", icon: <Settings />, onSelect: () => onAction?.(\"workspace-settings\") },\n          ]}\n        />\n\n        {project && (\n          <>\n            <span aria-hidden className=\"hidden text-lg font-light text-border sm:inline\">\n              /\n            </span>\n\n            <DropdownMenu\n              align=\"start\"\n              className=\"w-56\"\n              trigger={\n                <Button variant=\"ghost\" className=\"hidden gap-2 px-2 sm:inline-flex\">\n                  <span aria-hidden className={cn(\"size-2 rounded-full\", project.status)} />\n                  {project.name}\n                  <ChevronsUpDown className=\"text-muted-foreground\" aria-hidden />\n                </Button>\n              }\n              items={[\n                { type: \"label\", label: \"Projects\" },\n                {\n                  type: \"radio\",\n                  value: projectId,\n                  onValueChange: setProjectId,\n                  options: projects.map((p) => ({ value: p.id, label: p.name, icon: <span aria-hidden className={cn(\"size-2 rounded-full\", p.status)} /> })),\n                },\n                { type: \"separator\" },\n                { label: \"New project\", icon: <Plus />, onSelect: () => onAction?.(\"new-project\") },\n              ]}\n            />\n          </>\n        )}\n\n        <div className=\"ms-auto flex items-center gap-1\">\n          <Button variant=\"outline\" size=\"sm\" className=\"hidden md:inline-flex\" onClick={() => onAction?.(\"feedback\")}>\n            <MessageSquare aria-hidden /> Feedback\n          </Button>\n          <Tooltip content=\"Help and docs\">\n            <Button variant=\"ghost\" size=\"icon\" aria-label=\"Help and docs\" onClick={() => onAction?.(\"help\")}>\n              <CircleHelp />\n            </Button>\n          </Tooltip>\n          <Tooltip content=\"Notifications\">\n            <Button\n              variant=\"ghost\"\n              size=\"icon\"\n              aria-label={notifications ? `Notifications, ${notifications} unread` : \"Notifications\"}\n              className=\"relative\"\n              onClick={() => onAction?.(\"notifications\")}\n            >\n              <Bell />\n              {notifications > 0 && <span aria-hidden className=\"absolute top-2 right-2 size-2 rounded-full bg-primary ring-2 ring-background\" />}\n            </Button>\n          </Tooltip>\n          <DropdownMenu\n            align=\"end\"\n            className=\"w-56\"\n            trigger={\n              <button type=\"button\" aria-label=\"Account\" className=\"ms-1 rounded-full outline-none focus-visible:ring-2 focus-visible:ring-ring/50\">\n                <Avatar name={user.name} src={user.src} size=\"md\" />\n              </button>\n            }\n            items={[\n              {\n                type: \"label\",\n                label: (\n                  <span className=\"flex flex-col\">\n                    <span className=\"text-sm font-medium text-foreground\">{user.name}</span>\n                    <span className=\"text-xs font-normal text-muted-foreground\">{user.email}</span>\n                  </span>\n                ),\n              },\n              { type: \"separator\" },\n              { label: \"Profile\", icon: <User />, onSelect: () => onAction?.(\"profile\") },\n              { label: \"Billing\", icon: <CreditCard />, onSelect: () => onAction?.(\"billing\") },\n              { type: \"separator\" },\n              { label: \"Sign out\", icon: <LogOut />, color: \"destructive\", onSelect: () => onAction?.(\"sign-out\") },\n            ]}\n          />\n        </div>\n      </div>\n\n      {/* The section's pages: an underline slides to the one you're on. Scrolls sideways on phones. */}\n      {sections.length > 0 && (\n        <nav ref={navRef} aria-label=\"Workspace\" className=\"relative flex gap-1 overflow-x-auto px-2 [scrollbar-width:none] sm:px-4\">\n          {underline && (\n            <span\n              aria-hidden\n              className={cn(indicatorMotion, \"h-0.5 rounded-full bg-foreground\")}\n              style={{ translate: `${underline.x + 8}px ${underline.y + underline.height - 2}px`, width: underline.width - 16 }}\n            />\n          )}\n          {sections.map(({ label: name, href }) => (\n            <a\n              key={name}\n              href={href ?? \"#\"}\n              onClick={(event) => {\n                if (!href) event.preventDefault()\n                setOwnSection(name)\n                onSectionChange?.(name)\n              }}\n              aria-current={section === name ? \"page\" : undefined}\n              className={cn(\n                \"shrink-0 rounded-md px-3 py-3 text-sm font-medium transition-colors outline-none hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring/50\",\n                section === name ? \"text-foreground\" : \"text-muted-foreground\"\n              )}\n            >\n              {name}\n            </a>\n          ))}\n        </nav>\n      )}\n    </header>\n  )\n}\n"}],"cssVars":{"theme":{"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)"},"light":{"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"},"dark":{"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"}}}