You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
666 B
31 lines
666 B
<script>
|
|
import Icon from './Icon.svelte';
|
|
import {onMount} from 'svelte';
|
|
|
|
export let theme = localStorage.getItem('theme') ? localStorage.getItem('theme') : 'light';
|
|
|
|
const set_theme = () => {
|
|
document.documentElement.setAttribute('data-theme', theme);
|
|
localStorage.setItem('theme', theme);
|
|
}
|
|
|
|
const toggle = () => {
|
|
theme = theme == 'light' ? 'dark' : 'light';
|
|
set_theme();
|
|
}
|
|
|
|
onMount(() => {
|
|
set_theme()
|
|
});
|
|
</script>
|
|
|
|
{#if theme == 'dark'}
|
|
<span on:click={ () => toggle() }>
|
|
<Icon name="sunrise" size="32" />
|
|
</span>
|
|
{:else}
|
|
<span on:click={ () => toggle() }>
|
|
<Icon name="sunset" size="32"/>
|
|
</span>
|
|
{/if}
|
|
|
|
|