Components
- 手风琴
- 提示
- 警告对话框
- 宽高比
- 附件
- 头像
- 徽章
- 面包屑导航
- Bubble
- 按钮
- 按钮组
- 日历 Calendar
- 卡片
- 轮播图
- 图表 Chart
- 复选框
- 折叠面板
- 组合框
- 命令
- 上下文菜单
- 数据表格 Data Table
- 日期选择器 Date Picker
- 对话框 Dialog
- 方向
- 抽屉
- 下拉菜单
- 空状态
- 字段
- 悬停卡片
- 输入
- 输入组
- Input OTP
- 项目
- Kbd
- 标签
- 标记
- 菜单栏
- 消息
- 消息滚动器
- 原生选择框
- 导航菜单 Navigation Menu
- 分页
- 弹出框
- 进度 Progress
- 单选框组
- 可调整大小
- 滚动区域 Scroll Area
- 选择框
- 分隔符 Separator
- 侧边栏 Sheet
- 侧边栏 Sidebar
- 骨架屏
- 滑块
- Sonner
- 加载指示器 Spinner
- 开关
- 表格
- 标签页 Tabs
- 文本域
- 吐司
- 切换按钮 Toggle
- 切换组
- 提示 Tooltip
- 排版
@shadcn/react
Utilities
BadgeSecondaryDestructiveOutline
import { Badge } from "@/components/ui/badge"
export function BadgeDemo() {安装#
pnpm dlx shadcn@latest add badge
使用#
import { Badge } from "@/components/ui/badge"<Badge variant="default | outline | secondary | destructive">徽章</Badge>Example#
Variants#
Use the variant prop to change the badge variant.
DefaultSecondaryDestructiveOutlineGhost
import { Badge } from "@/components/ui/badge"
export function BadgeVariants() {With Icon#
You can render icons inside a badge. Use data-icon="inline-start" to render the icon on the left, and data-icon="inline-end" to render the icon on the right.
VerifiedBookmark
import { BadgeCheck, BookmarkIcon } from "lucide-react"
import { Badge } from "@/components/ui/badge"With Spinner#
You can render a loading spinner inside a badge. Remember to add the data-icon="inline-start" or data-icon="inline-end" attribute to the spinner.
DeletingGenerating
import { Badge } from "@/components/ui/badge"
import { Spinner } from "@/components/ui/spinner"
Links#
Use the asChild prop to render a link as a badge.
import { ArrowUpRightIcon } from "lucide-react"
import { Badge } from "@/components/ui/badge"Custom Colors#
You can customize the badge colors by adding custom classes such as bg-green-50 dark:bg-green-800 to the Badge component.
BlueGreenSkyPurpleRed
import { Badge } from "@/components/ui/badge"
export function BadgeCustomColors() {RTL#
要在 shadcn/ui 中启用 RTL 支持,请参见 RTL 配置指南。
شارةثانويمدمرمخططمتحققإشارة مرجعية
"use client"
import * as React from "react"API 参考#
Badge#
Badge 组件用于显示徽章或看起来像徽章的组件。
| 属性 | 类型 | 默认值 |
|---|---|---|
variant | "default" | "secondary" | "destructive" | "outline" | "ghost" | "link" | "default" |
className | string | - |