UNPKG

@opensig/opendesign

Version:

171 lines (170 loc) 6.19 kB
"use strict"; const vue = require("vue"); const types = require("./types.js"); const icons = require("../_utils/icons.js"); const provide = require("./provide.js"); const is = require("../_utils/is.js"); const useElementOverflown = require("../hooks/use-element-overflown.js"); require("../hooks/use-theme.js"); require("../_utils/global.js"); require("@vueuse/core"); const index = require("../popover/index.js"); const _hoisted_1 = ["data-level"]; const _hoisted_2 = { key: 0, class: "o-sub-menu-arrow" }; const _hoisted_3 = { key: 1, class: "o-sub-menu-title-icon" }; const _hoisted_4 = { key: 2, class: "o-sub-menu-arrow" }; const _hoisted_5 = { class: "o-sub-menu-children-wrap" }; const _sfc_main = /* @__PURE__ */ vue.defineComponent({ __name: "OSubMenu", props: types.subMenuProps, setup(__props) { const props = __props; const menuInjection = vue.inject(provide.menuInjectKey, null); const subMenuInjection = vue.inject(provide.subMenuInjectKey, null); const { arrowPosition } = menuInjection || {}; const isExpanded = vue.computed(() => { if (is.isUndefined(props.value)) { return false; } if (menuInjection) { return menuInjection.realExpanded.value.includes(props.value); } return false; }); const isAssociatedSelected = vue.computed(() => { if (menuInjection) { return menuInjection.activeNodes.value.includes(props.value); } return false; }); const isSelected = vue.computed(() => { if (menuInjection) { return menuInjection.realValue.value === props.value; } return false; }); const onSubItemClick = (ev) => { ev.stopPropagation(); if (is.isUndefined(props.value)) { return; } let set = menuInjection ? /* @__PURE__ */ new Set([...menuInjection.realExpanded.value]) : /* @__PURE__ */ new Set([]); if (isExpanded.value && set.has(props.value)) { set.delete(props.value); } if (!isExpanded.value && !set.has(props.value)) { if (menuInjection == null ? void 0 : menuInjection.accordion.value) { const siblings = (menuInjection == null ? void 0 : menuInjection.menuTree.getSiblings(props.value)) || []; siblings.forEach((val) => { set.delete(val); }); } set.add(props.value); } const expandedVal = Array.from(set); menuInjection == null ? void 0 : menuInjection.updateExpanded(expandedVal); if (props.selectable) { menuInjection == null ? void 0 : menuInjection.updateModelValue(props.value); } }; const currentDepth = subMenuInjection ? subMenuInjection.parentDepth + 1 : 0; vue.provide(provide.subMenuInjectKey, { value: props.value, parentDepth: currentDepth }); menuInjection == null ? void 0 : menuInjection.menuTree.addChild({ value: props.value, parentVal: subMenuInjection == null ? void 0 : subMenuInjection.value }); menuInjection == null ? void 0 : menuInjection.notifyTreeChange(); const subMenuTitleRef = vue.useTemplateRef("subMenuTitleRef"); const itemContentRef = vue.useTemplateRef("itemContentRef"); const isContentOverflow = useElementOverflown.useElementOverflown(itemContentRef); return (_ctx, _cache) => { return vue.openBlock(), vue.createElementBlock("li", { class: vue.normalizeClass({ "o-sub-menu": true, "o-sub-menu-selected": isSelected.value, "o-sub-menu-associated-selected": isAssociatedSelected.value, "o-sub-menu-expanded": isExpanded.value }), style: vue.normalizeStyle({ "--menu-level": vue.unref(currentDepth) }), "data-level": vue.unref(currentDepth) }, [ vue.createElementVNode( "div", { ref_key: "subMenuTitleRef", ref: subMenuTitleRef, class: "o-sub-menu-title", onClick: onSubItemClick }, [ vue.unref(arrowPosition) === "left" ? (vue.openBlock(), vue.createElementBlock("div", _hoisted_2, [ vue.createVNode(vue.unref(icons.IconChevronDownBold)) ])) : vue.createCommentVNode("v-if", true), _ctx.$slots.icon || props.icon ? (vue.openBlock(), vue.createElementBlock("div", _hoisted_3, [ vue.renderSlot(_ctx.$slots, "icon", {}, () => [ (vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(props.icon))) ]) ])) : vue.createCommentVNode("v-if", true), vue.createElementVNode( "div", { ref_key: "itemContentRef", ref: itemContentRef, class: "o-sub-menu-title-content" }, [ vue.renderSlot(_ctx.$slots, "title") ], 512 /* NEED_PATCH */ ), !vue.unref(arrowPosition) || vue.unref(arrowPosition) === "right" ? (vue.openBlock(), vue.createElementBlock("div", _hoisted_4, [ vue.createVNode(vue.unref(icons.IconChevronDownBold)) ])) : vue.createCommentVNode("v-if", true) ], 512 /* NEED_PATCH */ ), vue.createElementVNode( "ul", { class: vue.normalizeClass(["o-sub-menu-children", { expanded: isExpanded.value }]) }, [ vue.createElementVNode("div", _hoisted_5, [ vue.renderSlot(_ctx.$slots, "default") ]) ], 2 /* CLASS */ ), vue.unref(isContentOverflow) ? (vue.openBlock(), vue.createBlock(vue.unref(index.OPopover), { key: 0, offset: 12, target: subMenuTitleRef.value, position: "bottom", "wrap-class": "o-menu-popover" }, { default: vue.withCtx(() => [ vue.renderSlot(_ctx.$slots, "title") ]), _: 3 /* FORWARDED */ }, 8, ["target"])) : vue.createCommentVNode("v-if", true) ], 14, _hoisted_1); }; } }); module.exports = _sfc_main;