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

feat: darkmode fix for refreshing a browser #784

Merged
merged 1 commit into from
May 21, 2023
Merged
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
4 changes: 4 additions & 0 deletions src/lib/darkmode/DarkMode.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

// declare initialTheme as a prop with a default value of 'light'
export let initialTheme: string = 'light';

export let btnClass: string =
'text-gray-500 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-700 focus:outline-none focus:ring-4 focus:ring-gray-200 dark:focus:ring-gray-700 rounded-lg text-sm p-2.5';

Expand All @@ -18,6 +19,9 @@
let toggleTheme: () => void;

onMount(() => {
if(localStorage.getItem('color-theme')){
initialTheme = localStorage.getItem('color-theme') || 'light'
}
localStorage.getItem('color-theme') === initialTheme ||
(!('color-theme' in localStorage) && window.matchMedia('(prefers-color-scheme: dark)').matches)
? window.document.documentElement.classList.add(initialTheme)
Expand Down