vuux
Version:
Vue3 Nuxt3 Nuxt4 组件库
30 lines (29 loc) • 1.02 kB
JavaScript
import { inject as m, computed as n, nextTick as h } from "vue";
const C = (e, i) => {
const t = m("checkBoxContext", {}), a = n(() => !!t.modelValue), d = n(() => e.indeterminate ? e.indeterminate : !1), c = n(() => a.value && t.disabled.value || e.disabled), r = n(() => t && t.themeColor?.value ? t.themeColor?.value : e.theme ? e.theme : "var(--app-theme)"), l = n({
get() {
return a.value ? t.modelValue?.value : e.modelValue;
},
set(u) {
a.value ? t.changeEvent(u) : i("update:modelValue", u);
}
}), s = n(() => e.indeterminate ? !1 : a.value ? l.value.includes(e.value) : l.value), o = n(() => ({
"app-checkbox": !0,
"is-checked": s.value,
"is-disabled": e.disabled ? e.disabled : !1,
"is-indeterminate": e.indeterminate ? e.indeterminate : !1
}));
return {
isIndeterminate: d,
isDisabled: c,
themeColor: r,
model: l,
classNames: o,
onChange: () => {
h(() => i("change", l.value));
}
};
};
export {
C as useCheckBox
};