UNPKG

code-monkey-ui

Version:

A Component Library for Vue 3

179 lines (176 loc) 5.88 kB
import { defineComponent, computed, unref, reactive, toRefs, getCurrentInstance, onBeforeUnmount, nextTick, createElementVNode, resolveComponent, openBlock, createElementBlock, normalizeClass, withModifiers, renderSlot, createBlock, withCtx, toDisplayString, createCommentVNode } from 'vue'; import { ElCheckbox } from '../../checkbox/index.mjs'; import '../../../hooks/index.mjs'; import { useOption } from './useOption.mjs'; import _export_sfc from '../../../_virtual/plugin-vue_export-helper.mjs'; import { useNamespace } from '../../../hooks/use-namespace/index.mjs'; import { useId } from '../../../hooks/use-id/index.mjs'; const _sfc_main = defineComponent({ name: "ElDshOption", componentName: "ElDshOption", components: { ElCheckbox }, props: { value: { required: true, type: [String, Number, Boolean, Object] }, label: [String, Number], created: Boolean, disabled: Boolean, tip: [String, Number] }, setup(props) { const ns = useNamespace("dsh-select"); const id = useId(); const containerKls = computed(() => [ ns.be("dropdown", "item"), ns.is("disabled", unref(isDisabled)), { selected: unref(itemSelected), hover: unref(hover) } ]); const states = reactive({ index: -1, groupDisabled: false, visible: true, hitState: false, hover: false }); const { currentLabel, itemSelected, isDisabled, select, currentTip, hoverItem, checkBoxRef, currentValue, onlyThis } = useOption(props, states); const { visible, hover } = toRefs(states); const vm = getCurrentInstance().proxy; select.onOptionCreate(vm); onBeforeUnmount(() => { const key = vm.value; const { selected } = select; const selectedOptions = select.props.multiple ? selected : [selected]; const doesSelected = selectedOptions.some((item) => { return item.value === vm.value; }); nextTick(() => { if (select.cachedOptions.get(key) === vm && !doesSelected) { select.cachedOptions.delete(key); } }); select.onOptionDestroy(key, vm); }); const selectOptionClick = (value) => { if (props.value === "select-all") { select.handleOptionSelect("select-all"); nextTick(() => { value.target.className.includes("select-dropdown") && select.handleCheckAllChange(!select.checkAll); select.resetCheckBoxValues(); }); return; } if (props.value === "reverse") { select.handleOptionSelect("reverse"); nextTick(() => { select.resetCheckBoxValues(); }); return; } if (props.value === "select-hidden") { select.handleOptionSelect("select-hidden"); nextTick(() => { select.resetCheckBoxValues(); }); return; } if (props.disabled !== true && states.groupDisabled !== true) { select.handleOptionSelect(vm); nextTick(() => { value.target.className.includes("select-dropdown") && [ select.resetCheckBoxValues(), select.handleCheckedChange() ]; }); } }; const onlyCheck = (event) => { select.deleteSelected(event); setTimeout(() => { select.handleOptionSelect(vm); nextTick(() => { select.resetCheckBoxValues(); select.handleCheckedChange(); select.handleConfirm(); }); }); }; return { ns, id, containerKls, currentLabel, currentValue, currentTip, itemSelected, isDisabled, select, hoverItem, visible, hover, selectOptionClick, states, checkBoxRef, onlyThis, onlyCheck }; } }); const _hoisted_1 = ["id", "aria-disabled", "aria-selected"]; const _hoisted_2 = { class: "text-sub" }; const _hoisted_3 = /* @__PURE__ */ createElementVNode("span", null, "\u4EC5\u7B5B\u9009\u6B64\u9879", -1); const _hoisted_4 = [ _hoisted_3 ]; function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) { const _component_el_checkbox = resolveComponent("el-checkbox"); return _ctx.visible ? (openBlock(), createElementBlock("li", { key: 0, id: _ctx.id, class: normalizeClass(_ctx.containerKls), role: "option", "aria-disabled": _ctx.isDisabled || void 0, "aria-selected": _ctx.itemSelected, onMouseenter: _cache[1] || (_cache[1] = (...args) => _ctx.hoverItem && _ctx.hoverItem(...args)), onClick: _cache[2] || (_cache[2] = withModifiers((...args) => _ctx.selectOptionClick && _ctx.selectOptionClick(...args), ["stop"])) }, [ renderSlot(_ctx.$slots, "default", {}, () => [ (openBlock(), createBlock(_component_el_checkbox, { ref: "checkBoxRef", key: _ctx.currentValue, label: _ctx.currentValue, onClick: withModifiers(_ctx.selectOptionClick, ["stop"]) }, { default: withCtx(() => [ createElementVNode("span", null, toDisplayString(_ctx.currentLabel), 1), createElementVNode("span", _hoisted_2, toDisplayString(_ctx.currentTip), 1) ]), _: 1 }, 8, ["label", "onClick"])), _ctx.onlyThis ? (openBlock(), createElementBlock("div", { key: 0, class: "select-tag", onClick: _cache[0] || (_cache[0] = (...args) => _ctx.onlyCheck && _ctx.onlyCheck(...args)) }, _hoisted_4)) : createCommentVNode("v-if", true) ]) ], 42, _hoisted_1)) : createCommentVNode("v-if", true); } var DshOption = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render], ["__file", "D:\\project\\work\\code-monkey-ui\\packages\\components\\dsh-select\\src\\option.vue"]]); export { DshOption as default }; //# sourceMappingURL=option.mjs.map