-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ui/web): move theme handling to ui package
Signed-off-by: Jordan Shatford <[email protected]>
- Loading branch information
1 parent
5a440aa
commit 7cb9137
Showing
8 changed files
with
83 additions
and
70 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
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,11 @@ | ||
<script lang="ts"> | ||
import IconButton from '../IconButton.svelte'; | ||
import { MoonIcon, SunIcon } from '../../icons'; | ||
import { theme } from './store'; | ||
</script> | ||
|
||
<IconButton | ||
on:click={() => theme.toggle()} | ||
src={$theme === 'dark' ? SunIcon : MoonIcon} | ||
class="h-10 w-10 text-zinc-500 hover:text-indigo-800 dark:bg-zinc-800 dark:text-zinc-200 dark:hover:text-indigo-600" | ||
/> |
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,2 @@ | ||
export { theme } from './store'; | ||
export { default as ThemeToggle } from './ThemeToggle.svelte'; |
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,61 @@ | ||
import { writable } from 'svelte/store'; | ||
import { browser } from '../../utilities'; | ||
|
||
type Theme = 'dark' | 'light'; | ||
|
||
const THEME_LOCALSTORAGE_KEY = 'theme'; | ||
const DEFAULT_THEME: Theme = 'light'; | ||
|
||
// Get the default theme value inferred by the browser settings. | ||
function getInferredDefaultTheme(): Theme { | ||
if (browser()) { | ||
// Cant match preferred color scheme, return default. | ||
if (!window.matchMedia) { | ||
return DEFAULT_THEME; | ||
} | ||
// Use dark theme if preferred by the user. | ||
if (window.matchMedia('(prefers-color-scheme: dark)').matches) { | ||
return 'dark'; | ||
} else { | ||
return 'light'; | ||
} | ||
} else { | ||
return DEFAULT_THEME; | ||
} | ||
} | ||
|
||
function createThemeStore() { | ||
const { subscribe, set, update } = writable<Theme>(getInferredDefaultTheme()); | ||
|
||
if (browser()) { | ||
let data = localStorage?.getItem(THEME_LOCALSTORAGE_KEY) as Theme; | ||
if (!data) { | ||
data = getInferredDefaultTheme(); | ||
} | ||
set(data); | ||
if (data === 'dark') { | ||
document.querySelector('html')?.classList.add('dark'); | ||
} | ||
} | ||
|
||
subscribe((value) => { | ||
if (browser()) { | ||
localStorage?.setItem(THEME_LOCALSTORAGE_KEY, value); | ||
} | ||
}); | ||
|
||
function toggle() { | ||
update((state) => { | ||
state = state === 'dark' ? 'light' : 'dark'; | ||
return state; | ||
}); | ||
document.querySelector('html')?.classList.toggle('dark'); | ||
} | ||
|
||
return { | ||
subscribe, | ||
toggle | ||
}; | ||
} | ||
|
||
export const theme = createThemeStore(); |
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
7cb9137
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
youtube-audio-downloader – ./
youtube-audio-downloader-git-main-jordanshatford.vercel.app
youtubeaudiodownloader.vercel.app
ytdownloading.vercel.app
youtbedownloader.vercel.app
youtube-audio-downloader-jordanshatford.vercel.app
youtubedownloading.vercel.app
utubedownloader.vercel.app
yt-downloading.vercel.app
youtube-downloading.vercel.app