@vuesax-alpha/nightly
Version:
A Component Library for Vue 3
40 lines (35 loc) • 1.17 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
var vue = require('vue');
require('../../../constants/index.js');
var event = require('../../../constants/event.js');
const useSwitch = (props, emit) => {
const checked = vue.computed(() => props.modelValue === props.activeValue);
const isLoading = vue.computed(() => props.loading);
const isDisabled = vue.computed(() => props.disabled || isLoading.value);
if (![props.activeValue, props.inactiveValue].includes(props.modelValue)) {
emit(event.UPDATE_MODEL_EVENT, props.inactiveValue);
emit(event.CHANGE_EVENT, props.inactiveValue);
emit(event.INPUT_EVENT, props.inactiveValue);
}
const handleChange = () => {
const val = checked.value ? props.inactiveValue : props.activeValue;
emit(event.UPDATE_MODEL_EVENT, val);
emit(event.CHANGE_EVENT, val);
emit(event.INPUT_EVENT, val);
};
const switchValue = () => {
if (isDisabled.value)
return;
handleChange();
};
return {
checked,
isDisabled,
isLoading,
handleChange,
switchValue
};
};
exports.useSwitch = useSwitch;
//# sourceMappingURL=use-switch.js.map