Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use OS color scheme to init light/dark mode (#2591) #2611

Merged
merged 2 commits into from Aug 9, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -31,12 +31,16 @@ window.addEventListener('load', () => {
const darkModeSwitch = () => {
const localStorageKey = "dokka-dark-mode"
const storage = localStorage.getItem(localStorageKey)
const savedDarkMode = storage ? JSON.parse(storage) : false
const osDarkSchemePreferred = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches
const savedDarkMode = storage ? JSON.parse(storage) : osDarkSchemePreferred
IgnatBeresnev marked this conversation as resolved.
Show resolved Hide resolved
const element = document.getElementById("theme-toggle-button")
const enabledClasses = document.getElementsByTagName("html")[0].classList
initPlayground(savedDarkMode ? samplesDarkThemeName : samplesLightThemeName)
if (savedDarkMode != enabledClasses.contains('theme-dark')) {
enabledClasses.toggle("theme-dark");
}
IgnatBeresnev marked this conversation as resolved.
Show resolved Hide resolved

element.addEventListener('click', () => {
const enabledClasses = document.getElementsByTagName("html")[0].classList
enabledClasses.toggle("theme-dark")

//if previously we had saved dark theme then we set it to light as this is what we save in local storage
Expand Down