Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions website/src/ThemeToggle.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<script>

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there should be <script lang="ts">

import { onMount } from 'svelte';

let isDark = false;

// Load theme from localStorage or system preference
onMount(() => {
const saved = localStorage.getItem('theme');
if (saved) {
isDark = saved === 'dark';
} else {
isDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
}
updateTheme();
});

function toggleTheme() {
isDark = !isDark;
updateTheme();
}

function updateTheme() {
const root = document.documentElement;
if (isDark) {
root.classList.add('dark');
localStorage.setItem('theme', 'dark');
} else {
root.classList.remove('dark');
localStorage.setItem('theme', 'light');
}
}
</script>

<button on:click={toggleTheme} aria-label="Toggle theme" class="p-2 rounded bg-gray-200 dark:bg-gray-700 text-sm">
{isDark ? '🌙 Dark' : '☀️ Light'}
</button>