import {
AlertDialog,
AlertDialogAction,安装
🌐 Installation
pnpm dlx shadcn@latest add alert-dialog
用法
🌐 Usage
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>示例
🌐 Examples
基础
🌐 Basic
一个带有标题、描述以及取消和继续按钮的基本警告对话框。
🌐 A basic alert dialog with a title, description, and cancel and continue buttons.
import {
AlertDialog,
AlertDialogAction,小
🌐 Small
使用 size="sm" 属性可以使警报对话框更小。
🌐 Use the size="sm" prop to make the alert dialog smaller.
import {
AlertDialog,
AlertDialogAction,媒体
🌐 Media
使用 AlertDialogMedia 组件向警报对话框添加媒体元素,例如图标或图片。
🌐 Use the AlertDialogMedia component to add a media element such as an icon or image to the alert dialog.
import {
AlertDialog,
AlertDialogAction,小与媒体
🌐 Small with Media
使用 size="sm" 属性可以使警报对话框更小,使用 AlertDialogMedia 组件可以向警报对话框添加媒体元素,例如图标或图片。
🌐 Use the size="sm" prop to make the alert dialog smaller and the AlertDialogMedia component to add a media element such as an icon or image to the alert dialog.
import {
AlertDialog,
AlertDialogAction,破坏性
🌐 Destructive
使用 AlertDialogAction 组件向警告对话框添加一个破坏性操作按钮。
🌐 Use the AlertDialogAction component to add a destructive action button to the alert dialog.
import {
AlertDialog,
AlertDialogAction,从右到左
🌐 RTL
要在 shadcn/ui 中启用 RTL 支持,请参阅 RTL 配置指南。
🌐 To enable RTL support in shadcn/ui, see the RTL configuration guide.
"use client"
import * as React from "react"API参考
🌐 API Reference
size
在 AlertDialogContent 组件上使用 size 属性来控制警告对话框的大小。它接受以下值:
🌐 Use the size props on the AlertDialogContent component to control the size of the alert dialog. It accepts the following values:
| 属性 | 类型 | 默认值 |
|---|---|---|
size | "default" | "sm" | "default" |
有关其他组件及其属性的更多信息,请参见 Radix UI 文档。
🌐 For more information about the other components and their props, see the Radix UI documentation.