1 | import _extends from 'babel-runtime/helpers/extends';
|
2 | import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties';
|
3 | import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
|
4 | import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
|
5 | import _inherits from 'babel-runtime/helpers/inherits';
|
6 | import classNames from 'classnames';
|
7 | import React from 'react';
|
8 | import PropTypes from 'prop-types';
|
9 |
|
10 | import { bsClass, getClassSet, splitBsProps } from './utils/bootstrapUtils';
|
11 |
|
12 |
|
13 |
|
14 | var propTypes = {
|
15 | pullRight: PropTypes.bool
|
16 | };
|
17 |
|
18 | var defaultProps = {
|
19 | pullRight: false
|
20 | };
|
21 |
|
22 | var Badge = function (_React$Component) {
|
23 | _inherits(Badge, _React$Component);
|
24 |
|
25 | function Badge() {
|
26 | _classCallCheck(this, Badge);
|
27 |
|
28 | return _possibleConstructorReturn(this, _React$Component.apply(this, arguments));
|
29 | }
|
30 |
|
31 | Badge.prototype.hasContent = function hasContent(children) {
|
32 | var result = false;
|
33 |
|
34 | React.Children.forEach(children, function (child) {
|
35 | if (result) {
|
36 | return;
|
37 | }
|
38 |
|
39 | if (child || child === 0) {
|
40 | result = true;
|
41 | }
|
42 | });
|
43 |
|
44 | return result;
|
45 | };
|
46 |
|
47 | Badge.prototype.render = function render() {
|
48 | var _props = this.props,
|
49 | pullRight = _props.pullRight,
|
50 | className = _props.className,
|
51 | children = _props.children,
|
52 | props = _objectWithoutProperties(_props, ['pullRight', 'className', 'children']);
|
53 |
|
54 | var _splitBsProps = splitBsProps(props),
|
55 | bsProps = _splitBsProps[0],
|
56 | elementProps = _splitBsProps[1];
|
57 |
|
58 | var classes = _extends({}, getClassSet(bsProps), {
|
59 | 'pull-right': pullRight,
|
60 |
|
61 |
|
62 | hidden: !this.hasContent(children)
|
63 | });
|
64 |
|
65 | return React.createElement(
|
66 | 'span',
|
67 | _extends({}, elementProps, { className: classNames(className, classes) }),
|
68 | children
|
69 | );
|
70 | };
|
71 |
|
72 | return Badge;
|
73 | }(React.Component);
|
74 |
|
75 | Badge.propTypes = propTypes;
|
76 | Badge.defaultProps = defaultProps;
|
77 |
|
78 | export default bsClass('badge', Badge); |
\ | No newline at end of file |