UNPKG

vuetify

Version:

Vue Material Component Framework

47 lines 1.66 kB
// Composables import { useToggleScope } from "./toggleScope.js"; // Utilities import { inject, onScopeDispose, provide, reactive, readonly, shallowRef, toRaw, toRef, toValue, watchEffect } from 'vue'; import { getCurrentInstance } from "../util/index.js"; // Types const StackSymbol = Symbol.for('vuetify:stack'); const globalStack = reactive([]); export function useStack(isActive, zIndex, disableGlobalStack) { const vm = getCurrentInstance('useStack'); const createStackEntry = !disableGlobalStack; const parent = inject(StackSymbol, undefined); const stack = reactive({ activeChildren: new Set() }); provide(StackSymbol, stack); const _zIndex = shallowRef(Number(toValue(zIndex))); useToggleScope(isActive, () => { const lastZIndex = globalStack.at(-1)?.[1]; _zIndex.value = lastZIndex ? lastZIndex + 10 : Number(toValue(zIndex)); if (createStackEntry) { globalStack.push([vm.uid, _zIndex.value]); } parent?.activeChildren.add(vm.uid); onScopeDispose(() => { if (createStackEntry) { const idx = toRaw(globalStack).findIndex(v => v[0] === vm.uid); globalStack.splice(idx, 1); } parent?.activeChildren.delete(vm.uid); }); }); const globalTop = shallowRef(true); if (createStackEntry) { watchEffect(() => { const _isTop = globalStack.at(-1)?.[0] === vm.uid; setTimeout(() => globalTop.value = _isTop); }); } const localTop = toRef(() => !stack.activeChildren.size); return { globalTop: readonly(globalTop), localTop, stackStyles: toRef(() => ({ zIndex: _zIndex.value })) }; } //# sourceMappingURL=stack.js.map