UNPKG

hongluan-ui

Version:
66 lines (63 loc) 2.35 kB
import { defineComponent, ref, getCurrentInstance, provide, reactive, toRefs, inject, onMounted, toRaw, watch, withDirectives, openBlock, createElementBlock, normalizeClass, createElementVNode, toDisplayString, renderSlot, vShow } from 'vue'; import '../../../hooks/index.mjs'; import { selectGroupKey, selectKey } from './token.mjs'; import _export_sfc from '../../../_virtual/plugin-vue_export-helper.mjs'; import { useNamespace } from '../../../hooks/use-namespace/index.mjs'; const _sfc_main = defineComponent({ name: "OptionGroup", componentName: "OptionGroup", props: { label: String, disabled: Boolean }, setup(props) { const { namespace } = useNamespace("option-group"); const visible = ref(true); const instance = getCurrentInstance(); const children = ref([]); provide(selectGroupKey, reactive({ ...toRefs(props) })); const select = inject(selectKey); onMounted(() => { children.value = flattedChildren(instance.subTree); }); const flattedChildren = (node) => { const children2 = []; if (Array.isArray(node.children)) { node.children.forEach((child) => { var _a; if (child.type && child.type.name === "Option" && child.component && child.component.proxy) { children2.push(child.component.proxy); } else if ((_a = child.children) == null ? void 0 : _a.length) { children2.push(...flattedChildren(child)); } }); } return children2; }; const { groupQueryChange } = toRaw(select); watch(groupQueryChange, () => { visible.value = children.value.some((option) => option.visible === true); }, { flush: "post" }); return { namespace, visible }; } }); function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) { return withDirectives((openBlock(), createElementBlock("li", { class: normalizeClass(_ctx.namespace) }, [ createElementVNode("strong", { class: "select-group-title" }, toDisplayString(_ctx.label), 1), createElementVNode("ul", null, [ renderSlot(_ctx.$slots, "default") ]) ], 2)), [ [vShow, _ctx.visible] ]); } var OptionGroup = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]]); export { OptionGroup as default }; //# sourceMappingURL=option-group.mjs.map