website/src/lib/ThemeToggle.svelte

25 lines
576 B
Svelte
Raw Normal View History

<script lang="ts">
import { afterUpdate } from "svelte";
import DarkMode from "svelte-dark-mode";
2022-09-16 19:35:27 +05:30
let theme: "dark" | "light";
afterUpdate(() => {
document.documentElement.className = theme;
});
let toggle = () => {
theme = theme === "dark" ? "light" : "dark";
};
</script>
<DarkMode bind:theme />
2022-10-01 18:41:54 +05:30
<button
on:click={toggle}
2022-12-27 20:58:47 +05:30
class="cursor-pointer flex items-center py-1 px-0 bg-transparent border-0 font-primary color-text"
2022-10-01 18:41:54 +05:30
>
<div class="i-fa6-solid:{theme === 'dark' ? 'sun' : 'moon'}" />
2022-12-27 20:58:47 +05:30
<span class="ml-2 nav:(hidden ml-1)">Toggle theme</span>
</button>