Panel.js
4.76 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
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
/* eslint-disable react/prop-types */
import * as React from 'react';
import classNames from 'classnames';
import CSSMotion from 'rc-motion';
import shallowEqual from 'shallowequal';
import PanelContent from './PanelContent';
var CollapsePanel = /*#__PURE__*/function (_React$Component) {
_inherits(CollapsePanel, _React$Component);
var _super = _createSuper(CollapsePanel);
function CollapsePanel() {
var _this;
_classCallCheck(this, CollapsePanel);
_this = _super.apply(this, arguments);
_this.handleItemClick = function () {
var _this$props = _this.props,
onItemClick = _this$props.onItemClick,
panelKey = _this$props.panelKey;
if (typeof onItemClick === 'function') {
onItemClick(panelKey);
}
};
_this.handleKeyPress = function (e) {
if (e.key === 'Enter' || e.keyCode === 13 || e.which === 13) {
_this.handleItemClick();
}
};
return _this;
}
_createClass(CollapsePanel, [{
key: "shouldComponentUpdate",
value: function shouldComponentUpdate(nextProps) {
return !shallowEqual(this.props, nextProps);
}
}, {
key: "render",
value: function render() {
var _classNames,
_classNames2,
_this2 = this;
var _this$props2 = this.props,
className = _this$props2.className,
id = _this$props2.id,
style = _this$props2.style,
prefixCls = _this$props2.prefixCls,
header = _this$props2.header,
headerClass = _this$props2.headerClass,
children = _this$props2.children,
isActive = _this$props2.isActive,
showArrow = _this$props2.showArrow,
destroyInactivePanel = _this$props2.destroyInactivePanel,
accordion = _this$props2.accordion,
forceRender = _this$props2.forceRender,
openMotion = _this$props2.openMotion,
expandIcon = _this$props2.expandIcon,
extra = _this$props2.extra,
collapsible = _this$props2.collapsible;
var disabled = collapsible === 'disabled';
var headerCls = classNames("".concat(prefixCls, "-header"), (_classNames = {}, _defineProperty(_classNames, headerClass, headerClass), _defineProperty(_classNames, "".concat(prefixCls, "-header-collapsible-only"), collapsible === 'header'), _classNames));
var itemCls = classNames((_classNames2 = {}, _defineProperty(_classNames2, "".concat(prefixCls, "-item"), true), _defineProperty(_classNames2, "".concat(prefixCls, "-item-active"), isActive), _defineProperty(_classNames2, "".concat(prefixCls, "-item-disabled"), disabled), _classNames2), className);
var icon = React.createElement("i", {
className: "arrow"
});
if (showArrow && typeof expandIcon === 'function') {
icon = expandIcon(this.props);
}
return React.createElement("div", {
className: itemCls,
style: style,
id: id
}, React.createElement("div", {
className: headerCls,
onClick: function onClick() {
return collapsible !== 'header' && _this2.handleItemClick();
},
role: accordion ? 'tab' : 'button',
tabIndex: disabled ? -1 : 0,
"aria-expanded": isActive,
onKeyPress: this.handleKeyPress
}, showArrow && icon, collapsible === 'header' ? React.createElement("span", {
onClick: this.handleItemClick,
className: "".concat(prefixCls, "-header-text")
}, header) : header, extra && React.createElement("div", {
className: "".concat(prefixCls, "-extra")
}, extra)), React.createElement(CSSMotion, Object.assign({
visible: isActive,
leavedClassName: "".concat(prefixCls, "-content-hidden")
}, openMotion, {
forceRender: forceRender,
removeOnLeave: destroyInactivePanel
}), function (_ref, ref) {
var motionClassName = _ref.className,
motionStyle = _ref.style;
return React.createElement(PanelContent, {
ref: ref,
prefixCls: prefixCls,
className: motionClassName,
style: motionStyle,
isActive: isActive,
forceRender: forceRender,
role: accordion ? 'tabpanel' : null
}, children);
}));
}
}]);
return CollapsePanel;
}(React.Component);
CollapsePanel.defaultProps = {
showArrow: true,
isActive: false,
onItemClick: function onItemClick() {},
headerClass: '',
forceRender: false
};
export default CollapsePanel;