Components
Sidebar
Built on Base UIA navigation column that collapses to a rail of icons.
Installation
npx nook-ui@latest add sidebarPrompt
Paste this into your AI coding assistant. It adds this exact component, the same way the CLI does, and tells the assistant how to use it.
Short. For assistants that can run commands in your project.
Add the Nook "Sidebar" component to this project, exactly as Nook ships it.
A navigation column that collapses to a rail of icons.
Steps
1. Check for `nook.json` in the project root. If it is missing, run `npx nook-ui@latest init` first (React or Next.js with Tailwind CSS v4). It adds the Nook tokens, the theme and `cn()`.
2. Run `npx nook-ui@latest add sidebar`. It writes `components/ui/sidebar.tsx` together with everything the component needs. Do not write the component from memory.
3. If you cannot run commands, fetch http://localhost:3000/r/sidebar.json, write every entry of `files` to the path it names, install the packages in `dependencies`, and repeat for each name in `registryDependencies`.
4. Use it where I ask. Start from this example:
```tsx
"use client";
import { CalendarIcon, CheckIcon, InfoIcon, SearchIcon, StarIcon } from "@/components/icons";
import { Avatar, AvatarFallback } from "@/components/ui/avatar";
import {
Sidebar,
SidebarContent,
SidebarFooter,
SidebarGroup,
SidebarGroupLabel,
SidebarHeader,
SidebarInset,
SidebarMenu,
SidebarMenuBadge,
SidebarMenuButton,
SidebarMenuItem,
SidebarProvider,
SidebarTrigger,
} from "@/components/ui/sidebar";
export default function SidebarDefault() {
return (
<SidebarProvider className="h-96 overflow-hidden rounded-lg border border-border bg-background">
<Sidebar aria-label="Workspace">
<SidebarHeader>
<SidebarMenuButton aria-label="Search">
<SearchIcon />
<span className="text-muted-foreground">Search</span>
</SidebarMenuButton>
</SidebarHeader>
<SidebarContent>
<SidebarGroup>
<SidebarGroupLabel>Work</SidebarGroupLabel>
<SidebarMenu>
<SidebarMenuItem>
<SidebarMenuButton active href="#tasks">
<CheckIcon />
<span>My tasks</span>
</SidebarMenuButton>
<SidebarMenuBadge>12</SidebarMenuBadge>
</SidebarMenuItem>
<SidebarMenuItem>
<SidebarMenuButton href="#calendar">
<CalendarIcon />
<span>Calendar</span>
</SidebarMenuButton>
</SidebarMenuItem>
<SidebarMenuItem>
<SidebarMenuButton href="#starred">
<StarIcon />
<span>Starred</span>
</SidebarMenuButton>
<SidebarMenuBadge>3</SidebarMenuBadge>
</SidebarMenuItem>
</SidebarMenu>
</SidebarGroup>
<SidebarGroup>
<SidebarGroupLabel>Help</SidebarGroupLabel>
<SidebarMenu>
<SidebarMenuItem>
<SidebarMenuButton href="#guides">
<InfoIcon />
<span>Guides</span>
</SidebarMenuButton>
</SidebarMenuItem>
</SidebarMenu>
</SidebarGroup>
</SidebarContent>
<SidebarFooter>
<div className="flex items-center gap-2 overflow-hidden px-1 py-1">
<Avatar className="size-7 shrink-0 text-xs">
<AvatarFallback>MC</AvatarFallback>
</Avatar>
<span className="min-w-0 truncate group-data-[collapsed]/sidebar:hidden">Maya Chen</span>
</div>
</SidebarFooter>
</Sidebar>
<SidebarInset>
<div className="flex h-12 shrink-0 items-center gap-2 border-b border-border px-3">
<SidebarTrigger />
<h3 className="text-sm font-medium">My tasks</h3>
</div>
<div className="grid flex-1 content-start gap-2 p-4 text-sm text-muted-foreground">
<p>12 open, 3 due this week.</p>
<p>Collapse the sidebar to give the page more room.</p>
</div>
</SidebarInset>
</SidebarProvider>
);
}
```
API
- `SidebarProvider`: Wraps the sidebar and the page, and holds the collapsed state.
- `collapsed` (`boolean`): Controlled state.
- `defaultCollapsed` (`boolean`, default false): Initial state when uncontrolled.
- `onCollapsedChange` (`(collapsed: boolean) => void`): Called when it changes.
- `Sidebar, SidebarHeader, SidebarContent, SidebarFooter`: The column and its three regions. The content scrolls.
- `SidebarGroup, SidebarGroupLabel, SidebarMenu, SidebarMenuItem, SidebarMenuBadge`: A labelled list of items, with optional counts.
- `SidebarMenuButton`: One row: an icon, then the name in a `span`.
- `active` (`boolean`): Marks the item for the page being viewed.
- `href` (`string`): Makes the row a link.
- `render` (`ReactElement`): Render your router's link instead.
- `SidebarTrigger, SidebarInset, useSidebar`: The collapse button, the page next to the sidebar, and a hook to read or set the state.
Rules
- Colors, radii, shadows and motion come from Nook tokens and classes such as `bg-primary`, `text-muted-foreground`, `border-border`, `rounded-lg` and `h-control`. Never hard-code them.
- Do not restyle or simplify the file. Change how it looks through `className`, its props and the theme.
- It must keep working with the keyboard, in light and dark mode, and in the sharp, soft and bold styles.
- Accessibility: The sidebar is a complementary landmark: name it with `aria-label`. The trigger reports `aria-expanded`. Collapsed items keep their names for assistive tech, and the current page is marked with `aria-current`.
Done when the component renders like the example in light and dark mode and the project type-checks.Usage
"use client";
import { CalendarIcon, CheckIcon, InfoIcon, SearchIcon, StarIcon } from "@/components/icons";
import { Avatar, AvatarFallback } from "@/components/ui/avatar";
import {
Sidebar,
SidebarContent,
SidebarFooter,
SidebarGroup,
SidebarGroupLabel,
SidebarHeader,
SidebarInset,
SidebarMenu,
SidebarMenuBadge,
SidebarMenuButton,
SidebarMenuItem,
SidebarProvider,
SidebarTrigger,
} from "@/components/ui/sidebar";
export default function SidebarDefault() {
return (
<SidebarProvider className="h-96 overflow-hidden rounded-lg border border-border bg-background">
<Sidebar aria-label="Workspace">
<SidebarHeader>
<SidebarMenuButton aria-label="Search">
<SearchIcon />
<span className="text-muted-foreground">Search</span>
</SidebarMenuButton>
</SidebarHeader>
<SidebarContent>
<SidebarGroup>
<SidebarGroupLabel>Work</SidebarGroupLabel>
<SidebarMenu>
<SidebarMenuItem>
<SidebarMenuButton active href="#tasks">
<CheckIcon />
<span>My tasks</span>
</SidebarMenuButton>
<SidebarMenuBadge>12</SidebarMenuBadge>
</SidebarMenuItem>
<SidebarMenuItem>
<SidebarMenuButton href="#calendar">
<CalendarIcon />
<span>Calendar</span>
</SidebarMenuButton>
</SidebarMenuItem>
<SidebarMenuItem>
<SidebarMenuButton href="#starred">
<StarIcon />
<span>Starred</span>
</SidebarMenuButton>
<SidebarMenuBadge>3</SidebarMenuBadge>
</SidebarMenuItem>
</SidebarMenu>
</SidebarGroup>
<SidebarGroup>
<SidebarGroupLabel>Help</SidebarGroupLabel>
<SidebarMenu>
<SidebarMenuItem>
<SidebarMenuButton href="#guides">
<InfoIcon />
<span>Guides</span>
</SidebarMenuButton>
</SidebarMenuItem>
</SidebarMenu>
</SidebarGroup>
</SidebarContent>
<SidebarFooter>
<div className="flex items-center gap-2 overflow-hidden px-1 py-1">
<Avatar className="size-7 shrink-0 text-xs">
<AvatarFallback>MC</AvatarFallback>
</Avatar>
<span className="min-w-0 truncate group-data-[collapsed]/sidebar:hidden">Maya Chen</span>
</div>
</SidebarFooter>
</Sidebar>
<SidebarInset>
<div className="flex h-12 shrink-0 items-center gap-2 border-b border-border px-3">
<SidebarTrigger />
<h3 className="text-sm font-medium">My tasks</h3>
</div>
<div className="grid flex-1 content-start gap-2 p-4 text-sm text-muted-foreground">
<p>12 open, 3 due this week.</p>
<p>Collapse the sidebar to give the page more room.</p>
</div>
</SidebarInset>
</SidebarProvider>
);
}Examples
Collapsed to icons
With a footer
Controlled
Props
SidebarProvider
Wraps the sidebar and the page, and holds the collapsed state.
| Prop | Type | Default | Description |
|---|---|---|---|
| collapsed | boolean | – | Controlled state. |
| defaultCollapsed | boolean | false | Initial state when uncontrolled. |
| onCollapsedChange | (collapsed: boolean) => void | – | Called when it changes. |
Sidebar, SidebarHeader, SidebarContent, SidebarFooter
The column and its three regions. The content scrolls.
SidebarGroup, SidebarGroupLabel, SidebarMenu, SidebarMenuItem, SidebarMenuBadge
A labelled list of items, with optional counts.
SidebarMenuButton
One row: an icon, then the name in a `span`.
| Prop | Type | Default | Description |
|---|---|---|---|
| active | boolean | – | Marks the item for the page being viewed. |
| href | string | – | Makes the row a link. |
| render | ReactElement | – | Render your router's link instead. |
SidebarTrigger, SidebarInset, useSidebar
The collapse button, the page next to the sidebar, and a hook to read or set the state.
Accessibility
The sidebar is a complementary landmark: name it with `aria-label`. The trigger reports `aria-expanded`. Collapsed items keep their names for assistive tech, and the current page is marked with `aria-current`.
Checked against WCAG 2.1 AA with automated axe tests and keyboard tests on every release.