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

AlertDialog

role="alertdialog" のモーダルダイアログ。スクリーンリーダーが即座に読み上げ、外側をクリックしても閉じない。破壊的な操作の確認やセッション切れなど、作業を中断させてでも応答を求める場面に限って使用。フォームや通常の情報表示には Dialog を使う。

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

インストール

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

基本的な使い方

破壊的な操作の確認を求めるアラートダイアログです。外側をクリックしても閉じず、明示的な選択を求めます。

alert-dialog.tsx
alert-dialog.module.css
import { AlertDialog, AlertDialogTitle, Button, DialogTrigger, Modal } from "@ginga-ui/core";
import styles from "./alert-dialog.module.css";
import { CircleAlert, Trash2 } from "lucide-react";

export function BasicExample() {
  return (
    <DialogTrigger>
      <Button variant="filled" startIcon={<Trash2 />}>
        ファイルを削除
      </Button>
      <Modal>
        <AlertDialog variant="danger">
          <AlertDialogTitle icon={<CircleAlert />}>
            ファイルの削除
          </AlertDialogTitle>
          <p>この操作は取り消せません。本当に削除しますか?</p>
          <div className={styles.actions}>
            <Button slot="close" variant="outline">
              キャンセル
            </Button>
            <Button slot="close" variant="filled" startIcon={<Trash2 />}>
              削除する
            </Button>
          </div>
        </AlertDialog>
      </Modal>
    </DialogTrigger>
  );
}

警告バリアント

variantプロップでタイトル色とアクセントを変更できます。

alert-dialog.tsx
alert-dialog.module.css
import { AlertDialog, AlertDialogTitle, Button, DialogTrigger, Modal } from "@ginga-ui/core";
import styles from "./alert-dialog.module.css";
import { LogOut, TriangleAlert } from "lucide-react";

export function WarningExample() {
  return (
    <DialogTrigger>
      <Button variant="outline" startIcon={<LogOut />}>
        ログアウト
      </Button>
      <Modal>
        <AlertDialog variant="warning">
          <AlertDialogTitle icon={<TriangleAlert />}>
            ログアウトの確認
          </AlertDialogTitle>
          <p>保存されていない変更は失われます。ログアウトしますか?</p>
          <div className={styles.actions}>
            <Button slot="close" variant="outline">
              キャンセル
            </Button>
            <Button slot="close" variant="filled" startIcon={<LogOut />}>
              ログアウト
            </Button>
          </div>
        </AlertDialog>
      </Modal>
    </DialogTrigger>
  );
}

バリアントなし

variantを指定しない場合は通常の配色で表示されます。セッションが切れて再ログインが必要になったことを知らせる例です。

alert-dialog.tsx
alert-dialog.module.css
import { AlertDialog, AlertDialogTitle, Button, DialogTrigger, Modal } from "@ginga-ui/core";
import styles from "./alert-dialog.module.css";
import { LogIn, TimerOff } from "lucide-react";

export function PlainExample() {
  return (
    <DialogTrigger>
      <Button variant="light" startIcon={<TimerOff />}>
        セッション切れを再現
      </Button>
      <Modal>
        <AlertDialog>
          <AlertDialogTitle>セッションの有効期限切れ</AlertDialogTitle>
          <p>
            安全のためログアウトしました。続けるには再度ログインしてください。
          </p>
          <div className={styles.actions}>
            <Button slot="close" variant="filled" startIcon={<LogIn />}>
              ログイン
            </Button>
          </div>
        </AlertDialog>
      </Modal>
    </DialogTrigger>
  );
}

Props

AlertDialog

role は "alertdialog" に固定されます。DialogTrigger と Modal の中に置きます。

名前型既定値説明
variant"info" | "success" | "warning" | "danger"-配色。省略すると通常の配色で表示されます。

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

AlertDialogTitle

名前型既定値説明
iconReactNode-タイトルの前に表示するアイコン。

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