UNPKG

winbox-ui-next

Version:

We Design Vue 2.0: A Vue.js 3 UI Library

132 lines (131 loc) 4.09 kB
var __defProp = Object.defineProperty; var __defProps = Object.defineProperties; var __getOwnPropDescs = Object.getOwnPropertyDescriptors; var __getOwnPropSymbols = Object.getOwnPropertySymbols; var __hasOwnProp = Object.prototype.hasOwnProperty; var __propIsEnum = Object.prototype.propertyIsEnumerable; var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __spreadValues = (a, b) => { for (var prop in b || (b = {})) if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]); if (__getOwnPropSymbols) for (var prop of __getOwnPropSymbols(b)) { if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]); } return a; }; var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b)); import { defineComponent, toRefs, computed, toRef, createVNode, mergeProps } from "vue"; import SubMenuInline from "./sub-menu-inline.js"; import SubMenuPop from "./sub-menu-pop.js"; import useMenu from "./hooks/use-menu.js"; import useLevel from "./hooks/use-level.js"; import IconDown from "../icon/icon-down/index.js"; import IconRight from "../icon/icon-right/index.js"; import useMenuContext from "./hooks/use-menu-context.js"; import useMenuDataCollector from "./hooks/use-menu-data-collector.js"; var SubMenu = defineComponent({ name: "SubMenu", props: { key: { type: String }, title: { type: String }, selectable: { type: Boolean }, popup: { type: [Boolean, Function], default: false }, popupMaxHeight: { type: [Boolean, Number], default: void 0 } }, setup(props, { attrs }) { const { key } = useMenu(); const { level } = useLevel(); const { popup } = toRefs(props); const menuContext = useMenuContext(); const computedPopup = computed(() => { const { mode, collapsed, inTrigger } = menuContext; const forcePopup = !!(typeof popup.value === "function" ? popup.value(level.value) : popup.value); return forcePopup || collapsed || inTrigger || mode !== "vertical"; }); const { subMenuKeys, menuItemKeys } = useMenuDataCollector({ key: key.value, type: "subMenu" }); const isChildrenSelected = computed(() => { const selectedKeys = menuContext.selectedKeys || []; const checkSelected = (menuKeys) => { for (let i = 0; i < selectedKeys.length; i++) { const selectedKey = selectedKeys[i]; if (menuKeys.includes(selectedKey)) { return true; } } return false; }; return checkSelected(subMenuKeys.value) || checkSelected(menuItemKeys.value); }); return { subMenuKeys, menuItemKeys, isChildrenSelected, props, attrs, computedKey: key, computedPopup, expandIconDown: toRef(menuContext, "expandIconDown"), expandIconRight: toRef(menuContext, "expandIconRight") }; }, render() { const { props, attrs, computedKey, computedPopup, expandIconDown, expandIconRight, isChildrenSelected } = this; const _slots = __spreadProps(__spreadValues({}, this.$slots), { "expand-icon-down": this.$slots["expand-icon-down"] || expandIconDown || (() => createVNode(IconDown, null, null)), "expand-icon-right": this.$slots["expand-icon-right"] || expandIconRight || (() => createVNode(IconRight, null, null)) }); return computedPopup ? createVNode(SubMenuPop, mergeProps({ "key": computedKey, "title": props.title, "selectable": props.selectable, "isChildrenSelected": isChildrenSelected, "popupMaxHeight": props.popupMaxHeight }, attrs), _slots) : createVNode(SubMenuInline, mergeProps({ "key": computedKey, "title": props.title, "isChildrenSelected": isChildrenSelected }, attrs), _slots); } }); export { SubMenu as default };