UNPKG

comic-plus

Version:

<p align="center"> <img width="200px" src="./logo.png"/> </p>

76 lines (75 loc) 2.94 kB
import { defineComponent, getCurrentInstance, inject, computed, onMounted, onBeforeUnmount, withDirectives, openBlock, createElementBlock, normalizeClass, unref, createBlock, resolveDynamicComponent, createCommentVNode, createElementVNode, renderSlot, createTextVNode, toDisplayString, vShow } from "vue"; import { useTooltip } from "../../tooltip/index.mjs"; import { useMenu } from "../utils/menu.mjs"; import { menuItemProps } from "./item.props.mjs"; import { MENU_PROVIDE } from "./type.mjs"; import "../../../utils/config.mjs"; import { isVueComponent } from "../../../utils/typescript.mjs"; import "@vueuse/core"; const _hoisted_1 = ["tooltip-disabled"]; const _sfc_main = /* @__PURE__ */ defineComponent({ ...{ name: "CuMenuItem" }, __name: "item", props: menuItemProps, setup(__props) { var _a, _b; const props = __props; const vMenuTooltip = useTooltip(); const instance = getCurrentInstance(); const { props: injectProps, menuClick } = inject(MENU_PROVIDE); const { parentMenu } = useMenu(instance); const parentProvideKey = "submenu:provide" + ((_b = (_a = parentMenu.value) == null ? void 0 : _a.exposed) == null ? void 0 : _b.submenuKey); const submenu = inject(parentProvideKey, void 0); const tooltipDisabled = computed(() => { return !(injectProps.collapse && !submenu || props.showEllipsis); }); const active = computed(() => { if (injectProps.modelValue) { return injectProps.modelValue === props.index; } return false; }); const menuItemKey = props.index ?? instance.uid.toString(); function itemClick() { menuClick(props.index); if (injectProps.mode === "horizontal" || injectProps.collapse) { submenu == null ? void 0 : submenu.closeMenu(true); } } onMounted(() => { submenu == null ? void 0 : submenu.setMenu({ idx: menuItemKey, active }); }); onBeforeUnmount(() => { submenu == null ? void 0 : submenu.removeMenu(menuItemKey); }); return (_ctx, _cache) => { return withDirectives((openBlock(), createElementBlock("li", { class: normalizeClass(["cu-menu-item", { "is-active": active.value }]), onClick: itemClick, "tooltip-disabled": tooltipDisabled.value }, [ unref(isVueComponent)(_ctx.icon) ? (openBlock(), createBlock(resolveDynamicComponent(_ctx.icon), { key: 0, class: "cu-menu__icon" })) : createCommentVNode("", true), withDirectives(createElementVNode("span", null, [ renderSlot(_ctx.$slots, "default", {}, () => [ createTextVNode(toDisplayString(_ctx.label), 1) ]) ], 512), [ [vShow, !unref(injectProps).collapse || unref(submenu)] ]) ], 10, _hoisted_1)), [ [unref(vMenuTooltip), props.label, "right-center"] ]); }; } }); export { _sfc_main as default };