misc: add theme color
This commit is contained in:
1 parent
58ba902c6f
commit
9a8b0e277b
3 files changed
+13
-1
No files matched your search
+10
-1
@@ -13,7 +13,7 @@ export enum Color {
|
||||
'borderDark' = 'border border-slate-200 dark:border-zinc-800 bg-slate-100 dark:bg-zinc-900 hover:bg-slate-200 hover:dark:bg-zinc-800',
|
||||
}
|
||||
|
||||
import { writable } from 'svelte/store'
|
||||
import { get, writable } from 'svelte/store'
|
||||
|
||||
export const theme = writable<'system' | 'light' | 'dark'>('system')
|
||||
|
||||
@@ -29,6 +29,15 @@ export const toggleTheme = () => {
|
||||
})
|
||||
}
|
||||
|
||||
export const inDarkTheme = (): boolean => {
|
||||
if (typeof window != 'undefined') {
|
||||
return get(theme) == 'system'
|
||||
? window.matchMedia('(prefers-color-scheme: dark)').matches
|
||||
: get(theme) == 'dark'
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
if (typeof localStorage != 'undefined') {
|
||||
const localTheme: 'system' | 'light' | 'dark' =
|
||||
(localStorage.getItem('theme') as 'system' | 'light' | 'dark') || 'system'
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
// @ts-ignore
|
||||
import { pwaInfo } from 'virtual:pwa-info'
|
||||
import PwaReload from '$lib/PwaReload.svelte'
|
||||
import { inDarkTheme } from '$lib/ui/colors.js'
|
||||
|
||||
nProgress.configure({
|
||||
minimum: 0.4,
|
||||
@@ -37,6 +38,7 @@
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<meta name="theme-color" content={inDarkTheme() ? '#020202' : '#f1f6f9'} />
|
||||
{@html webManifest}
|
||||
</svelte:head>
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ export default defineConfig({
|
||||
purpose: 'masked any',
|
||||
},
|
||||
],
|
||||
start_url: '/',
|
||||
},
|
||||
}),
|
||||
],
|
||||
|
||||
Reference in new issue
Block a user