{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "midnight-header",
  "title": "Midnight header",
  "author": "Vilqor <https://vilqor.com>",
  "description": "A header that is open at the top of the page and turns into a glass bar on scroll, with a wordmark, section links that follow the section you read, and one button.",
  "registryDependencies": [
    "button",
    "utils",
    "https://midnight-lite.vilqor.com/r/midnight-theme.json"
  ],
  "files": [
    {
      "path": "src/components/site/header.tsx",
      "content": "\"use client\"\n\nimport Link from \"next/link\"\nimport { useEffect, useMemo, useRef, useState } from \"react\"\n\nimport { buttonVariants } from \"@/components/ui/button\"\nimport { fill } from \"@/lib/fill\"\nimport { cn } from \"@/lib/utils\"\nimport { Logo } from \"./logo\"\n\nexport type HeaderContent = {\n  name: string\n  /** section links, shown from 768 px: \"/#product\" scrolls on the home page and leads home from other pages */\n  nav: { label: string; href: string }[]\n  /** a quiet text link left of the button, shown from 1024 px, where it fits without moving the links off centre;\n   *  `newTab` opens it in a new tab */\n  link?: { label: string; href: string; newTab?: boolean } | null\n  /** the one button; `short` is its label on phones */\n  cta: { label: string; short: string; href: string }\n  /** the logo link's name for screen readers; {name} is filled in */\n  backToTop: string\n}\n\nconst link =\n  \"relative inline-flex h-9 items-center pointer-coarse:h-11 rounded-full px-4 text-[14.5px] text-ink/80 transition-colors hover:text-ink focus-visible:ring-2 focus-visible:ring-ring focus-visible:outline-none\"\n\ntype Box = { x: number; w: number }\nconst boxOf = (el: HTMLElement | null): Box | null => (el ? { x: el.offsetLeft, w: el.offsetWidth } : null)\nconst idOf = (href: string) => href.split(\"#\")[1] ?? \"\"\n\n/** Open at the top of the page; once you scroll it gathers into a floating glass island.\n *  Three columns keep the links on the page's centre line whatever sits left and right.\n *  One lit pill moves under the links: to the one you point at, otherwise to the section you are reading. */\nexport function Header({ name, nav, link: aside, cta, backToTop }: HeaderContent) {\n  const [island, setIsland] = useState(false)\n  const listRef = useRef<HTMLUListElement>(null)\n  const [hoverBox, setHoverBox] = useState<Box | null>(null)\n  const [active, setActive] = useState<{ id: string; box: Box | null } | null>(null)\n\n  useEffect(() => {\n    const onScroll = () => setIsland(window.scrollY > 40)\n    onScroll()\n    window.addEventListener(\"scroll\", onScroll, { passive: true })\n    return () => window.removeEventListener(\"scroll\", onScroll)\n  }, [])\n\n  // scroll spy: the section crossing the middle band of the screen is the current one\n  const sections = useMemo(() => nav.map((item) => idOf(item.href)).filter(Boolean), [nav])\n  useEffect(() => {\n    const seen = new Map<string, boolean>()\n    const io = new IntersectionObserver(\n      (entries) => {\n        for (const e of entries) seen.set(e.target.id, e.isIntersecting)\n        const id = sections.find((s) => seen.get(s))\n        setActive(id ? { id, box: boxOf(listRef.current?.querySelector<HTMLElement>(`[data-nav=\"${id}\"]`) ?? null) } : null)\n      },\n      { rootMargin: \"-45% 0px -50% 0px\" },\n    )\n    for (const id of sections) {\n      const el = document.getElementById(id)\n      if (el) io.observe(el)\n    }\n    return () => io.disconnect()\n  }, [sections])\n\n  const point = (e: React.SyntheticEvent<HTMLElement>) => setHoverBox(boxOf(e.currentTarget))\n  const box = hoverBox ?? active?.box ?? null\n\n  return (\n    <header className={cn(\"fixed inset-x-0 top-0 z-50 flex justify-center px-3 pr-[max(12px,env(safe-area-inset-right))] pl-[max(12px,env(safe-area-inset-left))] transition-[padding] duration-500 ease-out-soft motion-reduce:transition-none\", island && \"pt-3\")}>\n      <div\n        className={cn(\n          \"grid w-full grid-cols-[1fr_auto] items-center gap-4 transition-[max-width,height,padding,border-radius,background-color,box-shadow] duration-500 ease-out-soft motion-reduce:transition-none md:grid-cols-[1fr_auto_1fr]\",\n          island ? \"glass h-14 max-w-[960px] rounded-full bg-surface/85 pr-2 pl-6 max-md:pl-5\" : \"h-[76px] max-w-[1200px] rounded-none px-3 max-md:h-16 md:px-7\",\n        )}\n      >\n        <Link href=\"/#top\" aria-label={fill(backToTop, { name })} className=\"justify-self-start rounded-md focus-visible:ring-2 focus-visible:ring-ring focus-visible:outline-none max-md:inline-flex max-md:min-h-11 max-md:items-center pointer-coarse:inline-flex pointer-coarse:min-h-11 pointer-coarse:items-center\">\n          <Logo name={name} className={cn(\"transition-[font-size] duration-500 motion-reduce:transition-none\", island && \"text-[22px]\")} />\n        </Link>\n\n        {/* the links sit in their own glass pill at the top; in the island the island is the pill */}\n        <nav className={cn(\"hidden rounded-full transition-[background-color,box-shadow] duration-500 motion-reduce:transition-none md:flex\", island ? \"p-0\" : \"glass p-1\")}>\n          <ul\n            ref={listRef}\n            className=\"relative flex items-center\"\n            onMouseLeave={() => setHoverBox(null)}\n            onBlur={(e) => {\n              if (!e.currentTarget.contains(e.relatedTarget as Node | null)) setHoverBox(null)\n            }}\n          >\n            {/* the lit pill: a faint fill, light on its top edge and a warm glow rising from below */}\n            <li\n              aria-hidden=\"true\"\n              className={cn(\"nav-lit pointer-events-none absolute top-0 left-0 h-9 rounded-full transition-[translate,width,opacity] duration-300 ease-out-soft motion-reduce:transition-none pointer-coarse:h-11\", !box && \"opacity-0\")}\n              style={{ width: box?.w ?? 0, translate: `${box?.x ?? 0}px 0` }}\n            />\n            {nav.map((item) => {\n              const id = idOf(item.href)\n              return (\n                <li key={item.href} data-nav={id} onMouseEnter={point} onFocus={point}>\n                  <a href={item.href} aria-current={active?.id === id ? \"true\" : undefined} className={cn(link, active?.id === id && \"text-ink\")}>\n                    {item.label}\n                  </a>\n                </li>\n              )\n            })}\n          </ul>\n        </nav>\n\n        <div className=\"flex items-center gap-1 justify-self-end\">\n          {aside && (\n            <a\n              href={aside.href}\n              target={aside.newTab ? \"_blank\" : undefined}\n              rel={aside.newTab ? \"noopener\" : undefined}\n              className={cn(link, \"whitespace-nowrap text-ink-2 max-lg:hidden\")}\n            >\n              {aside.label}\n            </a>\n          )}\n          <a href={cta.href} className={cn(buttonVariants(), \"shine bg-brand text-paper hover:bg-brand/85 h-10 rounded-full px-5 text-[14px] max-md:h-11 max-sm:px-4 pointer-coarse:h-11\")}>\n            <span className=\"sm:hidden\">{cta.short}</span>\n            <span className=\"max-sm:hidden\">{cta.label}</span>\n          </a>\n        </div>\n      </div>\n    </header>\n  )\n}\n",
      "type": "registry:component",
      "target": "@components/midnight/header.tsx"
    },
    {
      "path": "src/components/site/logo.tsx",
      "content": "import { cn } from \"@/lib/utils\"\n\n/** Wordmark: the product name in Fraunces, no symbol. */\nexport function Logo({ name, className }: { name: string; className?: string }) {\n  return <span className={cn(\"font-serif text-[25px] leading-none font-[380] tracking-[-0.02em]\", className)}>{name}</span>\n}\n",
      "type": "registry:component",
      "target": "@components/midnight/logo.tsx"
    },
    {
      "path": "src/lib/fill.ts",
      "content": "/** Fills {name} placeholders: fill(\"Source {n}: {title}\", { n: 1, title: \"FAQ\" }). */\nexport const fill = (text: string, values: Record<string, string | number>) =>\n  text.replace(/\\{(\\w+)\\}/g, (m, k: string) => (k in values ? String(values[k]) : m))\n",
      "type": "registry:lib",
      "target": "@lib/fill.ts"
    }
  ],
  "docs": "The block takes its words as props; the types sit at the top of the file. Name the theme in the same command, for example: npx shadcn@latest add https://midnight-lite.vilqor.com/r/midnight-theme.json https://midnight-lite.vilqor.com/r/midnight-header.json. A theme that only comes in as a dependency adds its colours but keeps your existing --background, --primary and fonts. If the page is not night-blue, run: npx shadcn@latest add https://midnight-lite.vilqor.com/r/midnight-theme.json. Works with the Radix and the Base UI styles of shadcn/ui; React Aria (aria-nova) is not supported yet.\nThe full Midnight template, with seven more sections, forms and analytics: https://templates.vilqor.com/midnight?ref=shadcn",
  "categories": [
    "header"
  ],
  "type": "registry:block"
}