Sidebar
App navigation down the left or right edge. It can collapse to icons or hide completely, and users can resize it.
// Plain markup
import { Sidebar, SidebarBody, SidebarFooter, SidebarHeader, SidebarNavItem, SidebarSection, SidebarTrigger, useSidebar } from "@shavin/ui";Collapsible navigation
variant="collapsible" lets the rail shrink to icons. SidebarTrigger in the header toggles it; collapsed items show their label in a tooltip.
Overview
Page content.
import { useState } from "react";
import {
Sidebar, SidebarHeader, SidebarBody, SidebarFooter, SidebarSection,
SidebarNavItem, SidebarTrigger, Avatar, Badge, Icon, Text,
} from "@shavin/ui";
export function BudgetSidebar() {
const [collapsed, setCollapsed] = useState(false);
const [active, setActive] = useState("overview");
return (
<Sidebar variant="collapsible" collapsed={collapsed} onCollapsedChange={setCollapsed}>
<SidebarHeader>
{!collapsed && <Text as="span" size="sm" weight="semibold">Household budget</Text>}
<SidebarTrigger />
</SidebarHeader>
<SidebarBody>
<SidebarSection title="Money">
<SidebarNavItem
label="Overview"
icon={<Icon name="LayoutDashboard" size="sm" color="inherit" />}
active={active === "overview"}
onClick={() => setActive("overview")}
/>
<SidebarNavItem
label="Bills"
icon={<Icon name="Receipt" size="sm" color="inherit" />}
badge={<Badge size="sm">3</Badge>}
active={active === "bills"}
onClick={() => setActive("bills")}
/>
</SidebarSection>
</SidebarBody>
<SidebarFooter>
<Avatar size="sm" fallback="SL" />
{!collapsed && <Text as="span" size="sm" truncate className="ml-2 flex-1">Sam Lee</Text>}
</SidebarFooter>
</Sidebar>
);
}Hide it completely
collapsibleMode="offcanvas" collapses to zero width and makes the sidebar inert, so its own trigger goes with it. Control collapsed from a button outside the sidebar.
Overview
Page content.
const [collapsed, setCollapsed] = useState(false);
<Sidebar variant="collapsible" collapsibleMode="offcanvas" collapsed={collapsed} onCollapsedChange={setCollapsed}>
…
</Sidebar>
<main>
<Button variant="outline" size="sm" onClick={() => setCollapsed(!collapsed)} aria-expanded={!collapsed}>
{collapsed ? "Show navigation" : "Hide navigation"}
</Button>
</main>Right side
side="right" moves the border to the left edge and points the trigger and tooltips the other way. Use it for a details or inspector panel next to the main content.
Transactions
Page content.
<Sidebar side="right" width="w-72">
<SidebarHeader>
<Text as="span" size="sm" weight="semibold">Transaction</Text>
</SidebarHeader>
<SidebarBody className="px-4">
{/* any content */}
</SidebarBody>
<SidebarFooter>
<Button size="sm" variant="outline" className="w-full">Split transaction</Button>
</SidebarFooter>
</Sidebar>Resizable
resizable adds a drag handle on the inner edge, clamped to minWidth and maxWidth. It is off while collapsed. persistKey remembers the width in localStorage.
Drag the sidebar's right edge
Page content.
<Sidebar resizable minWidth={200} maxWidth={360} persistKey="budget-nav">
…
</Sidebar>Floating and inset
floating sits off the edges with a margin and a raised shadow. inset is a rounded panel with a card shadow and no margin; place it inside padding of your own.
floating
Page content.
inset
Page content.
<Sidebar variant="floating" width="w-56">…</Sidebar>
<div className="p-3">
<Sidebar variant="inset" width="w-56">…</Sidebar>
</div>Parts
| Part | What it does |
|---|---|
| Sidebar | The <aside> landmark. Holds side, variant and collapsed state for every part inside it, and sets data-side, data-variant and data-state. |
| SidebarHeader | 56px top row for the product name and the trigger. Centres its content when collapsed. |
| SidebarTrigger | Inside a Sidebar, collapses and expands the rail. Inside an AppFrame but outside the Sidebar, opens the navigation drawer and only shows while the frame is compact. |
| SidebarBody | The scrolling middle. Put sections and items here. |
| SidebarSection | A group of items. With a title it becomes a labelled group; the title is visually hidden when collapsed. |
| SidebarNavItem | A button, or a link when you pass href. active sets aria-current="page". Collapsed, it shows only the icon, takes the label as its accessible name and gets a tooltip. |
| SidebarFooter | Bottom row for the signed-in person or a primary action. |
Every part except SidebarTrigger throws outside a Sidebar. For an app layout that turns the Sidebar into a drawer on narrow screens, wrap it in AppFrame; inside a compact frame the Sidebar always shows in full and the rail trigger hides.
Keyboard
| Key | Action |
|---|---|
| Tab | Moves through the trigger, the items and the resize handle. |
| Enter / Space | Activates the focused item or toggles the rail. |
| Arrow Left / Right | On the resize handle: moves the edge by 16px, 64px with Shift. |
| Home / End | On the resize handle: jumps to minWidth or maxWidth. |
| Enter | On the resize handle: resets to the starting width. Double-click does the same. |
Props
Sidebar
| Prop | Type | Default | Description |
|---|---|---|---|
| side | "left" | "right" | left | Sidebar dock side: "left" (Sidenav, left panel) or "right" (Configurator, Inspector). Default "left". |
| variant | "fixed" | "collapsible" | "floating" | "inset" | fixed | Sidebar visual variant: fixed width, collapsible rail, floating card, or inset panel. Default "fixed". |
| collapsibleMode | "icon" | "offcanvas" | "none" | icon | Collapsible mode: "icon" rail collapse, "offcanvas" full hide, or "none". Default "icon". |
| collapsed | boolean | — | Controlled collapsed state. |
| onCollapsedChange | (collapsed: boolean) => void | — | Callback fired when collapsed state changes. |
| defaultCollapsed | boolean | collapsed | Initial default collapsed state. |
| width | string | w-60 | Custom width CSS string (e.g. "w-60", "w-72", "w-80"). Default "w-60". |
| resizable | boolean | false | Enable interactive drag resizability. Default false. |
| minWidth | number | 180 | Minimum width in pixels when resizable. Default 180. |
| maxWidth | number | 420 | Maximum width in pixels when resizable. Default 420. |
| persistKey | string | — | Remember the resized width in localStorage under this key. |
| resizeColor | ResizeHandleColor | brand-subtle | Resize handle colour on hover, focus and drag. Default "brand-subtle". |
| children | ReactNode | — | Custom sidebar content. |
| className | string | — | Custom root class name. |
SidebarSection
| Prop | Type | Default |
|---|---|---|
| title | string | — |
SidebarNavItem
| Prop | Type | Default |
|---|---|---|
| icon | ReactNode | — |
| label* | string | — |
| active | boolean | — |
| badge | ReactNode | — |
| href | string | — |
| onClick | () => void | — |
| className | string | — |
* required
SidebarHeader, SidebarBody, SidebarFooter and SidebarTrigger take className and the attributes of the element they render.