Sidebar
Collapsible navigation sidebar with dot notation, icon items, groups, and layout variants.
Preview
Dashboard
Your main content goes here.
Installation
npx drivn add sidebarUsage
1 import { Sidebar } from "@/components/ui/sidebar" 2 import { Home, Settings, Users, Inbox, PanelLeft } from "lucide-react" 3 4 export default function Layout({ children }) { 5 const [collapsed, setCollapsed] = React.useState(false) 6 7 return ( 8 <div className="flex min-h-svh"> 9 <Sidebar collapsed={collapsed} onCollapsedChange={setCollapsed}> 10 <Sidebar.Header> 11 <span className="text-sm font-semibold">Drivn</span> 12 </Sidebar.Header> 13 <Sidebar.Content> 14 <Sidebar.Group heading="Menu"> 15 <Sidebar.Item icon={Home} active>Dashboard</Sidebar.Item> 16 <Sidebar.Item icon={Inbox} badge={3}>Inbox</Sidebar.Item> 17 <Sidebar.Item icon={Users}>Team</Sidebar.Item> 18 </Sidebar.Group> 19 </Sidebar.Content> 20 </Sidebar> 21 <main className="flex-1"> 22 <header className="flex items-center gap-3 px-4 py-3 border-b"> 23 <button onClick={() => setCollapsed(!collapsed)}> 24 <PanelLeft className="w-4 h-4" /> 25 </button> 26 <h1>Dashboard</h1> 27 </header> 28 <div className="p-6">{children}</div> 29 </main> 30 </div> 31 ) 32 }
Default
Standard sidebar with a right border.
Content area
Floating
Rounded corners, shadow, and margin for a detached look.
Content area
Collapsible
Use controlled state to toggle between expanded and collapsed views.
Dashboard
Toggle via the icon or the sidebar collapse button.
Groups
Organize items into labeled, collapsible groups.
Icons & Badges
Items support icon components and badge indicators.
API Reference
Sidebar
| Prop | Type | Default | Description |
|---|---|---|---|
defaultCollapsed | boolean | false | Whether the sidebar starts collapsed (uncontrolled). |
collapsed | boolean | — | Controlled collapsed state. Use with onCollapsedChange. |
onCollapsedChange | (collapsed: boolean) => void | — | Callback when collapsed state changes. |
variant | 'default' | 'floating' | 'default' | Visual style variant. |
side | 'left' | 'right' | 'left' | Which side the sidebar is on. |
className | string | — | Additional CSS classes to apply. |
Sidebar.Header
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | — | Header content (logo, branding). |
className | string | — | Additional CSS classes to apply. |
Sidebar.Content
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | — | Scrollable content area. |
className | string | — | Additional CSS classes to apply. |
Sidebar.Footer
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | — | Footer content (user info, settings). |
className | string | — | Additional CSS classes to apply. |
Sidebar.Group
| Prop | Type | Default | Description |
|---|---|---|---|
heading | string | — | Group label text. Hidden when sidebar is collapsed. |
defaultOpen | boolean | true | Whether the group starts expanded. |
collapsible | boolean | true | Whether the group heading toggles content visibility. |
className | string | — | Additional CSS classes to apply. |
Sidebar.Item
| Prop | Type | Default | Description |
|---|---|---|---|
icon | ComponentType | ReactElement | — | Icon component reference or JSX element. |
active | boolean | false | Whether the item is currently active. |
badge | string | number | — | Badge content displayed on the right side. |
children | ReactNode | — | Item label text. |
className | string | — | Additional CSS classes to apply. |
Sidebar.Separator
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | — | Additional CSS classes to apply. |
Sidebar.CollapseButton
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | — | Additional CSS classes to apply. |