Drawer
画面の端からスライドインするドロワー。4方向(left、right、top、bottom)に対応し、ページを操作したまま開いておける非モーダル表示もサポート。
インストール
import { Drawer } from "@ginga-ui/core";基本的な使い方
画面の右端からスライドインするドロワーです。
drawer.tsx
drawer.module.css
import { Button, DialogTrigger, Drawer, DrawerContent, DrawerTitle } from "@ginga-ui/core";
import { Menu, X } from "lucide-react";
import styles from "./drawer.module.css";
export function BasicExample() {
return (
<DialogTrigger>
<Button variant="filled" startIcon={<Menu />}>
メニューを開く
</Button>
<Drawer>
<DrawerContent>
<DrawerTitle>メニュー</DrawerTitle>
<p>右側からスライドインするドロワーです。</p>
<div className={styles.actions}>
<Button slot="close" variant="outline" startIcon={<X />}>
閉じる
</Button>
</div>
</DrawerContent>
</Drawer>
</DialogTrigger>
);
}表示位置
placementプロップでleft、right、top、bottomの4方向を指定できます。
drawer.tsx
drawer.module.css
import { Button, DialogTrigger, Drawer, DrawerContent, DrawerTitle } from "@ginga-ui/core";
import { X } from "lucide-react";
import styles from "./drawer.module.css";
export function PlacementsExample() {
return (
<div className={styles.placementRow}>
{(["left", "right", "top", "bottom"] as const).map((placement) => (
<DialogTrigger key={placement}>
<Button variant="outline">{placement}</Button>
<Drawer placement={placement}>
<DrawerContent>
<DrawerTitle>{placement}</DrawerTitle>
<p>{placement} から表示されるドロワーです。</p>
<div className={styles.actions}>
<Button slot="close" variant="outline" startIcon={<X />}>
閉じる
</Button>
</div>
</DrawerContent>
</Drawer>
</DialogTrigger>
))}
</div>
);
}外側クリックで閉じない
dismissable に false を渡すと、外側をクリックしても Esc キーを押してもドロワーは閉じず、閉じるボタンでのみ閉じます。Esc キーで閉じられるようにするには isKeyboardDismissDisabled={false} を渡します。
drawer.tsx
drawer.module.css
import { Button, DialogTrigger, Drawer, DrawerContent, DrawerTitle } from "@ginga-ui/core";
import { PanelRight, X } from "lucide-react";
import styles from "./drawer.module.css";
export function NotDismissableExample() {
return (
<DialogTrigger>
<Button variant="light" startIcon={<PanelRight />}>
外側クリックで閉じない
</Button>
<Drawer dismissable={false}>
<DrawerContent>
<DrawerTitle>確認が必要です</DrawerTitle>
<p>閉じるボタンを押すまでドロワーは閉じません。</p>
<div className={styles.actions}>
<Button slot="close" variant="filled" startIcon={<X />}>
閉じる
</Button>
</div>
</DrawerContent>
</Drawer>
</DialogTrigger>
);
}Props
Drawer
| 名前 | 型 | 既定値 | 説明 |
|---|---|---|---|
placement | "left" | "right" | "top" | "bottom" | "right" | ドロワーがスライドインする画面の端。 |
dismissable | boolean | true | 外側のクリックや Esc キーでドロワーを閉じます。 |
isKeyboardDismissDisabled | boolean | !dismissable | Esc キーでドロワーを閉じないようにします。 |
上記に加えて、React Aria の ModalOverlay(新しいタブで開く) の props を受け取ります。
DrawerContent
React Aria の Dialog(新しいタブで開く) の props を受け取ります。
DrawerTitle
React Aria の Heading(新しいタブで開く) の props を受け取ります。