UNPKG

bootstrap-vue-next

Version:

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

34 lines (33 loc) 1.62 kB
import { x as showHideRegistryKey } from "../../../keys-BgLwJbLV.js"; import { t as getActiveShowHide } from "../../../registryAccess-YFj5ZD5T.js"; 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; const component = findComponent(instance); const componentId = toValue(component?.exposed?.id); return getActiveShowHide(registry, componentId); }); 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