{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "magnetic-popover-menu",
  "type": "registry:ui",
  "title": "Magnetic Popover Menu",
  "author": "Rishabh Bose <https://theb0se.vercel.app/>",
  "description": "Floating command popover menu with origin-scaled spring entry, a shared-layout magnetic row highlight, and keyboard arrow navigation.",
  "dependencies": [
    "framer-motion",
    "lucide-react",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "components/ui/magnetic-popover-menu.tsx",
      "content": "\"use client\";\n\nimport React, { useEffect, useId, useRef, useState } from \"react\";\nimport { AnimatePresence, motion, useReducedMotion } from \"framer-motion\";\nimport {\n  Command,\n  Copy,\n  Sparkles,\n  Terminal,\n  Share2,\n  ChevronDown,\n} from \"lucide-react\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface PopoverCommandItem {\n  id: string;\n  label: string;\n  shortcut: string;\n  icon: React.ReactNode;\n}\n\nexport interface MagneticPopoverMenuProps {\n  /** Trigger button label. Default: \"Quick Actions\" */\n  triggerLabel?: string;\n  /** Array of popover menu items. */\n  items?: PopoverCommandItem[];\n  /** Hooke's Law spring stiffness coefficient. Default: 380 */\n  stiffness?: number;\n  /** Spring damping coefficient. Default: 26 */\n  damping?: number;\n  /** Callback fired when an item is selected */\n  onSelect?: (id: string) => void;\n  className?: string;\n}\n\nconst DEFAULT_ITEMS: PopoverCommandItem[] = [\n  {\n    id: \"install\",\n    label: \"Copy CLI Command\",\n    shortcut: \"⌘C\",\n    icon: <Terminal className=\"h-3.5 w-3.5\" />,\n  },\n  {\n    id: \"source\",\n    label: \"Copy .tsx Source\",\n    shortcut: \"⌘S\",\n    icon: <Copy className=\"h-3.5 w-3.5\" />,\n  },\n  {\n    id: \"tune\",\n    label: \"Tune Spring Constants\",\n    shortcut: \"⌘K\",\n    icon: <Sparkles className=\"h-3.5 w-3.5\" />,\n  },\n  {\n    id: \"share\",\n    label: \"Share Component URL\",\n    shortcut: \"⌘U\",\n    icon: <Share2 className=\"h-3.5 w-3.5\" />,\n  },\n];\n\nexport function MagneticPopoverMenu({\n  triggerLabel = \"Quick Actions\",\n  items = DEFAULT_ITEMS,\n  stiffness = 380,\n  damping = 26,\n  onSelect,\n  className,\n}: MagneticPopoverMenuProps) {\n  const shouldReduceMotion = useReducedMotion() ?? false;\n  const instanceId = useId();\n  const containerRef = useRef<HTMLDivElement | null>(null);\n  const itemRefs = useRef<Array<HTMLButtonElement | null>>([]);\n\n  const [isOpen, setIsOpen] = useState(false);\n  const [activeIndex, setActiveIndex] = useState<number>(0);\n\n  useEffect(() => {\n    if (!isOpen) return;\n    const handleOutside = (e: MouseEvent) => {\n      if (\n        containerRef.current &&\n        !containerRef.current.contains(e.target as Node)\n      ) {\n        setIsOpen(false);\n      }\n    };\n    const handleEsc = (e: KeyboardEvent) => {\n      if (e.key === \"Escape\") {\n        setIsOpen(false);\n      }\n    };\n    window.addEventListener(\"mousedown\", handleOutside);\n    window.addEventListener(\"keydown\", handleEsc);\n    return () => {\n      window.removeEventListener(\"mousedown\", handleOutside);\n      window.removeEventListener(\"keydown\", handleEsc);\n    };\n  }, [isOpen]);\n\n  const handleKeyDown = (e: React.KeyboardEvent<HTMLDivElement>) => {\n    if (!isOpen) return;\n    if (e.key === \"ArrowDown\") {\n      e.preventDefault();\n      const next = (activeIndex + 1) % items.length;\n      setActiveIndex(next);\n      itemRefs.current[next]?.focus();\n    } else if (e.key === \"ArrowUp\") {\n      e.preventDefault();\n      const prev = (activeIndex - 1 + items.length) % items.length;\n      setActiveIndex(prev);\n      itemRefs.current[prev]?.focus();\n    }\n  };\n\n  return (\n    <div\n      ref={containerRef}\n      onKeyDown={handleKeyDown}\n      className={cn(\"relative inline-block\", className)}\n    >\n      <motion.button\n        type=\"button\"\n        aria-haspopup=\"menu\"\n        aria-expanded={isOpen}\n        onClick={() => setIsOpen((prev) => !prev)}\n        whileTap={shouldReduceMotion ? undefined : { scale: 0.96 }}\n        className=\"inline-flex h-11 items-center gap-2 rounded-2xl border border-neutral-200 bg-white px-4 text-xs font-semibold text-black shadow-sm transition-colors hover:border-black focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-black dark:border-[#222222] dark:bg-[#0A0A0A] dark:text-white dark:hover:border-white dark:focus-visible:ring-white\"\n      >\n        <Command className=\"h-3.5 w-3.5\" />\n        <span>{triggerLabel}</span>\n        <ChevronDown\n          className={cn(\n            \"h-3.5 w-3.5 text-neutral-400 transition-transform duration-200\",\n            isOpen && \"rotate-180 text-black dark:text-white\"\n          )}\n        />\n      </motion.button>\n\n      <AnimatePresence>\n        {isOpen && (\n          <motion.div\n            role=\"menu\"\n            aria-label={triggerLabel}\n            initial={\n              shouldReduceMotion\n                ? { opacity: 0 }\n                : { opacity: 0, scale: 0.92, y: -6 }\n            }\n            animate={{ opacity: 1, scale: 1, y: 0 }}\n            exit={\n              shouldReduceMotion\n                ? { opacity: 0 }\n                : { opacity: 0, scale: 0.94, y: -4 }\n            }\n            transition={{ type: \"spring\", stiffness, damping }}\n            className=\"absolute left-0 top-full z-30 mt-2 w-60 origin-top-left rounded-2xl border border-neutral-200 bg-white p-1.5 shadow-xl dark:border-[#262626] dark:bg-[#0D0D0D]\"\n          >\n            {items.map((item, idx) => {\n              const isHighlighted = activeIndex === idx;\n\n              return (\n                <button\n                  key={item.id}\n                  ref={(el) => {\n                    itemRefs.current[idx] = el;\n                  }}\n                  type=\"button\"\n                  role=\"menuitem\"\n                  onMouseEnter={() => setActiveIndex(idx)}\n                  onFocus={() => setActiveIndex(idx)}\n                  onClick={() => {\n                    onSelect?.(item.id);\n                    setIsOpen(false);\n                  }}\n                  className=\"relative z-10 flex w-full items-center justify-between rounded-xl px-3 py-2 text-left text-xs font-medium text-black transition-colors focus-visible:outline-none dark:text-white\"\n                >\n                  {isHighlighted && (\n                    <motion.span\n                      layoutId={`${instanceId}-popover-highlight`}\n                      aria-hidden=\"true\"\n                      transition={\n                        shouldReduceMotion\n                          ? { duration: 0 }\n                          : { type: \"spring\", stiffness: 420, damping: 28 }\n                      }\n                      className=\"pointer-events-none absolute inset-0 -z-10 rounded-xl bg-neutral-100 dark:bg-[#1A1A1A]\"\n                    />\n                  )}\n\n                  <span className=\"flex items-center gap-2.5\">\n                    {item.icon}\n                    <span>{item.label}</span>\n                  </span>\n\n                  <kbd className=\"rounded border border-neutral-200 bg-white px-1.5 py-0.5 font-mono text-[10px] text-neutral-400 dark:border-[#262626] dark:bg-[#121212]\">\n                    {item.shortcut}\n                  </kbd>\n                </button>\n              );\n            })}\n          </motion.div>\n        )}\n      </AnimatePresence>\n    </div>\n  );\n}\n\nexport default MagneticPopoverMenu;\n",
      "type": "registry:ui",
      "target": "components/ui/magnetic-popover-menu.tsx"
    },
    {
      "path": "lib/utils.ts",
      "content": "import { type ClassValue, clsx } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nexport function cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\nexport async function copyToClipboard(text: string): Promise<boolean> {\n  if (typeof window === \"undefined\") return false;\n\n  try {\n    if (navigator.clipboard && window.isSecureContext) {\n      await navigator.clipboard.writeText(text);\n      return true;\n    }\n\n    const textArea = document.createElement(\"textarea\");\n    textArea.value = text;\n    textArea.style.position = \"fixed\";\n    textArea.style.left = \"-999999px\";\n    textArea.style.top = \"-999999px\";\n    document.body.appendChild(textArea);\n    textArea.focus();\n    textArea.select();\n    const succeeded = document.execCommand(\"copy\");\n    textArea.remove();\n    return succeeded;\n  } catch {\n    return false;\n  }\n}\n",
      "type": "registry:lib",
      "target": "lib/utils.ts"
    }
  ]
}
