Badge 徽标数
图标右上角的圆形徽标数字。
何时使用#
一般出现在通知图标或头像的右上角,用于显示需要处理的消息条数,通过醒目视觉形式吸引用户处理。
API#
<Badge count={5}>
<a href="#" className="head-example"></a>
</Badge>
参数 |
说明 |
类型 |
可选值 |
默认值 |
count |
展示的数字,大于 overflowCount 时显示为 ${overflowCount}+ ,为 0 时隐藏 |
Number |
|
|
overflowCount |
展示封顶的数字值 |
Number |
|
99 |
dot |
不展示数字,只有一个小红点 |
boolean |
|
false |
代码演示
import { Badge } from 'antd';
ReactDOM.render(
<Badge count={5}>
<a href="#" className="head-example"></a>
</Badge>
, mountNode);
.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(<div>
<Badge count={99}>
<a href="#" className="head-example"></a>
</Badge>
<Badge count={200}>
<a href="#" className="head-example"></a>
</Badge>
</div>, mountNode);
import { Badge, Icon } from 'antd';
ReactDOM.render(<div>
<Badge dot>
<Icon type="notification" />
</Badge>
<Badge dot>
<a href="#">一个链接</a>
</Badge>
</div>, mountNode);
import { Badge } from 'antd';
ReactDOM.render(<div>
<Badge count={99} overflowCount={10}>
<a href="#" className="head-example"></a>
</Badge>
<Badge count={1000} overflowCount={999}>
<a href="#" className="head-example"></a>
</Badge>
</div>, mountNode);
import { Badge } from 'antd';
ReactDOM.render(<div>
<Badge count={25} />
<Badge count={4} style={{ backgroundColor: '#fff', color: '#999', borderColor: '#d9d9d9' }} />
<Badge count={109} style={{ backgroundColor: '#87d068' }} />
</div>, mountNode);
import { Badge } from 'antd';
ReactDOM.render(
<a href="#">
<Badge count={5}>
<span className="head-example"></span>
</Badge>
</a>
, mountNode);
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,
});
},
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 }}>
<ButtonGroup>
<Button type="ghost" onClick={this.decline}>
<Icon type="minus" />
</Button>
<Button type="ghost" onClick={this.increase}>
<Icon type="plus" />
</Button>
</ButtonGroup>
<Button type="ghost" onClick={this.onClick} style={{ marginLeft: 8 }}>
切换红点显隐
</Button>
</div>
</div>
);
}
});
ReactDOM.render(
<Test />
, mountNode);