2025-11-24 01:00:50 +01:00
|
|
|
<script lang="ts">
|
|
|
|
|
import { Button } from '@cio/ui/base/button';
|
|
|
|
|
import { MonitorIcon, SunIcon, MoonIcon } from '@lucide/svelte';
|
2026-07-12 17:52:23 +01:00
|
|
|
import { userPrefersMode, setMode } from '@cio/ui/base/dark-mode';
|
2025-11-24 01:00:50 +01:00
|
|
|
|
2026-07-12 17:52:23 +01:00
|
|
|
type ThemeMode = 'light' | 'dark' | 'system';
|
2025-11-24 01:00:50 +01:00
|
|
|
|
2026-07-12 17:52:23 +01:00
|
|
|
const themes: { mode: ThemeMode; icon: typeof MonitorIcon }[] = [
|
2025-11-24 01:00:50 +01:00
|
|
|
{ mode: 'light', icon: SunIcon },
|
|
|
|
|
{ mode: 'dark', icon: MoonIcon },
|
|
|
|
|
{ mode: 'system', icon: MonitorIcon }
|
|
|
|
|
];
|
|
|
|
|
|
2026-07-12 17:52:23 +01:00
|
|
|
const activeMode = $derived(userPrefersMode.current ?? 'system');
|
|
|
|
|
|
|
|
|
|
const handleThemeChange = (newMode: ThemeMode) => {
|
2025-11-24 01:00:50 +01:00
|
|
|
if (newMode === 'light') {
|
|
|
|
|
setMode('light');
|
2026-07-12 17:52:23 +01:00
|
|
|
return;
|
2025-11-24 01:00:50 +01:00
|
|
|
}
|
|
|
|
|
|
2026-07-12 17:52:23 +01:00
|
|
|
if (newMode === 'dark') {
|
|
|
|
|
setMode('dark');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setMode('system');
|
|
|
|
|
};
|
2025-11-24 01:00:50 +01:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<div class="flex items-center justify-between gap-8">
|
|
|
|
|
<p>Theme</p>
|
|
|
|
|
|
|
|
|
|
<div class="flex items-center gap-1 rounded-md backdrop-blur-sm">
|
|
|
|
|
{#each themes as theme (theme.mode)}
|
|
|
|
|
<Button
|
|
|
|
|
size="icon-sm"
|
2026-07-12 17:52:23 +01:00
|
|
|
variant={activeMode === theme.mode ? 'outline' : 'ghost'}
|
|
|
|
|
class={[
|
|
|
|
|
'size-4 rounded-md p-1 transition-all duration-200',
|
|
|
|
|
activeMode === theme.mode && 'shadow-primary/20 shadow-lg'
|
|
|
|
|
]}
|
2025-11-24 01:00:50 +01:00
|
|
|
title={theme.mode}
|
|
|
|
|
onclick={() => handleThemeChange(theme.mode)}
|
|
|
|
|
>
|
|
|
|
|
<theme.icon class="size-4" />
|
|
|
|
|
</Button>
|
|
|
|
|
{/each}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|