-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathBadge.js
More file actions
57 lines (43 loc) · 1.16 KB
/
Badge.js
File metadata and controls
57 lines (43 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import classNames from 'classnames';
import React from 'react';
import PropTypes from 'prop-types';
import { bsClass, getClassSet, splitBsProps } from './utils/bootstrapUtils';
// TODO: `pullRight` doesn't belong here. There's no special handling here.
const propTypes = {
pullRight: PropTypes.bool
};
const defaultProps = {
pullRight: false
};
class Badge extends React.Component {
hasContent(children) {
let result = false;
React.Children.forEach(children, child => {
if (result) {
return;
}
if (child || child === 0) {
result = true;
}
});
return result;
}
render() {
const { pullRight, className, children, ...props } = this.props;
const [bsProps, elementProps] = splitBsProps(props);
const classes = {
...getClassSet(bsProps),
'pull-right': pullRight,
// Hack for collapsing on IE8.
hidden: !this.hasContent(children)
};
return (
<span {...elementProps} className={classNames(className, classes)}>
{children}
</span>
);
}
}
Badge.propTypes = propTypes;
Badge.defaultProps = defaultProps;
export default bsClass('badge', Badge);