|
1 | 1 | --- |
| 2 | +import { createSignal, onMount } from "solid-js"; |
| 3 | +import { Icon } from "solid-heroicons"; |
| 4 | +import { sun, moon, computerDesktop } from "solid-heroicons/solid"; |
| 5 | +
|
2 | 6 | const buttons = [ |
3 | | - { id: "theme-light", value: "light", pressed: false }, |
4 | | - { id: "theme-system", value: "system", pressed: false }, |
5 | | - { id: "theme-dark", value: "dark", pressed: false }, |
| 7 | + { id: "theme-light", icon: sun, value: "light", pressed: false }, |
| 8 | + { id: "theme-system", icon: computerDesktop, value: "system", pressed: true }, |
| 9 | + { id: "theme-dark", icon: moon, value: "dark", pressed: false }, |
6 | 10 | ]; |
7 | 11 | --- |
8 | 12 |
|
9 | | -<div class="flex gap-2" role="radiogroup"> |
10 | | - {buttons.map(({ id, value, pressed }) => ( |
11 | | - <button |
12 | | - id={id} |
13 | | - type="button" |
14 | | - class="text-black border-black dark:text-white dark:border-white px-3 py-1.5 rounded-xl text-sm font-medium border" |
15 | | - aria-pressed={pressed} |
16 | | - > |
17 | | - {value} |
18 | | - </button> |
| 13 | +<div id="theme-group" |
| 14 | + class="flex gap-2 border border-fg/20 rounded-xl p-1 flex items-center" role="radiogroup"> |
| 15 | + {buttons.map(({ id, icon, value, pressed }) => ( |
| 16 | + <button |
| 17 | + id={id} |
| 18 | + type="button" |
| 19 | + class="inline-flex items-center justify-center text-fg/60 p-1 rounded-sm hover:text-fg/100 aria-[pressed=true]:ring-1 aria-[pressed=true]:ring-accent/60" |
| 20 | + aria-pressed={pressed} |
| 21 | + onclick={`selectTheme('${value}')`} |
| 22 | + > |
| 23 | + <Icon path={icon} class="h-5 w-5" /> |
| 24 | + </button> |
19 | 25 | ))} |
20 | 26 | </div> |
21 | | - |
22 | | -<script is:inline> |
23 | | - function attachThemeHandler(id, value) { |
24 | | - const el = document.getElementById(id); |
25 | | - if (el) el.addEventListener("click", () => selectTheme(value)); |
26 | | - } |
27 | | - |
28 | | - attachThemeHandler("theme-light", "light"); |
29 | | - attachThemeHandler("theme-system", "system"); |
30 | | - attachThemeHandler("theme-dark", "dark"); |
31 | | -</script> |
0 commit comments