diff --git a/README.md b/README.md index 344ed9017da77318539170f944d3bdb4bd662d9c..7032a70ee6a51adac432ab6b7df70bea3d641396 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@

- DevUI Logo + DevUI Logo

diff --git a/devui/theme/core/theme.ts b/devui/theme/core/theme.ts new file mode 100644 index 0000000000000000000000000000000000000000..2b37e404e64d34f6280ffdd976ef47b198dba96e --- /dev/null +++ b/devui/theme/core/theme.ts @@ -0,0 +1,43 @@ +class Theme { + static imports: any = {} + + static import(name: string): any { + return this.imports[name] + } + + static register(name: string, target: any): void { + this.imports[name] = target + } + + constructor(theme: string) { + this.applyTheme(theme) + } + + applyTheme(name: string): void { + const theme = Theme.imports[name] + if (!theme) { + console.error(`主题 ${theme} 未注册!`) + return + } + + const id = 'devui-theme-variable' + const themeVariable = `:root { ${stringify(theme)} }` + let styleElement = document.getElementById(id) + if (styleElement) { + styleElement.innerText = themeVariable + } else { + styleElement = document.createElement('style') + styleElement.id = id + styleElement.innerText = themeVariable + document.head.appendChild(styleElement) + } + } +} + +function stringify(theme: any) { + return Object.entries(theme) + .map(([key, value]) => `--${key}:${value}`) + .join(';') +} + +export default Theme diff --git a/devui/theme/index.ts b/devui/theme/index.ts deleted file mode 100644 index 045f7781ecab2bb0cf055341d9fe8664214510a9..0000000000000000000000000000000000000000 --- a/devui/theme/index.ts +++ /dev/null @@ -1,10 +0,0 @@ -import Theme from './theme' -import dark from './themes/dark' -import light from './themes/light' - -Theme.register('dark', dark) -Theme.register('light', light) - -export { dark, light } - -export default Theme diff --git a/devui/theme/theme.ts b/devui/theme/theme.ts index 2b37e404e64d34f6280ffdd976ef47b198dba96e..95be1ea38613a3fb93af485237c5a438ccebe530 100644 --- a/devui/theme/theme.ts +++ b/devui/theme/theme.ts @@ -1,43 +1,8 @@ -class Theme { - static imports: any = {} +import Theme from './core/theme' +import dark from './themes/dark' +import light from './themes/light' - static import(name: string): any { - return this.imports[name] - } - - static register(name: string, target: any): void { - this.imports[name] = target - } - - constructor(theme: string) { - this.applyTheme(theme) - } - - applyTheme(name: string): void { - const theme = Theme.imports[name] - if (!theme) { - console.error(`主题 ${theme} 未注册!`) - return - } - - const id = 'devui-theme-variable' - const themeVariable = `:root { ${stringify(theme)} }` - let styleElement = document.getElementById(id) - if (styleElement) { - styleElement.innerText = themeVariable - } else { - styleElement = document.createElement('style') - styleElement.id = id - styleElement.innerText = themeVariable - document.head.appendChild(styleElement) - } - } -} - -function stringify(theme: any) { - return Object.entries(theme) - .map(([key, value]) => `--${key}:${value}`) - .join(';') -} +Theme.register('dark', dark) +Theme.register('light', light) export default Theme diff --git a/sites/.vitepress/devui-theme/components/NavBar.vue b/sites/.vitepress/devui-theme/components/NavBar.vue index 95bf76f36aa916d8344a94b3af9e651d1b48b388..9cf3acecca0f836cbb5c7b74ef95fe1ebc2acb15 100644 --- a/sites/.vitepress/devui-theme/components/NavBar.vue +++ b/sites/.vitepress/devui-theme/components/NavBar.vue @@ -1,6 +1,6 @@