{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "apple-context-menu",
  "type": "registry:ui",
  "title": "Context Menu & Popover",
  "author": "Rishabh Bose <https://theb0se.vercel.app/>",
  "description": "Frosted glassmorphic context menu and popover with a directional pointer arrow, hairline-divided action groups, keyboard shortcuts, and red destructive items.",
  "dependencies": [
    "framer-motion",
    "lucide-react",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "components/ui/apple-context-menu.tsx",
      "content": "\"use client\";\n\nimport React, { useState, useRef, useEffect } from \"react\";\nimport { AnimatePresence, motion, useReducedMotion } from \"framer-motion\";\nimport {\n  Copy,\n  Share2,\n  Pin,\n  FolderInput,\n  Trash2,\n  MoreHorizontal,\n  Check,\n} from \"lucide-react\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface ContextMenuItem {\n  id: string;\n  label: string;\n  shortcut?: string;\n  icon?: React.ReactNode;\n  destructive?: boolean;\n  onSelect?: () => void;\n}\n\nexport interface ContextMenuGroup {\n  id: string;\n  items: ContextMenuItem[];\n}\n\nexport interface AppleContextMenuProps {\n  /** Grouped menu items separated by hairline dividers */\n  groups?: ContextMenuGroup[];\n  /** Label shown on the trigger button */\n  triggerLabel?: string;\n  /** Initial open state for uncontrolled mode. Default: false */\n  defaultOpen?: boolean;\n  /** Callback fired when any menu item is clicked */\n  onSelect?: (item: ContextMenuItem) => void;\n  className?: string;\n}\n\nconst DEFAULT_GROUPS: ContextMenuGroup[] = [\n  {\n    id: \"primary\",\n    items: [\n      {\n        id: \"copy\",\n        label: \"Copy Component Link\",\n        shortcut: \"⌘C\",\n        icon: <Copy className=\"h-3.5 w-3.5\" />,\n      },\n      {\n        id: \"share\",\n        label: \"Share Preview...\",\n        shortcut: \"⇧⌘S\",\n        icon: <Share2 className=\"h-3.5 w-3.5\" />,\n      },\n      {\n        id: \"pin\",\n        label: \"Pin to Workspace\",\n        shortcut: \"⌘P\",\n        icon: <Pin className=\"h-3.5 w-3.5\" />,\n      },\n    ],\n  },\n  {\n    id: \"organize\",\n    items: [\n      {\n        id: \"move\",\n        label: \"Move to Collection\",\n        icon: <FolderInput className=\"h-3.5 w-3.5\" />,\n      },\n    ],\n  },\n  {\n    id: \"danger\",\n    items: [\n      {\n        id: \"delete\",\n        label: \"Delete Component\",\n        shortcut: \"⌘⌫\",\n        icon: <Trash2 className=\"h-3.5 w-3.5\" />,\n        destructive: true,\n      },\n    ],\n  },\n];\n\nexport function AppleContextMenu({\n  groups = DEFAULT_GROUPS,\n  triggerLabel = \"Actions Menu\",\n  defaultOpen = false,\n  onSelect,\n  className,\n}: AppleContextMenuProps) {\n  const shouldReduceMotion = useReducedMotion() ?? false;\n  const containerRef = useRef<HTMLDivElement>(null);\n\n  const [open, setOpen] = useState(defaultOpen);\n  const [lastAction, setLastAction] = useState<string | null>(null);\n\n  useEffect(() => {\n    if (!open) return;\n    const handleOutside = (e: MouseEvent) => {\n      if (\n        containerRef.current &&\n        !containerRef.current.contains(e.target as Node)\n      ) {\n        setOpen(false);\n      }\n    };\n    const handleEscape = (e: KeyboardEvent) => {\n      if (e.key === \"Escape\") {\n        setOpen(false);\n      }\n    };\n    document.addEventListener(\"mousedown\", handleOutside);\n    window.addEventListener(\"keydown\", handleEscape);\n    return () => {\n      document.removeEventListener(\"mousedown\", handleOutside);\n      window.removeEventListener(\"keydown\", handleEscape);\n    };\n  }, [open]);\n\n  const handleSelect = (item: ContextMenuItem) => {\n    item.onSelect?.();\n    onSelect?.(item);\n    setLastAction(item.label);\n    setOpen(false);\n  };\n\n  return (\n    <div\n      ref={containerRef}\n      onContextMenu={(e) => {\n        e.preventDefault();\n        setOpen(true);\n      }}\n      className={cn(\"relative inline-flex flex-col items-center\", className)}\n    >\n      {/* Trigger Bar */}\n      <div className=\"flex items-center gap-2.5\">\n        <button\n          type=\"button\"\n          aria-haspopup=\"menu\"\n          aria-expanded={open}\n          onClick={() => setOpen((v) => !v)}\n          className={cn(\n            \"inline-flex h-10 items-center gap-2 rounded-2xl border px-4 text-xs font-semibold shadow-2xs transition-all active:scale-95\",\n            open\n              ? \"border-neutral-900 bg-neutral-900 text-white dark:border-white dark:bg-white dark:text-black\"\n              : \"border-neutral-200 bg-white text-neutral-900 hover:border-neutral-900 dark:border-neutral-800 dark:bg-[#0A0A0A] dark:text-white dark:hover:border-white\"\n          )}\n        >\n          <span>{triggerLabel}</span>\n          <MoreHorizontal className=\"h-4 w-4\" />\n        </button>\n\n        {lastAction && (\n          <span className=\"inline-flex items-center gap-1 text-[11px] text-neutral-500 dark:text-neutral-400\">\n            <Check className=\"h-3 w-3 text-neutral-900 dark:text-white\" />\n            {lastAction}\n          </span>\n        )}\n      </div>\n\n      {/* Frosted Blurred Context Popover with Small Arrow */}\n      <AnimatePresence>\n        {open && (\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: 440, damping: 28 }}\n            style={{ originY: 0 }}\n            className=\"absolute top-[calc(100%+12px)] z-50 w-60 rounded-2xl border border-neutral-200/90 bg-white/90 p-1.5 shadow-2xl backdrop-blur-xl dark:border-neutral-800/90 dark:bg-[#121212]/90\"\n          >\n            {/* Small Top Arrow Caret */}\n            <div\n              aria-hidden=\"true\"\n              className=\"absolute -top-1.5 left-1/2 h-3 w-3 -translate-x-1/2 rotate-45 border-l border-t border-neutral-200/90 bg-white/90 dark:border-neutral-800/90 dark:bg-[#121212]/90\"\n            />\n\n            {/* Grouped Actions */}\n            <div className=\"relative z-10 divide-y divide-neutral-200/75 dark:divide-neutral-800/80\">\n              {groups.map((group) => (\n                <div key={group.id} className=\"py-1 first:pt-0 last:pb-0\">\n                  {group.items.map((item) => (\n                    <button\n                      key={item.id}\n                      type=\"button\"\n                      role=\"menuitem\"\n                      onClick={() => handleSelect(item)}\n                      className={cn(\n                        \"flex w-full items-center justify-between rounded-xl px-3 py-2 text-left text-xs font-medium transition-colors\",\n                        item.destructive\n                          ? \"text-red-600 hover:bg-red-500/10 dark:text-red-400 dark:hover:bg-red-500/15\"\n                          : \"text-neutral-800 hover:bg-neutral-100/90 dark:text-neutral-200 dark:hover:bg-neutral-800/70\"\n                      )}\n                    >\n                      <span className=\"flex items-center gap-2.5\">\n                        <span\n                          className={cn(\n                            item.destructive\n                              ? \"text-red-500 dark:text-red-400\"\n                              : \"text-neutral-500 dark:text-neutral-400\"\n                          )}\n                        >\n                          {item.icon}\n                        </span>\n                        <span>{item.label}</span>\n                      </span>\n\n                      {item.shortcut && (\n                        <kbd\n                          className={cn(\n                            \"font-mono text-[10px]\",\n                            item.destructive\n                              ? \"text-red-400 dark:text-red-500/80\"\n                              : \"text-neutral-400 dark:text-neutral-500\"\n                          )}\n                        >\n                          {item.shortcut}\n                        </kbd>\n                      )}\n                    </button>\n                  ))}\n                </div>\n              ))}\n            </div>\n          </motion.div>\n        )}\n      </AnimatePresence>\n    </div>\n  );\n}\n\nexport default AppleContextMenu;\n",
      "type": "registry:ui",
      "target": "components/ui/apple-context-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"
    }
  ]
}
