initial commit
This commit is contained in:
commit
61511ed28c
28 changed files with 5210 additions and 0 deletions
22
src/components/ThemeSwitcher.astro
Normal file
22
src/components/ThemeSwitcher.astro
Normal file
|
@ -0,0 +1,22 @@
|
|||
---
|
||||
---
|
||||
<button class="theme-switcher" id="theme-switcher">
|
||||
Toggle Theme
|
||||
</button>
|
||||
|
||||
<script>
|
||||
const themeSwitcher = document.getElementById('theme-switcher');
|
||||
const root = document.documentElement;
|
||||
|
||||
// Check for saved theme preference or default to dark
|
||||
const savedTheme = localStorage.getItem('theme') || 'dark';
|
||||
root.setAttribute('data-theme', savedTheme);
|
||||
|
||||
themeSwitcher?.addEventListener('click', () => {
|
||||
const currentTheme = root.getAttribute('data-theme');
|
||||
const newTheme = currentTheme === 'dark' ? 'light' : 'dark';
|
||||
|
||||
root.setAttribute('data-theme', newTheme);
|
||||
localStorage.setItem('theme', newTheme);
|
||||
});
|
||||
</script>
|
Loading…
Add table
Add a link
Reference in a new issue