- 手风琴
- 警报
- 警报对话框
- 纵横比
- 头像
- 徽章
- 面包屑
- 按钮
- 按钮组
- 日历
- 卡片
- 轮播
- 图表
- 复选框
- 可折叠
- 组合框
- 命令
- 上下文菜单
- 数据表格
- 日期选择器
- 对话框
- 方向
- 抽屉
- 下拉菜单
- 空
- 字段
- 悬停卡
- 输入
- 输入组
- 输入 OTP
- 条目
- 键盘
- 标签
- 菜单栏
- 原生选择
- 导航菜单
- 分页
- 弹出窗口
- 进度
- 单选按钮组
- 可调整大小
- 滚动区域
- 选择
- 分隔符
- 工作表
- 侧边栏
- 骨架
- 滑块
- Sonner
- 旋转器
- 切换
- 表格
- 标签
- 文本区域
- Toast
- 切换
- 切换组
- 工具提示
- 排版
- 手风琴
- 警报
- 警报对话框
- 纵横比
- 头像
- 徽章
- 面包屑
- 按钮
- 按钮组
- 日历
- 卡片
- 轮播
- 图表
- 复选框
- 可折叠
- 组合框
- 命令
- 上下文菜单
- 数据表格
- 日期选择器
- 对话框
- 方向
- 抽屉
- 下拉菜单
- 空
- 字段
- 悬停卡
- 输入
- 输入组
- 输入 OTP
- 条目
- 键盘
- 标签
- 菜单栏
- 原生选择
- 导航菜单
- 分页
- 弹出窗口
- 进度
- 单选按钮组
- 可调整大小
- 滚动区域
- 选择
- 分隔符
- 工作表
- 侧边栏
- 骨架
- 滑块
- Sonner
- 旋转器
- 切换
- 表格
- 标签
- 文本区域
- Toast
- 切换
- 切换组
- 工具提示
- 排版
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 render={<Button variant="outline" />}>
Show Dialog
</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 {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" |
有关其他组件及其属性的更多信息,请参阅 Base UI 文档。
🌐 For more information about the other components and their props, see the Base UI documentation.