Cómo funciona
Owns only the frame; the sidebar, header and content are slots. The root is a two-column grid, and collapsing transitions grid-template-columns rather than width. In the default inset look the sidebar has no background of its own and the header and content share one rounded card with the card shadow, so there is no dividing line; the content scrolls inside the card's rounded corners. It responds to its own width (a ResizeObserver on the root), not the viewport, so it works in iframes and cards. The drawer is absolute plus transform, not position: fixed, so a transformed ancestor cannot break it; give the shell a height. The content area is the only scroller and fades 16px at an edge that has more content.
Úsalo para
- Workspace and admin apps with a left menu, a top bar and content at lower right: wrap the whole app once and let pages supply only content.
- One set of pages used on wide screens, narrow windows and phones: the three layouts need no breakpoints of your own.
- A small app embedded in an iframe, a split pane or a card: it responds to its own width, so just give it a height.
Busca otra opción cuando
- Marketing sites and articles that scroll top to bottom: they need no fixed sidebar or separate scroller.
- Apps with only top navigation: a header plus a width-limited container is enough.
- A local slide-in panel such as filters or details: use a drawer; it is not a page frame.
- Main navigation of a phone app: use a bottom tab bar, which is easier for thumbs.
Uso
import { useState } from 'react'
import { AppShell } from './AppShell.jsx'
export function AdminLayout({ children }) {
const [current, setCurrent] = useState('overview')
return (
<AppShell
contentWidth={1280}
variant="inset"
sidebar={({ collapsed, closeDrawer }) => (
<SideNav
items={menu}
collapsed={collapsed}
selectedKey={current}
onSelect={(key) => {
setCurrent(key)
closeDrawer() // closes the drawer after a pick; does nothing side by side
}}
/>
)}
header={({ drawer, collapsed, toggleCollapsed }) => (
<div style={{ display: 'flex', alignItems: 'center', gap: 8, padding: '0 var(--ds-appshell-gutter, 24px)' }}>
<button type="button" aria-label={drawer ? 'Open menu' : collapsed ? 'Expand sidebar' : 'Collapse sidebar'} onClick={toggleCollapsed}>
<MenuIcon />
</button>
<UserMenu />
</div>
)}
>
{children}
</AppShell>
)
}
// Embedded in another container: give it a height; narrow the content for form pages
<AppShell height={640} contentWidth={720} sidebar={<Nav />} header={<Bar />}>
<SettingsForm />
</AppShell>Propiedades
| Propiedad | Tipo | Por defecto | Qué hace |
|---|---|---|---|
sidebar | ReactNode | ({ collapsed, drawer, closeDrawer }) => ReactNode | — | The left column, usually side navigation. As a function it receives collapsed, drawer and closeDrawer. Omit it for no sidebar. |
header | ReactNode | ({ drawer, openDrawer, collapsed, toggleCollapsed }) => ReactNode | — | The 56px top bar. As a function it receives drawer, openDrawer, collapsed and toggleCollapsed; in drawer mode toggleCollapsed opens the drawer. Omit it for no top bar. |
children | ReactNode | — | Page content, placed in a width-limited, centered container so headers, toolbars and tables share the same edges. |
contentWidth | 720 | 960 | 1280 | 1600 | 'full' | 1280 | Maximum content width: 720 for forms, 960 for details, 1280 for lists, 1600 for dashboards and wide tables; 'full' removes the limit. |
variant | 'inset' | 'flush' | 'inset' | inset: the sidebar sits on the canvas and the top bar and content form one floating rounded card, 8px from the edges; the drawer is a floating rounded panel. flush: a white sidebar column, a dividing line and the content on the canvas. |
collapsed | boolean | — | Controlled: whether the sidebar is collapsed when the shell is wide enough (at least collapseBelow). Use with onCollapsedChange. |
defaultCollapsed | boolean | false | Initial collapsed state when uncontrolled. |
onCollapsedChange | (collapsed) => void | — | Called when the user collapses or expands in a wide shell, handy for remembering the choice. Automatic collapsing and temporary expanding do not call it. |
collapseBelow | number | 1024 | Below this shell width the sidebar collapses to a 64px icon rail. |
drawerBelow | number | 768 | Below this shell width the sidebar hides and becomes a drawer sliding in from the left, with a mask. |
height | number | string | '100vh' | Shell height: a number in px or any CSS length. Fills the viewport by default (100dvh where supported). |
sidebarLabel | string | 'Sidebar' | Accessible name of the sidebar (the dialog name in drawer mode). |
skipLabel | string | 'Skip to main content' | Text of the skip link, which appears on the first Tab press. |
mainRef | Ref<HTMLElement> | — | Gives access to the scrolling <main>, for example to reset the scroll position on navigation. |
...rest | HTMLAttributes<HTMLDivElement> | — | Other attributes, such as className, style and id, go to the root. Sizes can be changed with --ds-appshell-sidebar (220px), --ds-appshell-rail (64px), --ds-appshell-pad (content padding, 16 / 24 / 32px by width) and --ds-appshell-radius (card and drawer corners, 20px). |
Accesibilidad
- Landmarks: the sidebar is an <aside> with a label, the top bar a <header> and the content a <main>, so screen readers can jump between them.
- The first focusable element is a skip link that drops in on keyboard focus and moves focus into the content on Enter, without changing the URL hash.
- In drawer mode the sidebar is a modal dialog: focus moves in and cycles with Tab, the header and content are inert, and Escape or a click on the dimmed mask closes it and returns focus to the opener.
- A closed drawer is visibility: hidden, so Tab and screen readers skip it; Escape closes only the drawer.
- The menu button lives in your header: give it an aria-label that changes with drawer and collapsed. With reduced motion widths change and the drawer appears instantly.
Movimiento
Sidebar collapse and expand 240ms standard (grid-template-columns); the drawer slides in 360ms ease-out from beyond the left edge and out 240ms ease-in, while the mask dims and blurs in 240ms; the skip link drops in 240ms ease-out. The first two frames after mount and the frame where the layout switches have no transition.
Añádelo a tu proyecto
Copia la instrucción en Codex o Claude Code. El agente lee el código publicado, te muestra lo que va a escribir y añade el componente junto a los tuyos.
AppShell.jsxapp-shell.csstokens.cssREADME.md
Los dos archivos se instalan juntos. La hoja de estilos lee las variables de tokens.css y lleva valores de reserva, así que también funciona sola.

