Sidebar Toggle
Responsive toggle button for opening and closing the sidebar. Install Sidebar Toggle from the VLLNT UI registry with the shadcn CLI.
Responsive toggle button for opening and closing the sidebar. Part of the navigation family in VLLNT UI, it ships as a machine-readable registry entry — copy the source directly into your app with the shadcn CLI and own it, no runtime dependency on a component library.
Preview
Switch between light and dark to inspect the embedded Storybook preview.
Installation
Add Sidebar Toggle to your project with the shadcn CLI. The source lands in your codebase, ready to adapt:
pnpm dlx shadcn@latest add https://ui.vllnt.ai/r/sidebar-toggle.jsonSource
"use client";
import { Menu, X } from "lucide-react";
import { cn } from "../../lib/utils";
import { Button } from "../button/button";
export type SidebarToggleProps = {
className?: string;
/** Called when user clicks the toggle. */
onToggle: () => void;
/** Whether the sidebar is open. */
open: boolean;
};
/** Responsive sidebar toggle button that shows Menu/X icons based on state. */
export function SidebarToggle({
className,
onToggle,
open,
}: SidebarToggleProps) {
return (
<>
{/* Mobile: shows X when open, Menu when closed */}
<Button
aria-label={open ? "Close menu" : "Open menu"}
className={cn("lg:hidden", className)}
onClick={onToggle}
size="icon"
variant="ghost"
>
{open ? <X className="size-5" /> : <Menu className="size-5" />}
</Button>
{/* Desktop: always shows Menu icon */}
<Button
aria-label="Toggle sidebar"
className={cn("hidden lg:flex", className)}
onClick={onToggle}
size="icon"
variant="ghost"
>
<Menu className="size-5" />
</Button>
</>
);
}
Stories
Explore every variant and state in the interactive Storybook:
Preview
Switch between light and dark to inspect the embedded Storybook preview.