{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "drawer",
  "type": "registry:ui",
  "title": "Drawer",
  "author": "Rishabh Bose <https://theb0se.vercel.app/>",
  "description": "Slide-over panel and bottom sheet drawer with 4-direction support, drag-to-dismiss gestures, top-level portal rendering, and Escape dismissal.",
  "dependencies": [
    "framer-motion",
    "lucide-react",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "components/ui/drawer.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 DrawerSide = \"right\" | \"left\" | \"bottom\" | \"top\";\n\nexport interface DrawerProps {\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  /** Edge of the viewport the drawer slides from */\n  side?: DrawerSide;\n  /** Drawer header title */\n  title?: string;\n  /** Optional subtitle below the title */\n  description?: string;\n  /** Trigger button label if used self-contained */\n  triggerLabel?: string;\n  /** Custom trigger element */\n  trigger?: React.ReactNode;\n  /** Drawer body content */\n  children?: React.ReactNode;\n  /** Optional footer actions */\n  footer?: React.ReactNode;\n  /** Additional panel class names */\n  className?: string;\n}\n\nconst SIDE_VARIANTS: Record<\n  DrawerSide,\n  {\n    initial: Record<string, string | number>;\n    animate: Record<string, string | number>;\n    exit: Record<string, string | number>;\n    panelClass: string;\n    dragAxis: \"x\" | \"y\";\n    dragConstraints: { top?: number; bottom?: number; left?: number; right?: number };\n  }\n> = {\n  right: {\n    initial: { x: \"100%\" },\n    animate: { x: 0 },\n    exit: { x: \"100%\" },\n    panelClass: \"inset-y-0 right-0 h-dvh w-full max-w-md border-l\",\n    dragAxis: \"x\",\n    dragConstraints: { left: 0 },\n  },\n  left: {\n    initial: { x: \"-100%\" },\n    animate: { x: 0 },\n    exit: { x: \"-100%\" },\n    panelClass: \"inset-y-0 left-0 h-dvh w-full max-w-md border-r\",\n    dragAxis: \"x\",\n    dragConstraints: { right: 0 },\n  },\n  bottom: {\n    initial: { y: \"100%\" },\n    animate: { y: 0 },\n    exit: { y: \"100%\" },\n    panelClass: \"inset-x-0 bottom-0 w-full max-h-[85dvh] rounded-t-2xl border-t\",\n    dragAxis: \"y\",\n    dragConstraints: { top: 0 },\n  },\n  top: {\n    initial: { y: \"-100%\" },\n    animate: { y: 0 },\n    exit: { y: \"-100%\" },\n    panelClass: \"inset-x-0 top-0 w-full max-h-[85dvh] rounded-b-2xl border-b\",\n    dragAxis: \"y\",\n    dragConstraints: { bottom: 0 },\n  },\n};\n\nexport function Drawer({\n  open: controlledOpen,\n  defaultOpen = false,\n  onOpenChange,\n  side = \"right\",\n  title = \"Drawer Panel\",\n  description,\n  triggerLabel = \"Open Drawer\",\n  trigger,\n  children,\n  footer,\n  className,\n}: DrawerProps) {\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 handleKeyDown = (e: KeyboardEvent) => {\n      if (e.key === \"Escape\") setOpen(false);\n    };\n    window.addEventListener(\"keydown\", handleKeyDown);\n    return () => {\n      document.body.style.overflow = previousOverflow;\n      window.removeEventListener(\"keydown\", handleKeyDown);\n    };\n  }, [isOpen, setOpen]);\n\n  const variant = SIDE_VARIANTS[side];\n\n  const overlayContent = (\n    <AnimatePresence>\n      {isOpen && (\n        <div className=\"fixed inset-0 z-[9999] flex\">\n          {/* Fullscreen Backdrop */}\n          <motion.div\n            initial={{ opacity: 0 }}\n            animate={{ opacity: 1 }}\n            exit={{ opacity: 0 }}\n            transition={{ duration: shouldReduceMotion ? 0 : 0.2 }}\n            onClick={() => setOpen(false)}\n            className=\"fixed inset-0 z-[9998] bg-black/60 backdrop-blur-xs\"\n            aria-hidden=\"true\"\n          />\n\n          {/* Sliding Panel */}\n          <motion.div\n            role=\"dialog\"\n            aria-modal=\"true\"\n            aria-label={title}\n            initial={shouldReduceMotion ? { opacity: 0 } : variant.initial}\n            animate={shouldReduceMotion ? { opacity: 1 } : variant.animate}\n            exit={shouldReduceMotion ? { opacity: 0 } : variant.exit}\n            transition={{\n              type: \"spring\",\n              stiffness: 380,\n              damping: 34,\n            }}\n            drag={shouldReduceMotion ? false : variant.dragAxis}\n            dragConstraints={variant.dragConstraints}\n            dragElastic={0.12}\n            onDragEnd={(_, info) => {\n              if (side === \"bottom\" && info.offset.y > 90) setOpen(false);\n              if (side === \"top\" && info.offset.y < -90) setOpen(false);\n              if (side === \"right\" && info.offset.x > 90) setOpen(false);\n              if (side === \"left\" && info.offset.x < -90) setOpen(false);\n            }}\n            className={cn(\n              \"fixed z-[9999] flex flex-col justify-between border-neutral-200 bg-white p-6 text-black shadow-2xl dark:border-[#222222] dark:bg-[#0A0A0A] dark:text-white\",\n              variant.panelClass,\n              className\n            )}\n          >\n            {side === \"bottom\" && (\n              <div className=\"mx-auto mb-4 h-1.5 w-12 rounded-full bg-neutral-300 dark:bg-neutral-700\" />\n            )}\n\n            {/* Header */}\n            <div className=\"flex items-start justify-between gap-4 border-b border-neutral-200 pb-4 dark:border-[#1F1F1F]\">\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 text-xs text-neutral-500 dark:text-neutral-400\">\n                    {description}\n                  </p>\n                )}\n              </div>\n              <button\n                type=\"button\"\n                onClick={() => setOpen(false)}\n                aria-label=\"Close drawer\"\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            <div className=\"my-4 flex-1 overflow-y-auto text-xs leading-relaxed text-neutral-600 dark:text-neutral-300\">\n              {children || (\n                <div className=\"space-y-3 py-2\">\n                  <p>\n                    This drawer renders in a top-level React portal (z-9999)\n                    above all headers, sidebars, and page content. You can also\n                    drag it toward the screen edge to dismiss.\n                  </p>\n                  <div className=\"rounded-xl border border-neutral-200 bg-neutral-50 p-3 font-mono text-[11px] dark:border-[#1F1F1F] dark:bg-[#111111]\">\n                    side=&quot;{side}&quot; · Drag or press ESC to close\n                  </div>\n                </div>\n              )}\n            </div>\n\n            {/* Footer */}\n            <div className=\"flex items-center justify-end gap-2 border-t border-neutral-200 pt-4 dark:border-[#1F1F1F]\">\n              {footer || (\n                <>\n                  <button\n                    type=\"button\"\n                    onClick={() => setOpen(false)}\n                    className=\"cursor-pointer rounded-lg border border-neutral-200 px-3.5 py-1.5 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                    Cancel\n                  </button>\n                  <button\n                    type=\"button\"\n                    onClick={() => setOpen(false)}\n                    className=\"cursor-pointer rounded-lg bg-black px-3.5 py-1.5 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                    Save Changes\n                  </button>\n                </>\n              )}\n            </div>\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 border border-neutral-200 bg-white px-4 py-2 text-xs font-medium text-black transition-colors hover:border-black dark:border-[#262626] dark:bg-[#0A0A0A] dark:text-white dark:hover:border-white\"\n        >\n          {triggerLabel}\n        </button>\n      )}\n\n      {mounted && createPortal(overlayContent, document.body)}\n    </>\n  );\n}\n\nexport default Drawer;\n",
      "type": "registry:ui",
      "target": "components/ui/drawer.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"
    }
  ]
}
