本文へ移動
日本語

仕組み

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.

向いている場面

  • 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.

向かない場面

  • 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.

使い方

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>

プロパティ

プロパティ型既定値説明
sidebarReactNode | ({ collapsed, drawer, closeDrawer }) => ReactNode—The left column, usually side navigation. As a function it receives collapsed, drawer and closeDrawer. Omit it for no sidebar.
headerReactNode | ({ 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.
childrenReactNode—Page content, placed in a width-limited, centered container so headers, toolbars and tables share the same edges.
contentWidth720 | 960 | 1280 | 1600 | 'full'1280Maximum 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.
collapsedboolean—Controlled: whether the sidebar is collapsed when the shell is wide enough (at least collapseBelow). Use with onCollapsedChange.
defaultCollapsedbooleanfalseInitial 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.
collapseBelownumber1024Below this shell width the sidebar collapses to a 64px icon rail.
drawerBelownumber768Below this shell width the sidebar hides and becomes a drawer sliding in from the left, with a mask.
heightnumber | string'100vh'Shell height: a number in px or any CSS length. Fills the viewport by default (100dvh where supported).
sidebarLabelstring'Sidebar'Accessible name of the sidebar (the dialog name in drawer mode).
skipLabelstring'Skip to main content'Text of the skip link, which appears on the first Tab press.
mainRefRef<HTMLElement>—Gives access to the scrolling <main>, for example to reset the scroll position on navigation.
...restHTMLAttributes<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).

アクセシビリティ

  • 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.

モーション

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.

プロジェクトに追加

プロンプトを Codex または Claude Code に貼り付けます。エージェントが公開ソースを読み、書き込む内容を示したうえで、既存のコンポーネントの隣に追加します。

AppShell.jsxapp-shell.csstokens.cssREADME.md

2 つのファイルを一緒に導入します。スタイルは tokens.css の変数を読み、予備の値も持つため、単体でも表示できます。

ナビゲーション
「ドックバー」は Pro に含まれます。解除するとプレビューが表示されます。