mirror of
https://github.com/Buriburizaem0n/nezha-dash-v1.git
synced 2026-05-06 13:58:43 +00:00
fix: prevent color fade during theme transitions
This commit is contained in:
@@ -26,6 +26,7 @@ export function ThemeProvider({ children, storageKey = "vite-ui-theme" }: ThemeP
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const root = window.document.documentElement
|
const root = window.document.documentElement
|
||||||
|
|
||||||
|
root.classList.add("disable-transitions")
|
||||||
root.classList.remove("light", "dark")
|
root.classList.remove("light", "dark")
|
||||||
|
|
||||||
if (theme === "system") {
|
if (theme === "system") {
|
||||||
@@ -34,12 +35,19 @@ export function ThemeProvider({ children, storageKey = "vite-ui-theme" }: ThemeP
|
|||||||
root.classList.add(systemTheme)
|
root.classList.add(systemTheme)
|
||||||
const themeColor = systemTheme === "dark" ? "hsl(30 15% 8%)" : "hsl(0 0% 98%)"
|
const themeColor = systemTheme === "dark" ? "hsl(30 15% 8%)" : "hsl(0 0% 98%)"
|
||||||
document.querySelector('meta[name="theme-color"]')?.setAttribute("content", themeColor)
|
document.querySelector('meta[name="theme-color"]')?.setAttribute("content", themeColor)
|
||||||
return
|
const timeoutId = window.setTimeout(() => {
|
||||||
|
root.classList.remove("disable-transitions")
|
||||||
|
}, 0)
|
||||||
|
return () => window.clearTimeout(timeoutId)
|
||||||
}
|
}
|
||||||
|
|
||||||
root.classList.add(theme)
|
root.classList.add(theme)
|
||||||
const themeColor = theme === "dark" ? "hsl(30 15% 8%)" : "hsl(0 0% 98%)"
|
const themeColor = theme === "dark" ? "hsl(30 15% 8%)" : "hsl(0 0% 98%)"
|
||||||
document.querySelector('meta[name="theme-color"]')?.setAttribute("content", themeColor)
|
document.querySelector('meta[name="theme-color"]')?.setAttribute("content", themeColor)
|
||||||
|
const timeoutId = window.setTimeout(() => {
|
||||||
|
root.classList.remove("disable-transitions")
|
||||||
|
}, 0)
|
||||||
|
return () => window.clearTimeout(timeoutId)
|
||||||
}, [theme])
|
}, [theme])
|
||||||
|
|
||||||
const value = {
|
const value = {
|
||||||
|
|||||||
@@ -201,6 +201,15 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@layer base {
|
||||||
|
/* Avoid color fade when toggling themes. */
|
||||||
|
html.disable-transitions *,
|
||||||
|
html.disable-transitions *::before,
|
||||||
|
html.disable-transitions *::after {
|
||||||
|
transition: none !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@media (max-width: 640px) {
|
@media (max-width: 640px) {
|
||||||
.container {
|
.container {
|
||||||
@apply px-4;
|
@apply px-4;
|
||||||
|
|||||||
Reference in New Issue
Block a user