UNPKG

3.4 kBJavaScriptView Raw
1import _extends from 'babel-runtime/helpers/extends';
2import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
3import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
4import _inherits from 'babel-runtime/helpers/inherits';
5
6var _class, _temp;
7
8import React, { Component } from 'react';
9import PropTypes from 'prop-types';
10import classNames from 'classnames';
11import ConfigProvider from '../config-provider';
12import { obj } from '../util';
13import Sup from './sup';
14
15/**
16 * Badge
17 */
18var Badge = (_temp = _class = function (_Component) {
19 _inherits(Badge, _Component);
20
21 function Badge() {
22 _classCallCheck(this, Badge);
23
24 return _possibleConstructorReturn(this, _Component.apply(this, arguments));
25 }
26
27 Badge.prototype.render = function render() {
28 var _classNames;
29
30 var _props = this.props,
31 prefix = _props.prefix,
32 dot = _props.dot,
33 className = _props.className,
34 children = _props.children,
35 content = _props.content,
36 style = _props.style,
37 rtl = _props.rtl,
38 originCount = _props.count,
39 showZero = _props.showZero,
40 originOverflowCount = _props.overflowCount;
41
42 var count = parseInt(originCount, 10);
43 var overflowCount = parseInt(originOverflowCount, 10);
44 var others = obj.pickOthers(Badge.propTypes, this.props);
45
46 // 如果是数字,则添加默认的 title
47 if (count || count === 0 && showZero) {
48 others.title = others.title || '' + count;
49 }
50
51 var classes = classNames(prefix + 'badge', (_classNames = {}, _classNames[prefix + 'badge-not-a-wrapper'] = !children, _classNames), className);
52
53 return React.createElement(
54 'span',
55 _extends({ dir: rtl ? 'rtl' : undefined, className: classes }, others),
56 children,
57 React.createElement(Sup, {
58 prefix: prefix,
59 content: content,
60 count: count,
61 showZero: showZero,
62 overflowCount: overflowCount,
63 dot: dot,
64 style: style
65 })
66 );
67 };
68
69 return Badge;
70}(Component), _class.propTypes = {
71 // 样式类名的品牌前缀
72 prefix: PropTypes.string,
73 rtl: PropTypes.bool,
74 // 自定义类名
75 className: PropTypes.string,
76 // 自定义内联样式
77 style: PropTypes.object,
78 /**
79 * 徽标依托的内容,一般显示在其右上方
80 */
81 children: PropTypes.node,
82 /**
83 * 展示的数字,大于 `overflowCount` 时显示为 `${overflowCount}+`,为 `0` 时默认隐藏
84 */
85 count: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
86 /**
87 * 当`count`为`0`时,是否显示count
88 * @version 1.16
89 */
90 showZero: PropTypes.bool,
91 /**
92 * 自定义徽标中的内容
93 */
94 content: PropTypes.node,
95 /**
96 * 展示的封顶的数字
97 */
98 overflowCount: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
99 /**
100 * 不展示数字,只展示一个小红点
101 */
102 dot: PropTypes.bool
103}, _class.defaultProps = {
104 prefix: 'next-',
105 count: 0,
106 showZero: false,
107 overflowCount: 99,
108 dot: false
109}, _temp);
110Badge.displayName = 'Badge';
111
112
113export default ConfigProvider.config(Badge);
\No newline at end of file