Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix FOUC with ThemeSwitch in SSR #228

Merged
merged 1 commit into from
Feb 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>
Loading