@aliretail/react-materials-components
Version:
60 lines (50 loc) • 1.48 kB
JavaScript
import _Switch from "@alifd/next/es/switch";
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
import * as React from 'react';
import * as PropTypes from 'prop-types';
var SWITCH = /*#__PURE__*/function (_React$Component) {
_inheritsLoose(SWITCH, _React$Component);
function SWITCH(props) {
var _this;
_this = _React$Component.call(this, props) || this;
_this.onChange = function (checked) {
_this.setState({
checked: checked
});
_this.props.getStatus(!_this.state.isChecked);
};
_this.state = {
isChecked: true,
checked: props.isChecked
};
return _this;
}
var _proto = SWITCH.prototype;
_proto.render = function render() {
var disabled = this.props.disabled;
return /*#__PURE__*/React.createElement("div", {
className: "aliretail-switch"
}, /*#__PURE__*/React.createElement("label", {
className: "labelSwitch",
htmlFor: ""
}, this.state.checked ? '启用中' : '已禁用'), /*#__PURE__*/React.createElement(_Switch, {
checked: this.state.checked,
checkedChildren: "on",
size: "small",
onChange: this.onChange,
unCheckedChildren: "off",
disabled: disabled
}));
};
return SWITCH;
}(React.Component);
SWITCH.propTypes = {
getStatus: PropTypes.func,
isChecked: PropTypes.bool,
disabled: PropTypes.bool
};
SWITCH.defaultProps = {
isChecked: false,
disabled: false
};
export default SWITCH;