Skip to content

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.

Component Source
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.

Component Source
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.

Component Source
<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.

Component Source
<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.

Component Source
<Sidebar variant="floating" width="w-56">…</Sidebar>

<div className="p-3">
  <Sidebar variant="inset" width="w-56">…</Sidebar>
</div>

Parts

PartWhat it does
SidebarThe <aside> landmark. Holds side, variant and collapsed state for every part inside it, and sets data-side, data-variant and data-state.
SidebarHeader56px top row for the product name and the trigger. Centres its content when collapsed.
SidebarTriggerInside 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.
SidebarBodyThe scrolling middle. Put sections and items here.
SidebarSectionA group of items. With a title it becomes a labelled group; the title is visually hidden when collapsed.
SidebarNavItemA 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.
SidebarFooterBottom 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

KeyAction
TabMoves through the trigger, the items and the resize handle.
Enter / SpaceActivates the focused item or toggles the rail.
Arrow Left / RightOn the resize handle: moves the edge by 16px, 64px with Shift.
Home / EndOn the resize handle: jumps to minWidth or maxWidth.
EnterOn the resize handle: resets to the starting width. Double-click does the same.

Props

Sidebar

PropTypeDefaultDescription
side"left" | "right"leftSidebar dock side: "left" (Sidenav, left panel) or "right" (Configurator, Inspector). Default "left".
variant"fixed" | "collapsible" | "floating" | "inset"fixedSidebar visual variant: fixed width, collapsible rail, floating card, or inset panel. Default "fixed".
collapsibleMode"icon" | "offcanvas" | "none"iconCollapsible mode: "icon" rail collapse, "offcanvas" full hide, or "none". Default "icon".
collapsedboolean—Controlled collapsed state.
onCollapsedChange(collapsed: boolean) => void—Callback fired when collapsed state changes.
defaultCollapsedbooleancollapsedInitial default collapsed state.
widthstringw-60Custom width CSS string (e.g. "w-60", "w-72", "w-80"). Default "w-60".
resizablebooleanfalseEnable interactive drag resizability. Default false.
minWidthnumber180Minimum width in pixels when resizable. Default 180.
maxWidthnumber420Maximum width in pixels when resizable. Default 420.
persistKeystring—Remember the resized width in localStorage under this key.
resizeColorResizeHandleColorbrand-subtleResize handle colour on hover, focus and drag. Default "brand-subtle".
childrenReactNode—Custom sidebar content.
classNamestring—Custom root class name.

SidebarSection

PropTypeDefault
titlestring—

SidebarNavItem

PropTypeDefault
iconReactNode—
label*string—
activeboolean—
badgeReactNode—
hrefstring—
onClick() => void—
classNamestring—

* required

SidebarHeader, SidebarBody, SidebarFooter and SidebarTrigger take className and the attributes of the element they render.

Configure Theme
Theme
Brand Color
Custom
Gray Family
Appearance
Radius
Scaling
Panel Style
Heading Font
Body Font