ナビゲーション · 準拠済み
NavigationDrawer
NavigationDrawerNavigationDrawerPropsNavigationDrawerVariant
import { useState } from 'react'
import { Button, Icon, NavigationDrawer, Surface, Text } from '@language-lit/material3-expressive'
const items = [
// Selected by default (first item) in every variant below, so its
// `selectedIcon` is visually confirmed across all three.
{
value: 'inbox',
label: 'Inbox',
icon: <Icon source="inbox" />,
selectedIcon: <Icon source="inbox" fill={1} />,
},
{ value: 'sent', label: 'Sent', icon: <Icon source="send" /> },
{ value: 'trash', label: 'Trash', icon: <Icon source="delete" />, disabled: true },
{ value: 'docs', label: 'Docs', icon: <Icon source="description" />, href: '#' },
]
export function NavigationDrawerExample() {
const [dismissibleOpen, setDismissibleOpen] = useState(true)
const [modalOpen, setModalOpen] = useState(false)
return (
<Surface
as="section"
aria-labelledby="navigation-drawer-example-title"
color="surface-container-low"
shape="extra-large"
className="navigation-drawer-example"
>
<Text as="h2" id="navigation-drawer-example-title" variant="titleLarge" emphasis="emphasized">
Navigation drawer
</Text>
<Text as="p" variant="bodyMedium">
Modal (native dialog, slides from the edge), dismissible (collapses
in place), and permanent (always visible) variants.
</Text>
<div className="navigation-drawer-example__row">
<Button variant="outlined" onClick={() => setDismissibleOpen((open) => !open)}>
Toggle dismissible drawer
</Button>
<Button variant="outlined" onClick={() => setModalOpen(true)}>
Open modal drawer
</Button>
</div>
<div className="navigation-drawer-example__frame">
<NavigationDrawer
aria-label="Dismissible example"
variant="dismissible"
open={dismissibleOpen}
onOpenChange={setDismissibleOpen}
items={items}
/>
<NavigationDrawer aria-label="Permanent example" variant="permanent" items={items} />
</div>
<NavigationDrawer
aria-label="Modal example"
variant="modal"
open={modalOpen}
onOpenChange={setModalOpen}
items={items}
/>
</Surface>
)
}NavigationDrawerはナビゲーション項目を並べた全高のサイドパネルを表示します。一時的なモーダルオーバーレイ、その場で折りたたむ非モーダルパネル、常時表示のパネルという3種類のバリアントがあります。
import { useState } from 'react'
import { Icon, NavigationDrawer } from '@language-lit/material3-expressive'
import '@language-lit/material3-expressive/styles.css'
const [open, setOpen] = useState(false)
<NavigationDrawer
aria-label="Mail folders"
variant="modal"
open={open}
onOpenChange={setOpen}
items={[
{ value: 'inbox', label: 'Inbox', icon: <Icon source="inbox" /> },
{ value: 'sent', label: 'Sent', icon: <Icon source="send" /> },
]}
/>仕様
itemsとvalue/defaultValue/onValueChangeには、NavigationBarと同じNavigationItem形式と、リンクに対応したhrefの動作を使います。variantの既定値は'modal'です。'modal'は一時的なオーバーレイです。Dialogと同じネイティブ<dialog>の方法(showModal()/close()、Escape/外側クリックで閉じる)を使い、論理方向の開始辺からスライド表示します。open/defaultOpen/onOpenChangeで制御します。'dismissible'は、重ねずに隣接するコンテンツを押し広げながら、その場で折りたたむ/展開する非モーダルパネルです。こちらもopen/defaultOpen/onOpenChangeで制御します。'permanent'は常に表示されます。open/defaultOpen/onOpenChangeは受け付けますが、無視されます。
トークンと境界
色、形状、モーションの値は--m3e-comp-navigation-drawer-*の1つの登録にまとめられています。テーマの上書きはMaterial3Providerのスコープ内で適用されます。NavigationDrawerは実行時スタイルを注入せず、Next.js、Vite、ルーター、アニメーションライブラリ、非公開のアプリケーションコードをインポートしません。