{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "modal",
  "title": "Modal",
  "description": "An accessible modal dialog with a blurred backdrop, focus trap, Escape and backdrop close, scroll lock, focus restore, 3 sizes and scale, slide-up and fade animations.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/modal/modal.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { createPortal } from \"react-dom\";\nimport { motion, AnimatePresence, type TargetAndTransition } from \"motion/react\";\nimport { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nfunction cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\nexport type ModalSize = \"sm\" | \"md\" | \"lg\";\nexport type ModalAnimation = \"scale\" | \"slide-up\" | \"fade\";\n\nexport interface ModalProps {\n  open?: boolean;\n  defaultOpen?: boolean;\n  onOpenChange?: (open: boolean) => void;\n  title?: React.ReactNode;\n  description?: React.ReactNode;\n  children?: React.ReactNode;\n  footer?: React.ReactNode;\n  size?: ModalSize;\n  animation?: ModalAnimation;\n  theme?: \"dark\" | \"light\";\n  closeOnBackdrop?: boolean;\n  closeOnEscape?: boolean;\n  showCloseButton?: boolean;\n  blur?: boolean;\n  contained?: boolean;\n  className?: string;\n}\n\nconst PALETTES = {\n  dark: { bg: \"#0E0E0E\", border: \"rgba(255,255,255,0.08)\", text: \"#F5F4F1\", muted: \"rgba(245,244,241,0.55)\", overlay: \"rgba(0,0,0,0.62)\", closeBg: \"rgba(255,255,255,0.06)\", shadow: \"0 40px 100px rgba(0,0,0,0.6)\" },\n  light: { bg: \"#FFFFFF\", border: \"rgba(10,10,10,0.08)\", text: \"#0A0A0A\", muted: \"rgba(10,10,10,0.55)\", overlay: \"rgba(10,10,10,0.4)\", closeBg: \"rgba(10,10,10,0.05)\", shadow: \"0 40px 100px rgba(0,0,0,0.25)\" },\n};\n\nconst WIDTHS: Record<ModalSize, number> = { sm: 380, md: 480, lg: 640 };\n\nconst FOCUSABLE = 'a[href], button:not([disabled]), textarea:not([disabled]), input:not([disabled]), select:not([disabled]), [tabindex]:not([tabindex=\"-1\"])';\n\nconst VARIANTS: Record<ModalAnimation, { initial: TargetAndTransition; animate: TargetAndTransition; exit: TargetAndTransition }> = {\n  scale: { initial: { opacity: 0, scale: 0.94, y: 10 }, animate: { opacity: 1, scale: 1, y: 0 }, exit: { opacity: 0, scale: 0.96, y: 6 } },\n  \"slide-up\": { initial: { opacity: 0, y: 48 }, animate: { opacity: 1, y: 0 }, exit: { opacity: 0, y: 32 } },\n  fade: { initial: { opacity: 0 }, animate: { opacity: 1 }, exit: { opacity: 0 } },\n};\n\nexport function Modal({\n  open,\n  defaultOpen = false,\n  onOpenChange,\n  title,\n  description,\n  children,\n  footer,\n  size = \"md\",\n  animation = \"scale\",\n  theme = \"dark\",\n  closeOnBackdrop = true,\n  closeOnEscape = true,\n  showCloseButton = true,\n  blur = true,\n  contained = false,\n  className,\n}: ModalProps) {\n  const p = PALETTES[theme];\n  const uid = React.useId();\n  const dialogRef = React.useRef<HTMLDivElement>(null);\n  const [internal, setInternal] = React.useState(defaultOpen);\n  const [mounted, setMounted] = React.useState(contained);\n  const isControlled = open !== undefined;\n  const isOpen = isControlled ? open : internal;\n\n  const setOpen = React.useCallback(\n    (next: boolean) => {\n      if (!isControlled) setInternal(next);\n      onOpenChange?.(next);\n    },\n    [isControlled, onOpenChange],\n  );\n\n  React.useEffect(() => {\n    if (isOpen && !mounted) {\n      const id = setTimeout(() => setMounted(true), 0);\n      return () => clearTimeout(id);\n    }\n  }, [isOpen, mounted]);\n\n  React.useEffect(() => {\n    if (!isOpen) return;\n    const previous = document.activeElement as HTMLElement | null;\n    const focusTimer = setTimeout(() => {\n      const el = dialogRef.current;\n      if (!el) return;\n      const first = el.querySelector<HTMLElement>(FOCUSABLE);\n      (first ?? el).focus({ preventScroll: true });\n    }, 30);\n    const prevOverflow = document.body.style.overflow;\n    if (!contained) document.body.style.overflow = \"hidden\";\n    const onKey = (e: KeyboardEvent) => {\n      if (e.key === \"Escape\" && closeOnEscape) {\n        e.stopPropagation();\n        setOpen(false);\n      }\n    };\n    document.addEventListener(\"keydown\", onKey);\n    return () => {\n      clearTimeout(focusTimer);\n      document.removeEventListener(\"keydown\", onKey);\n      if (!contained) document.body.style.overflow = prevOverflow;\n      previous?.focus?.({ preventScroll: true });\n    };\n  }, [isOpen, closeOnEscape, contained, setOpen]);\n\n  const onDialogKeyDown = (e: React.KeyboardEvent<HTMLDivElement>) => {\n    if (e.key !== \"Tab\") return;\n    const el = dialogRef.current;\n    if (!el) return;\n    const items = Array.from(el.querySelectorAll<HTMLElement>(FOCUSABLE));\n    if (items.length === 0) {\n      e.preventDefault();\n      el.focus();\n      return;\n    }\n    const first = items[0];\n    const last = items[items.length - 1];\n    const activeEl = document.activeElement;\n    if (e.shiftKey && (activeEl === first || activeEl === el)) {\n      e.preventDefault();\n      last.focus();\n    } else if (!e.shiftKey && activeEl === last) {\n      e.preventDefault();\n      first.focus();\n    }\n  };\n\n  const v = VARIANTS[animation];\n  const node = (\n    <AnimatePresence>\n      {isOpen && (\n        <motion.div\n          key=\"modal-root\"\n          className={cn(contained ? \"absolute\" : \"fixed\", \"inset-0 z-[9998] flex items-center justify-center p-4\")}\n          initial={{ opacity: 0 }}\n          animate={{ opacity: 1 }}\n          exit={{ opacity: 0 }}\n          transition={{ duration: 0.18 }}\n          onMouseDown={(e) => {\n            if (closeOnBackdrop && e.target === e.currentTarget) setOpen(false);\n          }}\n          style={{ background: p.overlay, backdropFilter: blur ? \"blur(6px)\" : undefined, WebkitBackdropFilter: blur ? \"blur(6px)\" : undefined }}\n        >\n          <motion.div\n            ref={dialogRef}\n            role=\"dialog\"\n            aria-modal=\"true\"\n            aria-labelledby={title ? `${uid}-title` : undefined}\n            aria-describedby={description ? `${uid}-desc` : undefined}\n            tabIndex={-1}\n            onKeyDown={onDialogKeyDown}\n            className={cn(\"relative w-full outline-none\", className)}\n            style={{ maxWidth: WIDTHS[size], maxHeight: \"calc(100% - 8px)\", overflow: \"auto\", borderRadius: 20, background: p.bg, border: `1px solid ${p.border}`, boxShadow: p.shadow, color: p.text, fontFamily: \"Inter, sans-serif\", padding: 24 }}\n            initial={v.initial}\n            animate={v.animate}\n            exit={v.exit}\n            transition={{ type: \"spring\", stiffness: 420, damping: 34 }}\n          >\n            {showCloseButton && (\n              <button\n                type=\"button\"\n                aria-label=\"Close\"\n                onClick={() => setOpen(false)}\n                className=\"absolute flex cursor-pointer items-center justify-center rounded-full border-none outline-none focus-visible:ring-2\"\n                style={{ top: 16, right: 16, width: 30, height: 30, background: p.closeBg, color: p.muted }}\n              >\n                <svg width=\"13\" height=\"13\" viewBox=\"0 0 12 12\" fill=\"none\" aria-hidden=\"true\">\n                  <path d=\"M3 3L9 9M9 3L3 9\" stroke=\"currentColor\" strokeWidth=\"1.7\" strokeLinecap=\"round\" />\n                </svg>\n              </button>\n            )}\n            {(title || description) && (\n              <div style={{ paddingRight: showCloseButton ? 36 : 0, marginBottom: children || footer ? 16 : 0 }}>\n                {title && (\n                  <h2 id={`${uid}-title`} className=\"m-0 font-semibold tracking-[-0.015em]\" style={{ fontSize: 19, lineHeight: 1.3, color: p.text }}>\n                    {title}\n                  </h2>\n                )}\n                {description && (\n                  <p id={`${uid}-desc`} className=\"m-0\" style={{ marginTop: 6, fontSize: 14, lineHeight: 1.55, color: p.muted }}>\n                    {description}\n                  </p>\n                )}\n              </div>\n            )}\n            {children && <div style={{ fontSize: 14, lineHeight: 1.6, color: p.text }}>{children}</div>}\n            {footer && <div className=\"flex flex-wrap items-center justify-end gap-2.5\" style={{ marginTop: 22 }}>{footer}</div>}\n          </motion.div>\n        </motion.div>\n      )}\n    </AnimatePresence>\n  );\n\n  if (contained) return node;\n  if (!mounted) return null;\n  return createPortal(node, document.body);\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}