1 | import _extends from "@babel/runtime/helpers/extends";
|
2 | import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
3 | import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
4 | import _createClass from "@babel/runtime/helpers/createClass";
|
5 | import _inherits from "@babel/runtime/helpers/inherits";
|
6 | import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
7 | import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
8 |
|
9 | function _createSuper(Derived) {
|
10 | function isNativeReflectConstruct() {
|
11 | if (typeof Reflect === "undefined" || !Reflect.construct) return false;
|
12 | if (Reflect.construct.sham) return false;
|
13 | if (typeof Proxy === "function") return true;
|
14 |
|
15 | try {
|
16 | Date.prototype.toString.call(Reflect.construct(Date, [], function () {}));
|
17 | return true;
|
18 | } catch (e) {
|
19 | return false;
|
20 | }
|
21 | }
|
22 |
|
23 | return function () {
|
24 | var Super = _getPrototypeOf(Derived),
|
25 | result;
|
26 |
|
27 | if (isNativeReflectConstruct()) {
|
28 | var NewTarget = _getPrototypeOf(this).constructor;
|
29 |
|
30 | result = Reflect.construct(Super, arguments, NewTarget);
|
31 | } else {
|
32 | result = Super.apply(this, arguments);
|
33 | }
|
34 |
|
35 | return _possibleConstructorReturn(this, result);
|
36 | };
|
37 | }
|
38 |
|
39 | import React, { Component } from 'react';
|
40 | import classnames from 'classnames';
|
41 | import omit from 'lodash/omit';
|
42 | export default function createTableRow() {
|
43 | var Cmp = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'tr';
|
44 |
|
45 | var BodyRow =
|
46 |
|
47 | function (_Component) {
|
48 | _inherits(BodyRow, _Component);
|
49 |
|
50 | var _super = _createSuper(BodyRow);
|
51 |
|
52 | function BodyRow(props) {
|
53 | var _this;
|
54 |
|
55 | _classCallCheck(this, BodyRow);
|
56 |
|
57 | _this = _super.call(this, props);
|
58 | _this.store = props.store;
|
59 |
|
60 | var _this$store$getState = _this.store.getState(),
|
61 | selectedRowKeys = _this$store$getState.selectedRowKeys;
|
62 |
|
63 | _this.state = {
|
64 | selected: selectedRowKeys.indexOf(props.rowKey) >= 0
|
65 | };
|
66 | return _this;
|
67 | }
|
68 |
|
69 | _createClass(BodyRow, [{
|
70 | key: "componentDidMount",
|
71 | value: function componentDidMount() {
|
72 | this.subscribe();
|
73 | }
|
74 | }, {
|
75 | key: "componentWillUnmount",
|
76 | value: function componentWillUnmount() {
|
77 | if (this.unsubscribe) {
|
78 | this.unsubscribe();
|
79 | }
|
80 | }
|
81 | }, {
|
82 | key: "subscribe",
|
83 | value: function subscribe() {
|
84 | var _this2 = this;
|
85 |
|
86 | var _this$props = this.props,
|
87 | store = _this$props.store,
|
88 | rowKey = _this$props.rowKey;
|
89 | this.unsubscribe = store.subscribe(function () {
|
90 | var state = _this2.state;
|
91 |
|
92 | var _this2$store$getState = _this2.store.getState(),
|
93 | selectedRowKeys = _this2$store$getState.selectedRowKeys;
|
94 |
|
95 | var selected = selectedRowKeys.indexOf(rowKey) >= 0;
|
96 |
|
97 | if (selected !== state.selected) {
|
98 | _this2.setState({
|
99 | selected: selected
|
100 | });
|
101 | }
|
102 | });
|
103 | }
|
104 | }, {
|
105 | key: "render",
|
106 | value: function render() {
|
107 | var props = this.props;
|
108 | var selected = this.state.selected;
|
109 | var className = props.className,
|
110 | prefixCls = props.prefixCls,
|
111 | children = props.children;
|
112 | var otherProps = omit(props, ['prefixCls', 'rowKey', 'store', 'children']);
|
113 | var classString = classnames(className, _defineProperty({}, "".concat(prefixCls, "-row-selected"), selected));
|
114 | return React.createElement(Cmp, _extends({}, otherProps, {
|
115 | className: classString
|
116 | }), children);
|
117 | }
|
118 | }]);
|
119 |
|
120 | return BodyRow;
|
121 | }(Component);
|
122 |
|
123 | return BodyRow;
|
124 | }
|
125 |
|