UNPKG

various-ui

Version:

This is a test version of the Vue 3 component library

50 lines (47 loc) 1.61 kB
import { inject, computed } from 'vue'; import { UiCheckboxGroupInjectionKey } from '../../default-group/index.mjs'; const useComposable = (define, emits) => { const checkboxGroup = inject(UiCheckboxGroupInjectionKey, void 0); const methods = { switchData: (ev) => { const el = ev.target; emits("update:modelValue", el.checked || false); emits("change", ev); checkboxGroup && checkboxGroup.change(define.value); } }; const computeds = { //* 是否已被选中 checked: computed(() => { if (checkboxGroup == null ? void 0 : checkboxGroup.define.modelValue.includes(define.value)) return true; else return define.modelValue; }), //* 是否禁用 disabled: computed(() => { if (define.disabled) return true; if (checkboxGroup) { if (checkboxGroup.define.modelValue.includes(define.value)) { if (checkboxGroup.define.min && checkboxGroup.define.modelValue.length <= checkboxGroup.define.min) { return true; } } else { if (checkboxGroup.define.max && checkboxGroup.define.modelValue.length >= checkboxGroup.define.max) { return true; } } } else { return false; } }), //* 主体类名 className: computed(() => { const result = []; if (computeds.disabled.value) result.push("ui-disabled-status"); if (computeds.checked.value) result.push("ui-active"); return result.join(" "); }) }; return { methods, computeds }; }; export { useComposable }; //# sourceMappingURL=composable.mjs.map