Drawer
Drawer is a compound component that provides drawer functionality.
Active
Examples
direction
Different direction options for the Drawer component.
bottom
top
left
right
Installation
npm install @your-design-system/drawer"use client"
import * as React from "react"
import { Minus, Plus } 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)
function onClick(adjustment: number) {
setGoal(Math.max(200, Math.min(400, goal + adjustment)))
}
return (
<Drawer>
<DrawerTrigger asChild>
<Button variant="outline">Open Drawer</Button>
</DrawerTrigger>
<DrawerContent>
<div className="mx-auto w-full max-w-sm">
<DrawerHeader>
<DrawerTitle>Move Goal</DrawerTitle>
<DrawerDescription>Set your daily activity goal.</DrawerDescription>
</DrawerHeader>
<div className="p-4 pb-0">
<div className="flex items-center justify-center space-x-2">
<Button
variant="outline"
size="sm"
className="h-8 w-8 shrink-0 rounded-full"
onClick={() => onClick(-10)}
disabled={goal <= 200}
>
<Minus className="h-4 w-4" />
<span className="sr-only">Decrease</span>
</Button>
<div className="flex-1 text-center">
<div className="text-7xl font-bold tracking-tighter">
{goal}
</div>
<div className="text-[0.70rem] uppercase text-muted-foreground">
Calories/day
</div>
</div>
<Button
variant="outline"
size="sm"
className="h-8 w-8 shrink-0 rounded-full"
onClick={() => onClick(10)}
disabled={goal >= 400}
>
<Plus className="h-4 w-4" />
<span className="sr-only">Increase</span>
</Button>
</div>
<div className="mt-3 h-[120px]">
<div className="flex h-full items-end justify-center space-x-1">
{Array.from({ length: 7 }).map((_, i) => (
<div
key={i}
className="bg-muted rounded-sm flex-1"
style={{
height: `${Math.random() * 100}%`,
}}
/>
))}
</div>
</div>
</div>
<DrawerFooter>
<Button>Submit</Button>
<DrawerClose asChild>
<Button variant="outline">Cancel</Button>
</DrawerClose>
</DrawerFooter>
</div>
</DrawerContent>
</Drawer>
)
}API Reference
| Prop | Type | Default | Description |
|---|---|---|---|
open | boolean | - | The open prop for the component. |
title | string | - | The title prop for the component. |
description | string | - | The description prop for the component. |
Styling
The component uses Tailwind CSS classes for styling. You can customize the appearance by overriding these classes.
Base Classes
fixedz-50flexflex-colborderbg-backgrounddirection Variants
bottom
inset-x-0bottom-0rounded-t-[10px]top
inset-x-0top-0rounded-b-[10px]left
inset-y-0left-0rounded-r-[10px]right
inset-y-0right-0rounded-l-[10px]Design System Compliance
This component is validated against atomic design principles and foundation token usage.
⚠ Atomic Design Issues
Issue 1Hardcoded spacing found: bottom-0, top-0. Use semantic spacing tokens.
Fix these issues to ensure your component integrates properly with the design system.
On This Page