{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "drawer",
  "type": "registry:ui",
  "title": "Drawer",
  "description": "A panel that slides in from an edge and follows the finger: drag it back toward its edge and it goes, let go early and it settles back. The bottom sheet of a phone app, on the web. Base UI's Drawer owns the gesture, the open state, the focus trap, page…",
  "author": "ofri-peretz <https://github.com/ofri-peretz>",
  "categories": [
    "overlay",
    "primitive"
  ],
  "dependencies": [
    "@base-ui/react",
    "lucide-react"
  ],
  "registryDependencies": [
    "https://ds.interlace.tools/r/interlace-base.json",
    "https://ds.interlace.tools/r/cn.json"
  ],
  "files": [
    {
      "path": "registry/interlace-ui/drawer.tsx",
      "target": "components/ui/drawer.tsx",
      "type": "registry:ui",
      "content": "'use client';\n\nimport * as React from 'react';\n\n// @interlace/drawer v1.2.1 — Interlace design system.\n// Docs, props and live preview: https://ds.interlace.tools/c/drawer\n// What changed since: https://ds.interlace.tools/c/drawer#history\n// Generated banner — keep it, the upgrade diff reads this version.\n\n// Mirrors the shadcn Drawer canon (Drawer, DrawerTrigger, DrawerContent,\n// DrawerHeader, DrawerFooter, DrawerTitle, DrawerDescription, DrawerClose),\n// built on Base UI's Drawer instead of vaul.\n// Upstream: https://base-ui.com/react/components/drawer\n\n/**\n * @interlace/ui — Drawer\n *\n * A panel that slides in from an edge and follows the finger: drag it back\n * toward its edge and it goes, let go early and it settles back. The bottom\n * sheet of a phone app, on the web. Base UI's Drawer owns the gesture, the\n * open state, the focus trap, page inerting, Escape and outside-press\n * dismissal, and snap points; we own the scrim, the surface, the handle and\n * the motion.\n *\n * Reach for `Sheet` when the panel is a desktop side pane that nobody drags,\n * and `Dialog` when the task must be finished before returning. A Drawer is\n * for touch first: a filter panel, a share sheet, an action list, a mobile\n * menu.\n *\n * ## Anatomy\n *\n *   Drawer                           (Drawer.Root — renders no DOM node; `direction`)\n *     ├─ DrawerTrigger               (Drawer.Trigger)\n *     └─ DrawerContent               (Portal → Backdrop → Viewport → Popup)\n *          ├─ handle                 (top or bottom drawers — data-slot=\"drawer-handle\", aria-hidden)\n *          ├─ Drawer.Content         (data-slot=\"drawer-body\" — scrolls; text stays selectable)\n *          │    ├─ DrawerHeader → DrawerTitle + DrawerDescription\n *          │    ├─ children\n *          │    └─ DrawerFooter      (mt-auto)\n *          └─ a Drawer.Close \"X\"     (always rendered, sr-only label \"Close\")\n *\n * `DrawerContent` mounts its own portal, scrim and viewport, as `SheetContent`\n * does, so a call site never stacks two scrims.\n *\n * ## Gesture and motion\n *\n * `direction` (bottom by default) picks the edge and the swipe that dismisses.\n * While a finger drags, Base UI writes `--drawer-swipe-movement-x/y` and the\n * popup follows it with no transition; the scrim fades by\n * `--drawer-swipe-progress`. On release the popup springs back or leaves, and\n * a fast flick leaves faster (`--drawer-swipe-strength` scales the exit).\n * Overshoot toward the open side shows a `bleed` of the same surface instead\n * of a gap. Snap points (`snapPoints` on the root) move the resting height\n * through `--drawer-snap-point-offset` (bottom drawers only), and the body pads by the same amount\n * so its last line stays reachable.\n *\n * Under `prefers-reduced-motion: reduce` the open and close slides are\n * instant. Dragging still moves the panel: the reader is the motion, as with\n * a scrollbar.\n *\n * ## Safe areas\n *\n * A bottom drawer pads its body by `env(safe-area-inset-bottom)`, so the last\n * action clears the home indicator on a phone with `viewport-fit=cover`.\n *\n * ## MIN_VIEWPORT — 320\n *\n * Side drawers are `w-3/4` (240px at the floor) capped at `xs:max-w-96`;\n * top and bottom drawers are full width and at most the viewport height less\n * 2rem, so the page stays visible above and a tap there closes it.\n *\n * | Rule | Concept                          | Where in this file                                          |\n * | ---- | -------------------------------- | ----------------------------------------------------------- |\n * | R4   | Extends Base UI part props       | `React.ComponentProps<typeof BaseDrawer.*>`                 |\n * | R6   | data-slot per part               | drawer-trigger / -close / -portal / -overlay / -viewport / -content / -handle / -body / -header / -footer / -title / -description / -close-x |\n * | R7   | cn + ...rest                     | `cn(…, className)` + `{...props}`                           |\n * | R8   | Enum for edge                    | `direction = top | right | bottom | left | start | end` (default bottom) |\n * | R12  | Reuse over wrap                  | Base UI Drawer owns the gesture, focus trap and dismissal   |\n * | R14  | Declares min viewport            | `data-min-viewport` on the popup + exported const           |\n * | R19  | Tokens only                      | `bg-background`, `bg-muted-foreground/40` handle, motion tokens (the scrim excepted, as in Sheet) |\n * | R25  | Client component                 | Required — Base UI Drawer ships client hooks                |\n * | R26  | Keyboard contract                | Escape-dismissal + focus restore asserted by `Drawer.stories.tsx`, locked by `overlay-nav-keyboard-lock` |\n */\n\nimport { Drawer as BaseDrawer } from '@base-ui/react/drawer';\nimport { useDirection } from '@base-ui/react/direction-provider';\nimport { XIcon } from 'lucide-react';\n\nimport { cn } from '@/lib/utils';\n\n/**\n * Minimum viable viewport (CSS px) — DESIGN_PRINCIPLES #14. Side drawers are\n * `w-3/4` (240px at the 320 floor); top and bottom drawers are full width.\n * Projected onto the popup, because `Drawer.Root` renders no DOM node.\n */\nexport const MIN_VIEWPORT = 320 as const;\n\ntype DrawerDirection = 'top' | 'right' | 'bottom' | 'left';\n\n/** The swipe that dismisses a drawer is toward its own edge. */\nconst SWIPE = { top: 'up', right: 'right', bottom: 'down', left: 'left' } as const;\n\nconst DirectionContext = React.createContext<DrawerDirection>('bottom');\n\ntype DrawerProps = Omit<React.ComponentProps<typeof BaseDrawer.Root>, 'swipeDirection'> & {\n  /**\n   * The edge the drawer is attached to; dragging toward it dismisses. `start` and `end` follow\n   * the reading direction from `DirectionProvider`: `start` is the left edge in English and the\n   * right edge in Hebrew or Arabic. @default 'bottom'\n   */\n  direction?: DrawerDirection | 'start' | 'end';\n  /** Heights a bottom drawer rests at (fractions of the viewport, px, or rem strings). Bottom drawers only: other directions ignore it. */\n  snapPoints?: React.ComponentProps<typeof BaseDrawer.Root>['snapPoints'];\n};\n\nfunction Drawer({ direction = 'bottom', ...props }: DrawerProps) {\n  // Resolved from context, not the DOM: the panel is portalled outside any `dir` wrapper.\n  const rtl = useDirection() === 'rtl';\n  const edge: DrawerDirection =\n    direction === 'start' ? (rtl ? 'right' : 'left') : direction === 'end' ? (rtl ? 'left' : 'right') : direction;\n  return (\n    <DirectionContext.Provider value={edge}>\n      <BaseDrawer.Root swipeDirection={SWIPE[edge]} {...props} />\n    </DirectionContext.Provider>\n  );\n}\n\nfunction DrawerTrigger(props: React.ComponentProps<typeof BaseDrawer.Trigger>) {\n  return <BaseDrawer.Trigger data-slot=\"drawer-trigger\" {...props} />;\n}\n\nfunction DrawerClose(props: React.ComponentProps<typeof BaseDrawer.Close>) {\n  return <BaseDrawer.Close data-slot=\"drawer-close\" {...props} />;\n}\n\nfunction DrawerPortal(props: React.ComponentProps<typeof BaseDrawer.Portal>) {\n  return <BaseDrawer.Portal data-slot=\"drawer-portal\" {...props} />;\n}\n\nfunction DrawerOverlay({\n  className,\n  ...props\n}: React.ComponentProps<typeof BaseDrawer.Backdrop>) {\n  return (\n    <BaseDrawer.Backdrop\n      data-slot=\"drawer-overlay\"\n      className={cn(\n        // `bg-black/50` is the deliberate scrim colour, as in Sheet: a\n        // theme-paired token would invert in dark mode and light the page.\n        // It thins as the panel is dragged away, and follows the finger\n        // with no transition while it does.\n        'fixed inset-0 z-overlay min-h-dvh bg-black/50 opacity-[calc(1-var(--drawer-swipe-progress,0))]',\n        'ease-enter transition-opacity duration-(--duration-slow) motion-reduce:transition-none',\n        'data-[starting-style]:opacity-0 data-[ending-style]:opacity-0 data-[swiping]:duration-0',\n        'data-[ending-style]:ease-exit data-[ending-style]:duration-[calc(var(--drawer-swipe-strength,1)*var(--duration-medium))]',\n        className,\n      )}\n      {...props}\n    />\n  );\n}\n\n/** Where the viewport puts the panel, per edge. */\nconst VIEWPORT: Record<DrawerDirection, string> = {\n  bottom: 'items-end justify-center',\n  top: 'items-start justify-center',\n  right: 'items-stretch justify-end',\n  left: 'items-stretch justify-start',\n};\n\n/**\n * The panel per edge: its size, its border, where it rests (following the\n * finger and the snap offset), where it enters from and leaves to, and the\n * bleed that fills the gap when it is pulled past open. One static string per\n * edge so Tailwind can scan them.\n */\nconst POPUP: Record<DrawerDirection, string> = {\n  bottom: cn(\n    'max-h-[calc(100dvh-2rem)] w-full rounded-t-xl border-t touch-none',\n    '[transform:translateY(calc(var(--drawer-snap-point-offset,0px)+var(--drawer-swipe-movement-y,0px)))]',\n    'data-[starting-style]:[transform:translateY(100%)] data-[ending-style]:[transform:translateY(100%)]',\n    \"after:absolute after:inset-x-0 after:top-full after:h-12 after:bg-inherit after:content-['']\",\n  ),\n  top: cn(\n    'max-h-[calc(100dvh-2rem)] w-full rounded-b-xl border-b touch-none',\n    '[transform:translateY(var(--drawer-swipe-movement-y,0px))]',\n    'data-[starting-style]:[transform:translateY(-100%)] data-[ending-style]:[transform:translateY(-100%)]',\n    \"after:absolute after:inset-x-0 after:bottom-full after:h-12 after:bg-inherit after:content-['']\",\n  ),\n  right: cn(\n    'h-full w-3/4 border-l xs:max-w-96',\n    '[transform:translateX(var(--drawer-swipe-movement-x,0px))]',\n    'data-[starting-style]:[transform:translateX(100%)] data-[ending-style]:[transform:translateX(100%)]',\n    \"after:absolute after:inset-y-0 after:left-full after:w-12 after:bg-inherit after:content-['']\",\n  ),\n  left: cn(\n    'h-full w-3/4 border-r xs:max-w-96',\n    '[transform:translateX(var(--drawer-swipe-movement-x,0px))]',\n    'data-[starting-style]:[transform:translateX(-100%)] data-[ending-style]:[transform:translateX(-100%)]',\n    \"after:absolute after:inset-y-0 after:right-full after:w-12 after:bg-inherit after:content-['']\",\n  ),\n};\n\n/**\n * The body pads its far edge so a snapped or bottom drawer's last line stays reachable.\n * `--drawer-snap-point-offset` is the positive distance the panel sits below full height, and\n * `--drawer-swipe-movement-y` is the live drag (down is positive), so their sum is the height\n * currently off-screen. `max(0px, …)` stops an upward over-drag from going negative.\n */\nconst BODY: Record<DrawerDirection, string> = {\n  bottom:\n    'pb-[calc(env(safe-area-inset-bottom,0px)+max(0px,var(--drawer-snap-point-offset,0px)+var(--drawer-swipe-movement-y,0px)))]',\n  top: '',\n  right: '',\n  left: '',\n};\n\nfunction DrawerHandle({ className }: { className?: string }) {\n  return (\n    <div\n      data-slot=\"drawer-handle\"\n      aria-hidden\n      className={cn('bg-muted-foreground/40 mx-auto h-1.5 w-12 shrink-0 rounded-full', className)}\n    />\n  );\n}\n\ntype DrawerContentProps = React.ComponentProps<typeof BaseDrawer.Popup>;\n\nfunction DrawerContent({ className, children, ...props }: DrawerContentProps) {\n  const direction = React.useContext(DirectionContext);\n  const vertical = direction === 'top' || direction === 'bottom';\n  return (\n    <DrawerPortal>\n      <DrawerOverlay />\n      <BaseDrawer.Viewport\n        data-slot=\"drawer-viewport\"\n        className={cn('fixed inset-0 z-modal flex', VIEWPORT[direction])}\n      >\n        <BaseDrawer.Popup\n          data-slot=\"drawer-content\"\n          data-direction={direction}\n          data-min-viewport={String(MIN_VIEWPORT)}\n          className={cn(\n            'bg-background text-foreground relative flex min-h-0 flex-col shadow-lg focus-visible:outline-hidden',\n            // Opening takes the slow band and leaves in the medium one, faster\n            // still after a flick. While a finger drags, no transition: the\n            // panel is wherever the finger is.\n            'ease-enter transition-transform duration-(--duration-slow) motion-reduce:transition-none',\n            'data-[swiping]:duration-0 data-[swiping]:select-none',\n            'data-[ending-style]:ease-exit data-[ending-style]:duration-[calc(var(--drawer-swipe-strength,1)*var(--duration-medium))]',\n            POPUP[direction],\n            className,\n          )}\n          {...props}\n        >\n          {direction === 'bottom' ? <DrawerHandle className=\"mt-3\" /> : null}\n          {/* The body is the scroller, so it takes focus: with only text\n              inside, arrow keys and Page Down could not reach a long body\n              otherwise (axe `scrollable-region-focusable`). */}\n          <BaseDrawer.Content\n            data-slot=\"drawer-body\"\n            tabIndex={0}\n            className={cn(\n              'flex min-h-0 flex-1 flex-col overflow-y-auto overscroll-contain',\n              'focus-visible:ring-ring focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-inset',\n              vertical && 'touch-auto',\n              BODY[direction],\n            )}\n          >\n            {children}\n          </BaseDrawer.Content>\n          {direction === 'top' ? <DrawerHandle className=\"mb-3\" /> : null}\n          <BaseDrawer.Close\n            data-slot=\"drawer-close-x\"\n            className=\"ring-offset-background focus-visible:ring-ring absolute top-1 end-1 inline-flex size-11 items-center justify-center rounded-md opacity-70 transition-opacity hover:opacity-100 focus-visible:opacity-100 focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:outline-hidden disabled:pointer-events-none\"\n          >\n            <XIcon className=\"size-4\" />\n            <span className=\"sr-only\">Close</span>\n          </BaseDrawer.Close>\n        </BaseDrawer.Popup>\n      </BaseDrawer.Viewport>\n    </DrawerPortal>\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-1.5 p-4 pe-12', className)}\n      {...props}\n    />\n  );\n}\n\nfunction DrawerFooter({ className, ...props }: React.ComponentProps<'div'>) {\n  return (\n    <div\n      data-slot=\"drawer-footer\"\n      className={cn('mt-auto flex flex-col gap-2 p-4', className)}\n      {...props}\n    />\n  );\n}\n\nfunction DrawerTitle({ className, ...props }: React.ComponentProps<typeof BaseDrawer.Title>) {\n  return (\n    <BaseDrawer.Title\n      data-slot=\"drawer-title\"\n      className={cn('text-foreground font-semibold', className)}\n      {...props}\n    />\n  );\n}\n\nfunction DrawerDescription({\n  className,\n  ...props\n}: React.ComponentProps<typeof BaseDrawer.Description>) {\n  return (\n    <BaseDrawer.Description\n      data-slot=\"drawer-description\"\n      className={cn('text-muted-foreground text-sm', className)}\n      {...props}\n    />\n  );\n}\n\nexport {\n  Drawer,\n  DrawerTrigger,\n  DrawerClose,\n  DrawerPortal,\n  DrawerOverlay,\n  DrawerContent,\n  DrawerHeader,\n  DrawerFooter,\n  DrawerTitle,\n  DrawerDescription,\n};\nexport type { DrawerProps, DrawerContentProps, DrawerDirection };\n"
    }
  ],
  "meta": {
    "tier": "primitive",
    "client": true,
    "minViewport": 320,
    "loading": false,
    "version": "1.2.1",
    "since": "2.0.0"
  },
  "docs": "## @interlace/drawer\n\nInstalled to `components/ui/drawer.tsx`.\n\n```tsx\nimport { /* … */ } from '@/components/ui/drawer';\n```\n\nProps, a11y contract, live preview and source: https://ds.interlace.tools/c/drawer\n\nRequires the `@interlace/interlace-base` CSS baseline (installed automatically as a registry dependency). For the Interlace look, also add `@interlace/theme`."
}
