Skip to content

Commit acc6c8f

Browse files
committed
feat: add ThemeButton
1 parent c696f33 commit acc6c8f

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

src/components/ThemeButton.svelte

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<script lang="ts">
2+
import LucideContrast from "~icons/lucide/contrast";
3+
4+
function toggleTheme() {
5+
if (document.documentElement.classList.contains("dark")) {
6+
localStorage.theme = "light";
7+
document.documentElement.classList.remove("dark");
8+
} else {
9+
localStorage.theme = "dark";
10+
document.documentElement.classList.add("dark");
11+
}
12+
}
13+
</script>
14+
15+
<button
16+
type="button"
17+
class="btn-sm-icon-outline"
18+
title="Change theme"
19+
onclick={() => {
20+
toggleTheme();
21+
}}
22+
>
23+
<LucideContrast class="size-4" />
24+
<span class="sr-only">Change theme</span>
25+
</button>

tsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
"noUncheckedIndexedAccess": true,
55
"noImplicitOverride": true,
66
"plugins": [{ "name": "@astrojs/ts-plugin" }, { "name": "typescript-svelte-plugin" }],
7-
"types": ["unplugin-icons/types/astro"]
7+
"types": ["unplugin-icons/types/astro", "unplugin-icons/types/svelte"],
88
},
99
"include": [".astro/types.d.ts", "**/*"],
10-
"exclude": ["old", "coverage", "dist", "node_modules", "public"]
10+
"exclude": ["old", "coverage", "dist", "node_modules", "public"],
1111
}

0 commit comments

Comments
 (0)