vue3-core/packages/runtime-dom/src/helpers/useCssModule.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

32 lines
919 B
TypeScript
Raw Normal View History

2020-07-10 04:25:29 +08:00
import { getCurrentInstance, warn } from '@vue/runtime-core'
2019-12-18 10:28:24 +08:00
import { EMPTY_OBJ } from '@vue/shared'
2020-07-13 06:04:09 +08:00
export function useCssModule(name = '$style'): Record<string, string> {
if (!__GLOBAL__) {
const instance = getCurrentInstance()!
if (!instance) {
2020-07-15 22:38:45 +08:00
__DEV__ && warn(`useCssModule must be called inside setup()`)
return EMPTY_OBJ
}
const modules = instance.type.__cssModules
if (!modules) {
__DEV__ && warn(`Current instance does not have CSS modules injected.`)
return EMPTY_OBJ
}
const mod = modules[name]
if (!mod) {
__DEV__ &&
warn(`Current instance does not have CSS module named "${name}".`)
return EMPTY_OBJ
}
return mod as Record<string, string>
} else {
/* v8 ignore start */
if (__DEV__) {
2020-07-15 22:38:45 +08:00
warn(`useCssModule() is not supported in the global build.`)
}
2019-12-18 10:28:24 +08:00
return EMPTY_OBJ
/* v8 ignore stop */
2019-12-18 10:28:24 +08:00
}
}