Panel.js
5.49 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
141
142
143
144
145
146
147
148
149
150
151
152
153
"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper"));
var React = _interopRequireWildcard(require("react"));
var _classnames = _interopRequireDefault(require("classnames"));
var _rcMotion = _interopRequireDefault(require("rc-motion"));
var _shallowequal = _interopRequireDefault(require("shallowequal"));
var _PanelContent = _interopRequireDefault(require("./PanelContent"));
/* eslint-disable react/prop-types */
var CollapsePanel = /*#__PURE__*/function (_React$Component) {
(0, _inherits2.default)(CollapsePanel, _React$Component);
var _super = (0, _createSuper2.default)(CollapsePanel);
function CollapsePanel() {
var _this;
(0, _classCallCheck2.default)(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;
}
(0, _createClass2.default)(CollapsePanel, [{
key: "shouldComponentUpdate",
value: function shouldComponentUpdate(nextProps) {
return !(0, _shallowequal.default)(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 = (0, _classnames.default)("".concat(prefixCls, "-header"), (_classNames = {}, (0, _defineProperty2.default)(_classNames, headerClass, headerClass), (0, _defineProperty2.default)(_classNames, "".concat(prefixCls, "-header-collapsible-only"), collapsible === 'header'), _classNames));
var itemCls = (0, _classnames.default)((_classNames2 = {}, (0, _defineProperty2.default)(_classNames2, "".concat(prefixCls, "-item"), true), (0, _defineProperty2.default)(_classNames2, "".concat(prefixCls, "-item-active"), isActive), (0, _defineProperty2.default)(_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(_rcMotion.default, 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.default, {
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
};
var _default = CollapsePanel;
exports.default = _default;