Skip to Content
AZMARA PLATFORM
Components

AppShell

A dashboard frame with a top bar, a side navigation and the content area. The sidebar can be pinned or hidden, peeks open on hover, and becomes a drawer on a phone.

View as Markdown for coding assistants, or see llms.txt.

Usage

import { AppShell, NavGroup, NavItem, Sidebar, SidebarFooter, TopBar } from "@azmr/ui/shell";
Preview theme
Preview density
Skip to content
Acme

Rest the mouse on the left edge.

The hidden sidebar slides over this content. Click the button at the left of the top bar to pin it open, and click again to hide it. On a phone it opens as a drawer.

import { Button } from "@azmr/ui/button";
import { AppShell, NavGroup, NavItem, Sidebar, SidebarFooter, TopBar } from "@azmr/ui/shell";
import { Bell, Home, List, Settings, Users } from "lucide-react";

// The shell is a page frame. To show one inside a docs page it is `embedded` (the page already has a
// main landmark), given a height with --shell-vh, and put in a box with a transform so its edge
// hot zone and peek stay inside the box. `persist={false}` keeps the demo from writing the cookie.
export default function ShellBasic() {
  return (
    <div className="h-[28rem] overflow-hidden rounded-lg border border-border [transform:translateZ(0)]">
      <AppShell
        embedded
        persist={false}
        defaultMode="hidden"
        className="h-full [--shell-vh:28rem]"
        topBar={
          <TopBar
            brand={<span className="font-semibold text-sm">Acme</span>}
            end={
              <Button variant="ghost" size="icon" aria-label="Notifications">
                <Bell className="size-4" aria-hidden="true" />
              </Button>
            }
          />
        }
        sidebar={
          <Sidebar label="Demo navigation">
            <NavGroup title="Orders">
              <NavItem href="#home" icon={<Home className="size-4" />} current>
                Home
              </NavItem>
              <NavItem href="#orders" icon={<List className="size-4" />} badge={3}>
                My orders
              </NavItem>
            </NavGroup>
            <NavGroup title="Account">
              <NavItem href="#team" icon={<Users className="size-4" />}>
                Team
              </NavItem>
              <NavItem href="#settings" icon={<Settings className="size-4" />}>
                Settings
              </NavItem>
            </NavGroup>
            <SidebarFooter>
              <span className="text-xs">Signed in as Sam</span>
            </SidebarFooter>
          </Sidebar>
        }
      >
        <div className="p-6">
          <p className="font-medium text-sm">Rest the mouse on the left edge.</p>
          <p className="mt-2 max-w-prose text-muted-foreground text-sm">
            The hidden sidebar slides over this content. Click the button at the left of the top bar
            to pin it open, and click again to hide it. On a phone it opens as a drawer.
          </p>
        </div>
      </AppShell>
    </div>
  );
}

AppShell takes the top bar and the sidebar as props and the page as its children:

<AppShell
  topBar={<TopBar brand={<Logo />} start={<SearchField />} end={<AccountMenu />} />}
  sidebar={
    <Sidebar label="Main">
      <NavGroup title="Orders">
        <NavItem href="/" icon={<Home />} current>Home</NavItem>
        <NavItem href="/orders" icon={<List />} badge={3}>My orders</NavItem>
      </NavGroup>
      <SidebarFooter>{/* optional: pinned below the list */}</SidebarFooter>
    </Sidebar>
  }
>
  {children}
</AppShell>

In a Client Component you can also write AppShell.TopBar, AppShell.Sidebar, AppShell.NavGroup, AppShell.NavItem and AppShell.SidebarFooter. In a Server Component use the named imports above: a Server Component cannot read a property of a client module.

How the sidebar behaves

On a wide screen the sidebar is in one of two modes, and you choose between them with the button at the left of the top bar:

  • Pinned: open beside the content, which makes room for it.
  • Hidden: it takes no room. Rest the mouse on the left edge of the screen and it slides over the content; move away and it closes. Following a link in it closes it too. Click the top bar's button to pin it open for good, and click again to hide it.

