2020-07-09 20:25:29 +00:00
|
|
|
import { warn, getCurrentInstance } from '@vue/runtime-core'
|
2019-12-18 02:28:24 +00:00
|
|
|
import { EMPTY_OBJ } from '@vue/shared'
|
|
|
|
|
2020-07-12 22:04:09 +00:00
|
|
|
export function useCssModule(name = '$style'): Record<string, string> {
|
2020-07-15 14:38:45 +00:00
|
|
|
/* istanbul ignore else */
|
2020-02-18 18:23:30 +00:00
|
|
|
if (!__GLOBAL__) {
|
|
|
|
const instance = getCurrentInstance()!
|
|
|
|
if (!instance) {
|
2020-07-15 14:38:45 +00:00
|
|
|
__DEV__ && warn(`useCssModule must be called inside setup()`)
|
2020-02-18 18:23:30 +00:00
|
|
|
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 {
|
|
|
|
if (__DEV__) {
|
2020-07-15 14:38:45 +00:00
|
|
|
warn(`useCssModule() is not supported in the global build.`)
|
2020-02-18 18:23:30 +00:00
|
|
|
}
|
2019-12-18 02:28:24 +00:00
|
|
|
return EMPTY_OBJ
|
|
|
|
}
|
|
|
|
}
|