mirror of
https://github.com/vbenjs/vue-vben-admin.git
synced 2025-01-23 17:50:25 +08:00
feat: Added support for tailwindcss night mode mechanism (#998)
* feat: 新增支持 tailwindcss 的夜间模式支持 (cherry picked from commit 1de8704b61c38c92bc6877d0bec9e6f67766b3c8) * docs: update changelog
This commit is contained in:
parent
a544dd3e58
commit
189bc6feb3
@ -1,6 +1,7 @@
|
|||||||
### ✨ Features
|
### ✨ Features
|
||||||
|
|
||||||
- **Preview** 添加新的属性及事件
|
- **Preview** 添加新的属性及事件
|
||||||
|
- **Dark Theme** 新增对 tailwindcss 夜间模式的支持
|
||||||
|
|
||||||
### 🐛 Bug Fixes
|
### 🐛 Bug Fixes
|
||||||
|
|
||||||
|
@ -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');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
mode: 'jit',
|
mode: 'jit',
|
||||||
// darkMode: 'class',
|
darkMode: 'class',
|
||||||
plugins: [createEnterPlugin()],
|
plugins: [createEnterPlugin()],
|
||||||
purge: {
|
purge: {
|
||||||
enable: process.env.NODE_ENV === 'production',
|
enable: process.env.NODE_ENV === 'production',
|
||||||
|
Loading…
Reference in New Issue
Block a user