1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 |
|
7 | var _react = require('react');
|
8 |
|
9 | var _react2 = _interopRequireDefault(_react);
|
10 |
|
11 | var _propTypes = require('prop-types');
|
12 |
|
13 | var _propTypes2 = _interopRequireDefault(_propTypes);
|
14 |
|
15 | var _shallowequal = require('shallowequal');
|
16 |
|
17 | var _shallowequal2 = _interopRequireDefault(_shallowequal);
|
18 |
|
19 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
20 |
|
21 | function _defaults(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; }
|
22 |
|
23 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
24 |
|
25 | function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
26 |
|
27 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : _defaults(subClass, superClass); }
|
28 |
|
29 | var propTypes = {
|
30 | record: _propTypes2["default"].object,
|
31 | clsPrefix: _propTypes2["default"].string,
|
32 | expandable: _propTypes2["default"].any,
|
33 | expanded: _propTypes2["default"].bool,
|
34 | needIndentSpaced: _propTypes2["default"].bool,
|
35 | onExpand: _propTypes2["default"].func
|
36 | };
|
37 |
|
38 | var ExpandIcon = function (_Component) {
|
39 | _inherits(ExpandIcon, _Component);
|
40 |
|
41 | function ExpandIcon(props) {
|
42 | _classCallCheck(this, ExpandIcon);
|
43 |
|
44 | var _this = _possibleConstructorReturn(this, _Component.call(this, props));
|
45 |
|
46 | _this.onExpand = function (status, record, e) {
|
47 | var onExpand = _this.props.onExpand;
|
48 |
|
49 | e.stopPropagation();
|
50 | onExpand(status, record, e);
|
51 | };
|
52 |
|
53 | return _this;
|
54 | }
|
55 |
|
56 | ExpandIcon.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps) {
|
57 | return !(0, _shallowequal2["default"])(nextProps, this.props);
|
58 | };
|
59 |
|
60 | ExpandIcon.prototype.render = function render() {
|
61 | var _this2 = this;
|
62 |
|
63 | var _props = this.props,
|
64 | expandable = _props.expandable,
|
65 | clsPrefix = _props.clsPrefix,
|
66 | onExpand = _props.onExpand,
|
67 | needIndentSpaced = _props.needIndentSpaced,
|
68 | expanded = _props.expanded,
|
69 | record = _props.record,
|
70 | isHiddenExpandIcon = _props.isHiddenExpandIcon,
|
71 | expandedIcon = _props.expandedIcon,
|
72 | collapsedIcon = _props.collapsedIcon;
|
73 |
|
74 | if (expandable && !isHiddenExpandIcon) {
|
75 | var expandClassName = expanded ? 'expanded' : 'collapsed';
|
76 | var currentIcon = _react2["default"].createElement('span', {
|
77 | className: clsPrefix + '-expand-icon ' + clsPrefix + '-' + expandClassName
|
78 | });
|
79 | if (expanded && expandedIcon) {
|
80 | currentIcon = expandedIcon;
|
81 | } else if (!expanded && collapsedIcon) {
|
82 | currentIcon = collapsedIcon;
|
83 | }
|
84 | return _react2["default"].createElement(
|
85 | 'span',
|
86 | { onClick: function onClick(e) {
|
87 | return _this2.onExpand(!expanded, record, e);
|
88 | }, className: 'expand-icon-con' },
|
89 | currentIcon
|
90 | );
|
91 | } else if (needIndentSpaced || isHiddenExpandIcon) {
|
92 | return _react2["default"].createElement('span', { className: clsPrefix + '-expand-icon ' + clsPrefix + '-spaced' });
|
93 | }
|
94 | return null;
|
95 | };
|
96 |
|
97 | return ExpandIcon;
|
98 | }(_react.Component);
|
99 |
|
100 | ;
|
101 |
|
102 | ExpandIcon.propTypes = propTypes;
|
103 |
|
104 | exports["default"] = ExpandIcon;
|
105 | module.exports = exports['default']; |
\ | No newline at end of file |