✨ feat: change default theme to OS default
Update the theme switcher code to set the default theme to the OS default, rather than the "light" theme. This provides a more seamless user experience for users whose OS is set to a dark mode. The current theme setting in local storage will still be respected if present. This change was made to improve the accessibility and usability. Fixes #38
This commit is contained in:
parent
2f4d0658d8
commit
af80aef00c
@ -1,14 +1,15 @@
|
||||
//https://codepen.io/codeorum/pen/bGedRJO
|
||||
|
||||
var themeSwitcher = document.querySelector('.theme-switcher input');
|
||||
var currentTheme = localStorage.getItem('theme');
|
||||
|
||||
// check what is current theme right now and activate it
|
||||
// detect the user's preferred color scheme and activate it
|
||||
if (currentTheme) {
|
||||
document.documentElement.setAttribute('data-theme', currentTheme);
|
||||
if (currentTheme === 'dark') {
|
||||
themeSwitcher.checked = true;
|
||||
}
|
||||
} else if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
|
||||
document.documentElement.setAttribute('data-theme', 'dark');
|
||||
themeSwitcher.checked = true;
|
||||
}
|
||||
|
||||
// switch between themes
|
||||
|
Loading…
x
Reference in New Issue
Block a user