UNPKG

1.98 kBJavaScriptView Raw
1import _extends from "@babel/runtime-corejs2/helpers/esm/extends";
2import _objectWithoutPropertiesLoose from "@babel/runtime-corejs2/helpers/esm/objectWithoutPropertiesLoose";
3import _inheritsLoose from "@babel/runtime-corejs2/helpers/esm/inheritsLoose";
4import classNames from 'classnames';
5import React from 'react';
6import PropTypes from 'prop-types';
7import { bsClass, getClassSet, splitBsProps } from './utils/bootstrapUtils'; // TODO: `pullRight` doesn't belong here. There's no special handling here.
8
9var propTypes = {
10 pullRight: PropTypes.bool
11};
12var defaultProps = {
13 pullRight: false
14};
15
16var Badge =
17/*#__PURE__*/
18function (_React$Component) {
19 _inheritsLoose(Badge, _React$Component);
20
21 function Badge() {
22 return _React$Component.apply(this, arguments) || this;
23 }
24
25 var _proto = Badge.prototype;
26
27 _proto.hasContent = function hasContent(children) {
28 var result = false;
29 React.Children.forEach(children, function (child) {
30 if (result) {
31 return;
32 }
33
34 if (child || child === 0) {
35 result = true;
36 }
37 });
38 return result;
39 };
40
41 _proto.render = function render() {
42 var _this$props = this.props,
43 pullRight = _this$props.pullRight,
44 className = _this$props.className,
45 children = _this$props.children,
46 props = _objectWithoutPropertiesLoose(_this$props, ["pullRight", "className", "children"]);
47
48 var _splitBsProps = splitBsProps(props),
49 bsProps = _splitBsProps[0],
50 elementProps = _splitBsProps[1];
51
52 var classes = _extends({}, getClassSet(bsProps), {
53 'pull-right': pullRight,
54 // Hack for collapsing on IE8.
55 hidden: !this.hasContent(children)
56 });
57
58 return React.createElement("span", _extends({}, elementProps, {
59 className: classNames(className, classes)
60 }), children);
61 };
62
63 return Badge;
64}(React.Component);
65
66Badge.propTypes = propTypes;
67Badge.defaultProps = defaultProps;
68export default bsClass('badge', Badge);
\No newline at end of file