feat(ThemeSwitch): create ThemeSwitch component that uses ThemeMager toggle to switch theme

This commit is contained in:
Ilia Mashkov
2026-02-27 12:22:37 +03:00
parent c4daf47628
commit 7b8b41021c
5 changed files with 89 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
<!--
Component: ThemeSwitch
Toggles the theme between light and dark mode.
-->
<script lang="ts">
import type { ResponsiveManager } from '$shared/lib';
import { IconButton } from '$shared/ui';
import MoonIcon from '@lucide/svelte/icons/moon';
import SunIcon from '@lucide/svelte/icons/sun';
import { getContext } from 'svelte';
import { themeManager } from '../../model';
const responsive = getContext<ResponsiveManager>('responsive');
const theme = $derived(themeManager.value);
</script>
<IconButton onclick={() => themeManager.toggle()} size={responsive.isMobile ? 'sm' : 'md'} title="Toggle theme">
{#snippet icon()}
{#if theme === 'light'}
<MoonIcon />
{:else}
<SunIcon />
{/if}
{/snippet}
</IconButton>