UNPKG

4.06 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6
7var _react = require('react');
8
9var _react2 = _interopRequireDefault(_react);
10
11var _propTypes = require('prop-types');
12
13var _propTypes2 = _interopRequireDefault(_propTypes);
14
15var _shallowequal = require('shallowequal');
16
17var _shallowequal2 = _interopRequireDefault(_shallowequal);
18
19function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
20
21function _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
23function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
24
25function _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
27function _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
29var 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
38var 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
102ExpandIcon.propTypes = propTypes;
103
104exports["default"] = ExpandIcon;
105module.exports = exports['default'];
\No newline at end of file