{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "morphing-pill-nav",
  "title": "Morphing Pill Nav",
  "description": "A responsive pill navigation with a spring-driven indicator that moves and changes width between links, optional hover following, icons and controlled active state.",
  "dependencies": [
    "motion",
    "lucide-react",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/morphing-pill-nav/morphing-pill-nav.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { motion } from \"motion/react\";\nimport { ArrowUpRight, Folder, Layers, Grid2X2 } from \"lucide-react\";\nimport { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nfunction cn(...inputs: ClassValue[]) { return twMerge(clsx(inputs)); }\n\nexport type NavbarTheme = \"dark\" | \"light\";\n\nexport interface NavbarLink {\n  /** A stable, unique item identifier. */\n  id: string;\n  label: string;\n  href: string;\n  description?: string;\n  badge?: string;\n  icon?: React.ReactNode;\n}\n\nconst DEFAULT_LINKS: NavbarLink[] = [\n  { id: \"work\", label: \"Work\", href: \"/work\", description: \"A few things, thoughtfully made.\", icon: <Grid2X2 size={16}/> },\n  { id: \"studio\", label: \"Studio\", href: \"/studio\", description: \"The people and the process.\", icon: <Layers size={16}/> },\n  { id: \"journal\", label: \"Journal\", href: \"/journal\", description: \"Notes from the in-between.\", icon: <Folder size={16}/> },\n  { id: \"contact\", label: \"Contact\", href: \"/contact\", description: \"Every good thing starts somewhere.\", icon: <ArrowUpRight size={16}/> },\n];\n\nfunction palette(theme: NavbarTheme): React.CSSProperties & Record<`--${string}`, string> {\n const light=theme===\"light\";\n return {\"--nav-page\":light?\"#f5f4f1\":\"#0e0e0e\",\"--nav-ink\":light?\"#0a0a0a\":\"#f5f4f1\",\"--nav-muted\":light?\"rgba(10,10,10,.52)\":\"rgba(245,244,241,.52)\",\"--nav-line\":light?\"rgba(10,10,10,.1)\":\"rgba(245,244,241,.1)\",\"--nav-soft\":light?\"rgba(10,10,10,.045)\":\"rgba(245,244,241,.045)\",\"--nav-panel\":light?\"rgba(245,244,241,.96)\":\"rgba(14,14,14,.96)\",\"--nav-serif\":\"var(--navbar-serif, 'Instrument Serif', Georgia, serif)\"};\n}\n\nconst focus=\"outline-none focus-visible:ring-2 focus-visible:ring-[var(--nav-ink)]/40 focus-visible:ring-offset-4 focus-visible:ring-offset-[var(--nav-page)]\";\n\nconst muted=\"text-[color:var(--nav-muted)]\";\n\nfunction useActive(value:string|undefined,initial:string,onChange?:(id:string)=>void){const[internal,setInternal]=React.useState(initial);const active=value??internal;const setActive=(id:string)=>{if(value===undefined)setInternal(id);onChange?.(id);};return[active,setActive]as const;}\n\nfunction moveFocus(e:React.KeyboardEvent<HTMLElement>,elements:HTMLElement[],current:number,onMove?:(index:number)=>void){let next=current;if(e.key===\"ArrowRight\"||e.key===\"ArrowDown\")next=(current+1)%elements.length;else if(e.key===\"ArrowLeft\"||e.key===\"ArrowUp\")next=(current-1+elements.length)%elements.length;else if(e.key===\"Home\")next=0;else if(e.key===\"End\")next=elements.length-1;else return;if(!elements.length)return;e.preventDefault();elements[next]?.focus();onMove?.(next);}\n\nfunction subscribeReducedMotion(onChange:()=>void){const query=window.matchMedia(\"(prefers-reduced-motion: reduce)\");query.addEventListener(\"change\",onChange);return()=>query.removeEventListener(\"change\",onChange);}\n\nfunction reducedMotionSnapshot(){return window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;}\n\nfunction serverReducedMotionSnapshot(){return false;}\n\nfunction useReducedMotion(){return React.useSyncExternalStore(subscribeReducedMotion,reducedMotionSnapshot,serverReducedMotionSnapshot);}\n\nexport interface MorphingPillNavProps extends Omit<React.ComponentPropsWithoutRef<\"nav\">,\"onChange\">{\n theme?:NavbarTheme;\n items?:NavbarLink[];\n activeId?:string;\n defaultActiveId?:string;\n onActiveChange?:(id:string)=>void;\n followHover?:boolean;\n showIcons?:boolean;\n onNavigate?:(item:NavbarLink,event:React.MouseEvent<HTMLAnchorElement>)=>void;\n}\nexport function MorphingPillNav({theme=\"dark\",items=DEFAULT_LINKS,activeId,defaultActiveId=\"work\",onActiveChange,followHover=true,showIcons=true,onNavigate,className,style,...props}:MorphingPillNavProps){\n const[active,setActive]=useActive(activeId,defaultActiveId,onActiveChange);const[hovered,setHovered]=React.useState<string|null>(null);const reduce=useReducedMotion();const id=React.useId();const root=React.useRef<HTMLElement>(null);const current=items.some(i=>i.id===active)?active:items[0]?.id;const highlighted=(followHover?hovered:null)??current;\n if(!items.length)return null;\n return <nav ref={root} {...props} data-theme={theme} aria-label={props[\"aria-label\"]??\"Pill navigation\"} className={cn(\"@container w-full text-[color:var(--nav-ink)]\",className)} style={{...palette(theme),...style}} onMouseLeave={e=>{setHovered(null);props.onMouseLeave?.(e);}}><div className=\"mx-auto flex w-fit max-w-full items-center gap-1 overflow-x-auto rounded-full border border-[var(--nav-line)] bg-[var(--nav-panel)] p-1.5 shadow-[0_8px_35px_rgba(0,0,0,.08)] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden\">{items.map((item,index)=>{const lit=highlighted===item.id;return <a data-nav-item key={item.id} href={item.href} aria-label={item.label} aria-current={current===item.id?\"page\":undefined} onClick={e=>{setActive(item.id);setHovered(null);onNavigate?.(item,e);}} onMouseEnter={()=>{if(followHover)setHovered(item.id);}} onFocus={()=>{if(followHover)setHovered(item.id);}} onBlur={()=>setHovered(null)} onKeyDown={e=>moveFocus(e,Array.from(root.current?.querySelectorAll<HTMLElement>(\"[data-nav-item]\")??[]),index)} className={cn(\"relative flex min-h-11 shrink-0 items-center justify-center gap-2 rounded-full px-3 text-xs transition-colors duration-200 @[440px]:px-5\",lit?\"text-[color:var(--nav-page)]\":muted,focus)}>{lit&&<motion.span layoutId={`${id}-pill`} initial={false} transition={reduce?{duration:0}:{type:\"spring\",stiffness:420,damping:32,mass:.7}} className=\"absolute inset-0 rounded-full bg-[var(--nav-ink)]\"/>}{showIcons&&<span className=\"relative flex shrink-0 items-center\">{item.icon??<span aria-hidden=\"true\" className=\"text-[11px]\">{item.label.slice(0,1)}</span>}</span>}<span className={cn(\"relative whitespace-nowrap\",showIcons&&current!==item.id&&\"hidden @[440px]:inline\")}>{item.label}</span>{item.badge&&<span className={cn(\"relative hidden text-[8px] @[540px]:inline\",lit?\"opacity-55\":\"opacity-40\")}>{item.badge}</span>}</a>;})}</div></nav>;\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}