Browse Source
* feat: 新增支持 tailwindcss 的夜间模式支持 (cherry picked from commit 1de8704b61c38c92bc6877d0bec9e6f67766b3c8) * docs: update changelogpull/1004/head
committed by
GitHub
3 changed files with 15 additions and 3 deletions
@ -1,13 +1,24 @@ |
|||||
import { darkCssIsReady, loadDarkThemeCss } from 'vite-plugin-theme/es/client'; |
import { darkCssIsReady, loadDarkThemeCss } from 'vite-plugin-theme/es/client'; |
||||
|
import { addClass, hasClass, removeClass } from '/@/utils/domUtils'; |
||||
|
|
||||
export async function updateDarkTheme(mode: string | null = 'light') { |
export async function updateDarkTheme(mode: string | null = 'light') { |
||||
const htmlRoot = document.getElementById('htmlRoot'); |
const htmlRoot = document.getElementById('htmlRoot'); |
||||
|
if (!htmlRoot) { |
||||
|
return; |
||||
|
} |
||||
|
const hasDarkClass = hasClass(htmlRoot, 'dark'); |
||||
if (mode === 'dark') { |
if (mode === 'dark') { |
||||
if (import.meta.env.PROD && !darkCssIsReady) { |
if (import.meta.env.PROD && !darkCssIsReady) { |
||||
await loadDarkThemeCss(); |
await loadDarkThemeCss(); |
||||
} |
} |
||||
htmlRoot?.setAttribute('data-theme', 'dark'); |
htmlRoot.setAttribute('data-theme', 'dark'); |
||||
|
if (!hasDarkClass) { |
||||
|
addClass(htmlRoot, 'dark'); |
||||
|
} |
||||
} else { |
} else { |
||||
htmlRoot?.setAttribute('data-theme', 'light'); |
htmlRoot.setAttribute('data-theme', 'light'); |
||||
|
if (hasDarkClass) { |
||||
|
removeClass(htmlRoot, 'dark'); |
||||
|
} |
||||
} |
} |
||||
} |
} |
||||
|
|||||
Loading…
Reference in new issue