> For AI agents: the complete documentation index is available at https://rickyshin93.github.io/tao-ui/zh/llms.txt, the full documentation bundle is available at https://rickyshin93.github.io/tao-ui/zh/llms-full.txt.

# Badge

数据展示`@rockshin/tao-ui`

[代码演示](#代码演示)[API](#api)

展示计数、紧凑状态标记与缎带。

组件采用 tao-ui 原生实现，公共 API 对齐 Ant Design 6.7.0。外观、主题 token 与 Semantic DOM 定制遵循 tao-ui，主题通过 `TaoProvider` 配置。

Badge 遵循 6.7.0 计数与状态 API；颜色和 Ribbon 使用 tao-ui token，计数变化直接更新。

## 何时使用

把计数关联到对应控件，状态信息同时提供文字。

## 代码演示


### 计数、零与溢出
```tsx preview
import { Avatar, Badge } from "@rockshin/tao-ui";

export default function Example() {
  return (
    <div
      style={{
        display: "flex",
        gap: 16,
        alignItems: "center",
        flexWrap: "wrap",
      }}
    >
      <Badge count={5}>
        <Avatar shape="square">A</Avatar>
      </Badge>
      <Badge count={0} showZero>
        <Avatar shape="square">B</Avatar>
      </Badge>
      <Badge count={120}>
        <Avatar shape="square">C</Avatar>
      </Badge>
      <Badge count={120} overflowCount={999}>
        <Avatar shape="square">D</Avatar>
      </Badge>
    </div>
  );
}
```

### 改变计数
```tsx preview
import { useState } from "react";
import { Badge, Button } from "@rockshin/tao-ui";

export default function Example() {
  const [count, setCount] = useState(5);
  return (
    <div
      style={{
        display: "flex",
        gap: 16,
        alignItems: "center",
        flexWrap: "wrap",
      }}
    >
      <Badge count={count} showZero />
      <Button onClick={() => setCount(Math.max(0, count - 1))}>−</Button>
      <Button onClick={() => setCount(count + 1)}>+</Button>
    </div>
  );
}
```

### 圆点与小尺寸
```tsx preview
import { Badge, Button } from "@rockshin/tao-ui";

export default function Example() {
  return (
    <div
      style={{
        display: "flex",
        gap: 16,
        alignItems: "center",
        flexWrap: "wrap",
      }}
    >
      <Badge dot>
        <Button>Updates</Button>
      </Badge>
      <Badge count={8} size="small">
        <Button>Messages</Button>
      </Badge>
      <Badge dot={false}>
        <Button>Read</Button>
      </Badge>
    </div>
  );
}
```

### 状态标签
```tsx preview
import { Badge } from "@rockshin/tao-ui";

export default function Example() {
  return (
    <div style={{ display: "flex", gap: 16, flexDirection: "column" }}>
      <Badge status="success" text="Synced" />
      <Badge status="processing" text="Processing" />
      <Badge status="warning" text="Needs review" />
      <Badge status="error" text="Failed" />
      <Badge status="default" text="Idle" />
    </div>
  );
}
```

### 自定义颜色与偏移
```tsx preview
import { Avatar, Badge } from "@rockshin/tao-ui";

export default function Example() {
  return (
    <div
      style={{
        display: "flex",
        gap: 16,
        alignItems: "center",
        flexWrap: "wrap",
      }}
    >
      <Badge count="New" color="#365e67" offset={[10, 4]}>
        <Avatar size={56} shape="square">
          AL
        </Avatar>
      </Badge>
      <Badge color="#8b5c3c" text="Custom status" />
    </div>
  );
}
```

### 缎带位置
```tsx preview
import { Badge, Card } from "@rockshin/tao-ui";

export default function Example() {
  return (
    <div style={{ display: "grid", gap: 24 }}>
      <Badge.Ribbon text="Featured">
        <Card title="Team plan">Shared workspace and collaboration.</Card>
      </Badge.Ribbon>
      <Badge.Ribbon
        text="Preview"
        color="var(--tao-color-success)"
        placement="start"
      >
        <Card title="New workflow">Try the updated workflow.</Card>
      </Badge.Ribbon>
    </div>
  );
}
```

## API


### [#](#badge)Badge



| 属性 | 说明 | 类型 | 默认值 |
| --- | --- | --- | --- |

