Layout
AppShell & Sidebar
The frame of an application — header, navigation sidebar and main content — with a skip link and landmarks. Below a breakpoint the sidebar becomes a drawer; above it, it can collapse to an icon rail.
import { AppShell, Sidebar } from '@reactloom/ui';Examples
Application frame
Collapse the rail with the button next to the logo; on a narrow screen the menu button opens the sidebar in a drawer.
Invoices
Outstanding
Paid
Overdue
import { AppShell, Avatar, Badge, Button, Card, PageHeader, Sidebar, SimpleGrid, Spacer, Text } from '@reactloom/ui';
import { BarChart3, FileText, Home, Settings, Users } from 'lucide-react';
import { useState } from 'react';
export default function Example() {
const [page, setPage] = useState('invoices');
const item = (id: string, label: string, icon: React.ReactNode, badge?: number) => (
<Sidebar.Item
href={`#${id}`}
icon={icon}
badge={badge}
active={page === id}
onClick={(e) => {
e.preventDefault(); // a real app navigates with its router
setPage(id);
}}
>
{label}
</Sidebar.Item>
);
return (
// Embedded in a 440 px panel here; in an app the shell fills the viewport.
<div style={{ width: '100%', height: 440, overflow: 'auto', border: '1px solid var(--pl-color-border-default)', borderRadius: 8 }}>
<AppShell
// The docs page already has <main> and a banner; an embedded shell must not add more.
landmarks={false}
style={{ '--pl-app-height': '440px' } as React.CSSProperties}
header={
<>
<AppShell.MenuButton />
<AppShell.CollapseButton />
<strong>Acme Finance</strong>
<Spacer />
<Avatar name="Ada Lovelace" size="sm" />
</>
}
sidebar={
<Sidebar footer={<Sidebar.Section>{item('settings', 'Settings', <Settings />)}</Sidebar.Section>}>
<Sidebar.Section title="Workspace">
{item('home', 'Dashboard', <Home />)}
{item('invoices', 'Invoices', <FileText />, 12)}
{item('customers', 'Customers', <Users />)}
</Sidebar.Section>
<Sidebar.Section title="Insights">{item('reports', 'Reports', <BarChart3 />)}</Sidebar.Section>
</Sidebar>
}
>
<div style={{ padding: 24 }}>
<PageHeader
headingLevel={4}
title={page[0]?.toUpperCase() + page.slice(1)}
meta={page === 'invoices' ? <Badge tone="warning">3 overdue</Badge> : undefined}
actions={<Button>New</Button>}
/>
<SimpleGrid minChildWidth="10rem" gap="3">
{['Outstanding', 'Paid', 'Overdue'].map((label) => (
<Card key={label}>
<Text size="sm" tone="muted">{label}</Text>
</Card>
))}
</SimpleGrid>
</div>
</AppShell>
</div>
);
}Router links
asChild renders your router’s link with ReactLoom’s layout and aria-current.
import { Sidebar } from '@reactloom/ui';
import { FileText, Home } from 'lucide-react';
import type { AnchorHTMLAttributes } from 'react';
// Stand-in for your router's link (Next.js `Link`, React Router `NavLink`, …).
const RouterLink = ({ to, ...rest }: AnchorHTMLAttributes<HTMLAnchorElement> & { to: string }) => <a href={to} {...rest} />;
const currentPath: string = '/invoices';
export default function Example() {
return (
<div style={{ width: 240 }}>
<Sidebar aria-label="Router example">
<Sidebar.Section>
{/* asChild: your link renders, with ReactLoom's layout, styles and aria-current. */}
<Sidebar.Item asChild icon={<Home />} active={currentPath === '/'}>
<RouterLink to="#home">Dashboard</RouterLink>
</Sidebar.Item>
<Sidebar.Item asChild icon={<FileText />} active={currentPath === '/invoices'}>
<RouterLink to="#invoices">Invoices</RouterLink>
</Sidebar.Item>
</Sidebar.Section>
</Sidebar>
</div>
);
}API reference
AppShell props
| Prop | Type | Default |
|---|---|---|
headerTop bar. Put AppShell.MenuButton (and CollapseButton) in it. | ReactNode | — |
sidebarUsually a Sidebar. | ReactNode | — |
childrenThe page, rendered in <main>. | ReactNode | — |
breakpointBelow it the sidebar moves into a drawer. | 'sm' | 'md' | 'lg' | 'md' |
sidebarCollapsed / defaultSidebarCollapsed / onSidebarCollapsedChangeDesktop icon rail. | boolean | — |
sidebarOpen / defaultSidebarOpen / onSidebarOpenChangeMobile drawer. | boolean | — |
sidebarLabel · skipLinkLabelTranslate these. | string | 'Navigation' · 'Skip to content' |
mainIdSkip-link target; generated when omitted. | string | — |
landmarksfalse when embedded in a page that already has <main> and a banner (micro-frontends, demos). | boolean | true |
Sidebar
| Prop | Type | Default |
|---|---|---|
aria-labelNames the navigation landmark. | string | 'Main' |
header · footerPinned areas. | ReactNode | — |
Sidebar.Section titleNames the list of items. | ReactNode | — |
Sidebar.Item activearia-current="page". | boolean | false |
Sidebar.Item icon · badgeIcon is the only thing visible in the rail. | ReactNode | — |
Sidebar.Item asChildRender your router link. | boolean | false |
CSS variables
| Prop | Type | Default |
|---|---|---|
--pl-app-sidebar-width | length | 16rem |
--pl-app-header-height | length | 3.5rem |
--pl-app-heightEmbed the shell in a panel. | length | 100dvh |
Customization
Extracted from the component’s source on every build, so it matches the code. How the layers fit together is explained in Customization.
AppShell
CSS variables
| Variable | Default |
|---|---|
--pl-app-header-height | 3.5rem |
--pl-app-height | 100dvh |
--pl-app-sidebar-width | 16rem |
State attributes
Target these in your CSS to style states without depending on class names.
| Attribute | Values |
|---|---|
[data-breakpoint] | sm · md · lg |
[data-collapsed] | present when on |
[data-has-sidebar] | present when on |
Theme tokens it reads
--pl-color-bg-canvas --pl-color-bg-surface --pl-color-border-default --pl-color-fg-default --pl-color-fg-link --pl-focus-ring-color --pl-focus-ring-width --pl-radius-md --pl-shadow-md
Sidebar
State attributes
Target these in your CSS to style states without depending on class names.
| Attribute | Values |
|---|---|
[data-collapsed] | present when on |
Theme tokens it reads
--pl-color-bg-inverse --pl-color-border-default --pl-color-fg-inverse --pl-font-size-sm --pl-font-size-xs --pl-radius-sm --pl-shadow-md
Accessibility
- A “Skip to content” link is the first focusable element; main, banner and navigation landmarks are in place.
- The current page is marked with aria-current="page", not colour alone.
- In the collapsed rail, link text stays the accessible name and appears as a flyout on hover and keyboard focus.
- The mobile drawer is a native modal dialog: focus moves into it, Escape closes it, and choosing a link closes it.
| Key | Action |
|---|---|
| Tab | Skip link, then header, sidebar and page |
| Enter | Follow a link; open the drawer from the menu button |
| Escape | Close the drawer |
Usage guidelines
Do
- Keep the sidebar to the places people go often; put the rest under Settings.
- Give every item an icon if the rail can collapse.
Don’t
- Don’t put actions (buttons that change data) in the navigation.