element-plus/packages/hooks/use-global-config/index.ts
三咲智子 4335b01d6c
refactor(utils)!: refactor global config (#4793)
* refactor(utils)!: remove global config

* refactor(utils): named export PopupManager

* fix tests
2021-12-30 19:31:35 +08:00

21 lines
706 B
TypeScript

import { inject, ref, toRef } from 'vue'
import { configProviderContextKey } from '@element-plus/tokens'
import { hasOwn, isObject } from '@element-plus/utils/util'
import type { Ref } from 'vue'
import type { ConfigProviderContext } from '@element-plus/tokens'
export function useGlobalConfig<K extends keyof ConfigProviderContext>(
key: K
): Ref<ConfigProviderContext[K]>
export function useGlobalConfig(): ConfigProviderContext
export function useGlobalConfig(key?: keyof ConfigProviderContext) {
const config = inject(configProviderContextKey, {})
if (key) {
return isObject(config) && hasOwn(config, key)
? toRef(config, key)
: ref(undefined)
} else {
return config
}
}