forked from react-component/collapse
/
PanelContent.jsx
41 lines (37 loc) · 1.16 KB
/
PanelContent.jsx
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
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
class PanelContent extends Component {
shouldComponentUpdate(nextProps) {
return this.props.isActive || nextProps.isActive;
}
render() {
this._isActived = this.props.forceRender || this._isActived || this.props.isActive;
if (!this._isActived) {
return null;
}
const { prefixCls, isActive, children, destroyInactivePanel, forceRender, role } = this.props;
const contentCls = classnames({
[`${prefixCls}-content`]: true,
[`${prefixCls}-content-active`]: isActive,
[`${prefixCls}-content-inactive`]: !isActive,
});
const child = !forceRender && !isActive && destroyInactivePanel ? null :
<div className={`${prefixCls}-content-box`}>{children}</div>;
return (
<div
className={contentCls}
role={role}
>{child}</div>
);
}
}
PanelContent.propTypes = {
prefixCls: PropTypes.string,
isActive: PropTypes.bool,
children: PropTypes.any,
destroyInactivePanel: PropTypes.bool,
forceRender: PropTypes.bool,
role: PropTypes.string,
};
export default PanelContent;