Skip to content

Badge ​

Introduction ​

The badge component is used to display unread message counts or status indicators next to icons or text.
You can use <MYBadge></MYBadge> or <MYBadge /> to create a badge.

Numeric Content ​

Use the content prop to set the badge content.

Code Demo
5
展开代码

Dot Mode ​

Use the dot prop to display a small red dot instead of a specific number.

Code Demo
展开代码

Custom Color ​

Use the color prop to customize the badge color.

Code Demo
8
展开代码

Position Adjustment ​

Use the position prop to adjust the badge position.

Code Demo
3
3
3
3
展开代码

Max Value Limit ​

Use the max prop to limit the maximum numeric value displayed on the badge.

Code Demo
99+
10+
5+
展开代码

Standalone Usage ​

The badge can also be used independently without wrapping any content.

Code Demo
5
New Message!
展开代码

Combined Usage ​

Finally, here's an example combining multiple APIs to create a badge:

Code Demo
展开代码

API Reference ​

Props ​

ParameterDescriptionTypeOptionsDefault
contentBadge contentstring | number—''
dotWhether to show a small red dotboolean—false
colorBadge colorstringSupports hex colors or color names'#ff4d4f'
positionBadge positionstringtop-right/top-left/bottom-right/bottom-left'top-right'
maxMaximum value limitnumber—99

Type Definitions ​

typescript
interface BadgeProps {
  content?: string | number;
  dot?: boolean;
  color?: string;
  position?: 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left';
  max?: number;
}

Released under the MIT License.