Badge 徽标数
定义/Definition
图标右上角的圆形徽标数字。一般出现在通知图标或头像的右上角,用于显示需要处理的消息条数,通过醒目视觉形式吸引用户处理。规则 / Rule
展示的数字,根据业务需求设定最大值,例如:大于 99 时展示封顶数字值为 99+。
展示数字为0时,徽标数隐藏。
中间元素可以是数字/字母/汉字,保证两边到边框距离为8px。
代码演示
简单的徽章展示。
import { Badge } from 'antd-mobile';
ReactDOM.render(
<div className="badge-container" style={{ padding: '40px 16px' }}>
<Badge text={9}>
<span className="head-example"></span>
</Badge>
<Badge text={'new'}>
<span className="head-example"></span>
</Badge>
</div>
, mountNode);
只有个讨嫌的小红点,没有具体数字
.am-badge {
margin-right: 8px;
}
import { Badge } from 'antd-mobile';
ReactDOM.render(
<div className="badge-container" style={{ padding: '40px 16px' }}>
<Badge dot>
<a href="#">一个链接</a>
</Badge>
<Badge dot size="large">
<span className="head-example"></span>
</Badge>
</div>
, mountNode);
像丝带一样的角标
.am-badge {
margin-right: 8px;
}
import { Badge } from 'antd-mobile';
ReactDOM.render(
<div className="badge-container" style={{ padding: '40px 16px' }}>
<Badge text={'new'} corner>
<span className="head-example"></span>
</Badge>
<Badge text={'限时优惠'} corner size="large">
<span className="head-example head-example-l"></span>
</Badge>
</div>
, mountNode);
数字大于99,会显示
.head-example {
width: 52px;
height: 52px;
background: rgba(255, 140, 101, 0.15);
display: inline-block;
}
.am-badge {
margin-right: 8px;
}
.head-example-l {
width: 72px;
height: 72px;
}
99+
import { Badge } from 'antd-mobile';ReactDOM.render( <div className="badge-container" style={{ padding: '40px 16px' }}> <Badge text={99}> <span className="head-example"></span> </Badge> <Badge text={108}> <span className="head-example"></span> </Badge> </div>, mountNode);
结合列表的案例参考
.am-badge { margin-right: 8px;}
import { List, Badge } from 'antd-mobile';
ReactDOM.render(
<div className="badge-container">
<form>
<List>
<List.Header>列表</List.Header>
<List.Body>
<List.Item extra="内容内容">
文本内容<Badge dot style={{ marginLeft: 8 }} />
</List.Item>
<List.Item extra="内容内容" arrow="horizontal">
文本内容<Badge text={'new'} style={{ marginLeft: 8 }} />
</List.Item>
<List.Item extra="内容内容" arrow="horizontal">
文本内容<Badge text={4} style={{ marginLeft: 8 }} />
</List.Item>
<List.Item extra="内容内容" arrow="horizontal">
文本内容<Badge text={100} style={{ marginLeft: 8 }} />
</List.Item>
</List.Body>
</List>
<List>
<List.Header>带icon</List.Header>
<List.Body>
<List.Item extra="内容内容" arrow="horizontal">
<div style={{ padding: '4px 0' }}>
<Badge dot>
<span style={{ width: 28, height: 28, background: 'rgba(255, 140, 101, 0.15)', display: 'inline-block' }}></span>
</Badge>小圆点
</div>
</List.Item>
<List.Item thumb="https://os.alipayobjects.com/rmsportal/JteFDJaPwHuwXgs.jpg" extra={<Badge text={77} />} arrow="horizontal">
右侧内容
</List.Item>
<List.Item thumb="https://os.alipayobjects.com/rmsportal/JteFDJaPwHuwXgs.jpg">
内容内容
</List.Item>
</List.Body>
</List>
<List>
<List.Body>
<List.Item extra="内容内容" arrow="horizontal">
<div style={{ padding: '4px 0' }}>
<Badge text={'new'} corner>
<span style={{ width: 52, height: 52, background: 'rgba(255, 140, 101, 0.15)', display: 'inline-block' }}></span>
</Badge>有角标
</div>
</List.Item>
<List.Item extra="内容内容" arrow="horizontal">
<div style={{ padding: '10px 0' }}>
<Badge text={9}>
<span style={{ width: 52, height: 52, background: 'rgba(255, 140, 101, 0.15)', display: 'inline-block' }}></span>
</Badge>数字
</div>
</List.Item>
<List.Item extra="内容内容" arrow="horizontal">
<div style={{ padding: '10px 0' }}>
<Badge text={108}>
<span style={{ width: 52, height: 52, background: 'rgba(255, 140, 101, 0.15)', display: 'inline-block' }}></span>
</Badge>超出99
</div>
</List.Item>
</List.Body>
</List>
<List>
<List.Body>
<List.Item extra="内容内容" arrow="horizontal">
<div style={{ padding: '4px 0' }}>
<Badge text={'限时优惠'} corner size="large">
<span style={{ width: 72, height: 72, background: 'rgba(255, 140, 101, 0.15)', display: 'inline-block' }}></span>
</Badge>角标
</div>
</List.Item>
</List.Body>
</List>
</form>
</div>
, mountNode);
.am-badge {
margin-right: 8px;
}
API
成员 | 说明 | 类型 | 默认值 |
---|---|---|---|
text | 展示的数字或文案,当为数字时候,大于 overflowCount 时显示为 ${overflowCount}+,为 0 时隐藏 | String| Number | - |
dot | 不展示数字,只有一个小红点 | Boolean | false |
corner | 展示位角标样式 | Boolean | false |
overflowCount | 展示封顶的数字值 | Number | 99 |
size | 红点及角标状态下可选默认(null)或者大号(large) | String | - |