|
2 | 2 | import Moon from "@lucide/svelte/icons/moon"; |
3 | 3 | import Sun from "@lucide/svelte/icons/sun"; |
4 | 4 | import SunMoon from "@lucide/svelte/icons/sun-moon"; |
5 | | - import type { FormEventHandler } from "svelte/elements"; |
6 | 5 | import Logo from "$lib/components/Logo.svelte"; |
7 | 6 |
|
8 | | - const oninput: FormEventHandler<HTMLInputElement> = (e) => |
9 | | - localStorage.setItem("theme", e.currentTarget.id); |
10 | | -
|
11 | 7 | let { children } = $props(); |
12 | 8 | </script> |
13 | 9 |
|
|
29 | 25 | </nav> |
30 | 26 | <theme-picker aria-label="Selector de temas" role="radiogroup"> |
31 | 27 | <label aria-label="Predeterminado"> |
32 | | - <input type="radio" name="theme" id="system" {oninput} checked /> |
| 28 | + <input type="radio" name="theme" id="system" checked /> |
33 | 29 | <SunMoon /> |
34 | 30 | </label> |
35 | 31 | <label aria-label="Claro"> |
36 | | - <input type="radio" name="theme" id="light" {oninput} /> |
| 32 | + <input type="radio" name="theme" id="light" /> |
37 | 33 | <Sun /> |
38 | 34 | </label> |
39 | 35 | <label aria-label="Oscuro"> |
40 | | - <input type="radio" name="theme" id="dark" {oninput} /> |
| 36 | + <input type="radio" name="theme" id="dark" /> |
41 | 37 | <Moon /> |
42 | 38 | </label> |
43 | 39 | </theme-picker> |
44 | 40 | <script> |
45 | | - // needs to be an inline script so that it runs asap |
| 41 | + // this is the only javascript that runs in the entire site |
| 42 | + // all it does is saving and loading the saved theme |
| 43 | + // all other logic is pure html/css |
46 | 44 | const theme = localStorage.getItem("theme"); |
47 | 45 | if (theme) { |
48 | 46 | document.getElementById(theme).checked = true; |
49 | 47 | } |
| 48 | +
|
| 49 | + const oninput = (e) => localStorage.setItem("theme", e.target.id); |
| 50 | +
|
| 51 | + document.getElementById("system").addEventListener("input", oninput); |
| 52 | + document.getElementById("light").addEventListener("input", oninput); |
| 53 | + document.getElementById("dark").addEventListener("input", oninput); |
50 | 54 | </script> |
51 | 55 | </header> |
52 | 56 | {@render children()} |
|
0 commit comments