Sidebar
uistableSidebar — from shadcn/ui (radix-nova style).
npx shadcn add @krawma/sidebarnpm: class-variance-authority@^0.7.1, lucide-react@^1.22.0, radix-ui@^1.6.1 · registry: @krawma/button, @krawma/input, @krawma/separator, @krawma/sheet, @krawma/skeleton, @krawma/tooltip, @krawma/use-mobile, @krawma/utils
Preview
Purpose
The app-shell navigation region: a collapsible left/right rail composing menu
groups, items, and actions. This is a block, not a leaf primitive — it brings
its own layout, state, and responsive behavior. Use it for primary app navigation;
for transient side content use sheet directly.
Anatomy
SidebarProvider (owns open/collapsed state; wrap the app) › Sidebar ›
SidebarHeader / SidebarContent (SidebarGroup › SidebarGroupLabel,
SidebarMenu › SidebarMenuItem › SidebarMenuButton [+ SidebarMenuAction,
SidebarMenuBadge, SidebarMenuSub]) / SidebarFooter, plus SidebarTrigger,
SidebarRail, and SidebarInset (the main content region). useSidebar() exposes
state.
Style
- The variant/size apply to
SidebarMenuButton:variantdefault|outline;sizedefault|sm|lg(default/default). All colors use the--sidebar-*tokens. - Collapsible modes are driven by
data-collapsible(icon/offcanvas); styling reacts togroup-data-[collapsible=…].
Behavior & functionality
SidebarProvidercontrols expanded/collapsed;SidebarTriggertoggles it; state persists (cookie) and exposesuseSidebar().- Responsive: below the mobile breakpoint (via
use-mobile) the sidebar renders as an off-canvasSheet— the mobile-first collapse rule inPRINCIPLES.md §4.
Accessibility
SidebarMenuButtons are buttons/links — operable with Enter/Space, visiblefocus-visible, anddata-activefor the current item.- The mobile
Sheetpresentation traps focus and closes on Escape (inheritssheet's dialog semantics). - Icon-collapsed items expose their label via
tooltip.
Do / Don't
- ✅ Wrap the app in
SidebarProviderand put page content inSidebarInset. - ✅ Use
SidebarMenuButtonisActive/data-activefor the current route. - ❌ Don't hand-build a nav rail from raw divs — compose these parts.
- ❌ Don't nest a second
SidebarProvider.