UNPKG

choerodon-ui

Version:

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

215 lines (176 loc) 6.06 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 _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf"; import _inherits from "@babel/runtime/helpers/inherits"; import _createSuper from "@babel/runtime/helpers/createSuper"; import { __decorate } from "tslib"; import React from 'react'; 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: "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; } }, { 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 /*#__PURE__*/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; } }]); return CheckBox; }(Radio); CheckBox.displayName = 'CheckBox'; /** * 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(_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 _createClass(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