Drawer
A panel that slides in from an edge and can be swiped away.
"use client"
import * as React from "react"
import { MinusIcon, PlusIcon } from "lucide-react"
import { Button } from "@/components/ui/button"
import {
Drawer,
DrawerClose,
DrawerContent,
DrawerDescription,
DrawerFooter,
DrawerHeader,
DrawerTitle,
DrawerTrigger,
} from "@/components/ui/drawer"
export default function DrawerDemo() {
const [goal, setGoal] = React.useState(500)
return (
<Drawer showSwipeHandle>
<DrawerTrigger render={<Button variant="secondary" />}>Move Goal…</DrawerTrigger>
<DrawerContent>
<div className="mx-auto w-full max-w-sm">
<DrawerHeader>
<DrawerTitle>Move Goal</DrawerTitle>
<DrawerDescription>Set your daily active calories.</DrawerDescription>
</DrawerHeader>
<div className="flex items-center justify-center gap-6 p-6">
<Button variant="secondary" size="icon-lg" aria-label="Less" onClick={() => setGoal((value) => Math.max(100, value - 10))}>
<MinusIcon />
</Button>
<div className="flex flex-col items-center">
<span className="text-[44px] leading-none font-bold tabular-nums">{goal}</span>
<span className="text-mac-subheadline font-semibold tracking-wide text-mac-label-secondary uppercase">Calories / Day</span>
</div>
<Button variant="secondary" size="icon-lg" aria-label="More" onClick={() => setGoal((value) => value + 10)}>
<PlusIcon />
</Button>
</div>
<DrawerFooter>
<DrawerClose render={<Button size="lg" />}>Set Goal</DrawerClose>
<DrawerClose render={<Button size="lg" variant="secondary" />}>Cancel</DrawerClose>
</DrawerFooter>
</div>
</DrawerContent>
</Drawer>
)
}Installation
pnpm dlx shadcn@latest add @cupertinoui/drawerThe first install also adds the macOS theme. See Installation to set up the registry.
Usage
import { Drawer, DrawerContent, DrawerHeader, DrawerTitle, DrawerTrigger } from "@/components/ui/drawer"
<Drawer>
<DrawerTrigger render={<Button variant="secondary" />}>Open</DrawerTrigger>
<DrawerContent>
<DrawerHeader><DrawerTitle>Move Goal</DrawerTitle></DrawerHeader>
</DrawerContent>
</Drawer>API Reference
Every part forwards the props of the underlying Base UI Drawer part. The props below are the ones CupertinoUI adds or changes.
Drawer
| Prop | Type | Description |
|---|---|---|
swipeDirection | "down" | "up" | "left" | "right"Default: "down" | The edge it slides from. |
snapPoints | (number | string)[] | Heights it rests at. |
showSwipeHandle | booleanDefault: false | Shows the grab bar. |
className | string | Extra classes, merged with the component's own. |