Skip to content

Commit

Permalink
fix: ensure light mode even if dark mode OS pref (#1029)
Browse files Browse the repository at this point in the history
  • Loading branch information
olizilla committed Jul 28, 2020
1 parent 2272e00 commit 605a49e
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 13 deletions.
7 changes: 2 additions & 5 deletions assets/_custom.scss
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@
padding: 1px .5rem;
border: 0;
border-radius: .25rem;
background: rgba(255,255,255,.1);
color: #e9ecef;
background: $book-search-results-bg;
margin-top: 3px;
}

Expand All @@ -89,9 +88,7 @@
#book-search-input {
outline: none;
}
#book-search-input:focus {
background: rgba(255,255,255,.2);
}

// Tweaks
summary {
outline: none;
Expand Down
2 changes: 2 additions & 0 deletions assets/_variables.scss
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/* You can override SASS variables here. */

$book-search-results-bg: #f8f9fa !default;
10 changes: 2 additions & 8 deletions assets/dark-mode/dark-mode.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
const lightMode = document.getElementById('light-mode-link')
const darkMode = document.getElementById('dark-mode-link')
const btn = document.querySelector('.dark-mode-toggle')
const prefersDarkScheme = window.matchMedia('(prefers-color-scheme: dark)').matches
let theme = prefersDarkScheme ? 'dark' : 'light'
let theme = 'light'

function enableLightMode () {
lightMode.disabled = false
Expand All @@ -20,16 +19,11 @@
btn.setAttribute('aria-pressed', theme === 'dark')
}

// enable dark theme optimistically on OS with dark theme enabled to reduce flashing of white theme.
if (prefersDarkScheme) {
enableDarkMode()
}

// wait for localstorage...
const previousChoice = localStorage.getItem('theme')
theme = previousChoice || theme

// Light is default, so enable dark if user previously chose it but their OS pref is light.
// Light is default, so enable dark if user previously chose it.
if (theme === 'dark') {
enableDarkMode()
}
Expand Down
2 changes: 2 additions & 0 deletions assets/plugins/_dark.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ $color-link: #0090ff;
$color-visited-link: #0090ff;

$icon-filter: brightness(0) invert(1);

$book-search-results-bg: rgba(255,255,255,.1);

0 comments on commit 605a49e

Please sign in to comment.