Skip to content

Early previewhamur is not on npm yet. The components are being built in the open, follow along on GitHub.

UIComponentsReact

Sidebar

A side panel that collapses on wide screens and opens as a sheet on small ones.

Rendered by React 19.3.1

sidebar.tsx

Installation

npx shadcn@4.23.0 add https://hamur.dev/r/react/sidebar.json

It also adds utils, button, input, separator, sheet, skeleton, tooltip. The app needs its setup first: Installation.

Usage

Wrap the page in SidebarProvider, with a Sidebar and a SidebarInset for the main content. Fill the sidebar with SidebarHeader, SidebarContent, SidebarFooter and SidebarGroups of SidebarMenu items; a SidebarMenuButton with a tooltip shows it while the sidebar is collapsed to icons. SidebarTrigger and SidebarRail toggle it. collapsible is offcanvas, icon or none, variant is sidebar, floating or inset, and side is left or right. defaultOpen, or open with onOpenChange, set the open state on wide screens; below 768px the sidebar is a Sheet. The open state comes from the headless Collapsible and Dialog.

import {
  Sidebar,
  SidebarContent,
  SidebarFooter,
  SidebarGroup,
  SidebarGroupAction,
  SidebarGroupContent,
  SidebarGroupLabel,
  SidebarHeader,
  SidebarInput,
  SidebarInset,
  SidebarMenu,
  SidebarMenuAction,
  SidebarMenuBadge,
  SidebarMenuButton,
  SidebarMenuItem,
  SidebarMenuSkeleton,
  SidebarMenuSub,
  SidebarMenuSubButton,
  SidebarMenuSubItem,
  SidebarProvider,
  SidebarRail,
  SidebarSeparator,
  SidebarTrigger,
} from '@/components/ui/sidebar'

Examples

Default

A sidebar with groups, menus and a sub-menu.

Its preview and code are at the top of the page.

Differences from shadcn's: the open state lives in the parts it composes, not in React state of the file's own. On wide screens SidebarProvider is a Base UI Collapsible root (its wrapper also gets data-open or data-closed) and SidebarTrigger and SidebarRail are its triggers, with aria-expanded. Below the breakpoint the sheet is a Base UI Dialog, opened through one module-level handle, so a page has one mobile sidebar sheet. useSidebar returns state, open and isMobile only: there is no setOpen or toggleSidebar (control the provider with open and onOpenChange, or render any element as SidebarTrigger with render) and no openMobile or setOpenMobile (close the sheet from a link with the Sheet item's SheetClose while isMobile). The ⌘B shortcut and the sidebar_state cookie are left to the app, which then controls the provider: its own key listener flips its open, its onOpenChange writes the cookie, and the cookie read on the server gives defaultOpen. There is no use-mobile item; the breakpoint is Base UI's useMediaQuery. SidebarMenuSkeleton's width is --skeleton-width (70% unless set in style) instead of a random one. While expanded, a trigger's aria-controls names the Collapsible's panel id, which no element carries, since the sidebar is not a Collapsible panel. base-vega's provider has no TooltipProvider and neither does this one: wrap the app in the Tooltip item's TooltipProvider for its delay. On the mobile sheet the props of Sidebar other than side and dir are not passed on, as in shadcn's.

API reference

Sidebar wraps no headless component of its own: its parts are elements with classes, and their props are the element's.