Sidebar
An app shell sidebar with a top bar, app-provided nav content, and a footer — collapses to a 64px icon rail on desktop and a drawer with an overlay on mobile
pnpm add @wandercom/design-system-web
Sidebar renders no nav logic of its own — pass NavItems (and
NavSectionHeaders) as children, and thread the effective collapsed
state to each NavItem's rail prop so they collapse together. Derive
that value with the exported SIDEBAR_DESKTOP_QUERY rather than using
your own collapsed state directly — Sidebar is never collapsed below
1024px (it's a drawer there), even while collapsed stays true, and your
NavItems need to follow:
import { useState } from 'react';
import { IconHome } from '@wandercom/design-system-icons/home';
import { useMediaQuery } from '@wandercom/design-system-shared/hooks/use-media-query';
import { NavItem } from '@wandercom/design-system-web/ui/nav-item';
import { Sidebar, SIDEBAR_DESKTOP_QUERY } from '@wandercom/design-system-web/blocks/sidebar';
export function Example() {
const [collapsed, setCollapsed] = useState(false);
const isDesktop = useMediaQuery(SIDEBAR_DESKTOP_QUERY);
const rail = isDesktop !== false && collapsed;
return (
<Sidebar collapsed={collapsed}>
<NavItem active href="/" icon={<IconHome />} rail={rail}>
Home
</NavItem>
</Sidebar>
);
}Sidebar needs real viewport height and width to show its breakpoints accurately, so this one is best viewed full screen — use the sidebar button in the page header to see the rail, and shrink the window to see the mobile drawer:
Sidebar sits on the app canvas (bg-surface-canvas). It is 256px wide
(64px on the rail) and fills its parent's height, so give it a viewport-height parent
(such as AppShell.Sidebar): the 64px top bar and the footer stay put, and
only the nav area scrolls. The nav has a 16px start and 8px end inset, and
its rows sit with no gap between them. Every icon stays in the same place
whether the sidebar is expanded or on the rail. Place NavSectionHeaders
directly among the NavItems: each header after the first starts a new
section 20px below the previous row.
Sidebar renders no collapse or expand toggle of its own. Inside
AppShell, clicking the canvas's left edge collapses and expands it (see
App Shell). While it is collapsed, render a
SidebarTrigger in your page header that sets your collapsed state back
to false, labelled with
DEFAULT_SIDEBAR_LABELS.expandToggle:
import {
DEFAULT_SIDEBAR_LABELS,
SidebarTrigger,
} from '@wandercom/design-system-web/blocks/sidebar';
<PageShellHeader>
{collapsed && (
<SidebarTrigger
aria-label={DEFAULT_SIDEBAR_LABELS.expandToggle}
className="max-[1024px]:hidden"
onClick={() => setCollapsed(false)}
/>
)}
{/* title, actions, etc. */}
</PageShellHeader>The top bar starts with logo, which defaults to <SidebarHomeButton href="/" />: a 32×32 link home with an 18px Wander logomark that turns
like a globe while hovered or focused. It stays in place, and keeps linking
home, on the rail. Pass asChild to render it around your router's link:
import { SidebarHomeButton } from '@wandercom/design-system-web/blocks/sidebar';
<Sidebar
logo={
<SidebarHomeButton asChild>
<Link href="/" />
</SidebarHomeButton>
}
>
{/* nav content */}
</Sidebar>Pass tool buttons to actions. They render at the right of the top bar,
8px apart, and hide on the rail. Use SidebarToolButton, a 32×32 ghost
icon button:
import { IconBellLight } from '@wandercom/design-system-icons/bell-light';
import { IconSearchLight } from '@wandercom/design-system-icons/search-light';
import { Sidebar, SidebarToolButton } from '@wandercom/design-system-web/blocks/sidebar';
<Sidebar
actions={
<>
<SidebarToolButton aria-label="Activity" asChild>
<Link href="/tasks"><IconBellLight /></Link>
</SidebarToolButton>
<SidebarToolButton aria-label="Search" onClick={openCommandMenu}>
<IconSearchLight />
</SidebarToolButton>
</>
}
>
{/* nav content */}
</Sidebar>footer is a full-override slot — pass any node, or use the built-in
SidebarFooter: the account row, a 24px avatar (icon, 4px radius) and
the ellipsized account name on a 34px row with an 8px inset. On the rail
it shows the avatar alone, on a 34×34 button:
import {
Sidebar,
SidebarFooter,
} from '@wandercom/design-system-web/blocks/sidebar';
<Sidebar
footer={
<SidebarFooter
label="Acme Inc"
onPress={() => openSettings()}
/>
}
>
{/* nav content */}
</Sidebar>footerAction takes a SidebarFooterAction: a round 32px button at the
right of the footer. On hover (with a mouse or trackpad), keyboard focus or
while its popover is open, it widens over the account row and reveals its
label, while the account name fades out. On the rail it sits above the account, icon only, with a native
tooltip. It forwards its ref and props, so it works as a PopoverTrigger asChild:
import { IconBolt } from '@wandercom/design-system-icons/bolt';
import { SidebarFooterAction } from '@wandercom/design-system-web/blocks/sidebar';
import { Popover, PopoverContent, PopoverTrigger } from '@wandercom/design-system-web/ui/popover';
<Sidebar
footer={<SidebarFooter icon={<OrgAvatar />} label="Westlake Cabins" />}
footerAction={
<Popover>
<PopoverTrigger asChild>
<SidebarFooterAction icon={<IconBolt />} label="What's new?" />
</PopoverTrigger>
<PopoverContent align="start" side="top">…</PopoverContent>
</Popover>
}
>
{/* nav content */}
</Sidebar>Its animation lives in the package's styles.css
(@wandercom/design-system-web/components), which apps already import.
For a settings/account popover instead of a plain click, build it with the
existing Dropdown primitives and wrap SidebarFooter as the trigger via
asChild:
import { SidebarFooter } from '@wandercom/design-system-web/blocks/sidebar';
import {
Dropdown,
DropdownContent,
DropdownItem,
DropdownLinkItem,
DropdownSeparator,
DropdownSub,
DropdownSubContent,
DropdownSubTrigger,
DropdownTrigger,
} from '@wandercom/design-system-web/ui/dropdown';
<Dropdown>
<DropdownTrigger asChild>
<SidebarFooter label="Acme Inc" />
</DropdownTrigger>
<DropdownContent align="start" className="w-64" side="top">
<DropdownLinkItem href="/settings">Settings</DropdownLinkItem>
<DropdownLinkItem href="/whats-new">What's new</DropdownLinkItem>
<DropdownLinkItem href="/help">Help center</DropdownLinkItem>
<DropdownSeparator />
<DropdownSub>
<DropdownSubTrigger>Switch organization</DropdownSubTrigger>
<DropdownSubContent>
<DropdownItem onClick={() => switchOrg('acme')}>Acme Inc</DropdownItem>
<DropdownItem onClick={() => switchOrg('globex')}>Globex Corp</DropdownItem>
</DropdownSubContent>
</DropdownSub>
<DropdownItem onClick={() => signOut()}>Sign out</DropdownItem>
</DropdownContent>
</Dropdown>Since the popover shape (an org section, a user section, nested submenus,
checkmarks for the current selection) varies by app, Sidebar doesn't ship
an opinionated version of it — compose it from Dropdown/DropdownSub in
your own code instead, same as any other menu in the app. See the
Dropdown docs for the full set of primitives
(links, actions, checkboxes, nested submenus, separators).
Below 1024px, Sidebar renders itself in a 256px drawer from the left, over
an overlay, instead of inline. Its top bar keeps your actions and adds a
close button (the sidebar icon) after them.
Open and close it from code with open/onOpenChange:
<Sidebar open={mobileNavOpen} onOpenChange={setMobileNavOpen}>
{/* nav content */}
</Sidebar>Below 1024px, render a SidebarTrigger (a 32px round ghost button with the
sidebar icon) in your own header (e.g. PageShellHeader), wired to the same
state:
import { SidebarTrigger } from '@wandercom/design-system-web/blocks/sidebar';
import { PageShellHeader } from '@wandercom/design-system-web/blocks/page-shell';
<PageShellHeader>
<SidebarTrigger className="hidden max-[1024px]:inline-flex" onClick={() => setMobileNavOpen(true)} />
{/* title, actions, etc. */}
</PageShellHeader>Sidebar never overwrites your collapsed value on resize — it's your
persisted preference, not Sidebar's to clobber. Derive the effective value
(see Usage above) with the exported SIDEBAR_DESKTOP_QUERY wherever you
need it, rather than reading collapsed directly:
import { useMediaQuery } from '@wandercom/design-system-shared/hooks/use-media-query';
import { SIDEBAR_DESKTOP_QUERY } from '@wandercom/design-system-web/blocks/sidebar';
const isDesktop = useMediaQuery(SIDEBAR_DESKTOP_QUERY);
const effectiveCollapsed = isDesktop !== false && collapsed;From 1024px up, collapsed shrinks Sidebar to the 64px icon rail. The
logo stays in place, actions hide, and NavItems become 34×34 icon
buttons with their icons where they sit when expanded. SidebarFooter
collapses to its avatar alone and keeps whatever onPress or Dropdown
behavior you wired to it.
logo?:
actions?:
collapsed?:
defaultCollapsed?:
onCollapsedChange?:
collapsible?:
open?:
defaultOpen?:
onOpenChange?:
children:
className?:
labels?:
A thin Button wrapper (variant="ghost", size="icon-sm": 32px and
round, with the sidebar icon) for your own header: below 1024px it opens the
drawer, and from 1024px it expands the collapsed sidebar (pass
aria-label={DEFAULT_SIDEBAR_LABELS.expandToggle}). Accepts every
Button prop; aria-label defaults to "Open navigation".
The Wander logomark link for Sidebar's logo: 32×32, 8px radius, an
18px logo that turns like a globe while hovered or focused. Accepts every
native <a> prop; aria-label defaults to "Home". Pass asChild to merge
its props, styles and logo onto its only child, such as a router Link.
A 32×32 ghost icon button (8px radius, 18px text-secondary icon,
surface-quaternary hover fill) for Sidebar's actions. Requires an
aria-label, supports asChild, and accepts every native <button> prop,
including ref.
The What's new trigger for Sidebar's footerAction. Takes icon (16px)
and label (revealed on hover, focus or open, and the accessible name),
plus every native <button> prop, including ref.
The account row for Sidebar's footer slot: a 24px avatar and the
account name on a 34px row with an 8px inset, filled with
surface-quaternary on hover and while its menu is open. Collapses to the
34×34 avatar on the icon rail. Its account name carries data-account-fade, which fades out
while a SidebarFooterAction is active. Wrap it in your own Dropdown (via
asChild on DropdownTrigger) for an account menu — see
Footer above.
icon?:
label:
onPress?:
chevronDirection?:
className?:
Also accepts any other native <button> prop (e.g. aria-label), spread
onto the rendered button — including the props a wrapping DropdownTrigger asChild injects, so it composes as a dropdown trigger.