Below the breakpoint (lg by default, set it with breakpoint="md" | "lg" | "xl") there is no hover. The same button opens the sidebar as a drawer from the left: it traps focus, closes with Escape, the scrim or a link, and gives focus back to the button. Growing the window closes the drawer and leaves your pinned or hidden choice alone.

Only a real mouse peeks. A tap on a touch screen fires the same pointer events and does not.

Remember the choice on the server

The mode is saved in a cookie called azmr-sidebar, and the server reads it so the first paint is already right, with no flash and no inline script. The reader lives in its own server-safe entry:

// app/layout.tsx (a Server Component)
import { cookies } from "next/headers";
import { AppShell, Sidebar, TopBar } from "@azmr/ui/shell";
import { readSidebarMode } from "@azmr/ui/shell-state";

export default async function Layout({ children }: { children: React.ReactNode }) {
  const defaultMode = readSidebarMode((await cookies()).toString());
  return (
    <AppShell
      defaultMode={defaultMode}
      topBar={<TopBar brand="Acme" />}
      sidebar={<Sidebar label="Main">{/* your NavGroups */}</Sidebar>}
    >
      {children}
    </AppShell>
  );
}

readSidebarMode gives "pinned" when there is no cookie or it holds anything unexpected. Pass persist={false} to stop the shell writing the cookie.

Marking the current page with Next.js

NavItem renders an <a> and takes render for your router's link. The current page comes from the URL, which a Server Component does not have, so wrap the item in a small Client Component:

"use client";
import Link from "next/link";
import { usePathname } from "next/navigation";
import { NavItem, type NavItemProps } from "@azmr/ui/shell";

export function NavLink({ href, ...props }: NavItemProps & { href: string }) {
  const current = usePathname() === href;
  return <NavItem {...props} current={current} render={<Link href={href} />} />;
}

Reading and driving it

useAppShell() returns { mode, setMode, peeking, drawerOpen, setDrawerOpen, isDesktop }, for apps that need to react to the sidebar or change it from elsewhere. It throws if used outside AppShell.

Props

Prop

Type

TopBar takes brand, start (hidden below md) and end; the navigation button is added for you.

Prop

Type

NavItem also takes every attribute of an <a>.

Prop

Type

Accessibility

  • A skip link is the first thing a keyboard reaches, and it moves focus to the content.
  • The sidebar is a nav landmark with the name you give it (label is required). Each group's heading names its list. The current page has aria-current="page".
  • Hover is only a shortcut. A hidden sidebar is inert, so it is not in the tab order. A keyboard user reaches the navigation through the top bar's button, which pins it open.
  • The button reports aria-expanded, and names itself "Open navigation" or "Close navigation". Replace every piece of the shell's text, including the skip link and the drawer's name, with the labels prop.
  • Pinning and unpinning move the content at once. Only the peek slides, using transform, as the library's motion rules allow, so there is no animated layout. Durations come from the motion tokens, which are switched off by prefers-reduced-motion.
Keyboard interactions
KeyAction
TabReaches the skip link first, then the top bar's navigation button, then the sidebar's links in order.
EnterorSpaceOn the navigation button: pins or unpins the sidebar on a wide screen, and opens or closes the drawer on a narrow one.
EscapeCloses a peeking sidebar (from anywhere, unless a menu in it is open, which takes the first Escape) or the open drawer. If focus was inside, it returns to the navigation button.
EnterOn a link in the sidebar: follows it, which also closes a peeking sidebar or the drawer.

Size

The @azmr/ui/shell entry is about 44 kB compressed, most of it the modal drawer and the scroll area it is built from. @azmr/ui/shell-state (the cookie reader for the server) is under 1 kB. Both limits are checked by pnpm size.

Things to know

  • The shell is a page frame: it is as tall as the window and renders the page's main and banner. To place one inside a page that already has a main (a panel, or a demo like the one above), pass embedded, give it a height with className="[--shell-vh:28rem]", and put it in a box with transform: translateZ(0) so the hidden sidebar's edge zone and peek stay inside the box. The demo's source shows all three.
  • Showing or hiding an item in the sidebar is not access control. Refuse the request on the server too.
  • Pass text, not HTML. The shell never renders HTML from props.