UNPKG

bootstrap-vue-next

Version:

Seamless integration of Vue 3, Bootstrap 5, and TypeScript for modern, type-safe UI development

32 lines (31 loc) 1.56 kB
import { x as showHideRegistryKey } from "../../../keys-CQKrwmvN.mjs"; import { t as getActiveShowHide } from "../../../registryAccess-C1Ti_nxW.mjs"; import { computed, getCurrentInstance, inject, toValue } from "vue"; //#region src/composables/useToggle/index.ts var useToggle = (id = void 0) => { const instance = getCurrentInstance(); const storage = inject(showHideRegistryKey, null); if (!storage) throw new Error("useToggle() must be called within setup(), and BApp, useRegistry or plugin must be installed/provided."); const registry = storage.values; const findComponent = (component) => { if (!component.parent) return null; if (component.parent.exposed?.["id"] && registry.value.get(toValue(component.parent.exposed.id))) return component.parent; return findComponent(component.parent); }; const myComponent = computed(() => { const resolvedId = toValue(id); if (resolvedId) return getActiveShowHide(registry, resolvedId); if (!instance) return null; return getActiveShowHide(registry, toValue(findComponent(instance)?.exposed?.id)); }); return { value: computed(() => myComponent.value?.value), show: (resolveOnHide) => myComponent.value?.show(resolveOnHide) || Promise.reject("not found"), hide: (trigger) => myComponent.value?.hide(trigger, true) || Promise.reject("not found"), toggle: (resolveOnHide) => myComponent.value?.toggle(resolveOnHide) || Promise.reject("not found"), component: computed(() => myComponent.value?.component) }; }; //#endregion export { useToggle }; //# sourceMappingURL=index.mjs.map