Drawer
A fully reusable, accessible Drawer component inspired by iOS design patterns. It features focus trapping, scroll locking, and smooth Framer Motion animations. Built as a compound component for maximum flexibility.
ui@radix-ui/react-slotclass-variance-authorityframer-motionlucide-react
Installation
$npx futureuikit add drawer
Import
import { Drawer } from "@/components/ui/drawer"
Layout Variant
Color Theme
Placement
Size
Spacing
Named Keys & Props
Pass these exact named keys as props on <Drawer />. Click any color pill to copy the prop.
colorDefault is "default"(Black & White)variantVisual style"default""floating""glass""compact""elevated"spacingInner spacing"default""2x""4x""6x""8x"sizeComponent size"default""sm""md""lg""xl""full"Usage Example
A basic implementation example to get you started.
Example Implementation
import { Drawer, DrawerTrigger, DrawerContent, DrawerHeader, DrawerTitle, DrawerDescription, DrawerBody, DrawerFooter, DrawerClose } from"@/components/ui/drawer";
import { Button } from"@/components/ui/button";
export default function Example() {
return (
<Drawer placement="right"variant="floating">
<DrawerTrigger asChild>
<Button>Open Drawer</Button>
</DrawerTrigger>
<DrawerContent>
<DrawerHeader>
<DrawerTitle>Settings</DrawerTitle>
<DrawerDescription>Manage your preferences.</DrawerDescription>
</DrawerHeader>
<DrawerBody>
<div className="space-y-4">
<p>Profile configuration</p>
<p>Notifications</p>
</div>
</DrawerBody>
<DrawerFooter>
<DrawerClose asChild>
<Button variant="outline">Cancel</Button>
</DrawerClose>
<Button>Save Changes</Button>
</DrawerFooter>
</DrawerContent>
</Drawer>
);
}Features
Key capabilities and highlights.
Key Capabilities
- ◆Compound architecture: Drawer, Trigger, Content, Header, Title, Description, Body, Footer, and Close.
- ◆Five variants: Default, Floating, Glass, Compact, and Elevated.
- ◆Four placements: Left, Right, Top, and Bottom.
- ◆Accessible by default: Handles focus trapping, escape key to close, and scroll locking.
- ◆Smooth, physics-based animations using Framer Motion.
- ◆Clean, modern aesthetic utilizing a 4px spacing system.
Notes
Important implementation details to consider.
Implementation Details
- ◆Overview: A fully reusable, accessible Drawer component inspired by iOS design patterns. It features focus trapping, scroll locking, and smooth Framer Motion animations.
- ◆Installation: Run'npx futureuikit add drawer'to add the drawer component to your project.
- ◆Basic Usage: Import the components from'@/components/ui/drawer'and wrap your UI in the <Drawer> component. Use <DrawerTrigger> to open it and <DrawerContent> for the payload.
- ◆Variants: Pass the'variant'prop to <Drawer> to choose between'default','floating','glass','compact', and'elevated'aesthetics.
- ◆Placements: Control the slide-in direction by passing the'placement'prop ('left','right','top','bottom') to the <Drawer> component.
- ◆Accessibility: The drawer handles focus trapping, scroll locking, and Escape key functionality automatically to meet ARIA guidelines.
- ◆Best Practices: Use the'elevated'variant for dashboard settings,'floating'for quick actions, and'glass'over complex backgrounds.
- ◆API Reference: The <Drawer> accepts'isOpen'and'onOpenChange'for controlled state, and'defaultIsOpen'for uncontrolled state.
- ◆Examples: Check the live preview above to experiment with all variant and placement combinations interactively.