#Badge 角标
展示数量、未读提醒或简短状态。
#基础用法
交互预览基础用法
899+0
运行中待处理已停止更新中
basic.tsx
import { Badge, Button } from '@sudden3/leaf-ui';
import { Bell, Mail } from 'lucide-react';
export function BadgeBasic() {
return (
<div className="leaf-demo-stack leaf-demo-stack--wide">
<div className="leaf-demo-row">
<Badge count={8} aria-label="8 条通知">
<Button variant="outline" startIcon={<Bell />} aria-label="通知" />
</Badge>
<Badge count={120}>
<Button variant="outline">收件箱</Button>
</Badge>
<Badge dot aria-label="有新消息">
<Button variant="ghost" startIcon={<Mail />} aria-label="消息" />
</Badge>
<Badge count={0} showZero color="#7654c6" />
</div>
<div className="leaf-demo-row">
<Badge status="success" text="运行中" />
<Badge status="warning" text="待处理" />
<Badge status="error" text="已停止" />
<Badge status="info" text="更新中" />
</div>
</div>
);
}
#Badge API
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
children | ReactNode | — | 设置后将角标附着在该内容右上方 |
count | number | string | — | 角标内容 |
max | number | 99 | 超过该值时展示 max+ |
showZero | boolean | false | 允许展示 0 |
dot | boolean | false | 使用圆点提醒 |
status | 'success' | 'warning' | 'error' | 'info' | 'default' | — | 使用对应颜色的状态圆点 |
text | ReactNode | — | 圆点旁的说明 |
color | string | — | 自定义角标颜色 |
#类型
定义组件属性或组装列表时可导入相关类型。
import type { BadgeProps } from '@sudden3/leaf-ui';#使用说明
独立使用时可展示数量或状态。附着在按钮等内容上时,为圆点提醒提供 aria-label,以说明提醒的含义。