组件
- 手风琴 (Accordion)
- 警示框 (Alert)
- 对话框 (Alert Dialog)
- 宽高比 (Aspect Ratio)
- 头像 (Avatar)
- 徽章 (Badge)
- 面包屑 (Breadcrumb)
- 按钮 (Button)
- 按钮组 (Button Group)
- 日历 (Calendar)
- 卡片 (Card)
- 轮播 (Carousel)
- 图表 (Chart)
- 复选框 (Checkbox)
- 折叠面板 (Collapsible)
- 组合框 (Combobox)
- 命令栏 (Command)
- 上下文菜单 (Context Menu)
- 数据表格 (Data Table)
- 日期选择器 (Date Picker)
- 对话框 (Dialog)
- 方向 (Direction)
- 抽屉 (Drawer)
- 下拉菜单 (Dropdown Menu)
- 空状态 (Empty)
- 字段 (Field)
- 悬浮卡片 (Hover Card)
- 输入框 (Input)
- 输入框组 (Input Group)
- OTP 输入框 (Input OTP)
- 项目 (Item)
- 快捷键 (Kbd)
- 标签 (Label)
- 菜单栏 (Menubar)
- 原生选择框 (Native Select)
- 导航菜单 (Navigation Menu)
- 分页 (Pagination)
- 气泡卡片 (Popover)
- 进度条 (Progress)
- 单选组 (Radio Group)
- 可调节大小 (Resizable)
- 滚动区域 (Scroll Area)
- 选择框 (Select)
- 分隔线 (Separator)
- 侧边栏 (Sheet)
- 导航侧边栏 (Sidebar)
- 骨架屏 (Skeleton)
- 滑块 (Slider)
- Sonner (吐司通知)
- 加载器 (Spinner)
- 开关 (Switch)
- 表格 (Table)
- 标签页 (Tabs)
- 文本域 (Textarea)
- 吐司 (Toast)
- 切换按钮 (Toggle)
- 切换组 (Toggle Group)
- 文字提示 (Tooltip)
- 排版 (Typography)
支付成功
您的 29.99 美元付款已处理。收据已发送至您的电子邮箱。
新功能可用
我们已添加暗黑模式支持。您可以在账户设置中启用它。
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>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>示例
基础用法
一个带有图标、标题和描述的基本提示框。
账户更新成功
您的个人资料信息已保存。更改将立即生效。
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"
import { CheckCircle2Icon } from "lucide-react"
破坏性按钮
使用 variant="destructive" 创建毁灭性(警告)提示框。
支付失败
您的付款无法处理。请检查您的支付方式并重试。
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"
import { AlertCircleIcon } from "lucide-react"
操作
使用 AlertAction 向提示框添加按钮或其他操作元素。
暗黑模式现已可用
在您的个人资料设置中启用它即可开始使用。
import {
Alert,
AlertAction,自定义颜色
您可以通过在 Alert 组件上添加自定义类名(如 bg-amber-50 dark:bg-amber-950)来自定义提示框颜色。
您的订阅将在 3 天后过期。
立即续订以避免服务中断,或升级到付费计划以继续使用服务。
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"
import { AlertTriangleIcon } from "lucide-react"
RTL (从右至左)
要在 shadcn/ui 中启用 RTL 支持,请参阅 RTL 配置指南。
支付成功
您的 29.99 美元付款已处理。收据已发送至您的电子邮箱。
新功能可用
我们添加了暗黑模式支持。您可以在账户设置中启用它。
"use client"
import * as React from "react"API 参考
提示框 (Alert)
Alert 组件用于显示需要用户注意的提示信息。
| 属性 | 类型 | 默认 |
|---|---|---|
variant (变体) | "default" | "destructive" | "default" |
AlertTitle
AlertTitle 组件用于显示提示框的标题。
| 属性 | 类型 | 默认 |
|---|---|---|
className | string | - |
AlertDescription
AlertDescription 组件用于显示提示框的描述或正文内容。
| 属性 | 类型 | 默认 |
|---|---|---|
className | string | - |
AlertAction
AlertAction 组件用于显示操作元素(如按钮),它会被绝对定位在提示框的右上角。
| 属性 | 类型 | 默认 |
|---|---|---|
className | string | - |