{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"pill-nav","type":"registry:ui","title":"Pill Nav","description":"A pill navbar where the active pill slides between links and a softer pill previews where you point.","dependencies":["motion"],"registryDependencies":["https://ui.mekaigames.com/r/theme.json"],"files":[{"path":"components/ui/pill-nav.tsx","type":"registry:ui","content":"\"use client\";\n\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\";\nimport {\n  useEffect,\n  useId,\n  useRef,\n  useState,\n  type CSSProperties,\n  type FocusEvent,\n  type MouseEvent,\n  type ReactNode,\n} from \"react\";\n\nexport type PillNavItem = { label: string; href: string };\n\n/** Props handed to `renderLink`, ready to spread on a router's Link component. */\nexport type PillNavLinkProps = {\n  href: string;\n  className: string;\n  style?: CSSProperties;\n  children: ReactNode;\n  \"aria-current\"?: \"page\";\n  onClick: (e: MouseEvent<HTMLAnchorElement>) => void;\n  onPointerEnter?: () => void;\n  onFocus?: () => void;\n};\n\ntype PillNavColors = {\n  /** Bar background. */\n  bar?: string;\n  /** Active pill. */\n  pill?: string;\n  /** Text on the active pill. */\n  pillText?: string;\n  /** Resting link text. */\n  text?: string;\n  /** Hover preview pill. */\n  hover?: string;\n};\n\ntype PillNavProps = {\n  items: PillNavItem[];\n  /** Current page, for controlled use. */\n  activeHref?: string;\n  /** Current page when uncontrolled. Defaults to the first item. */\n  defaultActiveHref?: string;\n  /** Mark or wordmark shown at the start of the bar. */\n  logo?: ReactNode;\n  /** Accessible name for the logo link. */\n  logoLabel?: string;\n  logoHref?: string;\n  colors?: PillNavColors;\n  /** Called on a plain left click. The default navigation is prevented, so a client router can take over. */\n  onNavigate?: (href: string, e: MouseEvent<HTMLAnchorElement>) => void;\n  /** Render links with your router's component instead of a plain anchor. */\n  renderLink?: (props: PillNavLinkProps, item: PillNavItem) => ReactNode;\n  /** \"auto\" folds into a menu button when the nav is narrower than 36rem. */\n  collapse?: \"auto\" | \"always\" | \"never\";\n  align?: \"start\" | \"center\" | \"end\";\n  /** Accessible name of the nav. */\n  label?: string;\n  className?: string;\n};\n\nconst DEFAULT_COLORS: Required<PillNavColors> = {\n  bar: \"#171412\",\n  pill: \"#ff784f\",\n  pillText: \"#070606\",\n  text: \"#b9b0a4\",\n  hover: \"rgb(255 255 255 / 0.07)\",\n};\n\nconst ALIGN = { start: \"justify-start\", center: \"justify-center\", end: \"justify-end\" };\n\n// Literal class names, so Tailwind sees every container-query variant.\nconst LAYOUT = {\n  auto: { bar: \"hidden @xl:flex\", compact: \"flex @xl:hidden\" },\n  always: { bar: \"hidden\", compact: \"flex\" },\n  never: { bar: \"flex\", compact: \"hidden\" },\n};\n\nconst isPlainClick = (e: MouseEvent) => e.button === 0 && !e.metaKey && !e.ctrlKey && !e.shiftKey && !e.altKey;\n\n/** A pill navbar: the active pill slides between links, a softer pill previews where you point. Folds into a menu on narrow layouts. */\nexport function PillNav({\n  items,\n  activeHref,\n  defaultActiveHref,\n  logo,\n  logoLabel = \"Home\",\n  logoHref = \"/\",\n  colors,\n  onNavigate,\n  renderLink,\n  collapse = \"auto\",\n  align = \"center\",\n  label = \"Main\",\n  className = \"\",\n}: PillNavProps) {\n  const uid = useId();\n  const reduce = useReducedMotion();\n  const c = { ...DEFAULT_COLORS, ...colors };\n  const [internal, setInternal] = useState(defaultActiveHref ?? items[0]?.href ?? \"\");\n  const [hovered, setHovered] = useState<string | null>(null);\n  const [menuOpen, setMenuOpen] = useState(false);\n  const rootRef = useRef<HTMLElement>(null);\n  const toggleRef = useRef<HTMLButtonElement>(null);\n  const active = activeHref ?? internal;\n  const layout = LAYOUT[collapse];\n  const panelId = `${uid}-panel`;\n  const spring = reduce ? { duration: 0 } : ({ type: \"spring\", stiffness: 420, damping: 34 } as const);\n\n  // The compact menu closes on Escape and on a pointer down outside.\n  useEffect(() => {\n    if (!menuOpen) return;\n    function onPointerDown(e: PointerEvent) {\n      if (rootRef.current && !rootRef.current.contains(e.target as Node)) setMenuOpen(false);\n    }\n    function onKey(e: KeyboardEvent) {\n      if (e.key !== \"Escape\") return;\n      setMenuOpen(false);\n      toggleRef.current?.focus();\n    }\n    document.addEventListener(\"pointerdown\", onPointerDown);\n    document.addEventListener(\"keydown\", onKey);\n    return () => {\n      document.removeEventListener(\"pointerdown\", onPointerDown);\n      document.removeEventListener(\"keydown\", onKey);\n    };\n  }, [menuOpen]);\n\n  function go(href: string, e: MouseEvent<HTMLAnchorElement>) {\n    setMenuOpen(false);\n    if (activeHref === undefined) setInternal(href);\n    if (onNavigate && isPlainClick(e)) {\n      e.preventDefault();\n      onNavigate(href, e);\n    }\n  }\n\n  function link(props: PillNavLinkProps, item: PillNavItem) {\n    if (renderLink) return renderLink(props, item);\n    const { children, ...rest } = props;\n    return <a {...rest}>{children}</a>;\n  }\n\n  function onListBlur(e: FocusEvent<HTMLUListElement>) {\n    if (!e.currentTarget.contains(e.relatedTarget as Node | null)) setHovered(null);\n  }\n\n  const logoNode = logo ? (\n    <a\n      href={logoHref}\n      aria-label={logoLabel}\n      onClick={(e) => go(logoHref, e)}\n      className=\"grid size-10 shrink-0 place-items-center rounded-full font-display text-sm font-black\"\n      style={{ backgroundColor: c.pill, color: c.pillText }}\n    >\n      {logo}\n    </a>\n  ) : null;\n\n  return (\n    <nav ref={rootRef} aria-label={label} className={`@container relative w-full ${className}`}>\n      <div className={`flex ${ALIGN[align]}`}>\n        {/* Full bar */}\n        <div className={`${layout.bar} items-center gap-1 rounded-full p-1`} style={{ backgroundColor: c.bar }}>\n          {logoNode}\n          <ul className=\"flex items-center gap-0.5\" onPointerLeave={() => setHovered(null)} onBlur={onListBlur}>\n            {items.map((item) => {\n              const isActive = item.href === active;\n              return (\n                <li key={item.href}>\n                  {link(\n                    {\n                      href: item.href,\n                      \"aria-current\": isActive ? \"page\" : undefined,\n                      onClick: (e) => go(item.href, e),\n                      onPointerEnter: () => setHovered(item.href),\n                      onFocus: () => setHovered(item.href),\n                      className:\n                        \"relative block whitespace-nowrap rounded-full px-4 py-2 text-sm font-semibold transition-colors duration-200\",\n                      style: { color: isActive ? c.pillText : hovered === item.href ? \"#f4ede3\" : c.text },\n                      children: (\n                        <>\n                          {hovered === item.href && !isActive ? (\n                            <motion.span\n                              layoutId={`${uid}-hover`}\n                              aria-hidden=\"true\"\n                              className=\"absolute inset-0 rounded-full\"\n                              style={{ backgroundColor: c.hover }}\n                              transition={spring}\n                            />\n                          ) : null}\n                          {isActive ? (\n                            <motion.span\n                              layoutId={`${uid}-active`}\n                              aria-hidden=\"true\"\n                              className=\"absolute inset-0 rounded-full\"\n                              style={{ backgroundColor: c.pill }}\n                              transition={spring}\n                            />\n                          ) : null}\n                          <span className=\"relative\">{item.label}</span>\n                        </>\n                      ),\n                    },\n                    item,\n                  )}\n                </li>\n              );\n            })}\n          </ul>\n        </div>\n\n        {/* Compact bar */}\n        <div className={`${layout.compact} w-full items-center justify-between gap-2 rounded-full p-1`} style={{ backgroundColor: c.bar }}>\n          {logoNode ?? <span />}\n          <button\n            ref={toggleRef}\n            type=\"button\"\n            aria-expanded={menuOpen}\n            aria-controls={panelId}\n            onClick={() => setMenuOpen((o) => !o)}\n            className=\"flex h-10 items-center gap-2.5 rounded-full px-4 text-sm font-semibold text-bone transition-colors hover:bg-white/5\"\n          >\n            {items.find((i) => i.href === active)?.label ?? \"Menu\"}\n            <span className=\"relative block h-3 w-4\" aria-hidden=\"true\">\n              <motion.span\n                className=\"absolute left-0 right-0 top-0.5 h-0.5 rounded-full bg-current\"\n                animate={menuOpen ? { y: 3, rotate: 45 } : { y: 0, rotate: 0 }}\n                transition={spring}\n              />\n              <motion.span\n                className=\"absolute bottom-0.5 left-0 right-0 h-0.5 rounded-full bg-current\"\n                animate={menuOpen ? { y: -3, rotate: -45 } : { y: 0, rotate: 0 }}\n                transition={spring}\n              />\n            </span>\n            <span className=\"sr-only\">{menuOpen ? \"Close menu\" : \"Open menu\"}</span>\n          </button>\n        </div>\n      </div>\n\n      <AnimatePresence>\n        {menuOpen ? (\n          <motion.div\n            id={panelId}\n            initial={reduce ? { opacity: 0 } : { opacity: 0, y: -8, scale: 0.97 }}\n            animate={{ opacity: 1, y: 0, scale: 1 }}\n            exit={reduce ? { opacity: 0 } : { opacity: 0, y: -6, scale: 0.98, transition: { duration: 0.14 } }}\n            transition={reduce ? { duration: 0.12 } : { type: \"spring\", stiffness: 460, damping: 32 }}\n            style={{ backgroundColor: c.bar, transformOrigin: \"50% 0%\" }}\n            className={`absolute inset-x-0 top-full z-50 mt-2 rounded-3xl p-2 shadow-[0_24px_60px_-20px_rgb(0_0_0/0.9)] ${\n              collapse === \"never\" ? \"hidden\" : collapse === \"auto\" ? \"@xl:hidden\" : \"\"\n            }`}\n          >\n            <ul className=\"space-y-1\">\n              {items.map((item, i) => {\n                const isActive = item.href === active;\n                return (\n                  <motion.li\n                    key={item.href}\n                    initial={reduce ? false : { opacity: 0, y: 8 }}\n                    animate={{ opacity: 1, y: 0 }}\n                    transition={{ duration: 0.22, delay: reduce ? 0 : 0.03 * i }}\n                  >\n                    {link(\n                      {\n                        href: item.href,\n                        \"aria-current\": isActive ? \"page\" : undefined,\n                        onClick: (e) => go(item.href, e),\n                        className: \"flex items-center justify-between rounded-2xl px-4 py-3 text-base font-semibold transition-colors hover:bg-white/5\",\n                        style: isActive ? { backgroundColor: c.pill, color: c.pillText } : { color: \"#f4ede3\" },\n                        children: (\n                          <>\n                            {item.label}\n                            {isActive ? <span className=\"text-xs font-bold opacity-70\">Current</span> : null}\n                          </>\n                        ),\n                      },\n                      item,\n                    )}\n                  </motion.li>\n                );\n              })}\n            </ul>\n          </motion.div>\n        ) : null}\n      </AnimatePresence>\n    </nav>\n  );\n}\n"}]}