Update ThemeButton
All checks were successful
Build And Publish / BuildAndPublish (push) Successful in 2m22s

This commit is contained in:
Ryan Freeman 2024-09-14 09:55:49 +01:00
parent f5146f4b06
commit cf6423bbf8
2 changed files with 1 additions and 10 deletions

View File

@ -8,7 +8,7 @@ export function Providers({children}: {
}) { }) {
return ( return (
<ThemeProvider attribute="class"> <ThemeProvider attribute="class" disableTransitionOnChange>
{children} {children}
</ThemeProvider> </ThemeProvider>
) )

View File

@ -14,16 +14,7 @@ export function ThemeButton() {
return () => clearTimeout(timeout) return () => clearTimeout(timeout)
}, []) }, [])
function disableTransitionsTemporarily() {
document.documentElement.classList.add('[&_*]:!transition-none')
window.setTimeout(() => {
document.documentElement.classList.remove('[&_*]:!transition-none')
}, 0)
}
function toggleTheme() { function toggleTheme() {
disableTransitionsTemporarily()
let darkModeMediaQuery = window.matchMedia('(prefers-color-scheme: dark)') let darkModeMediaQuery = window.matchMedia('(prefers-color-scheme: dark)')
let isSystemDarkMode = darkModeMediaQuery.matches let isSystemDarkMode = darkModeMediaQuery.matches
let isDarkMode = theme === 'dark' let isDarkMode = theme === 'dark'