UNPKG

@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>

85 lines (84 loc) 2.51 kB
"use strict"; const vue = require("vue"); const provide = require("./provide.js"); const types = require("./types.js"); const menu = require("./menu.js"); const is = require("../_utils/is.js"); const _sfc_main = /* @__PURE__ */ vue.defineComponent({ __name: "OMenu", props: types.menuProps, emits: ["update:modelValue", "change", "update:expanded", "expanded-change"], setup(__props, { emit: __emit }) { const props = __props; const emits = __emit; const menuTree = new menu(NaN, null); const { size, accordion, modelValue, defaultValue, expanded, defaultExpanded } = vue.toRefs(props); const realValue = vue.ref((modelValue == null ? void 0 : modelValue.value) ?? defaultValue.value); vue.watch( () => modelValue == null ? void 0 : modelValue.value, (val) => { if (!is.isUndefined(val)) { realValue.value = val; } } ); const updateModelValue = (val) => { realValue.value = val; emits("update:modelValue", val); emits("change", val); }; const activeNodes = vue.ref([]); vue.watch( () => realValue.value, (val) => { activeNodes.value = menuTree.selectNode(val); } ); vue.onMounted(() => { activeNodes.value = menuTree.selectNode(realValue.value); }); const realExpanded = vue.ref(is.isArray(expanded == null ? void 0 : expanded.value) ? expanded == null ? void 0 : expanded.value : defaultExpanded.value); vue.watch( () => expanded == null ? void 0 : expanded.value, (val) => { if (is.isArray(val)) { realExpanded.value = val; } } ); const updateExpanded = (val) => { realExpanded.value = val; emits("update:expanded", val); emits("expanded-change", val); }; vue.provide(provide.menuInjectKey, { size, accordion, realValue, activeNodes, realExpanded, menuTree, updateModelValue, updateExpanded, arrowPosition: vue.toRef(props, "arrowPosition") }); return (_ctx, _cache) => { return vue.openBlock(), vue.createElementBlock( "ul", { class: vue.normalizeClass([ "o-menu", `o-menu-${vue.unref(size)}`, _ctx.arrowPosition && `o-menu-arrow-${_ctx.arrowPosition}` ]) }, [ vue.renderSlot(_ctx.$slots, "default") ], 2 /* CLASS */ ); }; } }); module.exports = _sfc_main;