A responsive component that automatically switches between a dropdown menu on desktop and a drawer on mobile devices for shadcn/ui.
The easiest way to install DropDrawer is through the shadcn registry:
DropDrawer is designed as a drop-in replacement for shadcn/ui's DropdownMenu component. Simply replace your imports:
import {
DropDrawer,
DropDrawerContent,
DropDrawerItem,
DropDrawerTrigger,
} from "@/components/ui/dropdrawer";import { MoreVertical } from "lucide-react";
import { Button } from "@/components/ui/button";
import {
DropDrawer,
DropDrawerContent,
DropDrawerItem,
DropDrawerTrigger,
} from "@/components/ui/dropdrawer";
export default function BasicExample() {
return (
<DropDrawer>
<DropDrawerTrigger asChild>
<Button variant="ghost" size="icon">
<MoreVertical className="h-4 w-4" />
</Button>
</DropDrawerTrigger>
<DropDrawerContent>
<DropDrawerItem>Profile</DropDrawerItem>
<DropDrawerItem>Settings</DropDrawerItem>
<DropDrawerItem variant="destructive">Sign out</DropDrawerItem>
</DropDrawerContent>
</DropDrawer>
);
}import { Settings, User, LogOut } from "lucide-react";
export default function WithIconsExample() {
return (
<DropDrawer>
<DropDrawerTrigger asChild>
<Button variant="outline">Menu</Button>
</DropDrawerTrigger>
<DropDrawerContent>
<DropDrawerItem icon={<User className="h-4 w-4" />}>
Profile
</DropDrawerItem>
<DropDrawerItem icon={<Settings className="h-4 w-4" />}>
Settings
</DropDrawerItem>
<DropDrawerItem
variant="destructive"
icon={<LogOut className="h-4 w-4" />}
>
Sign out
</DropDrawerItem>
</DropDrawerContent>
</DropDrawer>
);
}import {
DropDrawer,
DropDrawerContent,
DropDrawerItem,
DropDrawerSub,
DropDrawerSubContent,
DropDrawerSubTrigger,
DropDrawerTrigger,
} from "@/components/ui/dropdrawer";
export default function NestedExample() {
return (
<DropDrawer>
<DropDrawerTrigger asChild>
<Button variant="outline">Menu</Button>
</DropDrawerTrigger>
<DropDrawerContent>
<DropDrawerItem>Profile</DropDrawerItem>
<DropDrawerSub>
<DropDrawerSubTrigger>Settings</DropDrawerSubTrigger>
<DropDrawerSubContent>
<DropDrawerItem>General</DropDrawerItem>
<DropDrawerItem>Privacy</DropDrawerItem>
<DropDrawerItem>Security</DropDrawerItem>
</DropDrawerSubContent>
</DropDrawerSub>
<DropDrawerItem variant="destructive">Sign out</DropDrawerItem>
</DropDrawerContent>
</DropDrawer>
);
}NarakCODE
just now
Click the menu button to see it in action.
Switch between desktop and mobile view to see the responsive behavior.