UNPKG

@vuesax-alpha/nightly

Version:
36 lines (33 loc) 1.08 kB
import { computed } from 'vue'; import '../../../constants/index.mjs'; import { UPDATE_MODEL_EVENT, CHANGE_EVENT, INPUT_EVENT } from '../../../constants/event.mjs'; const useSwitch = (props, emit) => { const checked = computed(() => props.modelValue === props.activeValue); const isLoading = computed(() => props.loading); const isDisabled = computed(() => props.disabled || isLoading.value); if (![props.activeValue, props.inactiveValue].includes(props.modelValue)) { emit(UPDATE_MODEL_EVENT, props.inactiveValue); emit(CHANGE_EVENT, props.inactiveValue); emit(INPUT_EVENT, props.inactiveValue); } const handleChange = () => { const val = checked.value ? props.inactiveValue : props.activeValue; emit(UPDATE_MODEL_EVENT, val); emit(CHANGE_EVENT, val); emit(INPUT_EVENT, val); }; const switchValue = () => { if (isDisabled.value) return; handleChange(); }; return { checked, isDisabled, isLoading, handleChange, switchValue }; }; export { useSwitch }; //# sourceMappingURL=use-switch.mjs.map