{
  "schemaVersion": 1,
  "target": "react",
  "name": "drawer",
  "version": "0.1.0",
  "category": "overlays",
  "title": "Drawer",
  "description": "A bottom drawer for touch with a drag handle, swipe to dismiss, and optional snap points, built on Base UI Drawer; the handle doubles as a button that steps between heights.",
  "tags": [
    "overlay",
    "bottom-sheet",
    "mobile",
    "touch",
    "base-ui"
  ],
  "requires": {
    "projectTypes": [
      "next",
      "vite-react"
    ],
    "styling": "tailwind-v4"
  },
  "npmDependencies": {
    "@base-ui/react": "^1.9.0"
  },
  "registryDependencies": [
    {
      "name": "button",
      "version": "0.2.1"
    }
  ],
  "docsPath": "/components/drawer",
  "props": [
    {
      "name": "Drawer open / defaultOpen / onOpenChange",
      "type": "boolean / boolean / (open, details) => void",
      "description": "Root state. Leave open unset for an uncontrolled drawer."
    },
    {
      "name": "Drawer snapPoints",
      "type": "(number | string)[]",
      "description": "Resting heights: fractions of the viewport (0 to 1), pixel numbers, or px/rem strings. Without them the drawer sizes to its content."
    },
    {
      "name": "Drawer snapPoint / defaultSnapPoint / onSnapPointChange",
      "type": "SnapPoint | null / SnapPoint | null / (point, details?) => void",
      "description": "Active snap point. Defaults to the first one and resets to it after closing when uncontrolled. details is absent when the handle button caused the change."
    },
    {
      "name": "DrawerTrigger / DrawerClose",
      "type": "Base UI Drawer.Trigger / Drawer.Close props",
      "description": "Unstyled buttons that open and close the drawer. Pass className, or render={<Button />}."
    },
    {
      "name": "DrawerContent showHandle",
      "type": "boolean",
      "default": "true",
      "description": "Renders the drag handle at the top."
    },
    {
      "name": "DrawerHeader / DrawerBody / DrawerFooter",
      "type": "div / Base UI Drawer.Content / div props",
      "description": "Layout: the body scrolls; the footer stacks full-width actions and pads for the home indicator."
    },
    {
      "name": "DrawerTitle / DrawerDescription",
      "type": "Base UI Title / Description props",
      "description": "Heading and supporting text, wired to aria-labelledby and aria-describedby."
    }
  ],
  "accessibility": [
    "The panel has role=\"dialog\" and aria-modal, named by DrawerTitle and described by DrawerDescription; focus is trapped while open and returns to the trigger on close.",
    "Escape and a tap on the backdrop dismiss it, so swiping is never required.",
    "Without snap points the handle is decorative and hidden from assistive tech. With snap points it is a button named Expand drawer or Collapse drawer that steps to the next height, so keyboard and switch users can resize it.",
    "With reduced motion the slide and backdrop fade are removed; dragging still tracks the finger."
  ],
  "states": [
    "closed",
    "open",
    "snapped",
    "expanded",
    "swiping"
  ],
  "files": [
    {
      "path": "ui/drawer.tsx",
      "content": "\"use client\";\n\nimport { Drawer as BaseDrawer } from \"@base-ui/react/drawer\";\nimport { type ComponentProps, createContext, useCallback, useContext, useMemo, useState } from \"react\";\n\ntype ClassName<State> = string | ((state: State) => string | undefined) | undefined;\n\nfunction cx(...classes: (string | false | null | undefined)[]) {\n  return classes.filter(Boolean).join(\" \");\n}\n\n/** Prepends base classes while keeping Base UI's state-function form of className working. */\nfunction withBase<State>(base: string, className: ClassName<State>) {\n  return typeof className === \"function\" ? (state: State) => cx(base, className(state)) : cx(base, className);\n}\n\nexport type DrawerSnapPoint = BaseDrawer.Root.SnapPoint;\n\ninterface SnapContextValue {\n  snapPoints: readonly DrawerSnapPoint[] | undefined;\n  snapPoint: DrawerSnapPoint | null;\n  setSnapPoint: (point: DrawerSnapPoint | null) => void;\n}\n\nconst SnapContext = createContext<SnapContextValue>({ snapPoints: undefined, snapPoint: null, setSnapPoint: () => {} });\n\nexport interface DrawerProps extends Omit<BaseDrawer.Root.Props, \"swipeDirection\" | \"onSnapPointChange\"> {\n  /**\n   * Called when the drawer settles at a new snap point, after a drag or a press on the handle.\n   * `details` is absent when the handle button caused the change.\n   */\n  onSnapPointChange?: (snapPoint: DrawerSnapPoint | null, details?: BaseDrawer.Root.SnapPointChangeEventDetails) => void;\n}\n\n/**\n * Groups the drawer parts and holds its open state. Pass `open`/`onOpenChange` to control it.\n * The drawer rises from the bottom edge and is dismissed by swiping it down. Pass `snapPoints`\n * (fractions of the viewport height, pixel numbers, or `px`/`rem` strings) to let it rest at\n * several heights; without them it simply sizes to its content.\n */\nexport function Drawer({\n  snapPoints,\n  snapPoint: snapPointProp,\n  defaultSnapPoint,\n  onSnapPointChange,\n  onOpenChangeComplete,\n  ...props\n}: DrawerProps) {\n  const [uncontrolled, setUncontrolled] = useState<DrawerSnapPoint | null>(defaultSnapPoint ?? snapPoints?.[0] ?? null);\n  const snapPoint = snapPointProp !== undefined ? snapPointProp : uncontrolled;\n\n  const setSnapPoint = useCallback(\n    (point: DrawerSnapPoint | null, details?: BaseDrawer.Root.SnapPointChangeEventDetails) => {\n      if (snapPointProp === undefined) setUncontrolled(point);\n      onSnapPointChange?.(point, details);\n    },\n    [snapPointProp, onSnapPointChange],\n  );\n\n  const value = useMemo<SnapContextValue>(\n    () => ({ snapPoints, snapPoint, setSnapPoint: (point) => setSnapPoint(point) }),\n    [snapPoints, snapPoint, setSnapPoint],\n  );\n\n  return (\n    <SnapContext.Provider value={value}>\n      <BaseDrawer.Root\n        swipeDirection=\"down\"\n        {...(snapPoints ? { snapPoints, snapPoint, onSnapPointChange: setSnapPoint } : null)}\n        onOpenChangeComplete={(open) => {\n          // Reopen at the first resting height rather than wherever it was dismissed from.\n          if (!open && snapPoints && snapPointProp === undefined) setUncontrolled(defaultSnapPoint ?? snapPoints[0] ?? null);\n          onOpenChangeComplete?.(open);\n        }}\n        {...props}\n      />\n    </SnapContext.Provider>\n  );\n}\n\n/** A button that opens the drawer. Unstyled; pass `className`, or `render={<Button />}` to reuse your button. */\nexport const DrawerTrigger = BaseDrawer.Trigger;\n\n/** A button that closes the drawer. Unstyled; pass `className` or `render`. */\nexport const DrawerClose = BaseDrawer.Close;\n\nexport interface DrawerContentProps extends BaseDrawer.Popup.Props {\n  /** Renders the drag handle at the top. With snap points it is also a button that steps between heights. */\n  showHandle?: boolean;\n  /** Classes for the backdrop behind the panel. */\n  backdropClassName?: string;\n  /** Element to portal into. Defaults to `document.body`. */\n  container?: BaseDrawer.Portal.Props[\"container\"];\n}\n\n/**\n * The bottom panel, rendered in a portal above a backdrop. On wide screens it stays a centered\n * column instead of spanning the window. Lay it out with DrawerHeader, DrawerBody, and DrawerFooter.\n */\nexport function DrawerContent({\n  showHandle = true,\n  backdropClassName,\n  container,\n  className,\n  children,\n  ...props\n}: DrawerContentProps) {\n  const { snapPoints } = useContext(SnapContext);\n  const snapping = Boolean(snapPoints?.length);\n\n  return (\n    <BaseDrawer.Portal container={container}>\n      <BaseDrawer.Backdrop\n        className={cx(\n          \"fixed inset-0 z-50 bg-black/40 dark:bg-black/70\",\n          // Base UI reports full swipe progress while resting at a lower snap point, so only half the dim follows it.\n          \"opacity-[calc(1-0.5*var(--drawer-swipe-progress,0))]\",\n          \"transition-opacity duration-400 ease-[cubic-bezier(0.32,0.72,0,1)] motion-reduce:transition-none\",\n          \"data-[starting-style]:opacity-0 data-[ending-style]:opacity-0 data-[ending-style]:duration-[calc(var(--drawer-swipe-strength,1)*260ms)] data-[swiping]:duration-0\",\n          backdropClassName,\n        )}\n      />\n      <BaseDrawer.Viewport className=\"fixed inset-0 z-50 flex items-end justify-center\">\n        <BaseDrawer.Popup\n          data-snapping={snapping || undefined}\n          className={withBase(\n            cx(\n              \"relative flex w-full flex-col outline-none sm:max-w-xl\",\n              \"max-h-[calc(100dvh-2rem)] rounded-t-2xl border border-b-0 border-zinc-950/10 bg-white text-zinc-950\",\n              \"shadow-[0_-12px_40px_-12px_rgb(0_0_0/0.22)]\",\n              \"dark:border-white/15 dark:bg-black dark:text-white dark:shadow-[0_-16px_48px_-12px_rgb(0_0_0/1),inset_0_1px_0_rgb(255_255_255/0.08)]\",\n              \"focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-sky-500\",\n              // Overscroll fill: a strip below the panel in its own color, so an upward drag never shows a gap.\n              \"after:pointer-events-none after:absolute after:inset-x-[-1px] after:top-full after:h-12 after:border-x after:border-zinc-950/10 after:bg-inherit dark:after:border-white/15 after:content-['']\",\n              // Rests at the snap offset; the finger's movement is added while dragging.\n              \"translate-y-[calc(var(--drawer-snap-point-offset,0px)+var(--drawer-swipe-movement-y,0px))]\",\n              // With snap points the panel is full height and slides down, so pad the bottom to keep the end of the content reachable.\n              \"data-[snapping]:h-[calc(100dvh-2rem)] data-[snapping]:pb-[max(0px,var(--drawer-snap-point-offset,0px))]\",\n              \"data-[starting-style]:translate-y-full data-[ending-style]:translate-y-full\",\n              // Enter: 400ms with a soft landing, like a sheet of paper settling. Exit: faster, faster still after a flick.\n              \"transition-[translate] duration-400 ease-[cubic-bezier(0.32,0.72,0,1)] motion-reduce:transition-none\",\n              \"data-[ending-style]:duration-[calc(var(--drawer-swipe-strength,1)*260ms)]\",\n              \"data-[swiping]:duration-0 data-[swiping]:select-none\",\n            ),\n            className,\n          )}\n          {...props}\n        >\n          {showHandle ? <DrawerHandle /> : null}\n          {children}\n        </BaseDrawer.Popup>\n      </BaseDrawer.Viewport>\n    </BaseDrawer.Portal>\n  );\n}\n\nfunction sameSnap(a: DrawerSnapPoint | null, b: DrawerSnapPoint | null) {\n  return a === b || String(a) === String(b);\n}\n\n/**\n * The grabber bar. Without snap points it is decoration (hidden from assistive tech), since\n * Escape, the backdrop, and the swipe all dismiss. With snap points it is a real button that\n * steps to the next resting height, so keyboard and switch users can resize the drawer too.\n */\nexport function DrawerHandle({ className }: { className?: string }) {\n  const { snapPoints, snapPoint, setSnapPoint } = useContext(SnapContext);\n  const bar = cx(\n    \"block h-1 w-9 rounded-full bg-zinc-950/15 transition-[background-color,width] duration-150 ease-out motion-reduce:transition-none\",\n    \"dark:bg-white/20\",\n  );\n\n  if (!snapPoints?.length) {\n    return (\n      <div aria-hidden=\"true\" className={cx(\"flex h-6 shrink-0 items-center justify-center\", className)}>\n        <span className={bar} />\n      </div>\n    );\n  }\n\n  const index = Math.max(\n    0,\n    snapPoints.findIndex((point) => sameSnap(point, snapPoint)),\n  );\n  const atLast = index === snapPoints.length - 1;\n  const next = atLast ? snapPoints[0] : snapPoints[index + 1];\n\n  return (\n    <button\n      type=\"button\"\n      aria-label={atLast ? \"Collapse drawer\" : \"Expand drawer\"}\n      onClick={() => setSnapPoint(next ?? null)}\n      className={cx(\n        \"group mx-auto flex h-6 w-16 shrink-0 cursor-grab items-center justify-center rounded-full outline-none active:cursor-grabbing\",\n        \"focus-visible:outline-2 focus-visible:outline-offset-0 focus-visible:outline-sky-500\",\n        className,\n      )}\n    >\n      <span className={cx(bar, \"group-hover:bg-zinc-950/25 dark:group-hover:bg-white/30\")} />\n    </button>\n  );\n}\n\n/** Wraps the title and description. */\nexport function DrawerHeader({ className, ...props }: ComponentProps<\"div\">) {\n  return <div className={cx(\"grid shrink-0 gap-1 px-5 pt-1 pb-4 text-center sm:px-6\", className)} {...props} />;\n}\n\n/**\n * The scrolling middle of the drawer. Text in it can be selected with a mouse without starting a\n * swipe; mark a horizontal scroller inside it with `data-base-ui-swipe-ignore` to keep its drags.\n */\nexport function DrawerBody({ className, ...props }: BaseDrawer.Content.Props) {\n  return (\n    <BaseDrawer.Content\n      className={withBase(\"min-h-0 flex-1 overflow-y-auto overscroll-contain px-5 pb-5 text-sm sm:px-6\", className)}\n      {...props}\n    />\n  );\n}\n\n/** Holds the actions, full width and stacked, with room for the home indicator on phones. */\nexport function DrawerFooter({ className, ...props }: ComponentProps<\"div\">) {\n  return (\n    <div\n      className={cx(\n        \"grid shrink-0 gap-2 border-t border-zinc-950/[0.07] px-5 pt-4 pb-[max(1rem,env(safe-area-inset-bottom))] sm:px-6\",\n        \"dark:border-white/[0.08]\",\n        className,\n      )}\n      {...props}\n    />\n  );\n}\n\n/** The drawer's heading. Labels the panel with aria-labelledby. */\nexport function DrawerTitle({ className, ...props }: BaseDrawer.Title.Props) {\n  return <BaseDrawer.Title className={withBase(\"text-base leading-6 font-semibold tracking-[-0.01em]\", className)} {...props} />;\n}\n\n/** Supporting text. Describes the panel with aria-describedby. */\nexport function DrawerDescription({ className, ...props }: BaseDrawer.Description.Props) {\n  return (\n    <BaseDrawer.Description className={withBase(\"text-sm leading-relaxed text-zinc-600 dark:text-zinc-400\", className)} {...props} />\n  );\n}\n"
    }
  ],
  "example": {
    "content": "import { Button } from \"@/components/shaken/ui/button\";\nimport {\n  Drawer,\n  DrawerBody,\n  DrawerClose,\n  DrawerContent,\n  DrawerDescription,\n  DrawerFooter,\n  DrawerHeader,\n  DrawerTitle,\n  DrawerTrigger,\n} from \"@/components/shaken/ui/drawer\";\n\nconst steps = [\n  { time: \"0.4s\", text: \"Read package.json and the lockfile\" },\n  { time: \"1.2s\", text: \"Ran pnpm test --filter api: 212 passed\" },\n  { time: \"3.8s\", text: \"Opened src/limits.ts and src/handler.ts\" },\n  { time: \"6.1s\", text: \"Edited src/limits.ts: reads the plan limit\" },\n  { time: \"6.9s\", text: \"Edited src/handler.ts: returns 429 with Retry-After\" },\n  { time: \"9.4s\", text: \"Ran pnpm test --filter api: 215 passed\" },\n  { time: \"10.2s\", text: \"Wrote docs/rate-limits.md\" },\n  { time: \"11.0s\", text: \"Asked for approval to open a pull request\" },\n  { time: \"34.5s\", text: \"Approved by Mira Okafor\" },\n  { time: \"36.2s\", text: \"Opened pull request #482\" },\n];\n\nexport default function DrawerExample() {\n  return (\n    <div className=\"flex flex-wrap items-center justify-center gap-3\">\n      <Drawer>\n        <DrawerTrigger render={<Button variant=\"secondary\" />}>Share run</DrawerTrigger>\n        <DrawerContent>\n          <DrawerHeader>\n            <DrawerTitle>Share this run</DrawerTitle>\n            <DrawerDescription>Anyone with the link can read the transcript. Secrets stay redacted.</DrawerDescription>\n          </DrawerHeader>\n          <DrawerBody>\n            <div className=\"flex items-center gap-2 rounded-lg border border-zinc-950/[0.07] px-3 py-2.5 dark:border-white/[0.08]\">\n              <code className=\"min-w-0 flex-1 truncate font-mono text-xs text-zinc-600 dark:text-zinc-400\">\n                shaken.dev/runs/r_8f2k4q\n              </code>\n              <span className=\"text-xs text-zinc-500\">Expires in 7 days</span>\n            </div>\n          </DrawerBody>\n          <DrawerFooter>\n            <DrawerClose render={<Button size=\"lg\" />}>Copy link</DrawerClose>\n            <DrawerClose render={<Button size=\"lg\" variant=\"ghost\" />}>Cancel</DrawerClose>\n          </DrawerFooter>\n        </DrawerContent>\n      </Drawer>\n\n      <Drawer snapPoints={[\"21rem\", 1]}>\n        <DrawerTrigger render={<Button variant=\"secondary\" />}>Open run log</DrawerTrigger>\n        <DrawerContent>\n          <DrawerHeader className=\"text-left\">\n            <DrawerTitle>Run log</DrawerTitle>\n            <DrawerDescription>Drag the handle up for the full log, or press it to switch heights.</DrawerDescription>\n          </DrawerHeader>\n          <DrawerBody>\n            <ol className=\"divide-y divide-zinc-950/[0.07] rounded-lg border border-zinc-950/[0.07] dark:divide-white/[0.08] dark:border-white/[0.08]\">\n              {steps.map((step) => (\n                <li key={step.time} className=\"flex gap-3 px-3 py-2.5\">\n                  <span className=\"w-11 shrink-0 font-mono text-xs leading-5 text-zinc-500 tabular-nums\">{step.time}</span>\n                  <span className=\"text-zinc-700 dark:text-zinc-300\">{step.text}</span>\n                </li>\n              ))}\n            </ol>\n          </DrawerBody>\n        </DrawerContent>\n      </Drawer>\n    </div>\n  );\n}\n"
  }
}
