forked from fdzcxy212206413/gsl_grs
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.6 KiB
40 lines
1.6 KiB
import { ref, getCurrentInstance, inject, computed, unref } from 'vue';
|
|
import '../../utils/index.mjs';
|
|
import { isNumber } from '../../utils/types.mjs';
|
|
import { isClient } from '@vueuse/core';
|
|
import { debugWarn } from '../../utils/error.mjs';
|
|
|
|
const initial = {
|
|
current: 0
|
|
};
|
|
const zIndex = ref(0);
|
|
const defaultInitialZIndex = 2e3;
|
|
const ZINDEX_INJECTION_KEY = Symbol("elZIndexContextKey");
|
|
const zIndexContextKey = Symbol("zIndexContextKey");
|
|
const useZIndex = (zIndexOverrides) => {
|
|
const increasingInjection = getCurrentInstance() ? inject(ZINDEX_INJECTION_KEY, initial) : initial;
|
|
const zIndexInjection = zIndexOverrides || (getCurrentInstance() ? inject(zIndexContextKey, void 0) : void 0);
|
|
const initialZIndex = computed(() => {
|
|
const zIndexFromInjection = unref(zIndexInjection);
|
|
return isNumber(zIndexFromInjection) ? zIndexFromInjection : defaultInitialZIndex;
|
|
});
|
|
const currentZIndex = computed(() => initialZIndex.value + zIndex.value);
|
|
const nextZIndex = () => {
|
|
increasingInjection.current++;
|
|
zIndex.value = increasingInjection.current;
|
|
return currentZIndex.value;
|
|
};
|
|
if (!isClient && !inject(ZINDEX_INJECTION_KEY)) {
|
|
debugWarn("ZIndexInjection", `Looks like you are using server rendering, you must provide a z-index provider to ensure the hydration process to be succeed
|
|
usage: app.provide(ZINDEX_INJECTION_KEY, { current: 0 })`);
|
|
}
|
|
return {
|
|
initialZIndex,
|
|
currentZIndex,
|
|
nextZIndex
|
|
};
|
|
};
|
|
|
|
export { ZINDEX_INJECTION_KEY, defaultInitialZIndex, useZIndex, zIndexContextKey };
|
|
//# sourceMappingURL=index.mjs.map
|