Playground

App shell

The frame of an app: skip link, navbar, sidebar, main and aside in one responsive grid.

  • Built on native elements
  • Landmarks: banner (the navbar), navigation (the sidebar), main and complementary (the aside, named by asideLabel).
  • The first focusable element is a skip link to the main region; main takes focus when it is used.
  • The sidebar shows from 800px and the aside beside the page from 1100px; below those they move into a drawer or stack under the page.
  • Styles in one file: 09-links.css

Import

import '@monoline/css';
import {AppShell} from '@monoline/react';

Not installed yet? Pick a route.

Copies the source and its styles into your project.

npx monoline add app-shell

Usage

import {type CSSProperties} from 'react';
import {AppShell, Breadcrumb, Button, Command, DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, Navbar, PageHeader, Sidebar, SidebarContent, SidebarGroup, SidebarHeader, SidebarItem, SidebarToggle, SidebarTrigger} from '@monoline/react';

const Icon = ({d}: {d: string}) => <svg viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1.5" aria-hidden="true"><path d={d} /></svg>;

const height = {'--app-shell-height': '34rem'} as CSSProperties;

const actions = [{id: 'new', label: 'New project', group: 'Create'}, {id: 'invite', label: 'Invite a teammate', group: 'Create'}, {id: 'theme', label: 'Switch theme', group: 'View'}];

const sidebar = (
  <Sidebar drawerTitle="Acme">
    <SidebarHeader><span>Acme</span><SidebarToggle /></SidebarHeader>
    <SidebarContent>
      <SidebarGroup label="Workspace">
        <SidebarItem href="#overview" current icon={<Icon d="M2 8l6-5 6 5v6H2z" />}>Overview</SidebarItem>
        <SidebarItem href="#reports" icon={<Icon d="M3 13V8M8 13V3M13 13V6" />}>Reports</SidebarItem>
        <SidebarItem href="#team" icon={<Icon d="M8 8a3 3 0 100-6 3 3 0 000 6zM2 14c0-3 3-4 6-4s6 1 6 4" />}>Team</SidebarItem>
      </SidebarGroup>
    </SidebarContent>
  </Sidebar>
);

const navbar = (
  <Navbar
    leading={<SidebarTrigger />}
    actions={(
      <>
        <Command shortcut="mod+j" title="Command palette" items={actions} trigger={<Button size="sm">Search…</Button>} />
        <DropdownMenu>
          <DropdownMenuTrigger asChild><Button size="sm">Account</Button></DropdownMenuTrigger>
          <DropdownMenuContent align="end">
            <DropdownMenuLabel>Ada Example</DropdownMenuLabel>
            <DropdownMenuItem>Profile</DropdownMenuItem>
            <DropdownMenuItem>Settings</DropdownMenuItem>
            <DropdownMenuSeparator />
            <DropdownMenuItem>Sign out</DropdownMenuItem>
          </DropdownMenuContent>
        </DropdownMenu>
      </>
    )}
  />
);

const header = <PageHeader breadcrumbs={<Breadcrumb items={[{label: 'Home', href: '#'}, {label: 'Reports'}]} />} title="Reports" description="Weekly numbers for your workspace." actions={<Button variant="solid">New report</Button>} />;

<AppShell scroll="contained" style={height} navbar={navbar} sidebar={sidebar}>{header}<p>Your page goes here.</p></AppShell>

Examples

App shell

Navbar, sidebar, breadcrumb, page header, a user menu and a command palette (Ctrl or Cmd + J). The sidebar and main scroll on their own here (`scroll="contained"`); narrow the window for the drawer.

With an aside

From 1100px wide the aside sits beside the page; below that it stacks under it.

Props

AppShellProps

