Added support for theme setting via env var
This commit is contained in:
1 parent
300faba252
commit
495322b960
1 file changed
+5
-2
@@ -14,8 +14,11 @@ export enum Color {
|
|||||||
}
|
}
|
||||||
|
|
||||||
import { get, writable } from 'svelte/store'
|
import { get, writable } from 'svelte/store'
|
||||||
|
import { env } from '$env/dynamic/public'
|
||||||
|
|
||||||
|
const configuredTheme = env.PUBLIC_THEME ?? 'system'
|
||||||
|
export const theme = writable<'system' | 'light' | 'dark'>(configuredTheme)
|
||||||
|
|
||||||
export const theme = writable<'system' | 'light' | 'dark'>('system')
|
|
||||||
|
|
||||||
export const toggleTheme = () => {
|
export const toggleTheme = () => {
|
||||||
theme.update((theme) => {
|
theme.update((theme) => {
|
||||||
@@ -40,7 +43,7 @@ export const inDarkTheme = (): boolean => {
|
|||||||
|
|
||||||
if (typeof localStorage != 'undefined') {
|
if (typeof localStorage != 'undefined') {
|
||||||
const localTheme: 'system' | 'light' | 'dark' =
|
const localTheme: 'system' | 'light' | 'dark' =
|
||||||
(localStorage.getItem('theme') as 'system' | 'light' | 'dark') || 'system'
|
(localStorage.getItem('theme') as 'system' | 'light' | 'dark') || configuredTheme
|
||||||
|
|
||||||
theme.update((theme) => localTheme)
|
theme.update((theme) => localTheme)
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user