Sidebar
A clean, modern sidebar with expanded and collapsed states, sub-menus, and active states.
Installation
bunx --bun shadcn@latest add "https://quatadahnasdami.xyz/r/sidebar.json"
Usage
import {
Sidebar,
SidebarContent,
SidebarHeader,
SidebarItem,
SidebarProfile,
SidebarSearch,
} from "@/components/sidebar";export default function Layout({ children }) {
return (
<div className="flex h-screen overflow-hidden">
<Sidebar>
<SidebarHeader>
<SidebarProfile
name="Thomas Brown"
email="thomas@riverstone.com"
avatar="/avatar.png"
/>
</SidebarHeader>
<SidebarSearch />
<SidebarContent>
<SidebarItem icon={Home01Icon} label="Home" active />
<SidebarItem icon={PackageIcon} label="Products" />
</SidebarContent>
</Sidebar>
<main className="flex-1 overflow-auto">{children}</main>
</div>
);
}Collapsed State
The sidebar supports a collapsed state that shows only icons and a red dot for notifications.
const [expanded, setExpanded] = useState(true);
<Sidebar expanded={expanded} onExpandedChange={setExpanded}>
{/* ... */}
</Sidebar>Sub-menus
You can add sub-items to a sidebar item by passing hasChildren and rendering children.
const [paymentsExpanded, setPaymentsExpanded] = useState(false);
<SidebarItem
icon={CreditCardIcon}
label="Payments"
hasChildren
expanded={paymentsExpanded}
onClick={() => setPaymentsExpanded(!paymentsExpanded)}
>
<SidebarSubItem label="Pay" />
<SidebarSubItem label="Get paid" />
</SidebarItem>API Reference
Sidebar
| Prop | Type | Default | Description |
|---|---|---|---|
defaultExpanded | boolean | true | Initial expanded state. |
expanded | boolean | - | Controlled expanded state. |
onExpandedChange | function | - | Called when expanded state changes. |
SidebarItem
| Prop | Type | Default | Description |
|---|---|---|---|
icon | IconType | - | Hugeicons icon component. |
label | string | - | Item label text. |
active | boolean | false | Whether the item is active. |
badge | string | number | - | Notification badge value. |
hasChildren | boolean | false | Whether the item has sub-items. |
expanded | boolean | false | Whether the sub-menu is expanded. |
onClick | function | - | Click handler. |
TABLE OF CONTENTS