# Rail sidebar

A shadcn/ui app sidebar with an icon rail of areas beside a panel of links, where the rail, panel and top bar line up at any icon or row size.

> 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:** Apps with several areas, each with its own list; Mail, calendar and project tools in one app; Admin consoles with sections and sub-pages; Products moving from a flat sidebar to areas
- **Category:** Navigation · **Type:** Sidebars · **Style:** Minimal, Dark mode
- **See it:** [Live preview](https://www.craftui.space/docs/blocks/rail-sidebar) · [Screenshot](https://www.craftui.space/llms.md/preview/rail-sidebar.7d78189a.jpg)

![Rail sidebar](https://www.craftui.space/llms.md/preview/rail-sidebar.7d78189a.jpg)

## Install

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

This is a paid item (BLK-G20JA6): 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 RailSidebar from "@/components/blocks/rail-sidebar/rail-sidebar";

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

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

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `areas` | `Area[]` | `DEFAULT_AREAS` | The areas: a rail button each, and a panel of links. |
| `workspaces` | `Workspace[]` | `DEFAULT_WORKSPACES` | Workspaces in the rail's switcher; the first is current. |
| `user` | `SidebarUser` | `DEFAULT_USER` | The signed-in person, at the foot of the rail. |
| `defaultArea` | `string` | — | Id of the area that starts open. Defaults to "projects", or the first. |
| `defaultActive` | `string` | — | Id of the link that starts active. Defaults to the open area's first. |
| `onNavigate` | `(id: string) => void` | — | Called with the id of each link picked. |
| `onAreaChange` | `(id: string) => void` | — | Called with the id of each area opened from the rail. |
| `onSwitchWorkspace` | `(id: string) => void` | — | Called when a workspace is picked in the switcher. |
| `onCreateWorkspace` | `() => void` | — | Called from the switcher's "Create workspace". |
| `onCreate` | `(areaId: string) => void` | — | Called from the panel's new button, with the open area's id. |
| `onHelp` | `() => void` | — | Called from the rail's help button. |
| `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 numbers in sidebar-vars.ts, e.g. `{ "--sb-icon": "1.25rem", "--sb-panel": "16rem" }`. The rail's width and every line follow from them. |

### `Area`

| Field | Type | Description |
| --- | --- | --- |
| `id` (required) | `string` | Unique id. |
| `label` (required) | `string` | Name: the rail button's tooltip and the panel's title, e.g. "Projects". |
| `icon` (required) | `IconSvgElement` | A Hugeicons icon for the rail button. |
| `groups` (required) | `NavGroup[]` | The panel's groups, in order. |

### `Workspace`

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

### `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. |

### `NavGroup`

| Field | Type | Description |
| --- | --- | --- |
| `id` (required) | `string` | Unique id within the area. |
| `label` | `string` | Small heading above the links, e.g. "Archived". Leave out for none. |
| `items` (required) | `NavItem[]` | The links, in order. |

### `NavItem`

| Field | Type | Description |
| --- | --- | --- |
| `id` (required) | `string` | Unique id across all areas; matched against the active id. |
| `label` (required) | `string` | Text in the row, e.g. "Mobile app". |
| `icon` (required) | `IconSvgElement` | A Hugeicons icon from `@hugeicons/core-free-icons`. |
| `href` | `string` | Link target. Without it the row only changes the active item. |
| `count` | `number` | A small count shown on the right spine, e.g. open tasks. |

## Files

The install adds:

- `components/blocks/rail-sidebar/rail-sidebar.tsx`
- `components/blocks/rail-sidebar/rail.tsx`
- `components/blocks/rail-sidebar/panel.tsx`
- `components/blocks/rail-sidebar/nav-data.ts`
- `components/blocks/rail-sidebar/sidebar-vars.ts`
- `components/blocks/rail-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`, `tooltip`.