{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"navbar-flow","type":"registry:ui","title":"Navbar Flow","description":"A full-width navbar that flows into a floating glass pill as you scroll, with a sliding hover highlight, scroll progress line and an animated mobile menu.","dependencies":["motion"],"registryDependencies":["utils"],"files":[{"path":"registry/ui/navbar-flow.tsx","type":"registry:ui","content":"\"use client\";\n\nimport { useEffect, useId, useRef, useState, type CSSProperties, type ReactNode, type RefObject } from \"react\";\nimport { AnimatePresence, MotionConfig, motion } from \"motion/react\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface NavbarFlowLink {\n  label: string;\n  href: string;\n}\n\nexport interface NavbarFlowProps {\n  links: NavbarFlowLink[];\n  /** Logo / wordmark on the left. */\n  brand?: ReactNode;\n  /** Call to action on the right (a button or link). */\n  action?: ReactNode;\n  /** Scrolling ancestor to watch. Defaults to the window. */\n  scrollContainerRef?: RefObject<HTMLElement | null>;\n  /** Px scrolled before the bar morphs into a pill. */\n  threshold?: number;\n  /** Max width of the floating pill, in px. */\n  pillWidth?: number;\n  /** \"sticky\" inside a scroller, \"fixed\" for the page, \"absolute\" to overlay a container. */\n  position?: \"sticky\" | \"fixed\" | \"absolute\";\n  /** Thin scroll-progress line along the bottom of the pill. */\n  progress?: boolean;\n  /** Progress line and active-link dot color. */\n  accent?: string;\n  className?: string;\n}\n\nconst EASE = \"ease-[cubic-bezier(.7,0,.2,1)]\";\n\nexport function NavbarFlow({\n  links,\n  brand,\n  action,\n  scrollContainerRef,\n  threshold = 40,\n  pillWidth = 720,\n  position = \"sticky\",\n  progress = true,\n  accent = \"#a3e635\",\n  className,\n}: NavbarFlowProps) {\n  const root = useRef<HTMLElement>(null);\n  const toggle = useRef<HTMLButtonElement>(null);\n  const [scrolled, setScrolled] = useState(false);\n  const [open, setOpen] = useState(false);\n  const [active, setActive] = useState(0);\n  const [hover, setHover] = useState<number | null>(null);\n  const id = useId();\n\n  useEffect(() => {\n    const el = scrollContainerRef?.current ?? null;\n    const target: HTMLElement | Window = el ?? window;\n    let raf = 0;\n    const read = () => {\n      raf = 0;\n      const top = el ? el.scrollTop : window.scrollY;\n      const max = el ? el.scrollHeight - el.clientHeight : document.documentElement.scrollHeight - window.innerHeight;\n      setScrolled(top > threshold); // bails out when unchanged, so no per-frame renders\n      root.current?.style.setProperty(\"--nf-progress\", String(max > 0 ? Math.min(1, top / max) : 0));\n    };\n    const onScroll = () => {\n      if (!raf) raf = requestAnimationFrame(read);\n    };\n    read();\n    target.addEventListener(\"scroll\", onScroll, { passive: true });\n    return () => {\n      target.removeEventListener(\"scroll\", onScroll);\n      cancelAnimationFrame(raf);\n    };\n  }, [scrollContainerRef, threshold]);\n\n  useEffect(() => {\n    if (!open) return;\n    const onKey = (e: KeyboardEvent) => {\n      if (e.key !== \"Escape\") return;\n      setOpen(false);\n      toggle.current?.focus();\n    };\n    const onDown = (e: PointerEvent) => {\n      if (!root.current?.contains(e.target as Node)) setOpen(false);\n    };\n    document.addEventListener(\"keydown\", onKey);\n    document.addEventListener(\"pointerdown\", onDown);\n    return () => {\n      document.removeEventListener(\"keydown\", onKey);\n      document.removeEventListener(\"pointerdown\", onDown);\n    };\n  }, [open]);\n\n  const pick = (i: number) => {\n    setActive(i);\n    setOpen(false);\n  };\n\n  return (\n    <MotionConfig reducedMotion=\"user\">\n      <header\n        ref={root}\n        data-scrolled={scrolled || undefined}\n        className={cn(\"group/nf @container pointer-events-none inset-x-0 top-0 z-50 flex justify-center\", position, className)}\n        style={{ [\"--nf-w\" as string]: `${pillWidth}px`, [\"--nf-progress\" as string]: 0 } as CSSProperties}\n      >\n        <nav\n          aria-label=\"Main\"\n          className={cn(\n            \"pointer-events-auto relative flex h-16 w-full max-w-full items-center gap-3 border border-transparent border-b-border bg-background/60 px-5 backdrop-blur-xl\",\n            \"transition-[max-width,height,margin,border-radius,background-color,border-color,box-shadow,padding] duration-700 motion-reduce:transition-none\",\n            EASE,\n            \"group-data-[scrolled]/nf:mt-3 group-data-[scrolled]/nf:h-[52px] group-data-[scrolled]/nf:max-w-[min(var(--nf-w),calc(100%-24px))] group-data-[scrolled]/nf:rounded-[26px] group-data-[scrolled]/nf:border-border group-data-[scrolled]/nf:bg-card/70 group-data-[scrolled]/nf:pl-4 group-data-[scrolled]/nf:pr-2 group-data-[scrolled]/nf:shadow-[0_18px_50px_-18px_rgba(0,0,0,.55),inset_0_1px_0_rgba(255,255,255,.06)]\",\n          )}\n        >\n          {brand && <div className=\"flex shrink-0 items-center\">{brand}</div>}\n\n          <ul className=\"absolute left-1/2 hidden -translate-x-1/2 items-center gap-0.5 @3xl:flex\" onPointerLeave={() => setHover(null)}>\n            {links.map((l, i) => (\n              <li key={l.href + l.label} className=\"relative\">\n                <a\n                  href={l.href}\n                  aria-current={i === active ? \"page\" : undefined}\n                  onClick={() => pick(i)}\n                  onPointerEnter={() => setHover(i)}\n                  onFocus={() => setHover(i)}\n                  onBlur={() => setHover(null)}\n                  className={cn(\n                    \"relative block rounded-full px-3.5 py-1.5 text-sm font-medium outline-none transition-colors focus-visible:ring-2 focus-visible:ring-ring\",\n                    i === active ? \"text-foreground\" : \"text-muted-foreground hover:text-foreground\",\n                  )}\n                >\n                  {hover === i && (\n                    <motion.span\n                      layoutId={`${id}-hover`}\n                      className=\"absolute inset-0 -z-10 rounded-full bg-foreground/[.07]\"\n                      transition={{ type: \"spring\", stiffness: 500, damping: 38 }}\n                    />\n                  )}\n                  {l.label}\n                  {i === active && (\n                    <motion.span\n                      layoutId={`${id}-dot`}\n                      aria-hidden\n                      className=\"absolute -bottom-0.5 left-1/2 size-1 -translate-x-1/2 rounded-full\"\n                      style={{ background: accent, boxShadow: `0 0 8px ${accent}` }}\n                      transition={{ type: \"spring\", stiffness: 420, damping: 32 }}\n                    />\n                  )}\n                </a>\n              </li>\n            ))}\n          </ul>\n\n          <div className=\"ml-auto flex items-center gap-2\">\n            {action}\n            <button\n              ref={toggle}\n              type=\"button\"\n              aria-label={open ? \"Close menu\" : \"Open menu\"}\n              aria-expanded={open}\n              aria-controls={`${id}-menu`}\n              data-open={open || undefined}\n              onClick={() => setOpen((o) => !o)}\n              className=\"group/btn relative grid size-9 place-items-center rounded-full text-foreground outline-none transition-colors hover:bg-foreground/[.07] focus-visible:ring-2 focus-visible:ring-ring @3xl:hidden\"\n            >\n              {[-1, 1].map((s) => (\n                <span\n                  key={s}\n                  aria-hidden\n                  className=\"absolute h-[1.5px] w-[18px] translate-y-[var(--y)] rounded-full bg-current transition-[translate,rotate] duration-300 group-data-[open]/btn:translate-y-0 group-data-[open]/btn:rotate-[var(--r)] ease-[cubic-bezier(.7,0,.2,1)] motion-reduce:transition-none\"\n                  style={{ [\"--y\" as string]: `${s * 3.5}px`, [\"--r\" as string]: `${s * -45}deg` }}\n                />\n              ))}\n            </button>\n          </div>\n\n          {progress && (\n            <span\n              aria-hidden\n              className=\"pointer-events-none absolute inset-x-6 -bottom-px h-px origin-left opacity-0 transition-opacity duration-500 group-data-[scrolled]/nf:opacity-100\"\n              style={{ transform: \"scaleX(var(--nf-progress))\", background: `linear-gradient(90deg, transparent, ${accent})` }}\n            />\n          )}\n\n          <AnimatePresence>\n            {open && (\n              <motion.div\n                id={`${id}-menu`}\n                initial={{ opacity: 0, y: -8, scale: 0.97 }}\n                animate={{ opacity: 1, y: 0, scale: 1 }}\n                exit={{ opacity: 0, y: -6, scale: 0.98, transition: { duration: 0.18 } }}\n                transition={{ type: \"spring\", stiffness: 420, damping: 34 }}\n                className=\"absolute inset-x-2 top-full mt-2 origin-top overflow-hidden rounded-2xl border border-border bg-card p-2 shadow-[0_24px_60px_-20px_rgba(0,0,0,.6)] @3xl:hidden\"\n              >\n                <ul>\n                  {links.map((l, i) => (\n                    <motion.li\n                      key={l.href + l.label}\n                      initial={{ opacity: 0, x: -10, filter: \"blur(4px)\" }}\n                      animate={{ opacity: 1, x: 0, filter: \"blur(0px)\" }}\n                      transition={{ delay: 0.04 + i * 0.045, duration: 0.35, ease: [0.2, 0.8, 0.2, 1] }}\n                    >\n                      <a\n                        href={l.href}\n                        aria-current={i === active ? \"page\" : undefined}\n                        onClick={() => pick(i)}\n                        className={cn(\n                          \"flex items-center justify-between rounded-xl px-3 py-2.5 text-[15px] font-medium outline-none transition-colors hover:bg-foreground/[.06] focus-visible:ring-2 focus-visible:ring-ring\",\n                          i === active ? \"text-foreground\" : \"text-muted-foreground\",\n                        )}\n                      >\n                        {l.label}\n                        {i === active && <span aria-hidden className=\"size-1.5 rounded-full\" style={{ background: accent }} />}\n                      </a>\n                    </motion.li>\n                  ))}\n                </ul>\n              </motion.div>\n            )}\n          </AnimatePresence>\n        </nav>\n      </header>\n    </MotionConfig>\n  );\n}\n"}]}