125k

Alert Dialog

重要なコンテンツでユーザーを中断し、応答を期待するモーダルダイアログ。

import {
  AlertDialog,
  AlertDialogAction,

インストール

pnpm dlx shadcn@latest add alert-dialog

使用法

import {
  AlertDialog,
  AlertDialogAction,
  AlertDialogCancel,
  AlertDialogContent,
  AlertDialogDescription,
  AlertDialogFooter,
  AlertDialogHeader,
  AlertDialogTitle,
  AlertDialogTrigger,
} from "@/components/ui/alert-dialog"
<AlertDialog>
  <AlertDialogTrigger asChild>
    <Button variant="outline">Show Dialog</Button>
  </AlertDialogTrigger>
  <AlertDialogContent>
    <AlertDialogHeader>
      <AlertDialogTitle>Are you absolutely sure?</AlertDialogTitle>
      <AlertDialogDescription>
        This action cannot be undone. This will permanently delete your account
        from our servers.
      </AlertDialogDescription>
    </AlertDialogHeader>
    <AlertDialogFooter>
      <AlertDialogCancel>Cancel</AlertDialogCancel>
      <AlertDialogAction>Continue</AlertDialogAction>
    </AlertDialogFooter>
  </AlertDialogContent>
</AlertDialog>

構成

次の構成を使用して、AlertDialog を構築します。

AlertDialog
├── AlertDialogTrigger
└── AlertDialogContent
    ├── AlertDialogHeader
    │   ├── AlertDialogMedia
    │   ├── AlertDialogTitle
    │   └── AlertDialogDescription
    └── AlertDialogFooter
        ├── AlertDialogCancel
        └── AlertDialogAction

基本

タイトル、説明、キャンセルボタンと続行ボタンを備えた基本的なアラートダイアログ。

import {
  AlertDialog,
  AlertDialogAction,

小さい

size="sm" プロパティを使用して、アラートダイアログを小さくします。

import {
  AlertDialog,
  AlertDialogAction,

メディア

AlertDialogMedia コンポーネントを使用して、アイコンや画像などのメディア要素をアラートダイアログに追加します。

import { CircleFadingPlusIcon } from "lucide-react"

import {

メディア付きの小さいダイアログ

size="sm" プロパティを使用してアラートダイアログを小さくし、AlertDialogMedia コンポーネントを使用してアイコンや画像などのメディア要素をアラートダイアログに追加します。

import { BluetoothIcon } from "lucide-react"

import {

破壊的

AlertDialogAction コンポーネントを使用して、破壊的なアクションボタンをアラートダイアログに追加します。

import { Trash2Icon } from "lucide-react"

import {

RTL

shadcn/ui で RTL サポートを有効にするには、RTL 構成ガイド を参照してください。

"use client"

import * as React from "react"

API リファレンス

サイズ

AlertDialogContent コンポーネントの size プロパティを使用して、アラートダイアログのサイズを制御します。次の値を受け入れます。

プロパティタイプデフォルト
size"default" | "sm""default"

他のコンポーネントとそのプロパティの詳細については、Radix UI ドキュメント を参照してください。