bootstrap-vue-next
Version:
BootstrapVueNext is an early and lovely component library for Vue 3 & Nuxt 3 based on Bootstrap 5 and Typescript.
46 lines (45 loc) • 1.65 kB
JavaScript
import { getCurrentInstance, inject, computed, toValue } from "vue";
import { s as showHideRegistryKey } from "../../../keys-BLeKMItg.mjs";
const 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 (!registry) return null;
if (resolvedId) {
const value = registry.value.get(resolvedId);
return toValue(value) || null;
}
if (!instance) {
return null;
}
const component = findComponent(instance);
return toValue(registry.value.get(toValue(component?.exposed?.id))) || null;
});
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)
};
};
export {
useToggle
};
//# sourceMappingURL=index.mjs.map