@opensig/opendesign
Version:
<p align="center"><img src="../docs/public/opendesign-logo-light.png"/></p> <h1 align="center">opendesign</h1> <p align="center">一个 Vue 3 组件库</p> <p align="center"><b>皮肤可定制,使用 TypeScript</b></p>
111 lines (110 loc) • 3.62 kB
JavaScript
;
const vue = require("vue");
const types = require("./types.js");
const provide = require("./provide.js");
const is = require("../_utils/is.js");
const dom = require("../_utils/dom.js");
const index = require("../popover/index.js");
const _hoisted_1 = ["data-level"];
const _hoisted_2 = {
key: 0,
class: "o-menu-item-icon"
};
const _sfc_main = /* @__PURE__ */ vue.defineComponent({
__name: "OMenuItem",
props: types.menuItemProps,
emits: ["click"],
setup(__props, { emit: __emit }) {
const props = __props;
const emits = __emit;
const menuInjection = vue.inject(provide.menuInjectKey, null);
const subMenuInjection = vue.inject(provide.subMenuInjectKey, null);
const isSelected = vue.computed(() => {
if (menuInjection) {
return menuInjection.realValue.value === props.value;
}
return false;
});
const onItemClick = (ev) => {
ev.stopPropagation();
if (props.disabled) {
return;
}
if (is.isUndefined(props.value)) {
return;
}
emits("click", ev);
menuInjection == null ? void 0 : menuInjection.updateModelValue(props.value);
};
const currentDepth = subMenuInjection ? subMenuInjection.parentDepth + 1 : 0;
menuInjection == null ? void 0 : menuInjection.menuTree.addChild({
value: props.value,
parentVal: subMenuInjection == null ? void 0 : subMenuInjection.value
});
const menuItemRef = vue.ref();
const itemContentRef = vue.ref();
const isContentOverflow = vue.ref(false);
const content = vue.ref("");
vue.onMounted(() => {
var _a;
if (!itemContentRef.value) {
return;
}
isContentOverflow.value = dom.isOverflown(itemContentRef.value);
content.value = ((_a = itemContentRef.value) == null ? void 0 : _a.innerText) || "";
});
return (_ctx, _cache) => {
return vue.openBlock(), vue.createElementBlock("li", {
class: vue.normalizeClass({
"o-menu-item": true,
"o-menu-item-selected": isSelected.value,
"o-menu-item-disabled": _ctx.$props.disabled
}),
style: vue.normalizeStyle({
"--menu-level": vue.unref(currentDepth)
}),
"data-level": vue.unref(currentDepth),
onClick: onItemClick,
ref_key: "menuItemRef",
ref: menuItemRef
}, [
props.icon || _ctx.$slots.icon ? (vue.openBlock(), vue.createElementBlock("div", _hoisted_2, [
vue.renderSlot(_ctx.$slots, "icon", {}, () => [
(vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(props.icon)))
])
])) : vue.createCommentVNode("v-if", true),
vue.createElementVNode(
"div",
{
class: "o-menu-item-content",
ref_key: "itemContentRef",
ref: itemContentRef
},
[
vue.renderSlot(_ctx.$slots, "default")
],
512
/* NEED_PATCH */
),
isContentOverflow.value ? (vue.openBlock(), vue.createBlock(vue.unref(index.OPopover), {
key: 1,
offset: 12,
target: menuItemRef.value,
position: "bottom",
wrapClass: "o-menu-popover"
}, {
default: vue.withCtx(() => [
vue.createTextVNode(
vue.toDisplayString(content.value),
1
/* TEXT */
)
]),
_: 1
/* STABLE */
}, 8, ["target"])) : vue.createCommentVNode("v-if", true)
], 14, _hoisted_1);
};
}
});
module.exports = _sfc_main;