mirror of
https://github.com/pheralb/svgl.git
synced 2025-02-06 15:17:58 +08:00
Merge pull request #231 from pheralb/next
⚙️ Improvements when change light/dark theme & fix downloading svgs with wordmark.
This commit is contained in:
commit
17a67d14b2
@ -38,6 +38,7 @@
|
|||||||
"downloadjs": "1.4.7",
|
"downloadjs": "1.4.7",
|
||||||
"jszip": "3.10.1",
|
"jszip": "3.10.1",
|
||||||
"lucide-svelte": "0.314.0",
|
"lucide-svelte": "0.314.0",
|
||||||
|
"mode-watcher": "0.1.2",
|
||||||
"shiki": "0.14.7",
|
"shiki": "0.14.7",
|
||||||
"svelte-sonner": "0.3.6",
|
"svelte-sonner": "0.3.6",
|
||||||
"tailwind-merge": "2.2.1"
|
"tailwind-merge": "2.2.1"
|
||||||
|
11
pnpm-lock.yaml
generated
11
pnpm-lock.yaml
generated
@ -29,6 +29,9 @@ dependencies:
|
|||||||
lucide-svelte:
|
lucide-svelte:
|
||||||
specifier: 0.314.0
|
specifier: 0.314.0
|
||||||
version: 0.314.0(svelte@4.2.9)
|
version: 0.314.0(svelte@4.2.9)
|
||||||
|
mode-watcher:
|
||||||
|
specifier: 0.1.2
|
||||||
|
version: 0.1.2(svelte@4.2.9)
|
||||||
shiki:
|
shiki:
|
||||||
specifier: 0.14.7
|
specifier: 0.14.7
|
||||||
version: 0.14.7
|
version: 0.14.7
|
||||||
@ -2047,6 +2050,14 @@ packages:
|
|||||||
ufo: 1.3.2
|
ufo: 1.3.2
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
|
/mode-watcher@0.1.2(svelte@4.2.9):
|
||||||
|
resolution: {integrity: sha512-XTdPCdqC3kqSvB+Q262Kor983YJkkB2Z3vj9uqg5IqKQpOdiz+xB99Jihp8sWbyM67drC7KKp0Nt5FzCypZi2g==}
|
||||||
|
peerDependencies:
|
||||||
|
svelte: ^4.0.0
|
||||||
|
dependencies:
|
||||||
|
svelte: 4.2.9
|
||||||
|
dev: false
|
||||||
|
|
||||||
/mri@1.2.0:
|
/mri@1.2.0:
|
||||||
resolution: {integrity: sha512-tzzskb3bG8LvYGFF/mDTpq3jpI6Q9wc3LEmBaghu+DdCssd1FakN7Bc0hVNmEyGq1bq3RgfkCb3cmQLpNPOroA==}
|
resolution: {integrity: sha512-tzzskb3bG8LvYGFF/mDTpq3jpI6Q9wc3LEmBaghu+DdCssd1FakN7Bc0hVNmEyGq1bq3RgfkCb3cmQLpNPOroA==}
|
||||||
engines: {node: '>=4'}
|
engines: {node: '>=4'}
|
||||||
|
@ -84,7 +84,7 @@
|
|||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if typeof svgInfo.route === 'string'}
|
{#if typeof svgInfo.route === 'string' && svgInfo.wordmark === undefined}
|
||||||
<button
|
<button
|
||||||
title="Download Light & Dark variants"
|
title="Download Light & Dark variants"
|
||||||
class={mainDownloadStyles}
|
class={mainDownloadStyles}
|
||||||
@ -114,6 +114,28 @@
|
|||||||
'md:space-y-0 md:flex-row md:space-x-2 md:items-center md:justify-center'
|
'md:space-y-0 md:flex-row md:space-x-2 md:items-center md:justify-center'
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
|
{#if typeof svgInfo.route === 'string'}
|
||||||
|
<div class={cardDownloadStyles}>
|
||||||
|
<img
|
||||||
|
src={isDarkTheme() ? svgInfo.route : svgInfo.route}
|
||||||
|
alt={svgInfo.title}
|
||||||
|
class="h-8 my-4"
|
||||||
|
/>
|
||||||
|
<button
|
||||||
|
title="Download logo"
|
||||||
|
class={buttonStyles}
|
||||||
|
on:click={() => {
|
||||||
|
if (typeof svgInfo.route === 'string') {
|
||||||
|
downloadSvg(svgInfo.route);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<DownloadIcon class="mr-2" size={iconSize} />
|
||||||
|
<p>Icon logo</p>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
{:else}
|
||||||
<div class={cardDownloadStyles}>
|
<div class={cardDownloadStyles}>
|
||||||
<img
|
<img
|
||||||
src={isDarkTheme() ? svgInfo.route.dark : svgInfo.route.light}
|
src={isDarkTheme() ? svgInfo.route.dark : svgInfo.route.light}
|
||||||
@ -164,6 +186,7 @@
|
|||||||
Only dark variant
|
Only dark variant
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
{#if typeof svgInfo.wordmark === 'string' && svgInfo.wordmark !== undefined}
|
{#if typeof svgInfo.wordmark === 'string' && svgInfo.wordmark !== undefined}
|
||||||
<div class={cardDownloadStyles}>
|
<div class={cardDownloadStyles}>
|
||||||
|
@ -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