# Collapsible sidebar

A shadcn/ui app sidebar that collapses to icons, where no icon moves: names fade in place, counts become dots and names become tooltips.

> For the complete documentation index, see [llms.txt](/llms.txt). Markdown variants are available for the docs, pricing and about pages: append `.md` to the URL or send an `Accept: text/markdown` header (the home page answers the header too). An agent skill is available at [/.well-known/agent-skills/site-skill.md](/.well-known/agent-skills/site-skill.md).

## At a glance

- **Good for:** Dense work apps that need room for the page; Dashboards with an icons-only sidebar; SaaS apps people switch to a compact sidebar; Editors and tools with a collapsible nav
- **Category:** Navigation · **Type:** Sidebars · **Style:** Motion, Minimal, Dark mode
- **See it:** [Live preview](https://www.craftui.space/docs/blocks/collapsible-sidebar) · [Screenshot](https://www.craftui.space/llms.md/preview/collapsible-sidebar.6a8ce538.jpg)

![Collapsible sidebar](https://www.craftui.space/llms.md/preview/collapsible-sidebar.6a8ce538.jpg)

## Install

```bash
pnpm dlx shadcn@latest add https://www.craftui.space/r/collapsible-sidebar.json
```

This is a paid item (BLK-2RRQ1F): the install needs a craftUI plan or a purchase of it. Signed in, the docs page gives your personal install command. Plans: https://www.craftui.space/pricing

## Usage

```tsx
import CollapsibleSidebar from "@/components/blocks/collapsible-sidebar/collapsible-sidebar";

export default function Page() {
  return <CollapsibleSidebar />;
}
```

With no props it renders with demo content; pass your own through the props below.

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `workspaces` | `Workspace[]` | `DEFAULT_WORKSPACES` | Workspaces in the header's switcher; the first is current. |
| `top` | `NavItem[]` | `DEFAULT_TOP` | Rows above the first section, with no label (Home, Inbox, My issues). |
| `sections` | `NavSection[]` | `DEFAULT_SECTIONS` | Labelled sections, in order. |
| `user` | `SidebarUser` | `DEFAULT_USER` | The signed-in person, shown in the footer. |
| `defaultActive` | `string` | `"inbox"` | Id of the row that starts active. Defaults to "inbox", or the first. |
| `defaultCollapsed` | `boolean` | `false` | Whether it starts collapsed to icons. Defaults to full width. |
| `onNavigate` | `(id: string) => void` | — | Called with the id of each row picked. |
| `onSwitchWorkspace` | `(id: string) => void` | — | Called when a workspace is picked in the switcher. |
| `onCreateWorkspace` | `() => void` | — | Called from the switcher's "Create workspace". |
| `children` | `React.ReactNode` | — | The page beside the sidebar. Defaults to placeholder content. |
| `className` | `string` | — | Height and placement, e.g. "h-svh" (the default) or "h-[40rem]". |
| `style` | `React.CSSProperties` | — | Sizes for this one sidebar, overriding the five numbers in sidebar-vars.ts, e.g. `{ "--sb-icon": "1.25rem", "--sb-row": "2.5rem" }`. The collapsed width and every line follow from them. |

### `Workspace`

| Field | Type | Description |
| --- | --- | --- |
| `id` (required) | `string` | Unique id. |
| `name` (required) | `string` | Name shown in the header, e.g. "Northwind". |
| `color` (required) | `string` | Background of the workspace's monogram, any CSS colour. |

### `NavItem`

| Field | Type | Description |
| --- | --- | --- |
| `id` (required) | `string` | Unique id; matched against the active id. |
| `label` (required) | `string` | Text in the row; also its tooltip when the sidebar is collapsed. |
| `icon` (required) | `IconSvgElement` | A Hugeicons icon from `@hugeicons/core-free-icons`. Required: it's the only thing showing when collapsed. |
| `href` | `string` | Link target. Without it the row only changes the active item. |
| `count` | `number` | A small count on the right spine; collapsed, it becomes a dot on the icon. |

### `NavSection`

| Field | Type | Description |
| --- | --- | --- |
| `id` (required) | `string` | Unique id. |
| `label` (required) | `string` | Small heading above the links, e.g. "Workspace". Fades when collapsed. |
| `items` (required) | `NavItem[]` | The links, in order. |

### `SidebarUser`

| Field | Type | Description |
| --- | --- | --- |
| `name` (required) | `string` | Full name, e.g. "Maya Chen". |
| `avatar` | `string` | Photo URL; the initials show while it loads or when it's missing. |

## Files

The install adds:

- `components/blocks/collapsible-sidebar/collapsible-sidebar.tsx`
- `components/blocks/collapsible-sidebar/nav-rows.tsx`
- `components/blocks/collapsible-sidebar/workspace-switcher.tsx`
- `components/blocks/collapsible-sidebar/nav-data.ts`
- `components/blocks/collapsible-sidebar/sidebar-vars.ts`
- `components/blocks/collapsible-sidebar/DESIGN.md`

npm dependencies (installed for you): `@hugeicons/core-free-icons`, `@hugeicons/react`.

shadcn/ui components it uses (the shadcn CLI adds any that are missing): `avatar`, `dropdown-menu`, `sidebar`.