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
- 排版
Payment successful
Your payment of $29.99 has been processed. A receipt has been sent to your email address.
New feature available
We've added dark mode support. You can enable it in your account settings.
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"
import { CheckCircle2Icon, InfoIcon } from "lucide-react"
安装
pnpm dlx shadcn@latest add alert
使用方法
import {
Alert,
AlertAction,
AlertDescription,
AlertTitle,
} from "@/components/ui/alert"<Alert>
<InfoIcon />
<AlertTitle>注意!</AlertTitle>
<AlertDescription>
你可以使用命令行将组件和依赖添加到你的应用中。
</AlertDescription>
<AlertAction>
<Button variant="outline">启用</Button>
</AlertAction>
</Alert>示例
基础示例
一个带图标、标题和描述的基础提示。
Account updated successfully
Your profile information has been saved. Changes will be reflected immediately.
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"
import { CheckCircle2Icon } from "lucide-react"
危险示例
使用 variant="destructive" 创建一个危险提示。
Payment failed
Your payment could not be processed. Please check your payment method and try again.
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"
import { AlertCircleIcon } from "lucide-react"
操作示例
使用 AlertAction 添加按钮或其他操作元素到提示框中。
Dark mode is now available
Enable it under your profile settings to get started.
import {
Alert,
AlertAction,自定义颜色
你可以通过为 Alert 组件添加自定义类,如 bg-amber-50 dark:bg-amber-950 来定制提示框颜色。
Your subscription will expire in 3 days.
Renew now to avoid service interruption or upgrade to a paid plan to continue using the service.
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"
import { AlertTriangleIcon } from "lucide-react"
API 参考
Alert
Alert 组件用于显示提醒用户注意的提示框。
| 属性 | 类型 | 默认值 |
|---|---|---|
variant | "default" | "destructive" | "default" |
AlertTitle
AlertTitle 组件显示提示框的标题。
| 属性 | 类型 | 默认值 |
|---|---|---|
className | string | - |
AlertDescription
AlertDescription 组件显示提示框的描述或内容。
| 属性 | 类型 | 默认值 |
|---|---|---|
className | string | - |
AlertAction
AlertAction 组件显示一个操作元素(比如按钮),定位在提示框的右上角。
| 属性 | 类型 | 默认值 |
|---|---|---|
className | string | - |