ming-demo3
Version:
mdf metaui web
106 lines (91 loc) • 3.2 kB
JavaScript
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
var _react = _interopRequireDefault(require("react"));
var SwitchLabelControl = function (_React$Component) {
(0, _inherits2["default"])(SwitchLabelControl, _React$Component);
function SwitchLabelControl(props) {
var _this;
(0, _classCallCheck2["default"])(this, SwitchLabelControl);
_this = (0, _possibleConstructorReturn2["default"])(this, (0, _getPrototypeOf2["default"])(SwitchLabelControl).call(this, props));
_this.state = {
value: props.value || false
};
return _this;
}
(0, _createClass2["default"])(SwitchLabelControl, [{
key: "componentDidMount",
value: function componentDidMount() {
if (this.props.model) this.props.model.addListener(this);
}
}, {
key: "componentWillUnmount",
value: function componentWillUnmount() {
if (this.props.model) this.props.model.removeListener(this);
}
}, {
key: "componentDidUpdate",
value: function componentDidUpdate() {
if (this.props.model) this.props.model.addListener(this);
}
}, {
key: "componentWillReceiveProps",
value: function componentWillReceiveProps(nextProps) {
if (nextProps.model) {
if (!this.props.model) {
nextProps.model.addListener(this);
}
} else {
if (this.props.model) {
this.props.model.removeListener(this);
this.setState({
value: nextProps.value
});
}
}
if (nextProps.value != 'undefined' & nextProps.value != undefined) {
this.setState({
value: nextProps.value
});
}
}
}, {
key: "onClick",
value: function onClick() {
if (this.props.model) this.props.model.setValue(!this.state.value, true);
if (this.props.onChange) this.props.onChange(!this.state.value);
}
}, {
key: "render",
value: function render() {
var _this2 = this;
return this.state.value ? _react["default"].createElement("span", {
style: {
height: '30px'
},
className: 'red-circle',
onClick: function onClick() {
return _this2.onClick();
}
}, "\u8D1F\u8D23\u4EBA") : _react["default"].createElement("div", {
style: {
height: '30px'
},
onClick: function onClick() {
return _this2.onClick();
}
});
}
}]);
return SwitchLabelControl;
}(_react["default"].Component);
exports["default"] = SwitchLabelControl;
//# sourceMappingURL=switchlabel.js.map