hongluan-ui
Version:
Hongluan Component Library for Vue 3
126 lines (121 loc) • 4.15 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
var vue = require('vue');
var index = require('../../tooltip/index.js');
require('../../popper/index.js');
require('../../../utils/index.js');
require('../../../hooks/index.js');
var useMenu = require('./use-menu.js');
var menuItem = require('./menu-item2.js');
var pluginVue_exportHelper = require('../../../_virtual/plugin-vue_export-helper.js');
var index$1 = require('../../../hooks/use-namespace/index.js');
var error = require('../../../utils/error.js');
var popper = require('../../popper/src/popper.js');
const COMPONENT_NAME = "MenuItem";
const _sfc_main = vue.defineComponent({
name: COMPONENT_NAME,
components: {
HlTooltip: index.HlTooltip
},
props: menuItem.menuItemProps,
emits: ["click"],
setup(props, { emit }) {
const { namespace } = index$1.useNamespace();
const instance = vue.getCurrentInstance();
const rootMenu = vue.inject("rootMenu");
if (!rootMenu)
error.throwError(COMPONENT_NAME, "can not inject root menu");
const { parentMenu, indexPath } = useMenu["default"](instance, vue.toRef(props, "index"));
const subMenu = vue.inject(`subMenu:${parentMenu.value.uid}`);
if (!subMenu)
error.throwError(COMPONENT_NAME, "can not inject sub menu");
const active = vue.computed(() => props.index === rootMenu.activeIndex);
const backgroundColor = vue.computed(() => rootMenu.props.backgroundColor || "");
const activeTextColor = vue.computed(() => rootMenu.props.activeTextColor || "");
const textColor = vue.computed(() => rootMenu.props.textColor || "");
const item = vue.reactive({
index: props.index,
indexPath,
active
});
const itemStyle = vue.computed(() => {
const style = {
color: active.value ? activeTextColor.value : textColor.value,
backgroundColor: backgroundColor.value
};
return style;
});
const handleClick = () => {
if (!props.disabled) {
rootMenu.handleMenuItemClick({
index: props.index,
indexPath: indexPath.value,
route: props.route
});
emit("click", item);
}
};
vue.onMounted(() => {
subMenu.addSubMenu(item);
rootMenu.addMenuItem(item);
});
vue.onBeforeUnmount(() => {
subMenu.removeSubMenu(item);
rootMenu.removeMenuItem(item);
});
return {
namespace,
itemStyle,
Effect: popper.Effect,
parentMenu,
rootMenu,
active,
handleClick
};
}
});
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
const _component_hl_tooltip = vue.resolveComponent("hl-tooltip");
return vue.openBlock(), vue.createElementBlock("li", {
role: "menuitem",
tabindex: "-1",
style: vue.normalizeStyle([_ctx.itemStyle]),
class: vue.normalizeClass({
[_ctx.namespace + "-menu-item"]: true,
"is-active": _ctx.active,
"is-disabled": _ctx.disabled
}),
onClick: _ctx.handleClick
}, [
_ctx.parentMenu.type.name === "Menu" && _ctx.rootMenu.finalCollapse && _ctx.$slots.title ? (vue.openBlock(), vue.createBlock(_component_hl_tooltip, {
key: 0,
trigger: "hover",
class: "no-style",
placement: "right",
"fallback-placements": ["left"],
"show-arrow": false,
offset: 0,
"hide-after": 0,
"popper-class": `${_ctx.namespace}-menu-popover`
}, {
content: vue.withCtx(() => [
vue.renderSlot(_ctx.$slots, "title")
]),
default: vue.withCtx(() => [
vue.createElementVNode("div", { class: "item-content" }, [
vue.renderSlot(_ctx.$slots, "default")
])
]),
_: 3
}, 8, ["popper-class"])) : (vue.openBlock(), vue.createElementBlock("div", {
key: 1,
class: "item-content"
}, [
vue.renderSlot(_ctx.$slots, "default"),
vue.renderSlot(_ctx.$slots, "title")
]))
], 14, ["onClick"]);
}
var MenuItem = /* @__PURE__ */ pluginVue_exportHelper["default"](_sfc_main, [["render", _sfc_render]]);
exports["default"] = MenuItem;
//# sourceMappingURL=menu-item.js.map