{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "drawer",
  "title": "Drawer",
  "description": "An accessible slide-in drawer from any of 4 sides with a backdrop, focus trap, Escape and backdrop close, scroll lock, focus restore and drag-to-dismiss.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/drawer/drawer.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { createPortal } from \"react-dom\";\nimport { motion, AnimatePresence, useDragControls, type PanInfo } 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 DrawerSide = \"left\" | \"right\" | \"top\" | \"bottom\";\nexport type DrawerSize = \"sm\" | \"md\" | \"lg\";\n\nexport interface DrawerProps {\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  side?: DrawerSide;\n  size?: DrawerSize;\n  theme?: \"dark\" | \"light\";\n  closeOnBackdrop?: boolean;\n  closeOnEscape?: boolean;\n  showCloseButton?: boolean;\n  swipeToClose?: 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.6)\", closeBg: \"rgba(255,255,255,0.06)\", grab: \"rgba(255,255,255,0.2)\" },\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)\", grab: \"rgba(10,10,10,0.2)\" },\n};\n\nconst EXTENT: Record<DrawerSize, number> = { sm: 320, md: 420, lg: 560 };\nconst EXTENT_VERTICAL: Record<DrawerSize, number> = { sm: 240, md: 340, lg: 460 };\n\nconst FOCUSABLE = 'a[href], button:not([disabled]), textarea:not([disabled]), input:not([disabled]), select:not([disabled]), [tabindex]:not([tabindex=\"-1\"])';\n\nexport function Drawer({\n  open,\n  defaultOpen = false,\n  onOpenChange,\n  title,\n  description,\n  children,\n  footer,\n  side = \"right\",\n  size = \"md\",\n  theme = \"dark\",\n  closeOnBackdrop = true,\n  closeOnEscape = true,\n  showCloseButton = true,\n  swipeToClose = true,\n  blur = false,\n  contained = false,\n  className,\n}: DrawerProps) {\n  const p = PALETTES[theme];\n  const uid = React.useId();\n  const panelRef = React.useRef<HTMLDivElement>(null);\n  const dragControls = useDragControls();\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  const vertical = side === \"top\" || side === \"bottom\";\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 = panelRef.current;\n      if (!el) return;\n      (el.querySelector<HTMLElement>(FOCUSABLE) ?? 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 onPanelKeyDown = (e: React.KeyboardEvent<HTMLDivElement>) => {\n    if (e.key !== \"Tab\") return;\n    const el = panelRef.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 onDragEnd = (_: unknown, info: PanInfo) => {\n    const dist = vertical ? info.offset.y : info.offset.x;\n    const vel = vertical ? info.velocity.y : info.velocity.x;\n    const closing = side === \"right\" || side === \"bottom\" ? 1 : -1;\n    if (dist * closing > 90 || vel * closing > 500) setOpen(false);\n  };\n\n  const offscreen = side === \"right\" ? { x: \"100%\" } : side === \"left\" ? { x: \"-100%\" } : side === \"top\" ? { y: \"-100%\" } : { y: \"100%\" };\n  const extent = vertical ? EXTENT_VERTICAL[size] : EXTENT[size];\n  const panelBox: React.CSSProperties = vertical\n    ? { left: 0, right: 0, height: extent, maxHeight: \"100%\", ...(side === \"top\" ? { top: 0, borderBottomLeftRadius: 22, borderBottomRightRadius: 22 } : { bottom: 0, borderTopLeftRadius: 22, borderTopRightRadius: 22 }) }\n    : { top: 0, bottom: 0, width: extent, maxWidth: \"100%\", ...(side === \"left\" ? { left: 0, borderTopRightRadius: 22, borderBottomRightRadius: 22 } : { right: 0, borderTopLeftRadius: 22, borderBottomLeftRadius: 22 }) };\n\n  const startDrag = (e: React.PointerEvent) => {\n    if (swipeToClose) dragControls.start(e);\n  };\n\n  const node = (\n    <AnimatePresence>\n      {isOpen && (\n        <motion.div\n          key=\"drawer-root\"\n          className={cn(contained ? \"absolute\" : \"fixed\", \"inset-0 z-[9998]\")}\n          initial={{ opacity: 0 }}\n          animate={{ opacity: 1 }}\n          exit={{ opacity: 0 }}\n          transition={{ duration: 0.2 }}\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={panelRef}\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={onPanelKeyDown}\n            drag={swipeToClose ? (vertical ? \"y\" : \"x\") : false}\n            dragListener={false}\n            dragControls={dragControls}\n            dragConstraints={{ top: 0, bottom: 0, left: 0, right: 0 }}\n            dragElastic={{ top: side === \"top\" ? 0.5 : 0, bottom: side === \"bottom\" ? 0.5 : 0, left: side === \"left\" ? 0.5 : 0, right: side === \"right\" ? 0.5 : 0 }}\n            onDragEnd={onDragEnd}\n            className={cn(\"absolute flex flex-col outline-none\", className)}\n            style={{ ...panelBox, background: p.bg, border: `1px solid ${p.border}`, color: p.text, fontFamily: \"Inter, sans-serif\", boxShadow: \"0 0 80px rgba(0,0,0,0.5)\" }}\n            initial={offscreen}\n            animate={{ x: 0, y: 0 }}\n            exit={offscreen}\n            transition={{ type: \"spring\", stiffness: 380, damping: 38 }}\n          >\n            {vertical && swipeToClose && (\n              <div onPointerDown={startDrag} className=\"flex shrink-0 cursor-grab justify-center touch-none\" style={{ padding: \"10px 0 2px\", order: side === \"bottom\" ? 0 : 99 }}>\n                <span style={{ width: 40, height: 4, borderRadius: 4, background: p.grab }} />\n              </div>\n            )}\n            {(title || description || showCloseButton) && (\n              <div onPointerDown={startDrag} className={cn(\"relative shrink-0\", swipeToClose && \"touch-none\")} style={{ padding: \"20px 24px 0\", paddingRight: showCloseButton ? 64 : 24, cursor: swipeToClose ? \"grab\" : undefined }}>\n                {title && (\n                  <h2 id={`${uid}-title`} className=\"m-0 font-semibold tracking-[-0.015em]\" style={{ fontSize: 18, lineHeight: 1.3 }}>\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            {showCloseButton && (\n              <button\n                type=\"button\"\n                aria-label=\"Close\"\n                onClick={() => setOpen(false)}\n                className=\"absolute z-10 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            <div className=\"min-h-0 flex-1 overflow-auto\" style={{ padding: \"16px 24px\", fontSize: 14, lineHeight: 1.6 }}>\n              {children}\n            </div>\n            {footer && (\n              <div className=\"flex shrink-0 flex-wrap items-center justify-end gap-2.5\" style={{ padding: \"14px 24px 20px\", borderTop: `1px solid ${p.border}` }}>\n                {footer}\n              </div>\n            )}\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"
}