forked from ant-design/ant-design
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.jsx
59 lines (52 loc) · 1.52 KB
/
index.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import React from 'react';
import Animate from 'rc-animate';
import ScrollNumber from './ScrollNumber';
import classNames from 'classnames';
export default class Badge extends React.Component {
static defaultProps = {
prefixCls: 'ant-badge',
count: null,
dot: false,
overflowCount: 99,
}
static propTypes = {
count: React.PropTypes.oneOfType([
React.PropTypes.string,
React.PropTypes.number
]),
dot: React.PropTypes.bool,
overflowCount: React.PropTypes.number,
}
render() {
let { count, prefixCls, overflowCount, className, style, children } = this.props;
const dot = this.props.dot;
count = count > overflowCount ? `${overflowCount}+` : count;
// dot mode don't need count
if (dot) {
count = '';
}
// null undefined "" "0" 0
const hidden = (!count || count === '0') && !dot;
const scrollNumberCls = prefixCls + (dot ? '-dot' : '-count');
const badgeCls = classNames({
[className]: !!className,
[prefixCls]: true,
[`${prefixCls}-not-a-wrapper`]: !children,
});
return (
<span className={badgeCls} title={count} {...this.props} style={null}>
{children}
<Animate component=""
showProp="data-show"
transitionName={`${prefixCls}-zoom`}
transitionAppear>
{
hidden ? null :
<ScrollNumber data-show={!hidden} className={scrollNumberCls}
count={count} style={style} />
}
</Animate>
</span>
);
}
}