PropTypeDefaultDescription
navbarReactNode–A `Navbar`. Sticks to the top while the page scrolls.
sidebarReactNode–A `Sidebar`. Hidden below 800px (its drawer opens from a `SidebarTrigger`).
asideReactNode–Secondary content in a complementary landmark: a details panel, help, activity. Beside the page from 1100px, below it on narrower screens.
asideLabelstring'Details'Names the aside landmark. Default "Details".
skipLinkLabelstring'Skip to main content'Text of the skip link, the first thing a keyboard user can reach. Default "Skip to main content".
mainIdstring–The `id` of the main region, which the skip link targets. Default is generated.
scroll"page" | "contained"'page'`page` (default): the page scrolls; the navbar and sidebar stay in view. `contained`: the shell fills its height and the sidebar and main scroll on their own. Set the height with the CSS variable `--app-shell-height` (default full viewport); in `page` mode `--app-shell-min-height` sets the minimum.
collapsedboolean–Whether the sidebar is collapsed to icons, when controlled. Pair with `onCollapsedChange`.
defaultCollapsedboolean–Whether the sidebar starts collapsed when uncontrolled. Default false.
onCollapsedChange((collapsed: boolean) => void)–Called with the new collapsed state. Save it to persist the choice, then pass it back as `defaultCollapsed`.
children requiredReactNode–The page. Put one h1 in it (a `PageHeader` does).

Data Attributes

State is exposed through attributes. Style it with these selectors, not with class toggles.

AttributeStylesheet
[data-side="bottom"]drawer.css
[data-side="end"]drawer.css
[data-side="left"]drawer.css
[data-side="right"]drawer.css
[data-side="start"]drawer.css
[data-side="top"]drawer.css
[aria-current="page"]sidebar.css
[data-collapsed]sidebar.css
[aria-current="page"]navbar.css
[data-sticky]navbar.css
[data-scroll="contained"]app-shell.css

CSS classes

ClassStylesheet
.divider09-links.css
.link09-links.css
.skip-link09-links.css
.btn02-buttons.css
.btn-block02-buttons.css
.btn-danger02-buttons.css
.btn-ghost02-buttons.css
.btn-lg02-buttons.css
.btn-line02-buttons.css
.btn-sm02-buttons.css
.btn-solid02-buttons.css
.btnicon-button.css
.btn-iconicon-button.css
.btn-smicon-button.css
.tooltiptooltip.css
.commanddialog.css
.dialog-closedialog.css
.dialog-contentdialog.css
.dialog-descriptiondialog.css
.dialog-footerdialog.css
.dialog-headerdialog.css
.dialog-overlaydialog.css
.dialog-titledialog.css
.drawer-contentdialog.css
.drawer-contentdrawer.css
.sidebarsidebar.css
.sidebar-contentsidebar.css
.sidebar-drawersidebar.css
.sidebar-footersidebar.css
.sidebar-groupsidebar.css
.sidebar-group-labelsidebar.css
.sidebar-headersidebar.css
.sidebar-iconsidebar.css
.sidebar-innersidebar.css
.sidebar-itemsidebar.css
.sidebar-labelsidebar.css
.sidebar-listsidebar.css
.sidebar-togglesidebar.css
.sidebar-triggersidebar.css
.navbarnavbar.css
.navbar-actionsnavbar.css
.navbar-brandnavbar.css
.navbar-drawernavbar.css
.navbar-linknavbar.css
.navbar-linksnavbar.css
.navbar-listnavbar.css
.navbar-menunavbar.css
.app-shellapp-shell.css
.app-shell-asideapp-shell.css
.app-shell-mainapp-shell.css
.app-shell-navbarapp-shell.css
.sidebarapp-shell.css
.sidebar-innerapp-shell.css
.skip-linkapp-shell.css

Customization

Style it with the kit's tokens in your own CSS, loaded after @monoline/css. Prefer the attributes above over extra classes. See Theming for every token.

app.css
.divider {
  border-color: var(--accent);
}
.divider[data-side="bottom"] {
  background: var(--wash);
}

Accessibility

  • Landmarks: banner (the navbar), navigation (the sidebar), main and complementary (the aside, named by asideLabel).
  • The first focusable element is a skip link to the main region; main takes focus when it is used.
  • The sidebar shows from 800px and the aside beside the page from 1100px; below those they move into a drawer or stack under the page.
  • scroll="page" keeps the navbar and sidebar in view while the page scrolls; scroll="contained" scrolls the regions on their own.