Files
frontend-svelte/src/features/ChangeAppTheme/ui/ThemeSwitch/ThemeSwitch.svelte
T
Ilia Mashkov 3dca11fea8 refactor(theme): replace themeManager singleton with lazy getThemeManager
Convert the eager themeManager singleton to a getThemeManager() lazy accessor
(+ __resetThemeManager for tests), so the persistent-store subscription is set
up on first access rather than at module load. Update the barrel and consumers
(Layout init/destroy, ThemeSwitch, story, test).
2026-06-01 18:39:17 +03:00

28 lines
919 B
Svelte

<!--
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 { getThemeManager } from '../../model';
const responsive = getContext<ResponsiveManager>('responsive');
const themeManager = getThemeManager();
const theme = $derived(themeManager.value);
</script>
<IconButton onclick={() => themeManager.toggle()} size={responsive.isMobile ? 'sm' : 'md'} title="Toggle theme">
{#snippet icon()}
{#if theme === 'light'}
<MoonIcon class={responsive.isMobile ? 'size-4' : 'size-5'} />
{:else}
<SunIcon class={responsive.isMobile ? 'size-4' : 'size-5'} />
{/if}
{/snippet}
</IconButton>