-
Notifications
You must be signed in to change notification settings - Fork 70
/
Copy pathThemeSwitcher.astro
35 lines (33 loc) · 1.24 KB
/
ThemeSwitcher.astro
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
---
import { Icon } from "astro-icon/components";
---
<button>
<Icon
x-cloak
x-data="{ show: document.documentElement.classList.contains('dark') }"
x-init=`
const observer = new MutationObserver(() => {
show = document.documentElement.classList.contains('dark');
});
observer.observe(document.documentElement, { attributes: true, attributeFilter: ['class'] });
`
x-show="show"
name="heroicons:sun"
class="size-4 text-yellow duration-hover hover:text-dark-yellow md:size-5 lg:size-6"
@click="document.documentElement.classList.toggle('dark', false); localStorage.setItem('mode', 'light');"
/>
<Icon
x-cloak
x-data="{ show: !document.documentElement.classList.contains('dark') }"
x-init=`
const observer = new MutationObserver(() => {
show = !document.documentElement.classList.contains('dark');
});
observer.observe(document.documentElement, { attributes: true, attributeFilter: ['class'] });
`
x-show="show"
name="heroicons:moon"
class="size-4 text-light-blue duration-hover hover:text-blue dark:hidden md:size-5 lg:size-6"
@click="document.documentElement.classList.toggle('dark', true); localStorage.setItem('mode', 'dark');"
/>
</button>