Skip to content

Commit

Permalink
Fix ThemeSwitch SSR behavior by using dark class to define position…
Browse files Browse the repository at this point in the history
…ing and icon display (#228)
  • Loading branch information
dimfeld authored and techniq committed Feb 6, 2024
1 parent d863d6e commit 6eeebc7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/nice-cats-know.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"svelte-ux": patch
---

Fix ThemeSwitch SSR behavior by using `dark` class to define positioning and icon display
22 changes: 16 additions & 6 deletions packages/svelte-ux/src/lib/components/ThemeSwitch.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,22 @@
let newTheme = e.target?.checked ? 'dark' : 'light';
currentTheme.setTheme(newTheme);
}}
let:checked
classes={{
switch: 'dark:bg-primary dark:border-primary',
toggle: 'translate-x-0 dark:translate-x-full',
}}
{...$$restProps}
>
{#if checked}
<Icon data={mdiWeatherNight} size=".8rem" class="text-primary" />
{:else}
<Icon data={mdiWhiteBalanceSunny} size=".8rem" class="text-primary" />
{/if}
<div class="grid grid-cols-1 grid-rows-1">
<Icon
data={mdiWeatherNight}
size=".8rem"
class="row-[1] col-[1] text-primary opacity-0 dark:opacity-100"
/>
<Icon
data={mdiWhiteBalanceSunny}
size=".8rem"
class="row-[1] col-[1] text-primary opacity-100 dark:opacity-0"
/>
</div>
</Switch>

0 comments on commit 6eeebc7

Please sign in to comment.