mirror of
https://github.com/reonokiy/blog.nokiy.net.git
synced 2025-06-16 19:51:07 +02:00
fix: theme toggle error
- Streamlined theme toggle logic to better synchronize with user preferences and system settings. - Updated the initialization of the theme to utilize a more robust method for determining the default mode. - Improved accessibility by ensuring aria attributes are correctly set for the theme toggle button. - Enhanced global CSS styles for better consistency and added support for view transitions during theme changes. - Removed redundant code and improved overall readability of the theme toggle component.
This commit is contained in:
parent
77f94f646f
commit
419b8b5611
3 changed files with 49 additions and 82 deletions
|
@ -94,9 +94,10 @@ const { cdn, commentURL = '', imageHostURL = '', customGoogleAnalyticsURL = '',
|
|||
{baidu && <meta name="baidu-site-verification" content={baidu} />}
|
||||
|
||||
<!-- Theme Toggle -->
|
||||
<script is:inline>
|
||||
<script is:inline define:vars={{ defaultMode: themeConfig.color.mode }}>
|
||||
const systemTheme = matchMedia('(prefers-color-scheme: dark)')
|
||||
const theme = localStorage.getItem('theme')
|
||||
?? (matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light')
|
||||
?? (systemTheme.matches !== null ? (systemTheme.matches ? 'dark' : 'light') : defaultMode)
|
||||
document.documentElement.classList.toggle('dark', theme === 'dark')
|
||||
</script>
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue