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

fix: save choosen color scheme #1462

Merged
merged 1 commit into from
Aug 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion site/src/includes/inline.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const mq = window.matchMedia('(prefers-color-scheme: dark)')
const theme = localStorage.getItem('theme')

if (mq.matches) {
if ((theme && theme === 'dark') || (!theme && mq.matches)) {
document.documentElement.classList.add('dark')
}
6 changes: 3 additions & 3 deletions site/src/includes/script.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
function toggleTheme() {
const root = document.documentElement
const theme = root.classList.contains('dark') ? 'light' : 'dark'

root.classList.toggle('dark')
localStorage.setItem('theme', theme)

if (window.REMARK42) {
const isDark = root.classList.contains('dark')

window.REMARK42.changeTheme(isDark ? 'dark' : 'light')
window.REMARK42.changeTheme(theme)
}
}
2 changes: 1 addition & 1 deletion site/src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
@apply before:hidden after:hidden text-brand-800 dark:text-brand-300 font-light;
}
.prose strong code {
@apply font-bold text-yellow-600 dark:text-yellow-400;;
@apply font-bold text-yellow-600 dark:text-yellow-400;
}

.burger-icon {
Expand Down