UNPKG

@vuesax-alpha/nightly

Version:
67 lines (64 loc) 2.22 kB
import { defineComponent, inject, ref, computed, watch, provide, openBlock, createElementBlock, normalizeClass, unref, createElementVNode, toDisplayString, renderSlot } from 'vue'; import '../../../hooks/index.mjs'; import '../../../utils/index.mjs'; import { optionGroupProps } from './option-group.mjs'; import { selectContextKey, optionGroupRegisterKey } from './tokens.mjs'; import _export_sfc from '../../../_virtual/plugin-vue_export-helper.mjs'; import { useNamespace } from '../../../hooks/use-namespace/index.mjs'; import { throwError } from '../../../utils/error.mjs'; const __default__ = defineComponent({ name: "VsOptionGroup" }); const _sfc_main = defineComponent({ ...__default__, props: optionGroupProps, setup(__props) { const ns = useNamespace("option-group"); const select = inject(selectContextKey); if (!select) { throwError( "Option Group", "`option-group` component must be called inside `select` component" ); } const visible = ref(true); const options = ref(/* @__PURE__ */ new Map()); const optionsArray = computed(() => Array.from(options.value.values())); watch( () => select.queryChange, () => { visible.value = optionsArray.value.some((option) => option.visible === true); }, { flush: "post" } ); provide(optionGroupRegisterKey, (option) => { options.value.set(option.value, option); return { unregister() { options.value.delete(option.value); } }; }); return (_ctx, _cache) => { return openBlock(), createElementBlock( "div", { class: normalizeClass([unref(ns).b(), unref(ns).is("hidden", !visible.value)]) }, [ createElementVNode( "h5", null, toDisplayString(_ctx.label), 1 ), renderSlot(_ctx.$slots, "default") ], 2 ); }; } }); var OptionGroup = /* @__PURE__ */ _export_sfc(_sfc_main, [["__file", "/home/runner/work/vuesax-alpha/vuesax-alpha/packages/components/select/src/option-group.vue"]]); export { OptionGroup as default }; //# sourceMappingURL=option-group2.mjs.map