mirror of
https://github.com/pheralb/svgl.git
synced 2025-02-06 15:17:58 +08:00
🎨 Update theme config
This commit is contained in:
parent
c06f0adaf8
commit
b2caf5c371
@ -1,59 +1,12 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { onMount } from 'svelte';
|
import { toggleMode, mode } from 'mode-watcher';
|
||||||
let dark: boolean;
|
|
||||||
let hidden = true;
|
|
||||||
|
|
||||||
onMount(() => {
|
|
||||||
dark = document.documentElement.classList.contains('dark');
|
|
||||||
hidden = false;
|
|
||||||
const matcher = window.matchMedia('(prefers-color-scheme: dark)');
|
|
||||||
matcher.addEventListener('change', handleChange);
|
|
||||||
return () => matcher.removeEventListener('change', handleChange);
|
|
||||||
});
|
|
||||||
|
|
||||||
function handleChange({ matches: dark }: MediaQueryListEvent) {
|
|
||||||
if (!localStorage.theme) {
|
|
||||||
setMode(dark);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function toggle() {
|
|
||||||
setMode(!dark);
|
|
||||||
}
|
|
||||||
|
|
||||||
function setMode(value: boolean) {
|
|
||||||
dark = value;
|
|
||||||
if (dark) {
|
|
||||||
document.documentElement.classList.add('dark');
|
|
||||||
} else {
|
|
||||||
document.documentElement.classList.remove('dark');
|
|
||||||
}
|
|
||||||
localStorage.theme = dark ? 'dark' : 'light';
|
|
||||||
if (window.matchMedia(`(prefers-color-scheme: ${localStorage.theme})`).matches) {
|
|
||||||
localStorage.removeItem('theme');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Icons:
|
// Icons:
|
||||||
import { MoonIcon, SunIcon } from 'lucide-svelte';
|
import { MoonIcon, SunIcon } from 'lucide-svelte';
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svelte:head>
|
<button on:click={toggleMode} aria-label="Toggle dark mode" class="opacity-80 hover:opacity-100">
|
||||||
<script>
|
{#if $mode === 'light'}
|
||||||
if (
|
|
||||||
localStorage.theme === 'dark' ||
|
|
||||||
(!localStorage.theme && window.matchMedia('(prefers-color-scheme: dark)').matches)
|
|
||||||
) {
|
|
||||||
document.documentElement.classList.add('dark');
|
|
||||||
} else {
|
|
||||||
document.documentElement.classList.remove('dark');
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
</svelte:head>
|
|
||||||
|
|
||||||
<button on:click={toggle} aria-label="Toggle dark mode" class="opacity-80 hover:opacity-100">
|
|
||||||
<!-- moon icon -->
|
|
||||||
{#if dark}
|
|
||||||
<SunIcon size={20} strokeWidth={1.5} />
|
<SunIcon size={20} strokeWidth={1.5} />
|
||||||
{:else}
|
{:else}
|
||||||
<MoonIcon size={20} strokeWidth={1.5} />
|
<MoonIcon size={20} strokeWidth={1.5} />
|
||||||
|
@ -4,11 +4,12 @@
|
|||||||
|
|
||||||
// Global styles:
|
// Global styles:
|
||||||
import '../app.css';
|
import '../app.css';
|
||||||
|
import { ModeWatcher, mode } from 'mode-watcher';
|
||||||
|
|
||||||
// Get categories:
|
// Get categories:
|
||||||
import { svgs } from '@/data/svgs';
|
import { svgs } from '@/data/svgs';
|
||||||
const categories = svgs
|
const categories = svgs
|
||||||
.flatMap((svg) => Array.isArray(svg.category) ? svg.category : [svg.category])
|
.flatMap((svg) => (Array.isArray(svg.category) ? svg.category : [svg.category]))
|
||||||
.filter((category, index, array) => array.indexOf(category) === index);
|
.filter((category, index, array) => array.indexOf(category) === index);
|
||||||
|
|
||||||
// Toaster:
|
// Toaster:
|
||||||
@ -23,6 +24,7 @@
|
|||||||
import { cn } from '@/utils/cn';
|
import { cn } from '@/utils/cn';
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<ModeWatcher />
|
||||||
<Navbar currentPath={data.pathname} />
|
<Navbar currentPath={data.pathname} />
|
||||||
<main>
|
<main>
|
||||||
<aside
|
<aside
|
||||||
@ -74,9 +76,9 @@
|
|||||||
toastOptions={{
|
toastOptions={{
|
||||||
class: 'font-sans',
|
class: 'font-sans',
|
||||||
descriptionClass: 'font-mono',
|
descriptionClass: 'font-mono',
|
||||||
style: `background-color: #262626;
|
style: `background-color: ${$mode === 'light' ? '#f5f5f5' : '#262626'};
|
||||||
color: #ffff;
|
color: ${$mode === 'light' ? '#121212' : '#ffff'};
|
||||||
border-radius: 0.4rem; border: 1px solid #121212;`
|
border-radius: 0.4rem; border: 1px solid ${$mode === 'light' ? '#d4d4d4' : '#404040'};`
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user