Files
gpx.studio/website/src/lib/components/ModeSwitch.svelte

35 lines
882 B
Svelte
Raw Normal View History

2024-07-05 01:02:53 +02:00
<script lang="ts">
import * as Popover from '$lib/components/ui/popover';
import { Button } from '$lib/components/ui/button';
import { Moon, Sun } from 'lucide-svelte';
2024-07-05 18:47:37 +02:00
import { mode, resetMode, setMode, systemPrefersMode } from 'mode-watcher';
2024-07-05 01:02:53 +02:00
import { _ } from 'svelte-i18n';
export let size = '20';
let open = false;
2024-07-05 18:47:37 +02:00
$: selectedMode = $mode ?? $systemPrefersMode ?? 'light';
2024-07-05 01:02:53 +02:00
</script>
<Popover.Root bind:open>
<Popover.Trigger {...$$restProps}>
2024-07-05 18:47:37 +02:00
{#if selectedMode === 'light'}
2024-07-05 01:02:53 +02:00
<Sun {size} class="mr-1" />
2024-07-05 18:47:37 +02:00
{:else}
2024-07-05 01:02:53 +02:00
<Moon {size} class="mr-1" />
{/if}
</Popover.Trigger>
<Popover.Content class=" w-fit flex flex-col p-2">
2024-07-05 18:47:37 +02:00
{#each ['light', 'dark'] as m}
2024-07-05 01:02:53 +02:00
<Button
variant="ghost"
class="h-8 justify-start"
on:click={() => {
2024-07-05 18:47:37 +02:00
setMode(m);
2024-07-05 01:02:53 +02:00
open = false;
}}>{$_(`menu.${m}`)}</Button
>
{/each}
</Popover.Content>
</Popover.Root>