{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "pill-nav",
  "type": "registry:component",
  "title": "Pill Nav",
  "description": "A horizontal nav with a single pill that glides to the hovered or selected item.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "components",
    "nav",
    "tabs",
    "pill",
    "slide",
    "menu",
    "hover"
  ],
  "docs": "https://hyperblur.dev/effects/pill-nav",
  "files": [
    {
      "path": "registry/hyperblur/pill-nav.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/pill-nav.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface PillNavItem {\n  id: string;\n  label: string;\n  href?: string;\n}\n\nexport interface PillNavProps\n  extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onChange\" | \"children\" | \"defaultValue\"> {\n  items: PillNavItem[];\n  active?: string;\n  defaultActive?: string;\n  onChange?: (id: string) => void;\n  followHover?: boolean;\n}\n\nconst css = `\n.hb-pn {\n  position: relative;\n  display: inline-flex;\n  align-items: center;\n  gap: 2px;\n  padding: 4px;\n  border-radius: 999px;\n  background: rgba(255,255,255,.06);\n  box-shadow: inset 0 0 0 1px rgba(255,255,255,.12);\n}\n.hb-pn-pill {\n  position: absolute;\n  top: 0;\n  left: 0;\n  width: var(--hb-pw, 0px);\n  height: var(--hb-ph, 0px);\n  border-radius: 999px;\n  background: rgba(255,255,255,.16);\n  box-shadow: inset 0 0 0 1px rgba(255,255,255,.18);\n  transform: translate3d(var(--hb-px, 0px), var(--hb-py, 0px), 0);\n  opacity: 0;\n  pointer-events: none;\n  transition:\n    transform .4s cubic-bezier(.2, .9, .2, 1),\n    width .4s cubic-bezier(.2, .9, .2, 1),\n    height .4s cubic-bezier(.2, .9, .2, 1),\n    opacity .2s ease;\n}\n.hb-pn-pill[data-ready=\"true\"] { opacity: 1; }\n.hb-pn-tab {\n  position: relative;\n  z-index: 1;\n  display: inline-flex;\n  align-items: center;\n  box-sizing: border-box;\n  margin: 0;\n  padding: 7px 16px;\n  border: 0;\n  border-radius: 999px;\n  color: rgba(255,255,255,.6);\n  font: inherit;\n  font-size: 14px;\n  line-height: 1.2;\n  text-decoration: none;\n  white-space: nowrap;\n  cursor: pointer;\n  background: transparent;\n  transition: color .2s ease;\n  -webkit-tap-highlight-color: transparent;\n}\n.hb-pn-tab:hover,\n.hb-pn-tab[aria-selected=\"true\"] { color: #fff; }\n.hb-pn-tab:focus-visible { outline: 2px solid #2f7bff; outline-offset: 1px; }\n@media (prefers-reduced-motion: reduce) {\n  .hb-pn-pill { transition: opacity .01s linear; }\n  .hb-pn-tab { transition: none; }\n}\n`;\n\nexport function PillNav({\n  items,\n  active,\n  defaultActive,\n  onChange,\n  followHover = true,\n  className = \"\",\n  onPointerLeave,\n  onKeyDown,\n  ...rest\n}: PillNavProps) {\n  const rootRef = React.useRef<HTMLDivElement>(null);\n  const pillRef = React.useRef<HTMLSpanElement>(null);\n  const itemRefs = React.useRef<Map<string, HTMLElement>>(new Map());\n  const [inner, setInner] = React.useState(defaultActive ?? items[0]?.id ?? \"\");\n  const current = active ?? inner;\n  const currentRef = React.useRef(current);\n  const placedRef = React.useRef(false);\n\n  const place = React.useCallback((id: string, instant = false) => {\n    const pill = pillRef.current;\n    const el = itemRefs.current.get(id);\n    if (!pill) return;\n    if (!el) {\n      pill.dataset.ready = \"false\";\n      return;\n    }\n    if (instant) pill.style.transition = \"none\";\n    pill.style.setProperty(\"--hb-pw\", `${el.offsetWidth}px`);\n    pill.style.setProperty(\"--hb-ph\", `${el.offsetHeight}px`);\n    pill.style.setProperty(\"--hb-px\", `${el.offsetLeft}px`);\n    pill.style.setProperty(\"--hb-py\", `${el.offsetTop}px`);\n    pill.dataset.ready = \"true\";\n    if (instant) {\n      void pill.offsetWidth;\n      pill.style.transition = \"\";\n    }\n  }, []);\n\n  React.useEffect(() => {\n    currentRef.current = current;\n    place(current, !placedRef.current);\n    placedRef.current = true;\n  }, [current, items, place]);\n\n  React.useEffect(() => {\n    const root = rootRef.current;\n    if (!root) return;\n    const update = () => place(currentRef.current, true);\n    if (typeof ResizeObserver === \"undefined\") {\n      window.addEventListener(\"resize\", update);\n      return () => window.removeEventListener(\"resize\", update);\n    }\n    const ro = new ResizeObserver(update);\n    ro.observe(root);\n    return () => ro.disconnect();\n  }, [place]);\n\n  function select(id: string) {\n    if (active === undefined) setInner(id);\n    onChange?.(id);\n  }\n\n  function handleLeave(e: React.PointerEvent<HTMLDivElement>) {\n    onPointerLeave?.(e);\n    place(currentRef.current);\n  }\n\n  function handleKeyDown(e: React.KeyboardEvent<HTMLDivElement>) {\n    onKeyDown?.(e);\n    if (e.defaultPrevented || items.length === 0) return;\n    const n = items.length;\n    const idx = Math.max(0, items.findIndex((i) => i.id === current));\n    let next = -1;\n    if (e.key === \"ArrowRight\" || e.key === \"ArrowDown\") next = (idx + 1) % n;\n    else if (e.key === \"ArrowLeft\" || e.key === \"ArrowUp\") next = (idx - 1 + n) % n;\n    else if (e.key === \"Home\") next = 0;\n    else if (e.key === \"End\") next = n - 1;\n    if (next < 0) return;\n    e.preventDefault();\n    const id = items[next].id;\n    select(id);\n    itemRefs.current.get(id)?.focus();\n  }\n\n  const tabStop = items.some((i) => i.id === current) ? current : items[0]?.id;\n\n  return (\n    <div\n      ref={rootRef}\n      role=\"tablist\"\n      aria-orientation=\"horizontal\"\n      className={`hb-pn ${className}`}\n      onPointerLeave={handleLeave}\n      onKeyDown={handleKeyDown}\n      {...rest}\n    >\n      <style href=\"hb-pill-nav\" precedence=\"default\">{css}</style>\n      <span className=\"hb-pn-pill\" ref={pillRef} aria-hidden=\"true\" />\n      {items.map((item) => {\n        const common = {\n          role: \"tab\",\n          className: \"hb-pn-tab\",\n          \"aria-selected\": item.id === current,\n          tabIndex: item.id === tabStop ? 0 : -1,\n          onClick: () => select(item.id),\n          onPointerEnter: (e: React.PointerEvent<HTMLElement>) => {\n            if (followHover && e.pointerType !== \"touch\") place(item.id);\n          },\n        };\n        const setRef = (el: HTMLElement | null) => {\n          if (el) itemRefs.current.set(item.id, el);\n          else itemRefs.current.delete(item.id);\n        };\n        return item.href ? (\n          <a key={item.id} ref={setRef} href={item.href} {...common}>\n            {item.label}\n          </a>\n        ) : (\n          <button key={item.id} ref={setRef} type=\"button\" {...common}>\n            {item.label}\n          </button>\n        );\n      })}\n    </div>\n  );\n}\n"
    }
  ]
}