{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "sticky-header",
  "title": "Sticky Header",
  "description": "A site header that stays out of the way: it slides up while you scroll down and comes back the moment you scroll up, turns compact and frosted after the first few pixels, shows reading progress along its edge, and folds its links into a menu on narrow screens.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/sticky-header/sticky-header.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { motion, AnimatePresence, useReducedMotion } from \"motion/react\";\nimport { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nfunction cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\nexport interface StickyHeaderLink {\n  label: string;\n  href: string;\n}\n\nexport interface StickyHeaderProps {\n  brand?: React.ReactNode;\n  links?: StickyHeaderLink[];\n  cta?: { label: string; href: string };\n  /** hide: slides away while scrolling down, back on scrolling up. shrink: always visible, gets compact. */\n  behavior?: \"hide\" | \"shrink\";\n  /** Scroll distance (px) after which the header turns compact and solid. */\n  threshold?: number;\n  /** A thin reading-progress bar along the bottom edge. */\n  showProgress?: boolean;\n  /** Follow the nearest scrollable ancestor instead of the window (e.g. inside a preview box). */\n  contained?: boolean;\n  theme?: \"dark\" | \"light\";\n  className?: string;\n}\n\nconst PALETTES = {\n  dark: { text: \"#F5F4F1\", muted: \"rgba(245,244,241,0.62)\", solid: \"rgba(10,10,10,0.72)\", border: \"rgba(255,255,255,0.09)\", pill: \"rgba(255,255,255,0.08)\", cta: \"#F5F4F1\", ctaText: \"#0A0A0A\", bar: \"#F5F4F1\", menu: \"#111111\", focus: \"rgba(245,244,241,0.85)\" },\n  light: { text: \"#0A0A0A\", muted: \"rgba(10,10,10,0.62)\", solid: \"rgba(255,255,255,0.78)\", border: \"rgba(10,10,10,0.1)\", pill: \"rgba(10,10,10,0.06)\", cta: \"#0A0A0A\", ctaText: \"#FFFFFF\", bar: \"#0A0A0A\", menu: \"#FFFFFF\", focus: \"rgba(10,10,10,0.85)\" },\n};\n\nconst DEFAULT_LINKS: StickyHeaderLink[] = [\n  { label: \"Product\", href: \"#product\" },\n  { label: \"Pricing\", href: \"#pricing\" },\n  { label: \"Customers\", href: \"#customers\" },\n  { label: \"Docs\", href: \"#docs\" },\n];\n\nfunction scrollParent(el: HTMLElement | null): HTMLElement | null {\n  for (let n = el?.parentElement; n; n = n.parentElement) {\n    const o = getComputedStyle(n).overflowY;\n    if ((o === \"auto\" || o === \"scroll\") && n.scrollHeight > n.clientHeight) return n;\n  }\n  return null;\n}\n\nexport function StickyHeader({\n  brand = (\n    <span className=\"flex items-center gap-2 text-[15px] font-semibold tracking-[-0.01em]\">\n      <span className=\"block size-5 rounded-md bg-current\" />\n      Northwind\n    </span>\n  ),\n  links = DEFAULT_LINKS,\n  cta = { label: \"Get started\", href: \"#start\" },\n  behavior = \"hide\",\n  threshold = 24,\n  showProgress = true,\n  contained = false,\n  theme = \"dark\",\n  className,\n}: StickyHeaderProps) {\n  const p = PALETTES[theme];\n  const reduce = Boolean(useReducedMotion());\n  const uid = React.useId();\n  const ref = React.useRef<HTMLElement>(null);\n  const [scrolled, setScrolled] = React.useState(false);\n  const [hidden, setHidden] = React.useState(false);\n  const [progress, setProgress] = React.useState(0);\n  const [hover, setHover] = React.useState<string | null>(null);\n  const [menuOpen, setMenuOpen] = React.useState(false);\n  const [narrow, setNarrow] = React.useState(false);\n\n  React.useEffect(() => {\n    const header = ref.current;\n    if (!header) return;\n    const box = contained ? scrollParent(header) : null;\n    let last = 0;\n    const read = () => {\n      const y = box ? box.scrollTop : window.scrollY;\n      const max = box ? box.scrollHeight - box.clientHeight : document.documentElement.scrollHeight - window.innerHeight;\n      setScrolled(y > threshold);\n      setProgress(max > 0 ? Math.min(1, y / max) : 0);\n      // Hide only after a real move down past the header, show on any move up.\n      if (behavior === \"hide\") {\n        if (y > last + 4 && y > 120) setHidden(true);\n        else if (y < last - 4 || y <= 120) setHidden(false);\n      }\n      last = y;\n    };\n    const target: HTMLElement | Window = box ?? window;\n    target.addEventListener(\"scroll\", read, { passive: true });\n    const ro = new ResizeObserver(() => setNarrow(header.clientWidth < 640));\n    ro.observe(header);\n    read();\n    return () => {\n      target.removeEventListener(\"scroll\", read);\n      ro.disconnect();\n    };\n  }, [behavior, threshold, contained]);\n\n  const compact = scrolled;\n  const spring = reduce ? { duration: 0 } : { type: \"spring\" as const, stiffness: 420, damping: 40 };\n  const shown = hidden && !menuOpen ? \"-100%\" : \"0%\";\n\n  return (\n    <motion.header\n      ref={ref}\n      className={cn(\"sticky top-0 z-40 w-full\", className)}\n      style={{ fontFamily: \"Inter, sans-serif\", color: p.text }}\n      initial={false}\n      animate={{ y: shown }}\n      transition={reduce ? { duration: 0 } : { duration: 0.32, ease: [0.22, 1, 0.36, 1] }}\n    >\n      <div\n        className=\"relative\"\n        style={{ background: compact || menuOpen ? p.solid : \"transparent\", backdropFilter: compact || menuOpen ? \"blur(14px) saturate(1.4)\" : \"none\", WebkitBackdropFilter: compact || menuOpen ? \"blur(14px) saturate(1.4)\" : \"none\", borderBottom: `1px solid ${compact || menuOpen ? p.border : \"transparent\"}`, transition: \"background 0.3s ease, border-color 0.3s ease, backdrop-filter 0.3s ease\" }}\n      >\n        <motion.nav aria-label=\"Main\" className=\"mx-auto flex max-w-6xl items-center\" style={{ gap: 20, padding: \"0 20px\" }} initial={false} animate={{ height: compact ? 56 : 72 }} transition={spring}>\n          <a href=\"#top\" className=\"shrink-0 no-underline outline-none focus-visible:ring-2\" style={{ color: p.text, [\"--tw-ring-color\" as string]: p.focus }}>\n            {brand}\n          </a>\n          {!narrow && (\n            <ul className=\"m-0 flex list-none items-center p-0\" style={{ gap: 2 }} onMouseLeave={() => setHover(null)}>\n              {links.map((l) => (\n                <li key={l.href} className=\"relative\">\n                  <a href={l.href} onMouseEnter={() => setHover(l.href)} onFocus={() => setHover(l.href)} className=\"relative block rounded-full text-[13.5px] font-medium no-underline outline-none focus-visible:ring-2\" style={{ padding: \"7px 13px\", color: hover === l.href ? p.text : p.muted, transition: \"color 0.15s ease\", [\"--tw-ring-color\" as string]: p.focus }}>\n                    {hover === l.href && <motion.span layoutId={`${uid}-pill`} className=\"absolute inset-0 rounded-full\" style={{ background: p.pill }} transition={spring} />}\n                    <span className=\"relative\">{l.label}</span>\n                  </a>\n                </li>\n              ))}\n            </ul>\n          )}\n          <span className=\"flex-1\" />\n          {cta && !narrow && (\n            <motion.a href={cta.href} className=\"shrink-0 rounded-full text-[13.5px] font-semibold no-underline outline-none focus-visible:ring-2\" style={{ padding: \"8px 16px\", background: p.cta, color: p.ctaText, [\"--tw-ring-color\" as string]: p.focus }} whileHover={reduce ? undefined : { scale: 1.04 }} whileTap={{ scale: 0.97 }}>\n              {cta.label}\n            </motion.a>\n          )}\n          {narrow && (\n            <button type=\"button\" aria-label={menuOpen ? \"Close menu\" : \"Open menu\"} aria-expanded={menuOpen} onClick={() => setMenuOpen((o) => !o)} className=\"flex cursor-pointer items-center justify-center rounded-full border-none bg-transparent outline-none focus-visible:ring-2\" style={{ width: 38, height: 38, color: p.text, [\"--tw-ring-color\" as string]: p.focus }}>\n              <svg width=\"18\" height=\"18\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.8\" strokeLinecap=\"round\" aria-hidden=\"true\">\n                <motion.path d=\"M4 8h16\" animate={{ rotate: menuOpen ? 45 : 0, y: menuOpen ? 4 : 0 }} style={{ originX: \"50%\", originY: \"50%\" }} transition={spring} />\n                <motion.path d=\"M4 16h16\" animate={{ rotate: menuOpen ? -45 : 0, y: menuOpen ? -4 : 0 }} style={{ originX: \"50%\", originY: \"50%\" }} transition={spring} />\n              </svg>\n            </button>\n          )}\n        </motion.nav>\n        <AnimatePresence initial={false}>\n          {narrow && menuOpen && (\n            <motion.div key=\"menu\" className=\"overflow-hidden\" initial={{ height: 0, opacity: 0 }} animate={{ height: \"auto\", opacity: 1 }} exit={{ height: 0, opacity: 0 }} transition={{ duration: reduce ? 0 : 0.25, ease: [0.22, 1, 0.36, 1] }}>\n              <ul className=\"m-0 flex list-none flex-col p-0\" style={{ padding: \"4px 12px 16px\", gap: 2 }}>\n                {links.map((l) => (\n                  <li key={l.href}>\n                    <a href={l.href} onClick={() => setMenuOpen(false)} className=\"block rounded-xl text-[15px] font-medium no-underline\" style={{ padding: \"11px 12px\", color: p.text }}>\n                      {l.label}\n                    </a>\n                  </li>\n                ))}\n                {cta && (\n                  <li style={{ paddingTop: 6 }}>\n                    <a href={cta.href} className=\"block rounded-xl text-center text-[14px] font-semibold no-underline\" style={{ padding: \"11px 12px\", background: p.cta, color: p.ctaText }}>\n                      {cta.label}\n                    </a>\n                  </li>\n                )}\n              </ul>\n            </motion.div>\n          )}\n        </AnimatePresence>\n        {showProgress && <span aria-hidden=\"true\" className=\"absolute bottom-[-1px] left-0 block h-[2px] origin-left\" style={{ width: \"100%\", background: p.bar, transform: `scaleX(${progress})`, opacity: compact ? 1 : 0, transition: \"opacity 0.3s ease\" }} />}\n      </div>\n    </motion.header>\n  );\n}\n\nexport default StickyHeader;\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}