{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"pill-header","type":"registry:block","title":"Pill header","description":"The links in a pill in the middle with a sliding highlight, a GitHub star count, the theme, sign in and the main action.","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/sheet.json"],"files":[{"path":"registry/dashral/blocks/pill-header.tsx","type":"registry:file","target":"components/dashral/blocks/pill-header.tsx","content":"\"use client\"\n\nimport { useEffect, useState } from \"react\"\nimport { ArrowUpRight, Menu, Moon, Sparkles, Star, Sun } from \"lucide-react\"\nimport { Button } from \"../button\"\nimport { Sheet } from \"../sheet\"\nimport { indicatorMotion, useIndicator } from \"../lib/use-indicator\"\nimport { cn } from \"../lib/utils\"\n\n/** A link in the pill; `badge` is a short word beside it (\"New\"). */\nexport type PillLink = { title: string; href: string; badge?: string }\n/** A button: a link with `href`, or `onClick`. */\nexport type BlockAction = { label: string; href?: string; onClick?: () => void }\n\nconst sampleLinks: PillLink[] = [\n  { title: \"Components\", href: \"#\" },\n  { title: \"Blocks\", href: \"#\" },\n  { title: \"Templates\", href: \"#\" },\n  { title: \"Pro\", href: \"#\", badge: \"New\" },\n  { title: \"Pricing\", href: \"#\" },\n]\n\n/** GitHub's mark (lucide no longer ships brand icons). */\nfunction GitHubMark({ className }: { className?: string }) {\n  return (\n    <svg viewBox=\"0 0 24 24\" fill=\"currentColor\" aria-hidden className={className}>\n      <path d=\"M12 .5a11.5 11.5 0 0 0-3.64 22.41c.58.1.79-.25.79-.56v-2c-3.2.7-3.88-1.37-3.88-1.37-.52-1.33-1.28-1.69-1.28-1.69-1.05-.71.08-.7.08-.7 1.16.08 1.77 1.19 1.77 1.19 1.03 1.77 2.7 1.26 3.36.96.1-.75.4-1.26.73-1.55-2.55-.29-5.24-1.28-5.24-5.68 0-1.26.45-2.28 1.19-3.09-.12-.29-.52-1.46.11-3.05 0 0 .97-.31 3.17 1.18a11 11 0 0 1 5.77 0c2.2-1.49 3.17-1.18 3.17-1.18.63 1.59.23 2.76.11 3.05.74.81 1.19 1.83 1.19 3.09 0 4.41-2.69 5.38-5.25 5.67.41.36.78 1.06.78 2.14v3.17c0 .31.21.67.8.56A11.5 11.5 0 0 0 12 .5Z\" />\n    </svg>\n  )\n}\n\n/** An action as a button: a link when it has an href. */\nfunction Action({ action, className, variant, then, children }: { action: BlockAction; className: string; variant?: \"outline\"; then?: () => void; children?: React.ReactNode }) {\n  const content = (\n    <>\n      {action.label}\n      {children}\n    </>\n  )\n  return action.href ? (\n    <Button variant={variant} size=\"sm\" className={className} asChild>\n      <a href={action.href} onClick={then}>\n        {content}\n      </a>\n    </Button>\n  ) : (\n    <Button\n      variant={variant}\n      size=\"sm\"\n      className={className}\n      onClick={() => {\n        action.onClick?.()\n        then?.()\n      }}\n    >\n      {content}\n    </Button>\n  )\n}\n\n/**\n * A website header with the links in a pill in the middle — a highlight slides to the page you're on — a GitHub star\n * count, the theme, and sign in beside the main action. On phones the links move into a sheet. The theme button\n * toggles the `dark` class on <html>; pass `onToggleTheme` to use your own (next-themes, say). The brand, links,\n * GitHub repository and actions come from props; the page you're on is controllable, with `onNavigate`.\n */\nexport function PillHeader({\n  brand = { name: \"Acme\", href: \"#\" },\n  links = sampleLinks,\n  current: currentProp,\n  onNavigate,\n  github = { href: \"#\", stars: 786 },\n  signIn = { label: \"Sign in\", href: \"#\" },\n  cta = { label: \"Get started\", href: \"#\" },\n  onToggleTheme,\n}: {\n  brand?: { name: string; href: string; logo?: React.ReactNode }\n  links?: PillLink[]\n  /** The link you're on, by title (the header keeps it without it). */\n  current?: string\n  /** Called with the link's title; links to \"#\" stay on the page. */\n  onNavigate?: (title: string) => void\n  /** The star button; null hides it. */\n  github?: { href: string; stars: number } | null\n  /** null hides it. */\n  signIn?: BlockAction | null\n  cta?: BlockAction\n  onToggleTheme?: () => void\n}) {\n  const [ownCurrent, setOwnCurrent] = useState(links[1]?.title ?? links[0]?.title ?? \"\")\n  const current = currentProp ?? ownCurrent\n  const [dark, setDark] = useState(false)\n  const [sheetOpen, setSheetOpen] = useState(false)\n  const [navRef, highlight] = useIndicator<HTMLElement>(\"[aria-current=page]\")\n\n  useEffect(() => setDark(document.documentElement.classList.contains(\"dark\")), [])\n\n  function toggleTheme() {\n    if (onToggleTheme) return onToggleTheme()\n    const next = !document.documentElement.classList.contains(\"dark\")\n    document.documentElement.classList.toggle(\"dark\", next)\n    setDark(next)\n  }\n\n  const go = (link: PillLink) => (event: React.MouseEvent) => {\n    if (link.href === \"#\") event.preventDefault()\n    setOwnCurrent(link.title)\n    onNavigate?.(link.title)\n    setSheetOpen(false)\n  }\n  const close = () => setSheetOpen(false)\n\n  return (\n    <header className=\"sticky top-0 z-30 border-b bg-background/80 backdrop-blur-md\">\n      <div className=\"mx-auto grid h-16 max-w-7xl grid-cols-[1fr_auto] items-center gap-4 px-4 sm:px-6 lg:grid-cols-[1fr_auto_1fr]\">\n        <a href={brand.href} className=\"flex items-center gap-2 justify-self-start rounded-md text-lg font-semibold tracking-tight outline-none focus-visible:ring-2 focus-visible:ring-ring/50\">\n          {brand.logo ?? (\n            <span aria-hidden className=\"grid size-7 place-items-center rounded-lg bg-foreground text-background\">\n              <Sparkles className=\"size-3.5\" />\n            </span>\n          )}\n          {brand.name}\n        </a>\n\n        {/* The links, in a pill; the highlight slides to the current one. */}\n        <nav ref={navRef} aria-label=\"Main\" className=\"relative hidden items-center gap-0.5 rounded-[calc(var(--radius)*8/7_+_min(5px,var(--radius)))] border bg-muted/60 p-1 lg:flex\">\n          {highlight && (\n            <span\n              aria-hidden\n              className={cn(indicatorMotion, \"rounded-[calc(var(--radius)*8/7)] bg-background shadow-xs dark:bg-accent\")}\n              style={{ translate: `${highlight.x}px ${highlight.y}px`, width: highlight.width, height: highlight.height }}\n            />\n          )}\n          {links.map((link) => (\n            <a\n              key={link.title}\n              href={link.href}\n              onClick={go(link)}\n              aria-current={current === link.title ? \"page\" : undefined}\n              className={cn(\n                \"relative flex h-8 items-center gap-1.5 rounded-[calc(var(--radius)*8/7)] px-3.5 text-[13px] font-medium transition-colors outline-none hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring/50\",\n                current === link.title ? \"text-foreground\" : \"text-muted-foreground\"\n              )}\n            >\n              {link.title}\n              {link.badge && <span className=\"rounded-[calc(var(--radius)*4/7)] border border-primary/25 bg-primary/10 px-1.5 text-[10px] font-semibold text-primary-text\">{link.badge}</span>}\n            </a>\n          ))}\n        </nav>\n\n        <div className=\"flex items-center gap-1.5 justify-self-end\">\n          {github && (\n            <a\n              href={github.href}\n              className=\"hidden h-8 items-center rounded-[calc(var(--radius)*8/7)] border bg-card text-[13px] font-medium shadow-xs transition-colors outline-none hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring/50 md:inline-flex\"\n            >\n              <span className=\"flex items-center gap-1.5 px-3\">\n                <GitHubMark className=\"size-3.5\" /> Star\n              </span>\n              <span className=\"flex h-full items-center gap-1 border-s px-3 text-muted-foreground tabular-nums\">\n                <Star className=\"size-3 fill-current text-warning\" aria-hidden />\n                {new Intl.NumberFormat(\"en-US\", { notation: \"compact\" }).format(github.stars)}\n              </span>\n            </a>\n          )}\n          <Button variant=\"ghost\" size=\"icon-sm\" className=\"rounded-[calc(var(--radius)*8/7)]\" aria-label={dark ? \"Switch to light mode\" : \"Switch to dark mode\"} onClick={toggleTheme}>\n            {dark ? <Sun /> : <Moon />}\n          </Button>\n          {signIn && <Action action={signIn} variant=\"outline\" className=\"hidden rounded-[calc(var(--radius)*8/7)] px-3.5 sm:inline-flex\" />}\n          <Action action={cta} className=\"hidden rounded-[calc(var(--radius)*8/7)] px-3.5 sm:inline-flex\">\n            <ArrowUpRight aria-hidden />\n          </Action>\n          <Sheet\n            open={sheetOpen}\n            onOpenChange={setSheetOpen}\n            side=\"right\"\n            title=\"Menu\"\n            className=\"w-80\"\n            trigger={\n              <Button variant=\"ghost\" size=\"icon-sm\" className=\"rounded-[calc(var(--radius)*8/7)] lg:hidden\" aria-label=\"Open the menu\">\n                <Menu />\n              </Button>\n            }\n            footer={\n              <div className=\"grid w-full auto-cols-fr grid-flow-col gap-2\">\n                {signIn && <Action action={signIn} variant=\"outline\" className=\"h-9 rounded-[calc(var(--radius)*9/7)]\" then={close} />}\n                <Action action={cta} className=\"h-9 rounded-[calc(var(--radius)*9/7)]\" then={close}>\n                  <ArrowUpRight aria-hidden />\n                </Action>\n              </div>\n            }\n          >\n            <nav aria-label=\"Main\" className=\"grid gap-1\">\n              {links.map((link) => (\n                <a\n                  key={link.title}\n                  href={link.href}\n                  onClick={go(link)}\n                  aria-current={current === link.title ? \"page\" : undefined}\n                  className=\"flex items-center justify-between rounded-lg px-3 py-2.5 text-sm font-medium transition-colors hover:bg-accent aria-[current=page]:bg-accent\"\n                >\n                  {link.title}\n                  {link.badge && <span className=\"rounded-[calc(var(--radius)*4/7)] bg-primary/10 px-1.5 text-[10px] font-semibold text-primary-text\">{link.badge}</span>}\n                </a>\n              ))}\n            </nav>\n          </Sheet>\n        </div>\n      </div>\n    </header>\n  )\n}\n"}],"cssVars":{"theme":{"color-primary-text":"var(--primary-text, var(--primary))","color-warning":"var(--warning)","color-warning-foreground":"var(--warning-foreground)","color-warning-text":"var(--warning-text)"},"light":{"warning":"#f59200","warning-foreground":"oklch(0.3 0.07 60)","warning-text":"#964e00"},"dark":{"warning":"#f59200","warning-foreground":"oklch(0.25 0.06 60)","warning-text":"#ffba42"}}}