UNPKG

dk-plus

Version:
42 lines (41 loc) 1.25 kB
import { defineComponent as u, reactive as n, watch as L, toRefs as l } from "vue"; import "../../_icon/index.js"; import { getCheckboxGroupSlot as f } from "../../_hooks/get-checkbox-group/index.js"; import { checkboxGroup as p } from "./index3.js"; const S = u({ name: "DkCheckboxGroup", props: p, emits: ["change"], setup(c, { slots: s, emit: i }) { const r = f(c), { getSlot: m, refresh: k } = r, e = n({ max: c.max, slotList: m(s), checkedList: [] }); L( () => c.modelValue, () => { e.slotList = k(s, e.checkedList), e.checkedList = e.slotList.filter((t) => t.modelValue).map((t) => t.value), i("change", e.checkedList); }, { deep: !0 } ); const h = n({ handleItemChange: (t) => { const { value: a, checked: d } = t, o = e.checkedList.indexOf(a.toString()); d && o === -1 ? e.checkedList.push(a.toString()) : !d && o !== -1 && e.checkedList.splice(o, 1), i("change", e.checkedList); }, getCheckedList: () => { e.checkedList = e.slotList.filter((t) => t.modelValue).map((t) => t.value); } }); return h.getCheckedList(), { ...l(e), ...l(h) }; } }); export { S as default };