Badge 徽标数
图标右上角的圆形徽标数字。
何时使用#
一般出现在通知图标或头像的右上角,用于显示需要处理的消息条数,通过醒目视觉形式吸引用户处理。
API#
<Badge count={5}>
<a href="#" className="head-example"></a>
</Badge>
参数 |
说明 |
类型 |
可选值 |
默认值 |
count |
展示的数字,大于 99 时显示为 99+,为 0 时隐藏 |
Number |
|
|
dot |
不展示数字,只有一个小红点 |
boolean |
|
false |
代码演示
import { Badge } from 'antd';
ReactDOM.render(
<Badge count={5}>
<a href="#" className="head-example"></a>
</Badge>
, document.getElementById('components-badge-demo-basic'));
.ant-badge {
margin-right: 16px;
}
.head-example {
width: 42px;
height: 42px;
border-radius: 6px;
background: #eee;
display: inline-block;
}
import { Badge } from 'antd';
ReactDOM.render(
<a href="#">
<Badge count={5}>
<span className="head-example"></span>
</Badge>
</a>
, document.getElementById('components-badge-demo-link'));
import { Badge, Button, Icon } from 'antd';
const ButtonGroup = Button.Group;
const Test = React.createClass({
getInitialState() {
return {
count: 5,
show: true,
};
},
increase() {
const count = this.state.count + 1;
this.setState({ count });
},
decline() {
let count = this.state.count - 1;
if (count < 0) {
count = 0;
}
this.setState({ count });
},
onClick() {
this.setState({
show: !this.state.show
});
},
onNumberClick() {
const count = this.state.count;
this.setState({
count: count ? 0 : 5
});
},
render() {
return <div>
<Badge count={this.state.count}>
<a href="#" className="head-example"></a>
</Badge>
<Badge dot={this.state.show}>
<a href="#" className="head-example"></a>
</Badge>
<div style={{ marginTop: 10 }}>
<Button type="ghost" onClick={this.onNumberClick} style={{marginRight: 6}}>
切换数字显隐
</Button>
<Button type="ghost" onClick={this.onClick} style={{marginRight: 6}}>
切换红点显隐
</Button>
<ButtonGroup>
<Button type="ghost" onClick={this.decline}>
<Icon type="minus" />
</Button>
<Button type="ghost" onClick={this.increase}>
<Icon type="plus" />
</Button>
</ButtonGroup>
</div>
</div>;
}
});
ReactDOM.render(
<Test />
, document.getElementById('components-badge-demo-change'));
import { Badge } from 'antd';
ReactDOM.render(<div>
<Badge count={99}>
<a href="#" className="head-example"></a>
</Badge>
<Badge count={200}>
<a href="#" className="head-example"></a>
</Badge>
</div>, document.getElementById('components-badge-demo-99plus'));
import { Badge, Icon } from 'antd';
ReactDOM.render(<div>
<Badge dot>
<Icon type="notification" />
</Badge>
<Badge dot>
<a href="#">一个链接</a>
</Badge>
</div>, document.getElementById('components-badge-demo-dot'));