immich/web/src/lib/components/shared-components/theme-button.svelte

30 lines
885 B
Svelte
Raw Normal View History

2022-10-26 11:10:48 -05:00
<script lang="ts">
import { browser } from '$app/environment';
import { moonPath, sunPath, sunViewBox } from '$lib/assets/svg-paths';
import { colorTheme } from '$lib/stores/preferences.store';
import IconButton from '../elements/buttons/icon-button.svelte';
import Icon from '../elements/icon.svelte';
2022-10-26 11:10:48 -05:00
const toggleTheme = () => {
$colorTheme = $colorTheme === 'dark' ? 'light' : 'dark';
};
2022-10-26 11:10:48 -05:00
$: {
if (browser) {
if ($colorTheme === 'light') {
document.documentElement.classList.remove('dark');
} else {
document.documentElement.classList.add('dark');
}
}
}
2022-10-26 11:10:48 -05:00
</script>
<IconButton on:click={toggleTheme} title="Toggle theme">
{#if $colorTheme === 'light'}
<Icon path={moonPath} viewBox={sunViewBox} class="h-6 w-6" />
{:else}
<Icon path={sunPath} viewBox={sunViewBox} class="h-6 w-6" />
{/if}
</IconButton>