choerodon-ui
Version:
An enterprise-class UI design language and React-based implementation
236 lines (184 loc) • 7.01 kB
JavaScript
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = exports.CheckBox = void 0;
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper"));
var _tslib = require("tslib");
var _react = _interopRequireDefault(require("react"));
var _mobx = require("mobx");
var _mobxReact = require("mobx-react");
var _Radio2 = require("../radio/Radio");
var _enum = require("../data-set/enum");
var CheckBox = /*#__PURE__*/function (_Radio) {
(0, _inherits2["default"])(CheckBox, _Radio);
var _super = (0, _createSuper2["default"])(CheckBox);
function CheckBox(props, context) {
var _this;
(0, _classCallCheck2["default"])(this, CheckBox);
_this = _super.call(this, props, context);
_this.type = 'checkbox';
(0, _mobx.runInAction)(function () {
_this.value = _this.props.defaultChecked ? _this.checkedValue : _this.unCheckedValue;
});
return _this;
}
(0, _createClass2["default"])(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(_enum.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(_enum.BooleanValue.trueValue);
}
return true;
}
}, {
key: "getOmitPropsKeys",
value: function getOmitPropsKeys() {
return (0, _get2["default"])((0, _getPrototypeOf2["default"])(CheckBox.prototype), "getOmitPropsKeys", this).call(this).concat(['defaultChecked', 'unCheckedValue', 'unCheckedChildren', 'indeterminate']);
}
}, {
key: "renderInner",
value: function renderInner() {
return /*#__PURE__*/_react["default"].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 (0, _get2["default"])((0, _getPrototypeOf2["default"])(CheckBox.prototype), "getWrapperClassNames", this).call(this, (0, _defineProperty2["default"])({}, "".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;
}
(0, _get2["default"])((0, _getPrototypeOf2["default"])(CheckBox.prototype), "setValue", this).call(this, values, noVaidate);
} else {
(0, _get2["default"])((0, _getPrototypeOf2["default"])(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;
}(_Radio2.Radio);
exports.CheckBox = CheckBox;
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 = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, _Radio2.Radio.defaultProps), {}, {
suffixCls: 'checkbox',
indeterminate: false
});
(0, _tslib.__decorate)([_mobx.action], CheckBox.prototype, "setValue", null);
(0, _tslib.__decorate)([_mobx.action], CheckBox.prototype, "setChecked", null);
var ObserverCheckBox = /*#__PURE__*/function (_CheckBox) {
(0, _inherits2["default"])(ObserverCheckBox, _CheckBox);
var _super2 = (0, _createSuper2["default"])(ObserverCheckBox);
function ObserverCheckBox() {
(0, _classCallCheck2["default"])(this, ObserverCheckBox);
return _super2.apply(this, arguments);
}
return (0, _createClass2["default"])(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 = (0, _tslib.__decorate)([_mobxReact.observer], ObserverCheckBox);
var _default = ObserverCheckBox;
exports["default"] = _default;
//# sourceMappingURL=CheckBox.js.map