Getting Started
Components52
- Accordion
- Alert
- Alert Dialog
- Attachment
- Badge
- Breadcrumb
- Bubble
- Button
- Button Group
- Calendar
- Card
- Checkbox
- Collapsible
- Command
- Context Menu
- Data Table
- Dialog
- Drawer
- Dropdown Menu
- Empty
- Field
- Hover Card
- Input
- Input Group
- Item
- Kbd
- Label
- Marker
- Menubar
- Message
- Message Scroller
- Pagination
- Popover
- Progress
- Questionnaire
- Radio Group
- Scroll Area
- Select
- Separator
- Sheet
- Sidebar
- Skeleton
- Slider
- Sonner
- Spinner
- Switch
- Table
- Tabs
- Textarea
- Toggle
- Toggle Group
- Tooltip
"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 function DrawerDemo() {
const [goal, setGoal] = React.useState(350)
return (
<Drawer showSwipeHandle>
<DrawerTrigger render={<Button variant="secondary" />}>
Set goal
</DrawerTrigger>
<DrawerContent>
<div className="mx-auto flex w-full max-w-sm flex-1 flex-col">
<DrawerHeader>
<DrawerTitle>Move goal</DrawerTitle>
<DrawerDescription>Set your daily activity goal.</DrawerDescription>
</DrawerHeader>
<div className="flex items-center justify-center gap-4 p-4">
<Button
variant="secondary"
size="icon"
className="rounded-full"
aria-label="Decrease"
disabled={goal <= 200}
onClick={() => setGoal((g) => g - 10)}
>
<MinusIcon />
</Button>
<div className="flex flex-col items-center">
<span className="text-5xl font-semibold tracking-tight tabular-nums">
{goal}
</span>
<span className="text-xs text-muted-foreground uppercase">
Calories / day
</span>
</div>
<Button
variant="secondary"
size="icon"
className="rounded-full"
aria-label="Increase"
disabled={goal >= 500}
onClick={() => setGoal((g) => g + 10)}
>
<PlusIcon />
</Button>
</div>
<DrawerFooter>
<Button>Submit</Button>
<DrawerClose render={<Button variant="outline" />}>
Cancel
</DrawerClose>
</DrawerFooter>
</div>
</DrawerContent>
</Drawer>
)
}Installation#
pnpm dlx shadcn@latest add https://ui.ikramhasan.com/r/drawer.json
Usage#
import {
Drawer,
DrawerClose,
DrawerContent,
DrawerDescription,
DrawerFooter,
DrawerHeader,
DrawerTitle,
DrawerTrigger,
} from "@/components/ui/drawer"<Drawer>
<DrawerTrigger render={<Button variant="outline" />}>Open</DrawerTrigger>
<DrawerContent>
<DrawerHeader>
<DrawerTitle>Are you absolutely sure?</DrawerTitle>
<DrawerDescription>This action cannot be undone.</DrawerDescription>
</DrawerHeader>
<div className="p-4">{/* Content here */}</div>
<DrawerFooter>
<Button>Submit</Button>
<DrawerClose render={<Button variant="outline" />}>Cancel</DrawerClose>
</DrawerFooter>
</DrawerContent>
</Drawer>Examples#
Directions#
"use client"
import { Button } from "@/components/ui/button"
import {
Drawer,
DrawerClose,
DrawerContent,
DrawerDescription,
DrawerFooter,
DrawerHeader,
DrawerTitle,
DrawerTrigger,
} from "@/components/ui/drawer"
export function DrawerDirections() {
return (
<div className="flex flex-wrap items-center gap-2">
{(["right", "left", "up"] as const).map((direction) => (
<Drawer key={direction} swipeDirection={direction} showSwipeHandle>
<DrawerTrigger
render={<Button variant="secondary" className="capitalize" />}
>
{direction}
</DrawerTrigger>
<DrawerContent>
<DrawerHeader>
<DrawerTitle>Swipe {direction} to close</DrawerTitle>
<DrawerDescription>
Drag the panel, or press Escape.
</DrawerDescription>
</DrawerHeader>
<DrawerFooter>
<DrawerClose render={<Button variant="outline" />}>
Close
</DrawerClose>
</DrawerFooter>
</DrawerContent>
</Drawer>
))}
</div>
)
}API Reference#
Drawer is built on the Base UI Drawer primitive. See the Base UI documentation for every prop.