# @uiw/react-badge

> Badge component

Latest version **4.22.3** (published 2023-11-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install @uiw/react-badge
pnpm add @uiw/react-badge
yarn add @uiw/react-badge
bun add @uiw/react-badge
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; has provenance.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.22.3 |
| Published | 2023-11-29 |
| First published | 2020-05-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 21.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| Author | Kenny Wong |
| Maintainers | uiwjs, wcjiang |
| Keywords | badge, react-badge, design, uiw, uiw-react, react.js, react, react-component, component, components, ui, css, uikit, react-ui, framework, front-end, frontend |

## Links

- npm: https://www.npmjs.com/package/@uiw/react-badge
- Repository: https://github.com/uiwjs/uiw
- Homepage: https://uiwjs.github.io/#/components/badge
- Issues: https://github.com/uiwjs/uiw/issues
- Funding: https://jaywcjlove.github.io/#/sponsor
- npm.io page: https://npm.io/package/@uiw/react-badge

## Dependencies (1)

- [@uiw/utils](https://npm.io/package/@uiw/utils.md) ^4.22.3

## Alternatives

- [@progress/kendo-ooxml](https://npm.io/package/@progress/kendo-ooxml.md) — 152.1K weekly downloads
- [@progress/kendo-react-ripple](https://npm.io/package/@progress/kendo-react-ripple.md) — 8.0K weekly downloads
- [@progress/kendo-react-orgchart](https://npm.io/package/@progress/kendo-react-orgchart.md) — 4.3K weekly downloads
- [@praxisui/dynamic-fields](https://npm.io/package/@praxisui/dynamic-fields.md) — 2.4K weekly downloads
- [@progress/kendo-vue-listbox](https://npm.io/package/@progress/kendo-vue-listbox.md) — 932 weekly downloads

## Recent versions

- 4.22.3 (latest) — 2023-11-29
- 5.0.0-bate.2.1 (bate) — 2023-03-10
- 4.22.2 — 2023-11-09
- 4.22.1 — 2023-11-08
- 4.22.0 — 2023-09-19
- 4.21.28 — 2023-05-05
- 4.21.27 — 2023-04-21
- 4.21.26 — 2023-04-20
- 4.21.25 — 2023-03-14
- 4.21.24 — 2023-03-08
- 5.0.0-bate.2.0 — 2023-03-02
- 4.21.23 — 2022-12-21
- 4.21.22 — 2022-12-19
- 4.21.21 — 2022-12-19
- 5.0.0-bate-19 — 2022-12-12
- … 156 more at https://npm.io/package/@uiw/react-badge/versions

## README

Badge 标记
===

[![Buy me a coffee](https://img.shields.io/badge/Buy%20me%20a%20coffee-048754?logo=buymeacoffee)](https://jaywcjlove.github.io/#/sponsor)
[![Open in unpkg](https://img.shields.io/badge/Open%20in-unpkg-blue)](https://uiwjs.github.io/npm-unpkg/#/pkg/@uiw/react-badge/file/README.md)
[![NPM Downloads](https://img.shields.io/npm/dm/@uiw/react-badge.svg?style=flat)](https://www.npmjs.com/package/@uiw/react-badge)
[![npm version](https://img.shields.io/npm/v/@uiw/react-badge.svg?label=@uiw/react-badge)](https://npmjs.com/@uiw/react-badge)

出现在按钮、图标旁的数字或状态标记。

```jsx
import { Badge } from 'uiw';
// or
import Badge from '@uiw/react-badge';
```

### 基础用法

```jsx mdx:preview
import React from 'react';
import { Badge, Row, Col, Avatar, Divider } from 'uiw';

export default function Demo() {
  return(
    <div>
      <Row gutter={20}>
        <Col fixed>
          <Badge count={9}>
            <Avatar shape="square" size="large" />
          </Badge>
        </Col>
        <Col fixed>
          <Badge count={100}>
            <Avatar shape="square" size="large" />
          </Badge>
        </Col>
        <Col>
          <Badge dot count={9}>
            <Avatar shape="square" size="large" />
          </Badge>
        </Col>
      </Row>
      <Divider />
      <Badge count={12}>
        评论
      </Badge>
    </div>
  );
}
```

### 封顶数字

不包裹任何元素即是独立使用，可自定样式展现。

```jsx mdx:preview
import React from 'react';
import { Badge, Row, Col, Avatar, Divider } from 'uiw';

const styl={ marginRight: 20, display: 'inline-block' }

export default function Demo() {
  return (
    <Row gutter={20}>
      <Col fixed>
        <Badge count={99}>
          <Avatar shape="square" size="large" />
        </Badge>
      </Col>
      <Col fixed>
        <Badge count={100} style={{ backgroundColor: '#87d068' }}>
          <Avatar shape="square" size="large" />
        </Badge>
      </Col>
      <Col fixed>
        <Badge count={99} max={10} style={styl}>
          <Avatar shape="square" size="large" />
        </Badge>
      </Col>
      <Col fixed>
        <Badge count={100} max={999} style={styl}>
          <Avatar shape="square" size="large" />
        </Badge>
      </Col>
      <Col fixed>
        <Badge count={100} max={999} style={styl}>
          <Avatar shape="square" size="large" />
        </Badge>
      </Col>
    </Row>
  )
}
```

### 独立使用

不包裹任何元素即是独立使用，可自定样式展现。

```jsx mdx:preview
import React from 'react';
import { Badge, Row, Col } from 'uiw';

export default function Demo() {
  return (
    <Row gutter={10}>
      <Col fixed>
        <Badge count={25} />
      </Col>
      <Col fixed>
        <Badge count={4} style={{ backgroundColor: '#fff', color: '#f04134', boxShadow: 'rgb(217, 217, 217) 0px 0px 0px 1px inset' }} /> 
      </Col>
      <Col fixed>
        <Badge count={109} style={{ backgroundColor: '#87d068' }} /> 
      </Col>
    </Row>
  )
}
```

### 小红点

以红点的形式标注需要关注的内容。

```jsx mdx:preview
import React from 'react';
import { Badge, Icon } from 'uiw';

export default function Demo() {
  return (
    <div>
      <Badge dot style={{ marginRight: 10 }}>
        数据查询
      </Badge>
      <Badge dot count={4}>
        <Icon type='mail-o' />
      </Badge>
    </div>
  );
}
```

### 状态点

用于表示状态的小圆点，可以设置 `processing={true}` 让状态点，显示动画效果。

```jsx mdx:preview
import React from 'react';
import { Badge } from 'uiw';

export default function Demo() {
  return (
    <div>
      <Badge color="#28a745" />
      <Badge color="#008EF0" />
      <Badge color="#dc3545" />
      <Badge color="#393E48" />
      <Badge color="#ffc107" />
      <Badge color="#f95c2b" />
      <Badge color="#dc3545"/>
      <Badge color="#c2c2c2"/>
      <Badge color="#F95C2B" processing />
      <br />
      <Badge color="#28a745">Success</Badge>
      <br />
      <Badge color="#dc3545">Error</Badge>
      <br />
      <Badge color="#c2c2c2">Default</Badge>
      <br />
      <Badge color="#008EF0" processing>Processing</Badge>
      <br />
      <Badge color="#ffc107">Warning</Badge>
      <Badge color="#ffc107" processing>Warning</Badge>
    </div>
  );
}
```

## API

| 参数 | 说明 | 类型 | 默认值 |
|--------- |-------- |--------- |-------- |
| style | 默认设置计数圆点样式，设置 `color`，`style` 设置外层节点样式 | Object | - |
| count | 展示的数字 | Number | - |
| max | 最大值，超过最大值会显示 '{max}+' | Number | `99` |
| dot | 不展示数字，只有一个小红点 | Boolean | `false` |
| processing | 不展示数字，只有一个小红点 | Boolean | - |
| color | 设置 Badge 为状态点的颜色 | String | - |

---
_Source: https://npm.io/package/@uiw/react-badge · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
