Components
Collapsible Sidebar
A sidebar that collapses to icons.
<CollapsibleSidebar items={items} current="#inbox" />Installation
npx shadcn@latest add https://ui.zjkm.tech/r/collapsible-sidebar.jsonimport { CollapsibleSidebar } from "@/components/collapsible-sidebar"Using JavaScript? Set tsx: false in components.json and the CLI converts it.
New to shadcn? Run npx shadcn@latest init first. The CLI needs components.json and the @/ import alias.
Usage
A sidebar that collapses to icons with the button at its foot. Collapsed, each label stays as its link's accessible name and shows as a tooltip on hover.
import { HugeiconsIcon } from "@hugeicons/react";
import { Home01Icon, InboxIcon } from "@hugeicons/core-free-icons";
import { CollapsibleSidebar } from "@/components/collapsible-sidebar";
const items = [
{ label: "Home", href: "/", icon: <HugeiconsIcon icon={Home01Icon} size={18} /> },
{ label: "Inbox", href: "/inbox", icon: <HugeiconsIcon icon={InboxIcon} size={18} /> },
];
export function AppSidebar({ path }: { path: string }) {
return <CollapsibleSidebar items={items} current={path} />;
}Props
| Prop | Type | Default | Description |
|---|---|---|---|
items | { label, href, icon }[] | The links. | |
current | string | The current page's href, marked with aria-current. | |
label | string | "Main" | Accessible name of the nav. |
defaultCollapsed | boolean | false | Start collapsed. |
className | string | Classes for the root element. |
With reduced motion, it collapses without animating its width.