-
Notifications
You must be signed in to change notification settings - Fork 140
Expand file tree
/
Copy pathPanel.jsx
More file actions
140 lines (131 loc) · 3.35 KB
/
Panel.jsx
File metadata and controls
140 lines (131 loc) · 3.35 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
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
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import PanelContent from './PanelContent';
import Animate from 'rc-animate';
import shallowEqual from 'shallowequal';
class CollapsePanel extends Component {
shouldComponentUpdate(nextProps) {
return !shallowEqual(this.props, nextProps);
}
handleItemClick = () => {
const { onItemClick, panelKey } = this.props;
if (typeof onItemClick === 'function') {
onItemClick(panelKey);
}
}
handleKeyPress = (e) => {
if (e.key === 'Enter' || e.keyCode === 13 || e.which === 13) {
this.handleItemClick();
}
}
render() {
const {
className,
id,
style,
prefixCls,
header,
headerClass,
children,
isActive,
showArrow,
destroyInactivePanel,
disabled,
accordion,
forceRender,
expandIcon,
extra,
wrappedComponentRef,
} = this.props;
const headerCls = classNames(`${prefixCls}-header`, {
[headerClass]: headerClass,
});
const itemCls = classNames({
[`${prefixCls}-item`]: true,
[`${prefixCls}-item-active`]: isActive,
[`${prefixCls}-item-disabled`]: disabled,
}, className);
let icon = <i className="arrow" />;
if (showArrow && typeof expandIcon === 'function') {
icon = expandIcon(this.props);
}
const panelProps = {
id,
style,
className: itemCls,
};
if (wrappedComponentRef) {
panelProps.ref = wrappedComponentRef;
}
return (
<div {...panelProps}>
<div
className={headerCls}
onClick={this.handleItemClick}
role={accordion ? 'tab' : 'button'}
tabIndex={disabled ? -1 : 0}
aria-expanded={`${isActive}`}
onKeyPress={this.handleKeyPress}
>
{showArrow && icon}
{header}
{extra && <div className={`${prefixCls}-extra`}>{extra}</div>}
</div>
<Animate
showProp="isActive"
exclusive
component=""
animation={this.props.openAnimation}
>
<PanelContent
prefixCls={prefixCls}
isActive={isActive}
destroyInactivePanel={destroyInactivePanel}
forceRender={forceRender}
role={accordion ? 'tabpanel' : null}
>
{children}
</PanelContent>
</Animate>
</div>
);
}
}
CollapsePanel.propTypes = {
className: PropTypes.oneOfType([
PropTypes.string,
PropTypes.object,
]),
id: PropTypes.string,
children: PropTypes.any,
openAnimation: PropTypes.object,
prefixCls: PropTypes.string,
header: PropTypes.oneOfType([
PropTypes.string,
PropTypes.number,
PropTypes.node,
]),
headerClass: PropTypes.string,
showArrow: PropTypes.bool,
isActive: PropTypes.bool,
onItemClick: PropTypes.func,
style: PropTypes.object,
destroyInactivePanel: PropTypes.bool,
disabled: PropTypes.bool,
accordion: PropTypes.bool,
forceRender: PropTypes.bool,
expandIcon: PropTypes.func,
extra: PropTypes.node,
panelKey: PropTypes.any,
wrappedComponentRef: PropTypes.func,
};
CollapsePanel.defaultProps = {
showArrow: true,
isActive: false,
destroyInactivePanel: false,
onItemClick() { },
headerClass: '',
forceRender: false,
};
export default CollapsePanel;