Skip to content

Commit 6eeebc7

Browse files
dimfeldtechniq
authored andcommitted
Fix ThemeSwitch SSR behavior by using dark class to define positioning and icon display (#228)
1 parent d863d6e commit 6eeebc7

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

.changeset/nice-cats-know.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"svelte-ux": patch
3+
---
4+
5+
Fix ThemeSwitch SSR behavior by using `dark` class to define positioning and icon display

packages/svelte-ux/src/lib/components/ThemeSwitch.svelte

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,22 @@
1515
let newTheme = e.target?.checked ? 'dark' : 'light';
1616
currentTheme.setTheme(newTheme);
1717
}}
18-
let:checked
18+
classes={{
19+
switch: 'dark:bg-primary dark:border-primary',
20+
toggle: 'translate-x-0 dark:translate-x-full',
21+
}}
1922
{...$$restProps}
2023
>
21-
{#if checked}
22-
<Icon data={mdiWeatherNight} size=".8rem" class="text-primary" />
23-
{:else}
24-
<Icon data={mdiWhiteBalanceSunny} size=".8rem" class="text-primary" />
25-
{/if}
24+
<div class="grid grid-cols-1 grid-rows-1">
25+
<Icon
26+
data={mdiWeatherNight}
27+
size=".8rem"
28+
class="row-[1] col-[1] text-primary opacity-0 dark:opacity-100"
29+
/>
30+
<Icon
31+
data={mdiWhiteBalanceSunny}
32+
size=".8rem"
33+
class="row-[1] col-[1] text-primary opacity-100 dark:opacity-0"
34+
/>
35+
</div>
2636
</Switch>

0 commit comments

Comments
 (0)