Skip to content

Commit

Permalink
Update color-modes.js
Browse files Browse the repository at this point in the history
  • Loading branch information
XhmikosR authored Mar 14, 2023
1 parent b52c816 commit 3eed937
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions docs/assets/js/color-modes.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,17 @@
'use strict'

const storedTheme = localStorage.getItem('theme')
const prefersDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches

const getPreferredTheme = () => {
if (storedTheme) {
return storedTheme
}

return prefersDarkMode ? 'dark' : 'light'
return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'
}

const setTheme = function (theme) {
if (theme === 'auto' && prefersDarkMode) {
if (theme === 'auto' && window.matchMedia('(prefers-color-scheme: dark)').matches) {
document.documentElement.setAttribute('data-bs-theme', 'dark')
} else {
document.documentElement.setAttribute('data-bs-theme', theme)
Expand Down

0 comments on commit 3eed937

Please sign in to comment.