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.

Preview
Acme Finance

Invoices

Outstanding

Paid

Overdue

Example.tsx
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.

Preview
Example.tsx
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

AppShell props
PropTypeDefault
header
Top bar. Put AppShell.MenuButton (and CollapseButton) in it.
ReactNode—
sidebar
Usually a Sidebar.
ReactNode—
children
The page, rendered in <main>.
ReactNode—
breakpoint
Below it the sidebar moves into a drawer.
'sm' | 'md' | 'lg''md'
sidebarCollapsed / defaultSidebarCollapsed / onSidebarCollapsedChange
Desktop icon rail.
boolean—
sidebarOpen / defaultSidebarOpen / onSidebarOpenChange
Mobile drawer.
boolean—
sidebarLabel · skipLinkLabel
Translate these.
string'Navigation' · 'Skip to content'
mainId
Skip-link target; generated when omitted.
string—
landmarks
false when embedded in a page that already has <main> and a banner (micro-frontends, demos).
booleantrue

Sidebar

Sidebar
PropTypeDefault
aria-label
Names the navigation landmark.
string'Main'
header · footer
Pinned areas.
ReactNode—
Sidebar.Section title
Names the list of items.
ReactNode—
Sidebar.Item active
aria-current="page".
booleanfalse
Sidebar.Item icon · badge
Icon is the only thing visible in the rail.
ReactNode—
Sidebar.Item asChild
Render your router link.
booleanfalse

CSS variables

CSS variables
PropTypeDefault
--pl-app-sidebar-width
length16rem
--pl-app-header-height
length3.5rem
--pl-app-height
Embed the shell in a panel.
length100dvh

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

VariableDefault
--pl-app-header-height3.5rem
--pl-app-height100dvh
--pl-app-sidebar-width16rem

State attributes

Target these in your CSS to style states without depending on class names.

AttributeValues
[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.

AttributeValues
[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.
Keyboard interactions
KeyAction
TabSkip link, then header, sidebar and page
EnterFollow a link; open the drawer from the menu button
EscapeClose 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.