AlertDialog
role="alertdialog" のモーダルダイアログ。スクリーンリーダーが即座に読み上げ、外側をクリックしても閉じない。破壊的な操作の確認やセッション切れなど、作業を中断させてでも応答を求める場面に限って使用。フォームや通常の情報表示には Dialog を使う。
インストール
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
| 名前 | 型 | 既定値 | 説明 |
|---|---|---|---|
icon | ReactNode | - | タイトルの前に表示するアイコン。 |
上記に加えて、React Aria の Heading(新しいタブで開く) の props を受け取ります。