这一版本优化了很多

This commit is contained in:
王利强
2026-06-03 10:16:37 +08:00
parent 8046316216
commit 2af9f1fd59
954 changed files with 58194 additions and 1609 deletions

View File

@@ -0,0 +1,31 @@
import { computed, provide, unref, type Ref } from 'vue'
import { type ConfigProviderThemeVars } from '../wd-config-provider/types'
import { objToStyle } from '../common/util'
export const USE_CONFIG_PROVIDER_KEY = '__CONFIG_PROVIDER__'
export const kebabCase = (str: string): string => {
str = str.replace(str.charAt(0), str.charAt(0).toLocaleLowerCase())
return str.replace(/([a-z])([A-Z])/g, (_, p1, p2) => p1 + '-' + p2.toLowerCase())
}
export const mapThemeVarsToCSSVars = (themeVars: Record<string, string>) => {
if (!themeVars) return
const cssVars: Record<string, string> = {}
Object.keys(themeVars).forEach((key) => {
cssVars[`--wot-${kebabCase(key)}`] = themeVars[key]
})
return cssVars
}
export function useConfigProvider({ themeVars }: { themeVars: ConfigProviderThemeVars | Ref<ConfigProviderThemeVars> }) {
const themeStyle = computed(() => {
const styleObj = mapThemeVarsToCSSVars(unref(themeVars))
return styleObj ? `${objToStyle(styleObj)}` : ''
})
provide(USE_CONFIG_PROVIDER_KEY, {
themeStyle
})
}