{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "modal-popup",
  "type": "registry:ui",
  "title": "Modal Popup",
  "author": "Rishabh Bose <https://theb0se.vercel.app/>",
  "description": "Animated popup modal dialog with spring scale transitions, top-level portal rendering, danger/confirm variants, and Escape dismissal.",
  "dependencies": [
    "framer-motion",
    "lucide-react",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "components/ui/modal-popup.tsx",
      "content": "\"use client\";\n\nimport React, { useEffect, useState, useCallback } from \"react\";\nimport { createPortal } from \"react-dom\";\nimport { AnimatePresence, motion, useReducedMotion } from \"framer-motion\";\nimport { X } from \"lucide-react\";\nimport { cn } from \"@/lib/utils\";\n\nexport type ModalSize = \"sm\" | \"md\" | \"lg\";\nexport type ModalVariant = \"default\" | \"danger\";\n\nexport interface ModalPopupProps {\n  /** Controlled open state */\n  open?: boolean;\n  /** Default open state when uncontrolled */\n  defaultOpen?: boolean;\n  /** Callback when open state changes */\n  onOpenChange?: (open: boolean) => void;\n  /** Dialog title */\n  title?: string;\n  /** Dialog subtitle/description */\n  description?: string;\n  /** Width preset */\n  size?: ModalSize;\n  /** Visual style for confirm action (\"default\" | \"danger\") */\n  variant?: ModalVariant;\n  /** Default trigger button label */\n  triggerLabel?: string;\n  /** Custom trigger element */\n  trigger?: React.ReactNode;\n  /** Primary confirm button text */\n  confirmLabel?: string;\n  /** Cancel button text */\n  cancelLabel?: string;\n  /** Hide default footer buttons when rendering a custom form in children */\n  hideFooter?: boolean;\n  /** Callback when confirm button is clicked */\n  onConfirm?: () => void;\n  /** Custom body content */\n  children?: React.ReactNode;\n  /** Additional dialog class names */\n  className?: string;\n}\n\nconst SIZE_CLASSES: Record<ModalSize, string> = {\n  sm: \"max-w-sm\",\n  md: \"max-w-md\",\n  lg: \"max-w-lg\",\n};\n\nexport function ModalPopup({\n  open: controlledOpen,\n  defaultOpen = false,\n  onOpenChange,\n  title = \"Confirm Deployment\",\n  description = \"This action will build and deploy your latest commit to production.\",\n  size = \"md\",\n  variant = \"default\",\n  triggerLabel = \"Open Popup\",\n  trigger,\n  confirmLabel = \"Confirm\",\n  cancelLabel = \"Cancel\",\n  hideFooter = false,\n  onConfirm,\n  children,\n  className,\n}: ModalPopupProps) {\n  const shouldReduceMotion = useReducedMotion();\n  const [mounted, setMounted] = useState(false);\n  const [internalOpen, setInternalOpen] = useState(defaultOpen);\n  const isOpen = controlledOpen !== undefined ? controlledOpen : internalOpen;\n\n  useEffect(() => {\n    setMounted(true);\n  }, []);\n\n  const setOpen = useCallback(\n    (next: boolean) => {\n      if (controlledOpen === undefined) {\n        setInternalOpen(next);\n      }\n      onOpenChange?.(next);\n    },\n    [controlledOpen, onOpenChange]\n  );\n\n  useEffect(() => {\n    if (!isOpen) return;\n    const previousOverflow = document.body.style.overflow;\n    document.body.style.overflow = \"hidden\";\n\n    const handleKey = (e: KeyboardEvent) => {\n      if (e.key === \"Escape\") setOpen(false);\n    };\n    window.addEventListener(\"keydown\", handleKey);\n    return () => {\n      document.body.style.overflow = previousOverflow;\n      window.removeEventListener(\"keydown\", handleKey);\n    };\n  }, [isOpen, setOpen]);\n\n  const modalContent = (\n    <AnimatePresence>\n      {isOpen && (\n        <div className=\"fixed inset-0 z-[9999] flex items-center justify-center p-4\">\n          {/* Backdrop */}\n          <motion.div\n            initial={{ opacity: 0 }}\n            animate={{ opacity: 1 }}\n            exit={{ opacity: 0 }}\n            transition={{ duration: shouldReduceMotion ? 0 : 0.18 }}\n            onClick={() => setOpen(false)}\n            className=\"fixed inset-0 z-[9998] bg-black/60 backdrop-blur-xs\"\n            aria-hidden=\"true\"\n          />\n\n          {/* Dialog Card */}\n          <motion.div\n            role=\"dialog\"\n            aria-modal=\"true\"\n            aria-label={title}\n            initial={\n              shouldReduceMotion\n                ? { opacity: 0 }\n                : { opacity: 0, scale: 0.94, y: 10 }\n            }\n            animate={\n              shouldReduceMotion ? { opacity: 1 } : { opacity: 1, scale: 1, y: 0 }\n            }\n            exit={\n              shouldReduceMotion\n                ? { opacity: 0 }\n                : { opacity: 0, scale: 0.96, y: 6 }\n            }\n            transition={{\n              type: \"spring\",\n              stiffness: 420,\n              damping: 30,\n            }}\n            className={cn(\n              \"relative z-[9999] w-full overflow-hidden rounded-2xl border border-neutral-200 bg-white p-6 text-black shadow-2xl dark:border-[#242424] dark:bg-[#0A0A0A] dark:text-white\",\n              SIZE_CLASSES[size],\n              className\n            )}\n          >\n            {/* Header */}\n            <div className=\"flex items-start justify-between gap-4\">\n              <div>\n                <h3 className=\"text-base font-semibold tracking-tight text-black dark:text-white\">\n                  {title}\n                </h3>\n                {description && (\n                  <p className=\"mt-1.5 text-xs leading-relaxed text-neutral-500 dark:text-neutral-400\">\n                    {description}\n                  </p>\n                )}\n              </div>\n\n              <button\n                type=\"button\"\n                onClick={() => setOpen(false)}\n                aria-label=\"Close popup\"\n                className=\"cursor-pointer rounded-lg border border-neutral-200 p-1.5 text-neutral-500 transition-colors hover:border-black hover:text-black dark:border-[#262626] dark:hover:border-white dark:hover:text-white\"\n              >\n                <X className=\"h-4 w-4\" />\n              </button>\n            </div>\n\n            {/* Body */}\n            {children && (\n              <div className=\"mt-4 text-xs text-neutral-600 dark:text-neutral-300\">\n                {children}\n              </div>\n            )}\n\n            {/* Footer Actions */}\n            {!hideFooter && (\n              <div className=\"mt-6 flex items-center justify-end gap-2\">\n                <button\n                  type=\"button\"\n                  onClick={() => setOpen(false)}\n                  className=\"cursor-pointer rounded-xl border border-neutral-200 px-3.5 py-2 text-xs font-medium text-neutral-600 transition-colors hover:border-black hover:text-black dark:border-[#262626] dark:text-neutral-400 dark:hover:border-white dark:hover:text-white\"\n                >\n                  {cancelLabel}\n                </button>\n                <button\n                  type=\"button\"\n                  onClick={() => {\n                    onConfirm?.();\n                    setOpen(false);\n                  }}\n                  className={cn(\n                    \"cursor-pointer rounded-xl px-4 py-2 text-xs font-medium transition-colors\",\n                    variant === \"danger\"\n                      ? \"bg-red-600 text-white hover:bg-red-700\"\n                      : \"bg-black text-white hover:bg-neutral-800 dark:bg-white dark:text-black dark:hover:bg-neutral-200\"\n                  )}\n                >\n                  {confirmLabel}\n                </button>\n              </div>\n            )}\n          </motion.div>\n        </div>\n      )}\n    </AnimatePresence>\n  );\n\n  return (\n    <>\n      {trigger ? (\n        <div onClick={() => setOpen(true)} className=\"inline-block cursor-pointer\">\n          {trigger}\n        </div>\n      ) : (\n        <button\n          type=\"button\"\n          onClick={() => setOpen(true)}\n          className=\"inline-flex cursor-pointer items-center justify-center rounded-xl bg-black px-4 py-2 text-xs font-medium text-white transition-colors hover:bg-neutral-800 dark:bg-white dark:text-black dark:hover:bg-neutral-200\"\n        >\n          {triggerLabel}\n        </button>\n      )}\n\n      {mounted && createPortal(modalContent, document.body)}\n    </>\n  );\n}\n\nexport default ModalPopup;\n",
      "type": "registry:ui",
      "target": "components/ui/modal-popup.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"
    }
  ]
}
