1 | import _extends from 'babel-runtime/helpers/extends';
|
2 | import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
|
3 | import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
|
4 | import _inherits from 'babel-runtime/helpers/inherits';
|
5 |
|
6 | var _class, _temp;
|
7 |
|
8 | import React, { Component } from 'react';
|
9 | import PropTypes from 'prop-types';
|
10 | import classNames from 'classnames';
|
11 | import ConfigProvider from '../config-provider';
|
12 | import { obj } from '../util';
|
13 | import Sup from './sup';
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | var 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 |
|
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 |
|
84 |
|
85 | count: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
86 | |
87 |
|
88 |
|
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);
|
110 | Badge.displayName = 'Badge';
|
111 |
|
112 |
|
113 | export default ConfigProvider.config(Badge); |
\ | No newline at end of file |