This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
ListGroupItem.js
95 lines (81 loc) · 2.52 KB
/
ListGroupItem.js
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
var React = require('react');
var joinClasses = require('./utils/joinClasses');
var BootstrapMixin = require('./BootstrapMixin');
var classSet = require('./utils/classSet');
var cloneWithProps = require('./utils/cloneWithProps');
var ValidComponentChildren = require('./utils/ValidComponentChildren');
var ListGroupItem = React.createClass({displayName: "ListGroupItem",
mixins: [BootstrapMixin],
propTypes: {
bsStyle: React.PropTypes.oneOf(['danger','info','success','warning']),
active: React.PropTypes.any,
disabled: React.PropTypes.any,
header: React.PropTypes.node,
onClick: React.PropTypes.func,
eventKey: React.PropTypes.any,
href: React.PropTypes.string,
target: React.PropTypes.string
},
getDefaultProps: function () {
return {
bsClass: 'list-group-item'
};
},
render: function () {
var classes = this.getBsClassSet();
classes['active'] = this.props.active;
classes['disabled'] = this.props.disabled;
if (this.props.href || this.props.target || this.props.onClick) {
return this.renderAnchor(classes);
} else {
return this.renderSpan(classes);
}
},
renderSpan: function (classes) {
return (
React.createElement("span", React.__spread({}, this.props, {className: joinClasses(this.props.className, classSet(classes))}),
this.props.header ? this.renderStructuredContent() : this.props.children
)
);
},
renderAnchor: function (classes) {
return (
React.createElement("a", React.__spread({},
this.props,
{className: joinClasses(this.props.className, classSet(classes)),
onClick: this.handleClick}),
this.props.header ? this.renderStructuredContent() : this.props.children
)
);
},
renderStructuredContent: function () {
var header;
if (React.isValidElement(this.props.header)) {
header = cloneWithProps(this.props.header, {
className: 'list-group-item-heading'
});
} else {
header = (
React.createElement("h4", {className: "list-group-item-heading"},
this.props.header
)
);
}
var content = (
React.createElement("p", {className: "list-group-item-text"},
this.props.children
)
);
return {
header: header,
content: content
};
},
handleClick: function (e) {
if (this.props.onClick) {
e.preventDefault();
this.props.onClick(this.props.eventKey, this.props.href, this.props.target);
}
}
});
module.exports = ListGroupItem;