UNPKG

choerodon-ui

Version:

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

132 lines (109 loc) 3.54 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 React, { Component } from 'react'; import Checkbox from '../checkbox'; import Radio from '../radio'; var SelectionBox = /*#__PURE__*/ function (_Component) { _inherits(SelectionBox, _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; } _createClass(SelectionBox, [{ 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 store = this.props.store; this.unsubscribe = store.subscribe(function () { var checked = _this2.getCheckState(_this2.props); _this2.setState({ checked: checked }); }); } }, { key: "getCheckState", value: function getCheckState(props) { var store = props.store, defaultSelection = props.defaultSelection, rowIndex = props.rowIndex; var checked = false; if (store.getState().selectionDirty) { checked = store.getState().selectedRowKeys.indexOf(rowIndex) >= 0; } else { checked = store.getState().selectedRowKeys.indexOf(rowIndex) >= 0 || defaultSelection.indexOf(rowIndex) >= 0; } return checked; } }, { key: "render", value: function render() { var _this$props = this.props, type = _this$props.type, rowIndex = _this$props.rowIndex, rest = _objectWithoutProperties(_this$props, ["type", "rowIndex"]); var checked = this.state.checked; if (type === 'radio') { return React.createElement(Radio, _extends({ checked: checked, value: rowIndex }, rest)); } return React.createElement(Checkbox, _extends({ checked: checked }, rest)); } }]); return SelectionBox; }(Component); export { SelectionBox as default }; //# sourceMappingURL=SelectionBox.js.map