bootstrap-vue-next
Version:
Seamless integration of Vue 3, Bootstrap 5, and TypeScript for modern, type-safe UI development
46 lines (45 loc) • 1.69 kB
JavaScript
import { getCurrentInstance, inject, computed, toValue } from "vue";
import { s as showHideRegistryKey } from "../../../keys-BLeKMItg.mjs";
import { g as getActiveShowHide } from "../../../registryAccess-CjgwYkQG.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 (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)
};
};
export {
useToggle
};
//# sourceMappingURL=index.mjs.map