UNPKG

choerodon-ui

Version:

An enterprise-class UI design language and React-based implementation

112 lines (90 loc) 3.22 kB
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 _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 { __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, ["type", "rowIndex"]); if (type === 'radio') { return React.createElement(Radio, _extends({ checked: checked, value: rowIndex }, rest)); } return React.createElement(Checkbox, _extends({ checked: checked }, rest)); } }]); return SelectionBox; }(React.Component); SelectionBox = __decorate([observer], SelectionBox); export default SelectionBox; //# sourceMappingURL=SelectionBox.js.map