Components
- 手风琴
- 提示
- 警告对话框
- 宽高比
- 头像
- 徽章
- 面包屑导航
- 按钮
- 按钮组
- 日历 Calendar
- 卡片
- Carousel
- 图表 Chart
- 复选框
- 折叠面板
- 组合框
- 命令
- 上下文菜单
- 数据表格 Data Table
- 日期选择器 Date Picker
- 对话框 Dialog
- 抽屉
- 下拉菜单
- Empty
- 字段
- 悬停卡片
- 输入
- 输入组
- 输入 OTP
- 项目
- Kbd
- 标签
- 菜单栏
- 原生选择框
- 导航菜单 Navigation Menu
- 分页
- 弹出框
- 进度 Progress
- 单选框组
- 可调整大小
- 滚动区域 Scroll Area
- 选择框
- 分隔符 Separator
- 侧边栏 Sheet
- 侧边栏 Sidebar
- 骨架屏
- 滑块
- Sonner
- 加载指示器 Spinner
- 开关
- 表格
- 标签页 Tabs
- 文本域
- 吐司
- 切换按钮 Toggle
- 切换组
- 提示 Tooltip
- 排版
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">显示对话框</Button>
</AlertDialogTrigger>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>您确定要继续吗?</AlertDialogTitle>
<AlertDialogDescription>
此操作无法撤销。这将永久删除您在我们服务器上的账户。
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>取消</AlertDialogCancel>
<AlertDialogAction>继续</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>示例
基础示例
一个基础警告对话框,包含标题、描述,以及取消和继续按钮。
import {
AlertDialog,
AlertDialogAction,小尺寸
使用 size="sm" 属性使警告对话框更小。
import {
AlertDialog,
AlertDialogAction,媒体元素
使用 AlertDialogMedia 组件为警告对话框添加媒体元素,如图标或图片。
import {
AlertDialog,
AlertDialogAction,小尺寸带媒体元素
使用 size="sm" 属性使警告对话框更小,并使用 AlertDialogMedia 组件添加媒体元素,如图标或图片。
import {
AlertDialog,
AlertDialogAction,危险操作
使用 AlertDialogAction 组件为警告对话框添加危险操作按钮。
import {
AlertDialog,
AlertDialogAction,API 参考
size
在 AlertDialogContent 组件上使用 size 属性来控制警告对话框的大小。它接受以下值:
| 属性 | 类型 | 默认值 |
|---|---|---|
size | "default" | "sm" | "default" |
有关其它组件及其属性的更多信息,请参见 Radix UI 文档。