mirror of
https://github.com/pheralb/svgl.git
synced 2025-02-06 06:58:04 +08:00
🎨 Update theme config
This commit is contained in:
parent
c06f0adaf8
commit
b2caf5c371
@ -1,59 +1,12 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from 'svelte';
|
||||
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');
|
||||
}
|
||||
}
|
||||
import { toggleMode, mode } from 'mode-watcher';
|
||||
|
||||
// Icons:
|
||||
import { MoonIcon, SunIcon } from 'lucide-svelte';
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<script>
|
||||
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}
|
||||
<button on:click={toggleMode} aria-label="Toggle dark mode" class="opacity-80 hover:opacity-100">
|
||||
{#if $mode === 'light'}
|
||||
<SunIcon size={20} strokeWidth={1.5} />
|
||||
{:else}
|
||||
<MoonIcon size={20} strokeWidth={1.5} />
|
||||
|
@ -4,11 +4,12 @@
|
||||
|
||||
// Global styles:
|
||||
import '../app.css';
|
||||
import { ModeWatcher, mode } from 'mode-watcher';
|
||||
|
||||
// Get categories:
|
||||
import { svgs } from '@/data/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);
|
||||
|
||||
// Toaster:
|
||||
@ -23,6 +24,7 @@
|
||||
import { cn } from '@/utils/cn';
|
||||
</script>
|
||||
|
||||
<ModeWatcher />
|
||||
<Navbar currentPath={data.pathname} />
|
||||
<main>
|
||||
<aside
|
||||
@ -74,9 +76,9 @@
|
||||
toastOptions={{
|
||||
class: 'font-sans',
|
||||
descriptionClass: 'font-mono',
|
||||
style: `background-color: #262626;
|
||||
color: #ffff;
|
||||
border-radius: 0.4rem; border: 1px solid #121212;`
|
||||
style: `background-color: ${$mode === 'light' ? '#f5f5f5' : '#262626'};
|
||||
color: ${$mode === 'light' ? '#121212' : '#ffff'};
|
||||
border-radius: 0.4rem; border: 1px solid ${$mode === 'light' ? '#d4d4d4' : '#404040'};`
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
|
Loading…
x
Reference in New Issue
Block a user