App shell
The frame of an app: skip link, navbar, sidebar, main and aside in one responsive grid.
SourceStyles source@monoline/react 0.5.0Markdown for AI toolsbeta
- 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
| Prop | Type | Default | Description |
|---|---|---|---|
navbar | ReactNode | – | A `Navbar`. Sticks to the top while the page scrolls. |
sidebar | ReactNode | – | A `Sidebar`. Hidden below 800px (its drawer opens from a `SidebarTrigger`). |
aside | ReactNode | – | Secondary content in a complementary landmark: a details panel, help, activity. Beside the page from 1100px, below it on narrower screens. |
asideLabel | string | 'Details' | Names the aside landmark. Default "Details". |
skipLinkLabel | string | 'Skip to main content' | Text of the skip link, the first thing a keyboard user can reach. Default "Skip to main content". |
mainId | string | – | 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. |
collapsed | boolean | – | Whether the sidebar is collapsed to icons, when controlled. Pair with `onCollapsedChange`. |
defaultCollapsed | boolean | – | 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 required | ReactNode | – | 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.
| Attribute | Stylesheet |
|---|---|
[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
| Class | Stylesheet |
|---|---|
.divider | 09-links.css |
.link | 09-links.css |
.skip-link | 09-links.css |
.btn | 02-buttons.css |
.btn-block | 02-buttons.css |
.btn-danger | 02-buttons.css |
.btn-ghost | 02-buttons.css |
.btn-lg | 02-buttons.css |
.btn-line | 02-buttons.css |
.btn-sm | 02-buttons.css |
.btn-solid | 02-buttons.css |
.btn | icon-button.css |
.btn-icon | icon-button.css |
.btn-sm | icon-button.css |
.tooltip | tooltip.css |
.command | dialog.css |
.dialog-close | dialog.css |
.dialog-content | dialog.css |
.dialog-description | dialog.css |
.dialog-footer | dialog.css |
.dialog-header | dialog.css |
.dialog-overlay | dialog.css |
.dialog-title | dialog.css |
.drawer-content | dialog.css |
.drawer-content | drawer.css |
.sidebar | sidebar.css |
.sidebar-content | sidebar.css |
.sidebar-drawer | sidebar.css |
.sidebar-footer | sidebar.css |
.sidebar-group | sidebar.css |
.sidebar-group-label | sidebar.css |
.sidebar-header | sidebar.css |
.sidebar-icon | sidebar.css |
.sidebar-inner | sidebar.css |
.sidebar-item | sidebar.css |
.sidebar-label | sidebar.css |
.sidebar-list | sidebar.css |
.sidebar-toggle | sidebar.css |
.sidebar-trigger | sidebar.css |
.navbar | navbar.css |
.navbar-actions | navbar.css |
.navbar-brand | navbar.css |
.navbar-drawer | navbar.css |
.navbar-link | navbar.css |
.navbar-links | navbar.css |
.navbar-list | navbar.css |
.navbar-menu | navbar.css |
.app-shell | app-shell.css |
.app-shell-aside | app-shell.css |
.app-shell-main | app-shell.css |
.app-shell-navbar | app-shell.css |
.sidebar | app-shell.css |
.sidebar-inner | app-shell.css |
.skip-link | app-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.
.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.