UNPKG

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