- 手风琴
- 警报
- 警报对话框
- 纵横比
- 头像
- 徽章
- 面包屑
- 按钮
- 按钮组
- 日历
- 卡片
- 轮播
- 图表
- 复选框
- 可折叠
- 组合框
- 命令
- 上下文菜单
- 数据表格
- 日期选择器
- 对话框
- 方向
- 抽屉
- 下拉菜单
- 空
- 字段
- 悬停卡
- 输入
- 输入组
- 输入 OTP
- 条目
- 键盘
- 标签
- 菜单栏
- 原生选择
- 导航菜单
- 分页
- 弹出窗口
- 进度
- 单选按钮组
- 可调整大小
- 滚动区域
- 选择
- 分隔符
- 工作表
- 侧边栏
- 骨架
- 滑块
- Sonner
- 旋转器
- 切换
- 表格
- 标签
- 文本区域
- Toast
- 切换
- 切换组
- 工具提示
- 排版
- 手风琴
- 警报
- 警报对话框
- 纵横比
- 头像
- 徽章
- 面包屑
- 按钮
- 按钮组
- 日历
- 卡片
- 轮播
- 图表
- 复选框
- 可折叠
- 组合框
- 命令
- 上下文菜单
- 数据表格
- 日期选择器
- 对话框
- 方向
- 抽屉
- 下拉菜单
- 空
- 字段
- 悬停卡
- 输入
- 输入组
- 输入 OTP
- 条目
- 键盘
- 标签
- 菜单栏
- 原生选择
- 导航菜单
- 分页
- 弹出窗口
- 进度
- 单选按钮组
- 可调整大小
- 滚动区域
- 选择
- 分隔符
- 工作表
- 侧边栏
- 骨架
- 滑块
- Sonner
- 旋转器
- 切换
- 表格
- 标签
- 文本区域
- Toast
- 切换
- 切换组
- 工具提示
- 排版
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"
import { CheckCircle2Icon, InfoIcon } from "lucide-react"
安装
🌐 Installation
pnpm dlx shadcn@latest add alert
用法
🌐 Usage
import {
Alert,
AlertAction,
AlertDescription,
AlertTitle,
} from "@/components/ui/alert"<Alert>
<InfoIcon />
<AlertTitle>Heads up!</AlertTitle>
<AlertDescription>
You can add components and dependencies to your app using the cli.
</AlertDescription>
<AlertAction>
<Button variant="outline">Enable</Button>
</AlertAction>
</Alert>示例
🌐 Examples
基础
🌐 Basic
一个带有图标、标题和描述的基本警报。
🌐 A basic alert with an icon, title and description.
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"
import { CheckCircle2Icon } from "lucide-react"
破坏性
🌐 Destructive
使用 variant="destructive" 来创建破坏性警报。
🌐 Use variant="destructive" to create a destructive alert.
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"
import { AlertCircleIcon } from "lucide-react"
动作
🌐 Action
使用 AlertAction 将按钮或其他操作元素添加到警报中。
🌐 Use AlertAction to add a button or other action element to the alert.
import {
Alert,
AlertAction,自定义颜色
🌐 Custom Colors
你可以通过向 Alert 组件添加自定义类,例如 bg-amber-50 dark:bg-amber-950,来自定义警报颜色。
🌐 You can customize the alert colors by adding custom classes such as bg-amber-50 dark:bg-amber-950 to the Alert component.
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"
import { AlertTriangleIcon } from "lucide-react"
从右到左
🌐 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
警报
🌐 Alert
Alert 组件显示一个提示以引起用户注意。
🌐 The Alert component displays a callout for user attention.
| 属性 | 类型 | 默认值 |
|---|---|---|
variant | "default" | "destructive" | "default" |
AlertTitle
AlertTitle 组件显示警报的标题。
🌐 The AlertTitle component displays the title of the alert.
| 属性 | 类型 | 默认值 |
|---|---|---|
className | string | - |
AlertDescription
AlertDescription 组件显示警报的描述或内容。
🌐 The AlertDescription component displays the description or content of the alert.
| 属性 | 类型 | 默认值 |
|---|---|---|
className | string | - |
AlertAction
AlertAction 组件显示一个操作元素(比如按钮),该元素绝对定位在警告的右上角。
🌐 The AlertAction component displays an action element (like a button) positioned absolutely in the top-right corner of the alert.
| 属性 | 类型 | 默认值 |
|---|---|---|
className | string | - |