website/src/lib/ThemeToggle.svelte

34 lines
698 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}
class="cursor-pointer flex items-center py-1 px-0 bg-transparent border-0 font-[var(--font-primary)] color-[var(--text)]"
>
<div class="i-fa6-solid:{theme === 'dark' ? 'sun' : 'moon'}" />
<span class="ml-2">Toggle theme</span>
</button>
<style>
@media screen and (min-width: 900px) {
span {
display: none;
margin-left: 0.25rem;
}
}
2022-10-01 18:41:54 +05:30
</style>