-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from grzegorzxpatyk/develop
Develop
- Loading branch information
Showing
8 changed files
with
142 additions
and
14 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"javascript.preferences.quoteStyle": "single", | ||
"typescript.preferences.quoteStyle": "single", | ||
"prettier.jsxSingleQuote": true, | ||
"prettier.singleQuote": true, | ||
"svelte.plugin.svelte.format.config.singleQuote": true, | ||
"[svelte]": { | ||
"editor.defaultFormatter": "svelte.svelte-vscode" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
<script lang="ts"> | ||
import { onMount } from 'svelte'; | ||
import { theme } from '../../store'; | ||
import ThemeSwitchButton from './themeSwitchButton.svelte'; | ||
function setDarkTheme() { | ||
if ($theme === 'dark') { | ||
theme.set('OSDefault'); | ||
} else { | ||
theme.set('dark'); | ||
} | ||
} | ||
function setLightTheme() { | ||
if ($theme === 'light') { | ||
theme.set('OSDefault'); | ||
} else { | ||
theme.set('light'); | ||
} | ||
} | ||
function setOSDefaultTheme() { | ||
if (window.matchMedia('(prefers-color-scheme: dark)').matches) { | ||
document.documentElement.classList.add('dark'); | ||
} else { | ||
document.documentElement.classList.remove('dark'); | ||
} | ||
} | ||
onMount(() => { | ||
theme.set(localStorage?.theme); | ||
theme.subscribe((value) => { | ||
console.log(value); | ||
localStorage.theme = value; | ||
switch (value) { | ||
case 'dark': | ||
document.documentElement.classList.add('dark'); | ||
break; | ||
case 'light': | ||
document.documentElement.classList.remove('dark'); | ||
break; | ||
case 'OSDefault': | ||
default: | ||
setOSDefaultTheme(); | ||
break; | ||
} | ||
}); | ||
window | ||
.matchMedia('(prefers-color-scheme: dark)') | ||
.addEventListener('change', (event) => { | ||
console.log(event); | ||
if (localStorage.theme !== 'OSDefault') { | ||
return; | ||
} | ||
setOSDefaultTheme(); | ||
}); | ||
return () => { | ||
window | ||
.matchMedia('(prefers-color-scheme: dark)') | ||
.removeEventListener('change', () => { | ||
if (localStorage.theme !== 'OSDefault') { | ||
return; | ||
} | ||
setOSDefaultTheme(); | ||
}); | ||
}; | ||
}); | ||
</script> | ||
|
||
<svelte:head> | ||
<script> | ||
if ( | ||
localStorage.theme === 'dark' || | ||
(!localStorage.theme && | ||
window.matchMedia('(prefers-color-scheme: dark)').matches) || | ||
(localStorage.theme === 'OSDefault' && | ||
window.matchMedia('(prefers-color-scheme: dark)').matches) | ||
) { | ||
document.documentElement.classList.add('dark'); | ||
} else { | ||
document.documentElement.classList.remove('dark'); | ||
} | ||
</script> | ||
</svelte:head> | ||
|
||
<div | ||
class="fixed top-4 right-4 p-2 hidden sm:grid grid-cols-2 gap-2 bg-zinc-300 dark:bg-zinc-500 bg-opacity-30 rounded-md print:hidden" | ||
> | ||
<ThemeSwitchButton | ||
variant="light" | ||
clickHandler={setLightTheme} | ||
isActive={$theme === 'light'} | ||
/> | ||
<ThemeSwitchButton | ||
variant="dark" | ||
clickHandler={setDarkTheme} | ||
isActive={$theme === 'dark'} | ||
/> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<script lang="ts"> | ||
import { Moon, Sun } from 'radix-icons-svelte'; | ||
export let variant: 'light' | 'dark'; | ||
export let clickHandler: () => void; | ||
export let isActive: boolean; | ||
</script> | ||
|
||
<button | ||
class="p-2 bg-zinc-50 dark:bg-zinc-200 bg-opacity-30 dark:bg-opacity-30 hover:bg-opacity-50 dark:hover:bg-opacity-50 rounded-md border-2 {isActive | ||
? 'border-blue-400' | ||
: 'border-zinc-300 dark:border-zinc-300'}" | ||
on:click={clickHandler} | ||
> | ||
{#if variant === 'dark'} | ||
<Moon size={16} /> | ||
{:else} | ||
<Sun size={16} /> | ||
{/if} | ||
</button> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { writable, type Writable } from 'svelte/store'; | ||
|
||
export const theme: Writable<'light' | 'dark' | 'OSDefault'> = writable('OSDefault'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters