本文へスキップ
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)

Dialog

role="dialog" のモーダルダイアログ。フォームや詳細表示、お知らせなど、ユーザーが自分のペースで扱う内容に使用。作業を中断させて即座の応答を求める確認には AlertDialog を使う。

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

インストール

import { Dialog } from "@ginga-ui/core";

基本的な使い方

シンプルなダイアログの使用例です。

dialog.tsx
dialog.module.css
import { Button, Dialog, DialogTitle, DialogTrigger, Modal } from "@ginga-ui/core";
import { PanelTop, X } from "lucide-react";
import styles from "./dialog.module.css";

export function BasicExample() {
  return (
    <DialogTrigger>
      <Button variant="filled" startIcon={<PanelTop />}>
        ダイアログを開く
      </Button>
      <Modal>
        <Dialog>
          <DialogTitle>ようこそ</DialogTitle>
          <p>これは基本的なダイアログです。</p>
          <div className={styles.actions}>
            <Button slot="close" variant="outline" startIcon={<X />}>
              閉じる
            </Button>
          </div>
        </Dialog>
      </Modal>
    </DialogTrigger>
  );
}

フォーム付き

ダイアログ内にフォームを配置した例です。children に関数を渡すと close を受け取れ、送信時にダイアログを閉じられます。

dialog.tsx
dialog.module.css
import { Button, Dialog, DialogTitle, DialogTrigger, FormControl, Input, Modal } from "@ginga-ui/core";
import { Plus, UserPlus } from "lucide-react";
import styles from "./dialog.module.css";

export function FormExample() {
  return (
    <DialogTrigger>
      <Button variant="filled" startIcon={<UserPlus />}>
        サインアップ
      </Button>
      <Modal>
        <Dialog>
          {({ close }) => (
            <form
              onSubmit={(e) => {
                e.preventDefault();
                close();
              }}
            >
              <DialogTitle>アカウント作成</DialogTitle>
              <div className={styles.formFields}>
                <FormControl label="名前">
                  <Input type="text" autoComplete="name" />
                </FormControl>
                <FormControl label="メールアドレス">
                  <Input type="email" autoComplete="email" />
                </FormControl>
                <FormControl label="パスワード">
                  <Input type="password" autoComplete="new-password" />
                </FormControl>
              </div>
              <div className={styles.actions}>
                <Button slot="close" variant="outline">
                  キャンセル
                </Button>
                <Button type="submit" variant="filled" startIcon={<Plus />}>
                  作成
                </Button>
              </div>
            </form>
          )}
        </Dialog>
      </Modal>
    </DialogTrigger>
  );
}

お知らせ

読んでもらう情報を表示するダイアログです。作業を中断させて即座に応答を求める確認には AlertDialog を使います。

dialog.tsx
dialog.module.css
import { Button, Dialog, DialogTitle, DialogTrigger, Modal } from "@ginga-ui/core";
import { Check, Megaphone } from "lucide-react";
import styles from "./dialog.module.css";

export function NoticeExample() {
  return (
    <DialogTrigger>
      <Button variant="outline" startIcon={<Megaphone />}>
        重要なお知らせ
      </Button>
      <Modal>
        <Dialog>
          <DialogTitle>システムメンテナンス</DialogTitle>
          <p>
            2024年12月20日
            2:00〜4:00にシステムメンテナンスを実施します。この間、サービスをご利用いただけません。
          </p>
          <div className={styles.actions}>
            <Button slot="close" variant="filled" startIcon={<Check />}>
              了解
            </Button>
          </div>
        </Dialog>
      </Modal>
    </DialogTrigger>
  );
}

Props

DialogTrigger

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

Modal

名前型既定値説明
dismissablebooleanfalse外側をクリックしたときにモーダルを閉じます。
overlayClassNamestring-モーダルの背景(オーバーレイ)に付けるクラス名。
classNamestring | ((renderProps) => string)-オーバーレイではなくモーダル本体に付けるクラス名。
render(props, renderProps) => ReactElement-モーダル本体の要素を差し替える関数。className と同じくオーバーレイではなくモーダル本体に適用されます。

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

Dialog

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

DialogTitle

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