forked from react-bootstrap/react-bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathListGroupItem.js
More file actions
97 lines (81 loc) · 2.06 KB
/
ListGroupItem.js
File metadata and controls
97 lines (81 loc) · 2.06 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import classNames from 'classnames';
import React, { cloneElement } from 'react';
import { bsClass, bsStyles, getClassSet, prefix, splitBsProps }
from './utils/bootstrapUtils';
import { State } from './utils/StyleConfig';
const propTypes = {
active: React.PropTypes.any,
disabled: React.PropTypes.any,
header: React.PropTypes.node,
listItem: React.PropTypes.bool,
onClick: React.PropTypes.func,
href: React.PropTypes.string,
type: React.PropTypes.string,
};
const defaultProps = {
listItem: false,
};
class ListGroupItem extends React.Component {
renderHeader(header, headingClassName) {
if (React.isValidElement(header)) {
return cloneElement(header, {
className: classNames(header.props.className, headingClassName),
});
}
return (
<h4 className={headingClassName}>
{header}
</h4>
);
}
render() {
const {
active,
disabled,
className,
header,
listItem,
children,
...props
} = this.props;
const [bsProps, elementProps] = splitBsProps(props);
const classes = {
...getClassSet(bsProps),
active,
disabled,
};
let Component;
if (elementProps.href) {
Component = 'a';
} else if (elementProps.onClick) {
Component = 'button';
elementProps.type = elementProps.type || 'button';
} else if (listItem) {
Component = 'li';
} else {
Component = 'span';
}
elementProps.className = classNames(className, classes);
// TODO: Deprecate `header` prop.
if (header) {
return (
<Component {...elementProps}>
{this.renderHeader(header, prefix(bsProps, 'heading'))}
<p className={prefix(bsProps, 'text')}>
{children}
</p>
</Component>
);
}
return (
<Component {...elementProps}>
{children}
</Component>
);
}
}
ListGroupItem.propTypes = propTypes;
ListGroupItem.defaultProps = defaultProps;
export default bsClass('list-group-item',
bsStyles(Object.values(State), ListGroupItem)
);