{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"dashboard-header","type":"registry:block","title":"Dashboard header","description":"A sidebar toggle and breadcrumb, ⌘K search, notifications and the account menu.","dependencies":["lucide-react"],"registryDependencies":["https://dashral.com/r/utils.json","https://dashral.com/r/avatar.json","https://dashral.com/r/breadcrumb.json","https://dashral.com/r/button.json","https://dashral.com/r/command.json","https://dashral.com/r/dropdown-menu.json","https://dashral.com/r/popover.json"],"files":[{"path":"registry/dashral/blocks/dashboard-header.tsx","type":"registry:file","target":"components/dashral/blocks/dashboard-header.tsx","content":"\"use client\"\n\nimport { useEffect, useState } from \"react\"\nimport {\n  Bell,\n  CreditCard,\n  FileText,\n  LayoutDashboard,\n  LogOut,\n  PanelLeft,\n  Search,\n  Settings,\n  User,\n  UserPlus,\n  Users,\n} from \"lucide-react\"\nimport { Avatar } from \"../avatar\"\nimport { Breadcrumb } from \"../breadcrumb\"\nimport { Button } from \"../button\"\nimport { CommandDialog } from \"../command\"\nimport { DropdownMenu } from \"../dropdown-menu\"\nimport { Popover } from \"../popover\"\nimport { cn } from \"../lib/utils\"\n\n/** One line in the bell's list: who did what, and when (as you'd write it: \"2m ago\"). Unread unless `read`. */\nexport type HeaderNotification = { id: string | number; who: string; what: string; when: string; src?: string; read?: boolean }\n/** A row in the ⌘K search; it closes the search when picked. */\nexport type HeaderSearchItem = { label: string; icon?: React.ReactNode; shortcut?: string; onSelect?: () => void }\nexport type HeaderSearchGroup = { heading: string; items: HeaderSearchItem[] }\n/** What the account menu asks for. */\nexport type HeaderAccountAction = \"profile\" | \"billing\" | \"settings\" | \"sign-out\"\n\nconst sampleNotifications: HeaderNotification[] = [\n  { id: 1, who: \"Sofia Davis\", what: \"commented on Invoice #1042\", when: \"2m ago\" },\n  { id: 2, who: \"Liam Johnson\", what: \"invited you to Acme Marketing\", when: \"1h ago\" },\n  { id: 3, who: \"Budi Santoso\", what: \"exported the Q3 sales report\", when: \"Yesterday\" },\n]\nconst sampleSearch: HeaderSearchGroup[] = [\n  {\n    heading: \"Pages\",\n    items: [\n      { label: \"Overview\", icon: <LayoutDashboard /> },\n      { label: \"Customers\", icon: <Users /> },\n      { label: \"Invoices\", icon: <FileText /> },\n    ],\n  },\n  {\n    heading: \"Actions\",\n    items: [\n      { label: \"Invite a teammate\", icon: <UserPlus /> },\n      { label: \"Settings\", icon: <Settings />, shortcut: \"⌘,\" },\n    ],\n  },\n]\n\n/**\n * A dashboard's top bar: the sidebar toggle and where you are on the left; search (also on ⌘K / Ctrl+K),\n * notifications and the account menu on the right. The trail, notifications, search and account come from props,\n * with the sample by default; reading a notification calls `onRead` (all of them, `onReadAll`).\n */\nexport function DashboardHeader({\n  onToggleSidebar,\n  breadcrumb = [{ label: \"Dashboard\", href: \"#\" }, { label: \"Analytics\", href: \"#\" }, { label: \"Overview\" }],\n  notifications = sampleNotifications,\n  onRead,\n  onReadAll,\n  search = sampleSearch,\n  user = { name: \"Olivia Martin\", email: \"olivia@acme.com\", src: \"https://randomuser.me/api/portraits/women/44.jpg\" },\n  onAccount,\n}: {\n  onToggleSidebar?: () => void\n  /** Where you are; the last one is this page (on phones, the only one shown). */\n  breadcrumb?: { label: string; href?: string }[]\n  /** Re-read when you pass a new list. */\n  notifications?: HeaderNotification[]\n  onRead?: (id: HeaderNotification[\"id\"]) => void\n  onReadAll?: () => void\n  /** The groups in the ⌘K search. */\n  search?: HeaderSearchGroup[]\n  user?: { name: string; email: string; src?: string }\n  onAccount?: (action: HeaderAccountAction) => void\n}) {\n  const [searchOpen, setSearchOpen] = useState(false)\n  const unreadOf = (list: HeaderNotification[]) => new Set(list.filter((n) => !n.read).map((n) => n.id))\n  const [unread, setUnread] = useState(() => unreadOf(notifications))\n  const [lastNotifications, setLastNotifications] = useState(notifications)\n  if (notifications !== lastNotifications) {\n    setLastNotifications(notifications)\n    setUnread(unreadOf(notifications))\n  }\n\n  // ⌘K / Ctrl+K opens the search from anywhere on the page.\n  useEffect(() => {\n    const onKey = (event: KeyboardEvent) => {\n      if (event.key.toLowerCase() === \"k\" && (event.metaKey || event.ctrlKey)) {\n        event.preventDefault()\n        setSearchOpen((open) => !open)\n      }\n    }\n    document.addEventListener(\"keydown\", onKey)\n    return () => document.removeEventListener(\"keydown\", onKey)\n  }, [])\n\n  return (\n    <header className=\"sticky top-0 z-30 flex h-16 items-center gap-3 border-b bg-background/85 px-4 backdrop-blur-md sm:px-6\">\n      <Button variant=\"ghost\" size=\"icon\" aria-label=\"Toggle the sidebar\" onClick={onToggleSidebar}>\n        <PanelLeft />\n      </Button>\n      <span aria-hidden className=\"h-5 w-px bg-border\" />\n      {/* The whole trail where there's room; on phones, just the page. */}\n      <Breadcrumb className=\"hidden min-w-0 sm:block\" items={breadcrumb} />\n      <span className=\"truncate text-sm font-medium sm:hidden\">{breadcrumb.at(-1)?.label}</span>\n\n      <div className=\"ms-auto flex items-center gap-1.5\">\n        {/* A search field on wider screens, an icon on phones; both open the palette. */}\n        <Button\n          variant=\"outline\"\n          onClick={() => setSearchOpen(true)}\n          className=\"hidden w-60 justify-start gap-2 pe-[5px] has-[>svg]:pe-[5px] font-normal text-muted-foreground md:inline-flex\"\n        >\n          <Search aria-hidden />\n          Search…\n          <kbd className=\"ms-auto inline-flex h-6 items-center rounded-[max(0px,calc(var(--radius-md)-6px))] border bg-muted px-1.5 font-sans text-[11px] text-muted-foreground\">⌘K</kbd>\n        </Button>\n        <Button variant=\"ghost\" size=\"icon\" aria-label=\"Search\" onClick={() => setSearchOpen(true)} className=\"md:hidden\">\n          <Search />\n        </Button>\n\n        <Popover\n          align=\"end\"\n          className=\"w-80 p-0\"\n          trigger={\n            <Button variant=\"ghost\" size=\"icon\" aria-label={unread.size ? `Notifications, ${unread.size} unread` : \"Notifications\"} className=\"relative\">\n              <Bell />\n              {unread.size > 0 && (\n                <span aria-hidden className=\"absolute top-1 right-1 grid size-4 ring-2 ring-background place-items-center rounded-full bg-destructive text-[10px] font-semibold text-destructive-foreground\">\n                  {unread.size}\n                </span>\n              )}\n            </Button>\n          }\n        >\n          <div className=\"flex items-center justify-between border-b px-4 py-3\">\n            <p className=\"text-sm font-medium\">Notifications</p>\n            <Button\n              variant=\"link\"\n              size=\"inline\"\n              className=\"text-xs\"\n              disabled={!unread.size}\n              onClick={() => {\n                setUnread(new Set())\n                onReadAll?.()\n              }}\n            >\n              Mark all as read\n            </Button>\n          </div>\n          <ul className=\"p-1.5\">\n            {notifications.map((n) => (\n              <li key={n.id}>\n                <button\n                  type=\"button\"\n                  onClick={() => {\n                    if (unread.has(n.id)) onRead?.(n.id)\n                    setUnread((ids) => new Set([...ids].filter((id) => id !== n.id)))\n                  }}\n                  className=\"flex w-full items-start gap-3 rounded-md p-2.5 text-start transition-colors outline-none hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring/50\"\n                >\n                  <Avatar src={n.src} name={n.who} size=\"md\" />\n                  <span className=\"min-w-0 flex-1 text-sm\">\n                    <span className=\"font-medium\">{n.who}</span> <span className=\"text-muted-foreground\">{n.what}</span>\n                    <span className=\"mt-0.5 block text-xs text-muted-foreground\">{n.when}</span>\n                  </span>\n                  <span aria-label={unread.has(n.id) ? \"Unread\" : undefined} className={cn(\"mt-1.5 size-2 shrink-0 rounded-full\", unread.has(n.id) ? \"bg-primary\" : \"bg-transparent\")} />\n                </button>\n              </li>\n            ))}\n          </ul>\n        </Popover>\n\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 />, shortcut: \"⇧⌘P\", onSelect: () => onAccount?.(\"profile\") },\n            { label: \"Billing\", icon: <CreditCard />, onSelect: () => onAccount?.(\"billing\") },\n            { label: \"Settings\", icon: <Settings />, shortcut: \"⌘,\", onSelect: () => onAccount?.(\"settings\") },\n            { type: \"separator\" },\n            { label: \"Sign out\", icon: <LogOut />, color: \"destructive\", onSelect: () => onAccount?.(\"sign-out\") },\n          ]}\n        />\n      </div>\n\n      <CommandDialog\n        open={searchOpen}\n        onOpenChange={setSearchOpen}\n        groups={search.map((group) => ({\n          heading: group.heading,\n          items: group.items.map((item) => ({\n            ...item,\n            onSelect: () => {\n              setSearchOpen(false)\n              item.onSelect?.()\n            },\n          })),\n        }))}\n      />\n    </header>\n  )\n}\n"}],"cssVars":{"theme":{"color-destructive-foreground":"var(--destructive-foreground)","color-destructive-text":"var(--destructive-text)"},"light":{"destructive-foreground":"oklch(0.985 0 0)","destructive-text":"#bd2800"},"dark":{"destructive-foreground":"oklch(0.2 0 0)","destructive-text":"#ff8a5c"}}}