UNPKG

choerodon-ui

Version:

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

267 lines (219 loc) 7.12 kB
import _objectSpread from "@babel/runtime/helpers/objectSpread2"; import _defineProperty from "@babel/runtime/helpers/defineProperty"; import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; import _createClass from "@babel/runtime/helpers/createClass"; import _get from "@babel/runtime/helpers/get"; 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 React from 'react'; import PropTypes from 'prop-types'; import { action, runInAction } from 'mobx'; import { observer } from 'mobx-react'; import { Radio } from '../radio/Radio'; import { BooleanValue } from '../data-set/enum'; export var CheckBox = /*#__PURE__*/ function (_Radio) { _inherits(CheckBox, _Radio); var _super = _createSuper(CheckBox); function CheckBox(props, context) { var _this; _classCallCheck(this, CheckBox); _this = _super.call(this, props, context); _this.type = 'checkbox'; runInAction(function () { _this.value = _this.props.defaultChecked ? _this.checkedValue : _this.unCheckedValue; }); return _this; } _createClass(CheckBox, [{ key: "getOmitPropsKeys", value: function getOmitPropsKeys() { return _get(_getPrototypeOf(CheckBox.prototype), "getOmitPropsKeys", this).call(this).concat(['defaultChecked', 'unCheckedValue', 'unCheckedChildren', 'indeterminate']); } }, { key: "renderInner", value: function renderInner() { return React.createElement("i", { className: "".concat(this.prefixCls, "-inner") }); } }, { key: "getChildrenText", value: function getChildrenText() { var _this$props = this.props, children = _this$props.children, unCheckedChildren = _this$props.unCheckedChildren; return this.isChecked() ? children : unCheckedChildren || children; } }, { key: "getWrapperClassNames", value: function getWrapperClassNames() { var prefixCls = this.prefixCls, indeterminate = this.props.indeterminate; return _get(_getPrototypeOf(CheckBox.prototype), "getWrapperClassNames", this).call(this, _defineProperty({}, "".concat(prefixCls, "-indeterminate"), indeterminate)); } }, { key: "isChecked", value: function isChecked() { var _this$props2 = this.props, checked = _this$props2.checked, indeterminate = _this$props2.indeterminate; if (indeterminate) { return false; } var name = this.name, dataSet = this.dataSet, checkedValue = this.checkedValue; if (!this.isControlled && dataSet && name) { return this.getValues().indexOf(checkedValue) !== -1; } if (checked !== undefined) { return checked; } return this.value === checkedValue; } }, { key: "getDataSetValues", value: function getDataSetValues() { var values = this.getDataSetValue(); if (values === undefined) { return []; } return [].concat(values); } }, { key: "setValue", value: function setValue(value, noVaidate) { var record = this.record, checkedValue = this.checkedValue, multiple = this.multiple; if (record) { var values; if (multiple) { values = this.getValues(); if (value === checkedValue) { values.push(value); } else { var index = values.indexOf(checkedValue); if (index !== -1) { values.splice(index, 1); } } } else { values = value; } _get(_getPrototypeOf(CheckBox.prototype), "setValue", this).call(this, values, noVaidate); } else { _get(_getPrototypeOf(CheckBox.prototype), "setValue", this).call(this, value, noVaidate); } } }, { key: "setChecked", value: function setChecked(checked) { this.setValue(checked ? this.checkedValue : this.unCheckedValue); } }, { key: "getOldValue", value: function getOldValue() { return this.isChecked() ? this.checkedValue : this.unCheckedValue; } }, { key: "unCheckedValue", get: function get() { var unCheckedValue = this.props.unCheckedValue; if (unCheckedValue !== undefined) { return unCheckedValue; } var field = this.field; if (field) { return field.get(BooleanValue.falseValue); } return false; } }, { key: "checkedValue", get: function get() { var value = this.props.value; if (value !== undefined) { return value; } var field = this.field; if (field) { return field.get(BooleanValue.trueValue); } return true; } }]); return CheckBox; }(Radio); CheckBox.displayName = 'CheckBox'; CheckBox.propTypes = _objectSpread({ /** * 中间状态 */ indeterminate: PropTypes.bool, /** * 未选中时的值 */ unCheckedValue: PropTypes.any, /** * 未选中时的内容 */ unCheckedChildren: PropTypes.node }, Radio.propTypes); /** * tooltip disable sign */ // eslint-disable-next-line camelcase CheckBox.__PRO_CHECKBOX = true; // eslint-disable-next-line camelcase CheckBox.__IS_IN_CELL_EDITOR = true; CheckBox.defaultProps = _objectSpread({}, Radio.defaultProps, { suffixCls: 'checkbox', indeterminate: false }); __decorate([action], CheckBox.prototype, "setValue", null); __decorate([action], CheckBox.prototype, "setChecked", null); var ObserverCheckBox = /*#__PURE__*/ function (_CheckBox) { _inherits(ObserverCheckBox, _CheckBox); var _super2 = _createSuper(ObserverCheckBox); function ObserverCheckBox() { _classCallCheck(this, ObserverCheckBox); return _super2.apply(this, arguments); } return ObserverCheckBox; }(CheckBox); ObserverCheckBox.defaultProps = CheckBox.defaultProps; // eslint-disable-next-line camelcase ObserverCheckBox.__PRO_CHECKBOX = true; // eslint-disable-next-line camelcase ObserverCheckBox.__IS_IN_CELL_EDITOR = true; ObserverCheckBox = __decorate([observer], ObserverCheckBox); export default ObserverCheckBox; //# sourceMappingURL=CheckBox.js.map