App shell
The application frame, with a collapsible sidebar, a top bar and the main area, that turns the sidebar into a sheet on small viewports.
Revisar contestação
Processo 0001234-56.2024.8.26.0100. Aguardando o revisor.
Use the button at the foot of the sidebar to collapse and expand it. The preview shows the desktop layout; narrow the browser window below 768px to see the sheet.
When to use
- As the outer frame of a signed-in application: it holds the primary navigation, a top bar and the page.
- When the product needs keyboard users to skip the navigation, and a navigation that works on small viewports.
When not to use
- Pages without product navigation, such as sign-in or a public page. Render the page directly.
- A panel inside a page. Use a Card, or Tabs to split content.
- Navigation content itself. Build it with the Sidebar.
Anatomy
| Part | Role |
|---|---|
LayoutProvider |
Holds the layout state: sidebar open, mobile sheet open, fullscreen, and what to show. Import from @repo/ui/layout-provider. |
AppShell |
Renders the sidebar, the sheet, the top bar and main. Must be inside a LayoutProvider. |
sidebar |
A component you write. It receives collapsed and onNavigate. Build it with Sidebar. |
header |
Content of the top bar, such as a Breadcrumb. |
useLayout() |
Hook to read and change the layout state from any child. Throws outside the provider. |
Layout state
| State | Default | Meaning |
|---|---|---|
open |
false |
Desktop sidebar expanded. LayoutProvider defaultOpen sets it, so the default starts collapsed. |
openMobile |
false |
Navigation sheet open. Always starts closed. |
config |
all true |
showSidebar, showMobileSidebar, showTopbar. Change with setConfig or defaultConfig. |
isFullscreen |
false |
Hides the sidebar, the top bar and the sheet for focused work. setFullscreen(true). |
Examples
Expanded sidebar
Revisar contestação
Processo 0001234-56.2024.8.26.0100. Aguardando o revisor.
Collapsed sidebar
Pass defaultOpen={false} to the provider (the default). The sidebar is 56px wide and shows icons.
Revisar contestação
Processo 0001234-56.2024.8.26.0100. Aguardando o revisor.
Without the top bar
Set defaultConfig={{ showTopbar: false }}. On small viewports a bar with the menu button remains, so the user can still open the navigation.
Revisar contestação
Processo 0001234-56.2024.8.26.0100. Aguardando o revisor.
Sidebar that does not collapse
collapsible="none" keeps the sidebar expanded and removes the toggle.
Revisar contestação
Processo 0001234-56.2024.8.26.0100. Aguardando o revisor.
Collapsed, expanded and small viewports
- Expanded: 256px wide (
w-64), content receivescollapsed={false}. - Collapsed: 56px wide (
w-14), content receivescollapsed={true}and should show icons with tooltips. The width changes over 300ms. - Below 768px (
md): the sidebar is hidden. A menu button in the top bar opens a sheet from the left, 288px wide, with the same sidebar content always expanded and a close button. PressingEscape, clicking outside or choosing an item (the content callsonNavigate) closes it. - Resizing the window to 768px or wider closes the sheet.
showCollapseToggle={false}removes the shell’s own toggle, for sidebars that place one in their footer, asapps/appdoes.- Every string is passed in
labels.
The preview frame has a fixed height and the class [&>div]:h-full: the shell is h-svh (the height of the viewport) and the override is how an app, such as apps/us-app, fits it in a smaller box.
Content
- Labels are translated copy from the app: “Navegação principal”, “Abrir navegação”, “Fechar navegação”, “Expandir menu lateral”, “Recolher menu lateral” and “Ir para o conteúdo”.
- Put one thing in the top bar: a breadcrumb or the page title.
- The page content starts inside
main. Give the page one heading, “Revisar contestação”. - Links inside use
CustomLinkin the apps.
Accessibility
- The desktop sidebar is an
asidenamed bylabels.navigation. The content you render should hold anav. - A skip link (“Ir para o conteúdo”) is the first focusable element. It stays hidden until focused and moves focus to
main, which hastabIndex={-1}so it can receive it. - The collapse toggle is a
Buttonwitharia-expanded,aria-controlspointing to the sidebar, and anaria-labelthat changes between expand and collapse. - The mobile sheet is a Radix Dialog: focus moves into it, stays inside, and returns to the menu button on close.
Escapecloses it. Its title islabels.navigation. - The menu button and the close button have
aria-labels fromlabelsand 48px hit targets. - The sheet’s open and close animations are disabled with
motion-reduce.
Code
import { AppShell } from "@repo/ui/app-shell";
import type { SidebarRenderProps } from "@repo/ui/app-shell";
import { LayoutProvider } from "@repo/ui/layout-provider";
const Navigation = ({ collapsed, onNavigate }: SidebarRenderProps) => (
/* SidebarContainer and SidebarItem */
);
<LayoutProvider defaultOpen>
<AppShell
header={<DynamicBreadcrumb />}
labels={labels}
sidebar={Navigation}
>
{children}
</AppShell>
</LayoutProvider>;
Props
AppShell| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | — | Page content, rendered inside `main` |
collapsible | "icon" | "none" | icon | `icon` lets the desktop sidebar collapse to icons; `none` keeps it expanded. Mobile always uses a sheet |
header | ReactNode | — | Content of the top bar, such as a breadcrumb |
labels | { navigation, openNavigation, closeNavigation, expandSidebar, collapseSidebar, skipToContent } | — | Every accessible string of the shell, translated by the app |
showCollapseToggle | boolean | true | Renders the collapse button at the foot of the sidebar. Pass `false` when the sidebar content has its own toggle |
sidebar | ComponentType<SidebarRenderProps> | — | Component rendered in the desktop sidebar and in the mobile sheet. Receives `collapsed` and `onNavigate` |
AppShell labels| Prop | Type | Default | Description |
|---|---|---|---|
navigation | string | — | Name of the sidebar landmark and title of the sheet. |
openNavigation, closeNavigation | string | — | Accessible names of the menu button and of the sheet's close button. |
expandSidebar, collapseSidebar | string | — | Accessible name and tooltip of the collapse toggle. |
skipToContent | string | — | Text of the skip link. |
LayoutProvider| Prop | Type | Default | Description |
|---|---|---|---|
defaultOpen | boolean | false | Initial desktop state: `true` for expanded. |
defaultConfig | Partial<LayoutConfig> | — | Initial `showSidebar`, `showMobileSidebar` and `showTopbar`. All default to `true`. |
Known issues
| Issue | Effect |
|---|---|
The shell root is h-svh. |
It cannot fill a container that is smaller than the viewport without an override such as [&>div]:h-full. |
The desktop sidebar has transition-all duration-300 with no motion-reduce variant. |
The width animation runs for users who asked for reduced motion. apps/us-app disables it with a global rule. |
The 768px breakpoint is hardcoded in a matchMedia call and also in the md: classes. |
The two must be changed together or the sheet and the sidebar disagree. |
The components import siblings through @repo/ui/... instead of relative paths. |
The file depends on the package resolving itself, unlike the other components. |