Sidebar
A composable, themeable and customizable sidebar component.
Installation
pnpm dlx cubix@latest add sidebarUsage
import {
Sidebar,
SidebarContent,
SidebarGroup,
SidebarGroupContent,
SidebarGroupLabel,
SidebarInset,
SidebarMenu,
SidebarMenuButton,
SidebarMenuItem,
SidebarProvider,
SidebarTrigger,
} from "@/components/cubix/sidebar"<SidebarProvider>
<Sidebar>
<SidebarContent />
</Sidebar>
<SidebarInset>
<SidebarTrigger />
</SidebarInset>
</SidebarProvider>Composition
Use the following composition to build a sidebar layout:
SidebarProvider
├── Sidebar
│ ├── SidebarHeader
│ ├── SidebarContent
│ │ └── SidebarGroup
│ │ ├── SidebarGroupLabel
│ │ └── SidebarGroupContent
│ │ └── SidebarMenu
│ │ └── SidebarMenuItem
│ │ └── SidebarMenuButton
│ ├── SidebarFooter
│ └── SidebarRail
└── SidebarInset
└── SidebarTriggerSide
Use the side prop to place the sidebar on the left or right.
<Sidebar side="left" />
<Sidebar side="right" />Collapsible
Use the collapsible prop to control how the sidebar collapses. offcanvas slides away, icon collapses to icons, and none disables collapsing.
<Sidebar collapsible="offcanvas" />
<Sidebar collapsible="icon" />
<Sidebar collapsible="none" />API Reference
SidebarProvider
| Prop | Type | Default | Description |
|---|---|---|---|
| defaultOpen | boolean | true | Initial open state when uncontrolled. |
| open | boolean | - | Controlled open state of the sidebar. |
| onOpenChange | (open: boolean) => void | - | Called when the open state changes. |
| className | string | - | Additional Tailwind classes merged with the wrapper styles (last one wins). |
| children | React.ReactNode | - | Sidebar and inset content. |
Sidebar
| Prop | Type | Default | Description |
|---|---|---|---|
| side | "left" | "right" | "left" | Which side of the layout the sidebar appears on. |
| variant | "sidebar" | "floating" | "inset" | "sidebar" | Visual style of the sidebar panel. |
| collapsible | "offcanvas" | "icon" | "none" | "offcanvas" | How the sidebar collapses on desktop. |
| className | string | - | Additional Tailwind classes merged with the component styles (last one wins). |
| children | React.ReactNode | - | Header, content, footer, and related parts. |
SidebarMenuButton
| Prop | Type | Default | Description |
|---|---|---|---|
| isActive | boolean | false | Marks the menu button as the active item. |
| variant | "default" | "outline" | "default" | Visual variant of the menu button. |
| size | "default" | "sm" | "lg" | "default" | Size of the menu button. |
| tooltip | string | TooltipContent props | - | Tooltip shown when the sidebar is collapsed to icons. |
| render | React.ReactElement | - | Compose the button onto a child element such as an anchor (Base UI). |
| asChild | boolean | - | Compose the button onto a child element such as an anchor (Radix UI). |