choerodon-ui
Version:
An enterprise-class UI design language and React-based implementation
126 lines (104 loc) • 3.7 kB
JavaScript
import _extends from "@babel/runtime/helpers/extends";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _inherits from "@babel/runtime/helpers/inherits";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
function _createSuper(Derived) {
function isNativeReflectConstruct() {
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
if (Reflect.construct.sham) return false;
if (typeof Proxy === "function") return true;
try {
Date.prototype.toString.call(Reflect.construct(Date, [], function () {}));
return true;
} catch (e) {
return false;
}
}
return function () {
var Super = _getPrototypeOf(Derived),
result;
if (isNativeReflectConstruct()) {
var NewTarget = _getPrototypeOf(this).constructor;
result = Reflect.construct(Super, arguments, NewTarget);
} else {
result = Super.apply(this, arguments);
}
return _possibleConstructorReturn(this, result);
};
}
import React, { Component } from 'react';
import classnames from 'classnames';
import omit from 'lodash/omit';
export default function createTableRow() {
var Cmp = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'tr';
var BodyRow =
/*#__PURE__*/
function (_Component) {
_inherits(BodyRow, _Component);
var _super = _createSuper(BodyRow);
function BodyRow(props) {
var _this;
_classCallCheck(this, BodyRow);
_this = _super.call(this, props);
_this.store = props.store;
var _this$store$getState = _this.store.getState(),
selectedRowKeys = _this$store$getState.selectedRowKeys;
_this.state = {
selected: selectedRowKeys.indexOf(props.rowKey) >= 0
};
return _this;
}
_createClass(BodyRow, [{
key: "componentDidMount",
value: function componentDidMount() {
this.subscribe();
}
}, {
key: "componentWillUnmount",
value: function componentWillUnmount() {
if (this.unsubscribe) {
this.unsubscribe();
}
}
}, {
key: "subscribe",
value: function subscribe() {
var _this2 = this;
var _this$props = this.props,
store = _this$props.store,
rowKey = _this$props.rowKey;
this.unsubscribe = store.subscribe(function () {
var state = _this2.state;
var _this2$store$getState = _this2.store.getState(),
selectedRowKeys = _this2$store$getState.selectedRowKeys;
var selected = selectedRowKeys.indexOf(rowKey) >= 0;
if (selected !== state.selected) {
_this2.setState({
selected: selected
});
}
});
}
}, {
key: "render",
value: function render() {
var props = this.props;
var selected = this.state.selected;
var className = props.className,
prefixCls = props.prefixCls,
children = props.children;
var otherProps = omit(props, ['prefixCls', 'rowKey', 'store', 'children']);
var classString = classnames(className, _defineProperty({}, "".concat(prefixCls, "-row-selected"), selected));
return React.createElement(Cmp, _extends({}, otherProps, {
className: classString
}), children);
}
}]);
return BodyRow;
}(Component);
return BodyRow;
}
//# sourceMappingURL=createBodyRow.js.map