forked from alibaba-fusion/next
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.jsx
104 lines (97 loc) · 2.79 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import ConfigProvider from '../config-provider';
import { obj } from '../util';
import Sup from './sup';
/**
* Badge
*/
class Badge extends Component {
static propTypes = {
// 样式类名的品牌前缀
prefix: PropTypes.string,
rtl: PropTypes.bool,
// 自定义类名
className: PropTypes.string,
// 自定义内联样式
style: PropTypes.object,
/**
* 徽标依托的内容,一般显示在其右上方
*/
children: PropTypes.node,
/**
* 展示的数字,大于 `overflowCount` 时显示为 `${overflowCount}+`,为 `0` 时默认隐藏
*/
count: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
/**
* 当`count`为`0`时,是否显示count
* @version 1.16
*/
showZero: PropTypes.bool,
/**
* 自定义徽标中的内容
*/
content: PropTypes.node,
/**
* 展示的封顶的数字
*/
overflowCount: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
/**
* 不展示数字,只展示一个小红点
*/
dot: PropTypes.bool,
};
static defaultProps = {
prefix: 'next-',
count: 0,
showZero: false,
overflowCount: 99,
dot: false,
};
render() {
const {
prefix,
dot,
className,
children,
content,
style,
rtl,
count: originCount,
showZero,
overflowCount: originOverflowCount,
} = this.props;
const count = parseInt(originCount, 10);
const overflowCount = parseInt(originOverflowCount, 10);
const others = obj.pickOthers(Badge.propTypes, this.props);
// 如果是数字,则添加默认的 title
if (count || (count === 0 && showZero)) {
others.title = others.title || `${count}`;
}
const classes = classNames(
`${prefix}badge`,
{
[`${prefix}badge-not-a-wrapper`]: !children,
},
className
);
return (
<span dir={rtl ? 'rtl' : undefined} className={classes} {...others}>
{children}
<Sup
{...{
prefix,
content,
count,
showZero,
overflowCount,
dot,
style,
}}
/>
</span>
);
}
}
export default ConfigProvider.config(Badge);