An app sidebar that folds to an icon rail and becomes a sheet on phones, built from parts or from a tree. Plus a docs variant with filters, counts and Pro marks. This site's own sidebar and the account pages run on it.
expanded shows the list open in the flow, as a card, instead of in a popover: for environments, projects or teams that you switch often. Each workspace can carry a swatch, any CSS background, for a square avatar. The arrow keys move and pick, like radio buttons.
Docs sidebar
Installation
$
npx knowns-ui@latest add sidebar sidebar-docs
For Claude Code, Cursor or Codex: installs it and wires the props to your own data.
Paste this into your coding agent (Claude Code, Cursor, Codex). It checks your project, sets up the registry, runs the install and verifies it.
Install prompt
Install Sidebar, Docs sidebar from Knowns UI into this project. Work step by step, show me each change, and ask before you edit files outside this project.
Context: Knowns UI (https://ui.knowns.dev) is a shadcn registry. Items land in the project as source files. Docs: https://ui.knowns.dev/docs/sidebar
1. Check the project first. Stop and tell me if any of these is missing:
- React 19 and Tailwind CSS v4.
- A components.json at the project root. If there is none, ask me before running `npx knowns-ui@latest init --no-key` (it runs shadcn init when needed, then adds the registries).
2. Run:
```bash
npx knowns-ui@latest add sidebar sidebar-docs
```
It writes these files:
- lib/knowns/run.ts
- lib/knowns/json.tsx
- lib/knowns/status.ts
- lib/knowns/tone.ts
- lib/knowns/types.ts
- lib/knowns/use-abortable.ts
- lib/knowns/utils.ts
- lib/knowns/motion.tsx
- lib/knowns/motion-utils.ts
- components/ui/knowns/use-floating.ts
- components/ui/knowns/tooltip.tsx
- components/ui/knowns/tooltip-utils.ts
- components/ui/knowns/avatar.tsx
- components/ui/knowns/kbd.tsx
- components/ui/knowns/menu.tsx
- components/ui/knowns/popover.tsx
- components/ui/knowns/spinner.tsx
- components/ui/knowns/button.tsx
- components/ui/knowns/sheet.tsx
- components/ui/knowns/blocks/sidebar/sidebar.tsx
- components/ui/knowns/blocks/sidebar/sidebar-utils.ts
- components/ui/knowns/animated-number.tsx
- components/ui/knowns/blocks/sidebar/sidebar-docs.tsx
and installs these npm packages: clsx@^2.1.1, tailwind-merge@^3.7.0, class-variance-authority@^0.7.1.
3. While it runs:
- It also adds a few @keyframes (all named kn-*) to the global CSS file (globals.css or the file components.json points at). Let it: they only add animations.
- If it asks to overwrite files under lib/knowns/: these are shared by every Knowns UI item. List them, say whether I changed them (check git), and ask me before you answer.
- If it asks to overwrite any other file, show me the diff and ask me.
4. Verify:
- Every file in the list above exists.
- The project type-checks (for example `npx tsc --noEmit`) and the dev build has no new errors.
5. Use it: follow the examples and props on https://ui.knowns.dev/docs/sidebar, and ask me if anything about my data is unclear.
If the Knowns UI MCP server is connected (https://ui.knowns.dev/docs/ai-and-mcp), use get_component({ name: "sidebar" }) or search_docs for details.
Finish with a short summary: the files you added or changed, the packages you installed, and anything I still need to do.
storageKey
string
Remembers the collapse in localStorage (<key>:collapsed). Pair it with sidebarBootScript([key]) in a <head> script so a server-rendered page paints collapsed, with no flash.
defaultCollapsed / collapsed / onCollapsedChange
boolean / boolean / (v) => void
Defaultfalse
Start as the rail, or control it.
hotkey
boolean
Defaulttrue
Cmd+B on macOS, Ctrl+B elsewhere; ignored while typing in a field. Nested in another sidebar's layout, only while focus is inside it.
mobileBelow
number
Default768
Below this width the sidebar is a modal sheet opened by SidebarTrigger.
Prop
Type
Default
Description
storageKey
string
-
Remembers the collapse in localStorage (<key>:collapsed). Pair it with sidebarBootScript([key]) in a <head> script so a server-rendered page paints collapsed, with no flash.
defaultCollapsed / collapsed / onCollapsedChange
boolean / boolean / (v) => void
false
Start as the rail, or control it.
hotkey
boolean
true
Cmd+B on macOS, Ctrl+B elsewhere; ignored while typing in a field. Nested in another sidebar's layout, only while focus is inside it.
mobileBelow
number
768
Below this width the sidebar is a modal sheet opened by SidebarTrigger.
label
string
Default"Sidebar"
Accessible name of the landmark and the sheet.
landmark
boolean
Defaulttrue
Render as an aside landmark. Set false when the sidebar is nested inside another landmark or shown as a demo.
collapsible
boolean|"offcanvas"
Defaulttrue
true collapses to the 56px icon rail (branches open flyouts on hover or click); "offcanvas" hides it fully (width 0, inert); false never collapses.
width
number
Default256
Expanded width in px.
sticky / top
boolean / number
Defaulttrue / 0
Stick to the viewport (fill its height below `top`), or fill the parent.
sheetHeader
ReactNode
The sheet's top row, beside its close button.
Motion
-
Collapsing and expanding ease the width over 180ms. Opening, the labels fade in and slide 10px into place one after another down each list (30ms apart, at most four rows apart); closing, they fade out together in 120ms. Reduced motion: instant.
Prop
Type
Default
Description
label
string
"Sidebar"
Accessible name of the landmark and the sheet.
landmark
boolean
true
Render as an aside landmark. Set false when the sidebar is nested inside another landmark or shown as a demo.
collapsible
boolean|"offcanvas"
true
true collapses to the 56px icon rail (branches open flyouts on hover or click); "offcanvas" hides it fully (width 0, inert); false never collapses.
width
number
256
Expanded width in px.
sticky / top
boolean / number
true / 0
Stick to the viewport (fill its height below `top`), or fill the parent.
sheetHeader
ReactNode
-
The sheet's top row, beside its close button.
Motion
-
-
Collapsing and expanding ease the width over 180ms. Opening, the labels fade in and slide 10px into place one after another down each list (30ms apart, at most four rows apart); closing, they fade out together in 120ms. Reduced motion: instant.
toggle
boolean|{ collapse, expand }
Puts a SidebarTrigger at the end of the first row (a logo or switcher). In the rail that row gives way and the toggle takes its place. Not shown in the mobile sheet, which has its own close button.
Prop
Type
Default
Description
toggle
boolean|{ collapse, expand }
-
Puts a SidebarTrigger at the end of the first row (a logo or switcher). In the rail that row gives way and the toggle takes its place. Not shown in the mobile sheet, which has its own close button.
label
string
Default"Toggle sidebar"
Its name on mobile, where it opens the sheet (and on desktop without labels).
labels
{ collapse, expand }
Its name and tooltip on desktop by state, e.g. "Hide sidebar" / "Show sidebar". The tooltip adds the shortcut.
look
"ghost"|"field"|"float"
Default"ghost"
field matches a search field (36px, fill, radius); float is a 36px floating button (card, hairline border, soft shadow) for a trigger fixed over the page. Its chevron points in while the sidebar is open and turns 180 degrees to point out when it is collapsed.
Prop
Type
Default
Description
label
string
"Toggle sidebar"
Its name on mobile, where it opens the sheet (and on desktop without labels).
labels
{ collapse, expand }
-
Its name and tooltip on desktop by state, e.g. "Hide sidebar" / "Show sidebar". The tooltip adds the shortcut.
look
"ghost"|"field"|"float"
"ghost"
field matches a search field (36px, fill, radius); float is a 36px floating button (card, hairline border, soft shadow) for a trigger fixed over the page. Its chevron points in while the sidebar is open and turns 180 degrees to point out when it is collapsed.
The current row: aria-current, and its branches open.
onSelect
(node) => void
Every row picked; links still navigate.
linkAs
Component
Default"a"
Your router's link, e.g. Next's Link.
storageKey
string
Remembers which branches are open.
Active pill
-
One pill behind the rows travels to the picked row (180ms, transform only) instead of the fill jumping. It follows folds and the rail without travelling. Reduced motion: it moves at once.
The current row: aria-current, and its branches open.
onSelect
(node) => void
-
Every row picked; links still navigate.
linkAs
Component
"a"
Your router's link, e.g. Next's Link.
storageKey
string
-
Remembers which branches are open.
Active pill
-
-
One pill behind the rows travels to the picked row (180ms, transform only) instead of the fill jumping. It follows folds and the rail without travelling. Reduced motion: it moves at once.
sections
DocsSection[]
{ id, label, icon?, href?, pages? | categories? }; pages take isNew and pro (true or "variants").
current
string
The current page, section or category id. Its folds open and the row scrolls into view.
filters / chips
DocsFilter[] / number
Default[] / 3
{ id, label, match, expand?, dot? }; the first `chips` are a segmented control, the rest a More menu. Empty sections drop out.
filter / onFilterChange
string / (id) => void
Control the filter, e.g. from a ?tier= query.
renderMark
(page) => ReactNode
DefaultNew dot, Pro star
Your own marks after a page's name.
onSearch / footer / storageKey / linkAs
-
The search button, a slot under the list, remembered folds, your link.
Prop
Type
Default
Description
sections
DocsSection[]
-
{ id, label, icon?, href?, pages? | categories? }; pages take isNew and pro (true or "variants").
current
string
-
The current page, section or category id. Its folds open and the row scrolls into view.
filters / chips
DocsFilter[] / number
[] / 3
{ id, label, match, expand?, dot? }; the first `chips` are a segmented control, the rest a More menu. Empty sections drop out.
filter / onFilterChange
string / (id) => void
-
Control the filter, e.g. from a ?tier= query.
renderMark
(page) => ReactNode
New dot, Pro star
Your own marks after a page's name.
onSearch / footer / storageKey / linkAs
-
-
The search button, a slot under the list, remembered folds, your link.
Keyboard: the tree is one tab stop. ↑ ↓ move between rows, Home and End jump, → opens a branch or steps into it, ← closes it or steps back to its parent. In the rail every row keeps its name: hover or focus shows it as a tooltip, and a branch opens a small flyout of its pages. On phones the sidebar is a modal dialog: focus stays inside, Escape or a tap outside closes it, focus returns to the trigger, and following a link closes it too. Motion (the rail's width, folds, the sheet's slide) turns instant with reduced motion.
What it handles
01Renders a nav tree from SidebarNode items with the tree keyboard: arrows move between visible rows, Home and End jump, Right opens or steps in, Left closes or steps out, and disabled rows are skipped.
02Collapses to a 56px icon rail with tooltips, or hides fully with collapsible="offcanvas", and toggles on Cmd or Ctrl+B unless you set hotkey to false.
03Remembers the rail and the open branches in localStorage under `storageKey`, and sidebarBootScript applies a saved collapse before the first paint so nothing jumps.
04Shows a branch in the rail as an icon that opens a small flyout of its children, so nested pages stay reachable without expanding the bar.
05Turns into a modal sheet below `mobileBelow` (768px by default), where SidebarTrigger opens it and the row of the current page is scrolled into view.
06Ships the parts around the tree: SidebarSwitcher for workspaces, SidebarSearch with a Cmd K hint, SidebarGroup with a foldable label, SidebarFooter, SidebarReveal and SidebarInset.
States
First render
Nothing. It paints in its remembered width
none
Collapse to the rail
The width switches at once and the labels fade out
120ms, ease out
Open a branch or fold a group
The rows grow or shrink and fade, and the chevron turns
180ms, ease out
Hover the trigger
Background and colour change
120ms, ease out
Mobile sheet
It slides in from the Sheet component
none
Reduced motion
Labels no longer fade and groups fold with no motion
0ms
State
What moves
Timing
First render
Nothing. It paints in its remembered width
none
Collapse to the rail
The width switches at once and the labels fade out
120ms, ease out
Open a branch or fold a group
The rows grow or shrink and fade, and the chevron turns
180ms, ease out
Hover the trigger
Background and colour change
120ms, ease out
Mobile sheet
It slides in from the Sheet component
none
Reduced motion
Labels no longer fade and groups fold with no motion
Use Copy page for AI above to give your assistant this page, Copy prompt under the install command to have it installed and wired to your data, or connect the Knowns UI MCP server and just ask:
Add the Knowns UI Sidebar to my app and wire it to my own data.
I need the main navigation of an app: sections, nested projects, counts and a workspace switcher, folding to an icon rail. Set that up with the Knowns UI Sidebar.
Which Sidebar props do I need for a minimal setup? Show me a short example.
With the server connected, your assistant calls get_component({ name: "sidebar" }) and search_docs({ query: "sidebar" }).
Need help?
Stuck on Sidebar, or found something off? We read every message.