UNPKG

1.84 kBJavaScriptView Raw
1import _Object$values from "@babel/runtime-corejs2/core-js/object/values";
2import _extends from "@babel/runtime-corejs2/helpers/esm/extends";
3import _objectWithoutPropertiesLoose from "@babel/runtime-corejs2/helpers/esm/objectWithoutPropertiesLoose";
4import _inheritsLoose from "@babel/runtime-corejs2/helpers/esm/inheritsLoose";
5import classNames from 'classnames';
6import React from 'react';
7import { bsClass, bsStyles, getClassSet, splitBsProps } from './utils/bootstrapUtils';
8import { State, Style } from './utils/StyleConfig';
9
10var Label =
11/*#__PURE__*/
12function (_React$Component) {
13 _inheritsLoose(Label, _React$Component);
14
15 function Label() {
16 return _React$Component.apply(this, arguments) || this;
17 }
18
19 var _proto = Label.prototype;
20
21 _proto.hasContent = function hasContent(children) {
22 var result = false;
23 React.Children.forEach(children, function (child) {
24 if (result) {
25 return;
26 }
27
28 if (child || child === 0) {
29 result = true;
30 }
31 });
32 return result;
33 };
34
35 _proto.render = function render() {
36 var _this$props = this.props,
37 className = _this$props.className,
38 children = _this$props.children,
39 props = _objectWithoutPropertiesLoose(_this$props, ["className", "children"]);
40
41 var _splitBsProps = splitBsProps(props),
42 bsProps = _splitBsProps[0],
43 elementProps = _splitBsProps[1];
44
45 var classes = _extends({}, getClassSet(bsProps), {
46 // Hack for collapsing on IE8.
47 hidden: !this.hasContent(children)
48 });
49
50 return React.createElement("span", _extends({}, elementProps, {
51 className: classNames(className, classes)
52 }), children);
53 };
54
55 return Label;
56}(React.Component);
57
58export default bsClass('label', bsStyles(_Object$values(State).concat([Style.DEFAULT, Style.PRIMARY]), Style.DEFAULT, Label));
\No newline at end of file