{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "drawer",
  "title": "Drawer",
  "description": "Edge panel with panelTween slide, backdrop fade, and portal presence.",
  "dependencies": [
    "@base-ui/react",
    "lucide-react",
    "motion"
  ],
  "registryDependencies": [
    "@atroui/utils",
    "@atroui/motion",
    "@atroui/button"
  ],
  "files": [
    {
      "path": "registry/default/ui/drawer.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { Drawer as DrawerPrimitive } from \"@base-ui/react/drawer\"\nimport { X } from \"lucide-react\"\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\"\n\nimport {\n  backdropMotion,\n  drawerPanelMotion,\n  type DrawerPanelSide,\n} from \"@/lib/motion\"\nimport { cn } from \"@/lib/utils\"\nimport { Button } from \"./button\"\n\n/** Layered overlay elevation — heaviest stack. */\nconst dialogElevation = \"ds-elev-overlay\"\n\ntype DrawerOpenContextValue = {\n  open: boolean\n  side: DrawerPanelSide\n}\n\nconst DrawerOpenContext = React.createContext<DrawerOpenContextValue | null>(\n  null\n)\n\nfunction useDrawerContext() {\n  const ctx = React.useContext(DrawerOpenContext)\n  if (!ctx) {\n    throw new Error(\"Drawer parts must be used within <Drawer>\")\n  }\n  return ctx\n}\n\nfunction sideToSwipeDirection(\n  side: DrawerPanelSide\n): NonNullable<DrawerPrimitive.Root.Props[\"swipeDirection\"]> {\n  if (side === \"bottom\") return \"down\"\n  if (side === \"top\") return \"up\"\n  return side\n}\n\nfunction Drawer({\n  open: openProp,\n  defaultOpen = false,\n  onOpenChange,\n  side = \"right\",\n  swipeDirection,\n  ...props\n}: DrawerPrimitive.Root.Props & {\n  side?: DrawerPanelSide\n}) {\n  const [uncontrolledOpen, setUncontrolledOpen] = React.useState(defaultOpen)\n  const isControlled = openProp !== undefined\n  const open = isControlled ? openProp : uncontrolledOpen\n\n  const handleOpenChange = React.useCallback<\n    NonNullable<DrawerPrimitive.Root.Props[\"onOpenChange\"]>\n  >(\n    (next, eventDetails) => {\n      if (!isControlled) setUncontrolledOpen(next)\n      onOpenChange?.(next, eventDetails)\n    },\n    [isControlled, onOpenChange]\n  )\n\n  return (\n    <DrawerOpenContext.Provider value={{ open, side }}>\n      <DrawerPrimitive.Root\n        data-slot=\"drawer\"\n        open={open}\n        onOpenChange={handleOpenChange}\n        swipeDirection={swipeDirection ?? sideToSwipeDirection(side)}\n        {...props}\n      />\n    </DrawerOpenContext.Provider>\n  )\n}\n\nfunction DrawerTrigger({ ...props }: DrawerPrimitive.Trigger.Props) {\n  return <DrawerPrimitive.Trigger data-slot=\"drawer-trigger\" {...props} />\n}\n\nfunction DrawerPortal({ ...props }: DrawerPrimitive.Portal.Props) {\n  return <DrawerPrimitive.Portal data-slot=\"drawer-portal\" {...props} />\n}\n\nfunction DrawerClose({ ...props }: DrawerPrimitive.Close.Props) {\n  return <DrawerPrimitive.Close data-slot=\"drawer-close\" {...props} />\n}\n\nfunction DrawerOverlay({\n  className,\n  render,\n  ...props\n}: DrawerPrimitive.Backdrop.Props) {\n  const reduce = useReducedMotion()\n  return (\n    <DrawerPrimitive.Backdrop\n      data-slot=\"drawer-overlay\"\n      className={cn(\"dialog-overlay fixed inset-0 isolate z-50\", className)}\n      render={render ?? <motion.div {...backdropMotion(reduce)} />}\n      {...props}\n    />\n  )\n}\n\nconst sideViewportClass: Record<DrawerPanelSide, string> = {\n  right: \"items-stretch justify-end\",\n  left: \"items-stretch justify-start\",\n  bottom: \"items-end justify-center\",\n  top: \"items-start justify-center\",\n}\n\nconst sidePopupClass: Record<DrawerPanelSide, string> = {\n  right:\n    \"h-full w-full max-w-sm border-l border-border-subtle sm:max-w-md\",\n  left: \"h-full w-full max-w-sm border-r border-border-subtle sm:max-w-md\",\n  bottom:\n    \"max-h-[min(92dvh,40rem)] w-full border-t border-border-subtle rounded-t-[var(--radius)]\",\n  top: \"max-h-[min(92dvh,40rem)] w-full border-b border-border-subtle rounded-b-[var(--radius)]\",\n}\n\nfunction DrawerContent({\n  className,\n  children,\n  showCloseButton = true,\n  render,\n  ...props\n}: DrawerPrimitive.Popup.Props & {\n  showCloseButton?: boolean\n}) {\n  const { open, side } = useDrawerContext()\n  const reduce = useReducedMotion()\n\n  return (\n    <AnimatePresence>\n      {open ? (\n        <DrawerPortal keepMounted key=\"drawer-portal\">\n          <DrawerOverlay />\n          <DrawerPrimitive.Viewport\n            data-slot=\"drawer-viewport\"\n            className={cn(\n              \"fixed inset-0 z-50 flex outline-none\",\n              sideViewportClass[side]\n            )}\n          >\n            <DrawerPrimitive.Popup\n              data-slot=\"drawer-content\"\n              className={cn(\n                \"relative z-50 flex flex-col gap-4 overflow-hidden bg-popover p-5 text-sm text-popover-foreground outline-none\",\n                dialogElevation,\n                sidePopupClass[side],\n                className\n              )}\n              render={\n                render ?? <motion.div {...drawerPanelMotion(side, reduce)} />\n              }\n              {...props}\n            >\n              <DrawerPrimitive.Content\n                data-slot=\"drawer-body\"\n                className=\"flex min-h-0 flex-1 flex-col gap-4\"\n              >\n                {children}\n              </DrawerPrimitive.Content>\n              {showCloseButton ? (\n                <DrawerPrimitive.Close\n                  data-slot=\"drawer-close\"\n                  render={\n                    <Button\n                      variant=\"ghost\"\n                      size=\"icon-sm\"\n                      className=\"absolute top-3.5 right-3.5 text-muted-foreground hover:text-foreground\"\n                    />\n                  }\n                >\n                  <X className=\"size-3.5\" strokeWidth={1.75} />\n                  <span className=\"sr-only\">Close</span>\n                </DrawerPrimitive.Close>\n              ) : null}\n            </DrawerPrimitive.Popup>\n          </DrawerPrimitive.Viewport>\n        </DrawerPortal>\n      ) : null}\n    </AnimatePresence>\n  )\n}\n\nfunction DrawerHeader({ className, ...props }: React.ComponentProps<\"div\">) {\n  return (\n    <div\n      data-slot=\"drawer-header\"\n      className={cn(\"flex flex-col gap-2 pr-9\", className)}\n      {...props}\n    />\n  )\n}\n\nfunction DrawerFooter({\n  className,\n  showCloseButton = false,\n  children,\n  ...props\n}: React.ComponentProps<\"div\"> & {\n  showCloseButton?: boolean\n}) {\n  return (\n    <div\n      data-slot=\"drawer-footer\"\n      className={cn(\n        \"mt-auto flex flex-col-reverse gap-2 sm:flex-row sm:justify-end\",\n        className\n      )}\n      {...props}\n    >\n      {children}\n      {showCloseButton ? (\n        <DrawerPrimitive.Close render={<Button variant=\"outline\" />}>\n          Close\n        </DrawerPrimitive.Close>\n      ) : null}\n    </div>\n  )\n}\n\nfunction DrawerTitle({ className, ...props }: DrawerPrimitive.Title.Props) {\n  return (\n    <DrawerPrimitive.Title\n      data-slot=\"drawer-title\"\n      className={cn(\n        \"text-[0.9375rem] font-medium leading-snug tracking-tight\",\n        className\n      )}\n      {...props}\n    />\n  )\n}\n\nfunction DrawerDescription({\n  className,\n  ...props\n}: DrawerPrimitive.Description.Props) {\n  return (\n    <DrawerPrimitive.Description\n      data-slot=\"drawer-description\"\n      className={cn(\"text-sm leading-relaxed text-muted-foreground\", className)}\n      {...props}\n    />\n  )\n}\n\nexport {\n  Drawer,\n  DrawerClose,\n  DrawerContent,\n  DrawerDescription,\n  DrawerFooter,\n  DrawerHeader,\n  DrawerOverlay,\n  DrawerPortal,\n  DrawerTitle,\n  DrawerTrigger,\n}\n",
      "type": "registry:ui",
      "target": "components/ui/drawer.tsx"
    }
  ],
  "type": "registry:ui"
}