UNPKG

2.09 kBJavaScriptView Raw
1import _extends from 'babel-runtime/helpers/extends';
2import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties';
3import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
4import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
5import _inherits from 'babel-runtime/helpers/inherits';
6import classNames from 'classnames';
7import React from 'react';
8import PropTypes from 'prop-types';
9
10import { bsClass, getClassSet, splitBsProps } from './utils/bootstrapUtils';
11
12// TODO: `pullRight` doesn't belong here. There's no special handling here.
13
14var propTypes = {
15 pullRight: PropTypes.bool
16};
17
18var defaultProps = {
19 pullRight: false
20};
21
22var 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 // Hack for collapsing on IE8.
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
75Badge.propTypes = propTypes;
76Badge.defaultProps = defaultProps;
77
78export default bsClass('badge', Badge);
\No newline at end of file