UNPKG

hongluan-ui

Version:
123 lines (120 loc) 3.86 kB
import { defineComponent, reactive, toRefs, getCurrentInstance, onBeforeUnmount, nextTick, resolveComponent, openBlock, createElementBlock, withDirectives, normalizeClass, withModifiers, renderSlot, createElementVNode, toDisplayString, createBlock, withCtx, createVNode, createCommentVNode, vShow } from 'vue'; import '../../../hooks/index.mjs'; import { HlIcon } from '../../icon/index.mjs'; import '../../system-icon/index.mjs'; import { useOption } from './useOption.mjs'; import _export_sfc from '../../../_virtual/plugin-vue_export-helper.mjs'; import SystemChecked from '../../system-icon/src/checked.mjs'; import { useNamespace } from '../../../hooks/use-namespace/index.mjs'; import { useId } from '../../../hooks/use-id/index.mjs'; const _sfc_main = defineComponent({ name: "Option", components: { HlIcon, SystemChecked }, componentName: "Option", props: { value: { type: [String, Number, Boolean, Object] }, label: [String, Number], created: Boolean, disabled: Boolean, divider: Boolean }, setup(props) { const { namespace } = useNamespace("option"); const id = useId(); const states = reactive({ index: -1, groupDisabled: false, visible: true, hitState: false, hover: false }); const { currentLabel, itemSelected, isDisabled, select, hoverItem } = useOption(props, states); const { visible, hover } = toRefs(states); const vm = getCurrentInstance().proxy; select.onOptionCreate(vm); onBeforeUnmount(() => { const key = vm.value; const { selected } = select; let 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); }); function selectOptionClick() { if (props.disabled !== true && states.groupDisabled !== true) { select.handleOptionSelect(vm); } } return { id, namespace, currentLabel, itemSelected, isDisabled, select, hoverItem, visible, hover, selectOptionClick, states }; } }); function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) { const _component_system_checked = resolveComponent("system-checked"); const _component_hl_icon = resolveComponent("hl-icon"); return _ctx.divider ? (openBlock(), createElementBlock("li", { key: 0, class: "menu-divider" })) : withDirectives((openBlock(), createElementBlock("li", { key: 1, id: _ctx.id, role: "option", "aria-disabled": _ctx.isDisabled || void 0, "aria-selected": _ctx.itemSelected, class: normalizeClass({ [_ctx.namespace]: true, "select-dropdown-item": true, "is-selected": _ctx.itemSelected, "is-disabled": _ctx.isDisabled, "hover": _ctx.hover }), onMouseenter: _ctx.hoverItem, onClick: withModifiers(_ctx.selectOptionClick, ["stop"]) }, [ renderSlot(_ctx.$slots, "default", {}, () => [ createElementVNode("div", null, toDisplayString(_ctx.currentLabel), 1), _ctx.itemSelected ? (openBlock(), createBlock(_component_hl_icon, { key: 0 }, { default: withCtx(() => [ createVNode(_component_system_checked) ]), _: 1 })) : createCommentVNode("v-if", true) ]) ], 42, ["id", "aria-disabled", "aria-selected", "onMouseenter", "onClick"])), [ [vShow, _ctx.visible] ]); } var HlOption = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]]); export { HlOption as default }; //# sourceMappingURL=option.mjs.map