choerodon-ui
Version:
An enterprise-class UI design language and React-based implementation
79 lines (64 loc) • 2.4 kB
JavaScript
import _extends from "@babel/runtime/helpers/extends";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _inherits from "@babel/runtime/helpers/inherits";
import _createSuper from "@babel/runtime/helpers/createSuper";
var _excluded = ["type", "rowIndex"];
import { __decorate } from "tslib";
import * as React from 'react';
import { observer } from 'mobx-react';
import Checkbox from '../../../es/checkbox';
import Radio from '../../../es/radio';
var SelectionBox = /*#__PURE__*/function (_React$Component) {
_inherits(SelectionBox, _React$Component);
var _super = _createSuper(SelectionBox);
function SelectionBox(props) {
var _this;
_classCallCheck(this, SelectionBox);
_this = _super.call(this, props);
_this.state = {
checked: _this.getCheckState(props)
};
return _this;
} // eslint-disable-next-line class-methods-use-this
_createClass(SelectionBox, [{
key: "getCheckState",
value: function getCheckState(props) {
var defaultSelection = props.defaultSelection,
rowIndex = props.rowIndex,
store = props.store;
var selectionDirty = store.selectionDirty,
selectedRowKeys = store.selectedRowKeys;
var checked = false;
if (selectionDirty) {
checked = selectedRowKeys.indexOf(rowIndex) >= 0;
} else {
checked = selectedRowKeys.indexOf(rowIndex) >= 0 || defaultSelection.indexOf(rowIndex) >= 0;
}
return checked;
}
}, {
key: "render",
value: function render() {
var checked = this.getCheckState(this.props);
var _this$props = this.props,
type = _this$props.type,
rowIndex = _this$props.rowIndex,
rest = _objectWithoutProperties(_this$props, _excluded);
if (type === 'radio') {
return /*#__PURE__*/React.createElement(Radio, _extends({
checked: checked,
value: rowIndex
}, rest));
}
return /*#__PURE__*/React.createElement(Checkbox, _extends({
checked: checked
}, rest));
}
}]);
return SelectionBox;
}(React.Component);
SelectionBox = __decorate([observer], SelectionBox);
export default SelectionBox;
//# sourceMappingURL=SelectionBox.js.map