2021-12-30 19:31:35 +08:00
|
|
|
import { inject, ref, toRef } from 'vue'
|
2021-11-05 18:10:07 +08:00
|
|
|
import { configProviderContextKey } from '@element-plus/tokens'
|
2021-12-30 19:31:35 +08:00
|
|
|
import { hasOwn, isObject } from '@element-plus/utils/util'
|
2021-12-10 17:21:01 +08:00
|
|
|
import type { Ref } from 'vue'
|
2021-12-01 22:26:57 +08:00
|
|
|
import type { ConfigProviderContext } from '@element-plus/tokens'
|
2021-11-05 18:10:07 +08:00
|
|
|
|
2021-12-10 17:21:01 +08:00
|
|
|
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) {
|
2021-12-30 19:31:35 +08:00
|
|
|
return isObject(config) && hasOwn(config, key)
|
|
|
|
? toRef(config, key)
|
|
|
|
: ref(undefined)
|
2021-12-10 17:21:01 +08:00
|
|
|
} else {
|
|
|
|
return config
|
|
|
|
}
|
2021-11-05 18:10:07 +08:00
|
|
|
}
|