zent
Version:
一套前端设计语言和基于React的实现
36 lines (35 loc) • 1.48 kB
JavaScript
import { __extends } from "tslib";
import { jsx as _jsx } from "react/jsx-runtime";
import { Component } from 'react';
import cx from 'classnames';
import { DisabledContext } from '../disabled';
var Switch = (function (_super) {
__extends(Switch, _super);
function Switch() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.toggle = function () {
var _a = _this.props, onChange = _a.onChange, checked = _a.checked;
onChange && onChange(!checked);
};
return _this;
}
Switch.prototype.render = function () {
var _a;
var _b = this.props, className = _b.className, size = _b.size, _c = _b.disabled, disabled = _c === void 0 ? this.context.value : _c, loading = _b.loading, checked = _b.checked;
var switchDisabled = disabled || loading;
var classNames = cx((_a = {},
_a["zent-switch-" + size] = size !== 'default',
_a['zent-switch-disabled'] = switchDisabled,
_a['zent-switch-loading'] = loading,
_a['zent-switch-checked'] = checked,
_a), 'zent-switch', className);
return (_jsx("div", { className: classNames, onClick: switchDisabled ? undefined : this.toggle, "data-zv": '10.0.17' }, void 0));
};
Switch.defaultProps = {
size: 'default',
};
Switch.contextType = DisabledContext;
return Switch;
}(Component));
export { Switch };
export default Switch;