forked from react-bootstrap/react-bootstrap-bower
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPanel.js
147 lines (123 loc) · 3.47 KB
/
Panel.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
define(function (require, exports, module) {var React = require('react');
var joinClasses = require('./utils/joinClasses');
var classSet = require('./utils/classSet');
var cloneWithProps = require('./utils/cloneWithProps');
var BootstrapMixin = require('./BootstrapMixin');
var CollapsableMixin = require('./CollapsableMixin');
var Panel = React.createClass({displayName: 'Panel',
mixins: [BootstrapMixin, CollapsableMixin],
propTypes: {
onSelect: React.PropTypes.func,
header: React.PropTypes.node,
footer: React.PropTypes.node,
eventKey: React.PropTypes.any
},
getDefaultProps: function () {
return {
bsClass: 'panel',
bsStyle: 'default'
};
},
handleSelect: function (e) {
if (this.props.onSelect) {
this._isChanging = true;
this.props.onSelect(this.props.eventKey);
this._isChanging = false;
}
e.preventDefault();
this.setState({
expanded: !this.state.expanded
});
},
shouldComponentUpdate: function () {
return !this._isChanging;
},
getCollapsableDimensionValue: function () {
return this.refs.body.getDOMNode().offsetHeight;
},
getCollapsableDOMNode: function () {
if (!this.isMounted() || !this.refs || !this.refs.panel) {
return null;
}
return this.refs.panel.getDOMNode();
},
render: function () {
var classes = this.getBsClassSet();
classes['panel'] = true;
return (
React.createElement("div", React.__spread({}, this.props, {className: joinClasses(this.props.className, classSet(classes)),
id: this.props.collapsable ? null : this.props.id, onSelect: null}),
this.renderHeading(),
this.props.collapsable ? this.renderCollapsableBody() : this.renderBody(),
this.renderFooter()
)
);
},
renderCollapsableBody: function () {
return (
React.createElement("div", {className: classSet(this.getCollapsableClassSet('panel-collapse')), id: this.props.id, ref: "panel"},
this.renderBody()
)
);
},
renderBody: function () {
return (
React.createElement("div", {className: "panel-body", ref: "body"},
this.props.children
)
);
},
renderHeading: function () {
var header = this.props.header;
if (!header) {
return null;
}
if (!React.isValidElement(header) || Array.isArray(header)) {
header = this.props.collapsable ?
this.renderCollapsableTitle(header) : header;
} else if (this.props.collapsable) {
header = cloneWithProps(header, {
className: 'panel-title',
children: this.renderAnchor(header.props.children)
});
} else {
header = cloneWithProps(header, {
className: 'panel-title'
});
}
return (
React.createElement("div", {className: "panel-heading"},
header
)
);
},
renderAnchor: function (header) {
return (
React.createElement("a", {
href: '#' + (this.props.id || ''),
className: this.isExpanded() ? null : 'collapsed',
onClick: this.handleSelect},
header
)
);
},
renderCollapsableTitle: function (header) {
return (
React.createElement("h4", {className: "panel-title"},
this.renderAnchor(header)
)
);
},
renderFooter: function () {
if (!this.props.footer) {
return null;
}
return (
React.createElement("div", {className: "panel-footer"},
this.props.footer
)
);
}
});
module.exports = Panel;
});