{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "popover-card",
  "type": "registry:ui",
  "title": "Popover Card",
  "author": "Rishabh Bose <https://theb0se.vercel.app/>",
  "description": "Floating anchored popover card with configurable side and alignment, spring scale-in physics, outside-click dismissal, and interactive toggle controls.",
  "dependencies": [
    "framer-motion",
    "lucide-react",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "components/ui/popover-card.tsx",
      "content": "\"use client\";\n\nimport React, { useState, useRef, useEffect, useId } from \"react\";\nimport { AnimatePresence, motion, useReducedMotion } from \"framer-motion\";\nimport { SlidersHorizontal, Bell, ShieldCheck, Sparkles, X } from \"lucide-react\";\nimport { cn } from \"@/lib/utils\";\n\nexport type PopoverSide = \"top\" | \"bottom\" | \"left\" | \"right\";\nexport type PopoverAlign = \"start\" | \"center\" | \"end\";\n\nexport interface PopoverCardProps {\n  /** Label shown on the default trigger button */\n  triggerLabel?: string;\n  /** Header title inside the popover */\n  title?: string;\n  /** Subtitle inside the popover header */\n  description?: string;\n  /** Preferred side relative to trigger. Default: \"bottom\" */\n  side?: PopoverSide;\n  /** Alignment along the chosen side. Default: \"center\" */\n  align?: PopoverAlign;\n  /** Controlled open state */\n  open?: boolean;\n  /** Callback fired when open state changes */\n  onOpenChange?: (open: boolean) => void;\n  /** Custom body content inside the popover */\n  children?: React.ReactNode;\n  className?: string;\n}\n\nexport function PopoverCard({\n  triggerLabel = \"Display Settings\",\n  title = \"Workspace Preferences\",\n  description = \"Adjust real-time notification and layout behavior.\",\n  side = \"bottom\",\n  align = \"center\",\n  open: controlledOpen,\n  onOpenChange,\n  children,\n  className,\n}: PopoverCardProps) {\n  const shouldReduceMotion = useReducedMotion() ?? false;\n  const popoverId = useId();\n  const containerRef = useRef<HTMLDivElement>(null);\n\n  const isControlled = controlledOpen !== undefined;\n  const [internalOpen, setInternalOpen] = useState(false);\n  const isOpen = isControlled ? controlledOpen : internalOpen;\n\n  // Interactive demo state when default children are used\n  const [compactMode, setCompactMode] = useState(false);\n  const [instantAlerts, setInstantAlerts] = useState(true);\n  const [strictTypes, setStrictTypes] = useState(true);\n\n  const setOpen = (next: boolean) => {\n    if (!isControlled) {\n      setInternalOpen(next);\n    }\n    onOpenChange?.(next);\n  };\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        setOpen(false);\n      }\n    };\n    const handleKey = (e: KeyboardEvent) => {\n      if (e.key === \"Escape\") {\n        setOpen(false);\n      }\n    };\n    document.addEventListener(\"mousedown\", handleOutside);\n    window.addEventListener(\"keydown\", handleKey);\n    return () => {\n      document.removeEventListener(\"mousedown\", handleOutside);\n      window.removeEventListener(\"keydown\", handleKey);\n    };\n  }, [isOpen]);\n\n  const sideClasses: Record<PopoverSide, string> = {\n    bottom: \"top-[calc(100%+10px)]\",\n    top: \"bottom-[calc(100%+10px)]\",\n    left: \"right-[calc(100%+10px)] top-0\",\n    right: \"left-[calc(100%+10px)] top-0\",\n  };\n\n  const alignClasses: Record<PopoverAlign, string> = {\n    start: side === \"top\" || side === \"bottom\" ? \"left-0\" : \"top-0\",\n    center:\n      side === \"top\" || side === \"bottom\"\n        ? \"left-1/2 -translate-x-1/2\"\n        : \"top-1/2 -translate-y-1/2\",\n    end: side === \"top\" || side === \"bottom\" ? \"right-0\" : \"bottom-0\",\n  };\n\n  const initialOffset = {\n    bottom: { y: -6, x: 0 },\n    top: { y: 6, x: 0 },\n    left: { x: 6, y: 0 },\n    right: { x: -6, y: 0 },\n  }[side];\n\n  return (\n    <div ref={containerRef} className={cn(\"relative inline-block\", className)}>\n      <button\n        type=\"button\"\n        aria-expanded={isOpen}\n        aria-controls={popoverId}\n        aria-haspopup=\"dialog\"\n        onClick={() => setOpen(!isOpen)}\n        className={cn(\n          \"inline-flex h-10 items-center gap-2 rounded-xl border px-4 text-xs font-semibold transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-black dark:focus-visible:ring-white\",\n          isOpen\n            ? \"border-black bg-black text-white dark:border-white dark:bg-white dark:text-black\"\n            : \"border-neutral-200 bg-white text-black hover:border-black dark:border-[#262626] dark:bg-[#0A0A0A] dark:text-white dark:hover:border-white\"\n        )}\n      >\n        <SlidersHorizontal className=\"h-3.5 w-3.5\" />\n        <span>{triggerLabel}</span>\n      </button>\n\n      <AnimatePresence>\n        {isOpen && (\n          <motion.div\n            id={popoverId}\n            role=\"dialog\"\n            aria-label={title}\n            initial={\n              shouldReduceMotion\n                ? { opacity: 0 }\n                : { opacity: 0, scale: 0.95, ...initialOffset }\n            }\n            animate={{ opacity: 1, scale: 1, x: 0, y: 0 }}\n            exit={\n              shouldReduceMotion\n                ? { opacity: 0 }\n                : { opacity: 0, scale: 0.96, ...initialOffset }\n            }\n            transition={{ type: \"spring\", stiffness: 420, damping: 28 }}\n            className={cn(\n              \"absolute z-50 w-72 rounded-2xl border border-neutral-200 bg-white p-4 shadow-2xl dark:border-[#262626] dark:bg-[#0A0A0A]\",\n              sideClasses[side],\n              alignClasses[align]\n            )}\n          >\n            {/* Header */}\n            <div className=\"mb-3 flex items-start justify-between gap-2 border-b border-neutral-100 pb-2.5 dark:border-[#1A1A1A]\">\n              <div>\n                <h4 className=\"text-xs font-semibold text-black dark:text-white\">\n                  {title}\n                </h4>\n                {description && (\n                  <p className=\"mt-0.5 text-[11px] leading-relaxed text-neutral-500 dark:text-neutral-400\">\n                    {description}\n                  </p>\n                )}\n              </div>\n              <button\n                type=\"button\"\n                aria-label=\"Close popover\"\n                onClick={() => setOpen(false)}\n                className=\"rounded-lg p-1 text-neutral-400 transition-colors hover:bg-neutral-100 hover:text-black dark:hover:bg-[#161616] dark:hover:text-white\"\n              >\n                <X className=\"h-3.5 w-3.5\" />\n              </button>\n            </div>\n\n            {/* Body */}\n            {children ?? (\n              <div className=\"space-y-2.5\">\n                {[\n                  {\n                    id: \"alerts\",\n                    label: \"Instant Build Alerts\",\n                    icon: <Bell className=\"h-3.5 w-3.5\" />,\n                    checked: instantAlerts,\n                    onToggle: () => setInstantAlerts((v) => !v),\n                  },\n                  {\n                    id: \"strict\",\n                    label: \"Strict Type Checking\",\n                    icon: <ShieldCheck className=\"h-3.5 w-3.5\" />,\n                    checked: strictTypes,\n                    onToggle: () => setStrictTypes((v) => !v),\n                  },\n                  {\n                    id: \"compact\",\n                    label: \"Compact Grid Density\",\n                    icon: <Sparkles className=\"h-3.5 w-3.5\" />,\n                    checked: compactMode,\n                    onToggle: () => setCompactMode((v) => !v),\n                  },\n                ].map((setting) => (\n                  <button\n                    key={setting.id}\n                    type=\"button\"\n                    role=\"switch\"\n                    aria-checked={setting.checked}\n                    onClick={setting.onToggle}\n                    className=\"flex w-full items-center justify-between rounded-xl border border-neutral-200/70 bg-neutral-50/60 px-3 py-2 text-left text-xs transition-colors hover:border-neutral-300 dark:border-[#1F1F1F] dark:bg-[#121212] dark:hover:border-neutral-700\"\n                  >\n                    <span className=\"flex items-center gap-2 font-medium text-neutral-800 dark:text-neutral-200\">\n                      <span className=\"text-neutral-400\">{setting.icon}</span>\n                      {setting.label}\n                    </span>\n                    <span\n                      className={cn(\n                        \"relative inline-flex h-5 w-9 shrink-0 items-center rounded-full p-0.5 transition-colors\",\n                        setting.checked\n                          ? \"bg-black dark:bg-white\"\n                          : \"bg-neutral-300 dark:bg-neutral-700\"\n                      )}\n                    >\n                      <motion.span\n                        layout\n                        transition={{\n                          type: \"spring\",\n                          stiffness: 500,\n                          damping: 32,\n                        }}\n                        className={cn(\n                          \"h-4 w-4 rounded-full bg-white shadow-xs dark:bg-black\",\n                          setting.checked ? \"ml-auto\" : \"ml-0\"\n                        )}\n                      />\n                    </span>\n                  </button>\n                ))}\n              </div>\n            )}\n          </motion.div>\n        )}\n      </AnimatePresence>\n    </div>\n  );\n}\n\nexport default PopoverCard;\n",
      "type": "registry:ui",
      "target": "components/ui/popover-card.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"
    }
  ]
}
