website/src/lib/ThemeToggle.svelte

21 lines
567 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-09-29 16:47:40 +05:30
<button on:click={toggle} class="cursor-pointer flex items-center py-1 px-0 bg-transparent border-0 font-[var(--font-primary)]">
2022-09-25 15:20:05 +05:30
<div class="i-fa6-solid:{theme === "dark" ? "sun" : "moon"}" />
<span class="ml-1 sm:hidden">Toggle theme</span>
2022-09-28 22:41:54 +05:30
</button>