本文へスキップ
Ginga UI
Ginga UI
English

はじめに

  • 概要
  • クイックスタート
  • テーマ生成
  • 要素の差し替え
  • 全コンポーネント

フォーム

  • Button
  • Checkbox
  • Input
  • Radio
  • Questionnaire
  • SegmentedControl
  • Select
  • ComboBox
  • NumberField
  • SearchField
  • Slider
  • Switch
  • FormControl

表示

  • Accordion
  • Alert
  • AlertDialog
  • Badge
  • CodeBlock
  • Card
  • Dialog
  • Drawer
  • Image
  • List
  • Popover
  • Menu
  • Tooltip
  • Table
  • Tab
  • Toast
  • Trace

タイポグラフィ

  • Heading
  • Paragraph

ナビゲーション

  • Anchor

レイアウト

  • Box

リソース

  • 変更履歴
  • GitHub(新しいタブで開く)

ロゴ: Twemoji(新しいタブで開く) (CC-BY 4.0)

Drawer

画面の端からスライドインするドロワー。4方向(left、right、top、bottom)に対応し、ページを操作したまま開いておける非モーダル表示もサポート。

Storybook で見る(新しいタブで開く)

インストール

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"ドロワーがスライドインする画面の端。
dismissablebooleantrue外側のクリックや Esc キーでドロワーを閉じます。
isKeyboardDismissDisabledboolean!dismissableEsc キーでドロワーを閉じないようにします。

上記に加えて、React Aria の ModalOverlay(新しいタブで開く) の props を受け取ります。

DrawerContent

React Aria の Dialog(新しいタブで開く) の props を受け取ります。

DrawerTitle

React Aria の Heading(新しいタブで開く) の props を受け取ります。