mirror of
https://github.com/pheralb/svgl.git
synced 2025-02-06 06:58:04 +08:00
✨ Upgrade svgCard, theme, transition & warning components to svelte 5
This commit is contained in:
parent
63ce4d1e20
commit
d6bb70660e
@ -28,22 +28,26 @@
|
|||||||
import { insertSVG as figmaInsertSVG } from '@/figma/insert-svg';
|
import { insertSVG as figmaInsertSVG } from '@/figma/insert-svg';
|
||||||
|
|
||||||
// Props:
|
// Props:
|
||||||
export let svgInfo: iSVG;
|
interface Props {
|
||||||
export let searchTerm: string;
|
svgInfo: iSVG;
|
||||||
|
searchTerm: string;
|
||||||
|
}
|
||||||
|
|
||||||
let isInFigma = false;
|
let { svgInfo, searchTerm }: Props = $props();
|
||||||
|
|
||||||
|
let isInFigma = $state(false);
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
const searchParams = new URLSearchParams(window.location.search);
|
const searchParams = new URLSearchParams(window.location.search);
|
||||||
isInFigma = searchParams.get('figma') === '1';
|
isInFigma = searchParams.get('figma') === '1';
|
||||||
});
|
});
|
||||||
|
|
||||||
// Wordmark SVG:
|
// Wordmark SVG:
|
||||||
let wordmarkSvg = false;
|
let wordmarkSvg = $state(false);
|
||||||
$: {
|
$effect(() => {
|
||||||
if (searchTerm) {
|
if (searchTerm) {
|
||||||
wordmarkSvg = false;
|
wordmarkSvg = false;
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
const insertSVG = async (url?: string) => {
|
const insertSVG = async (url?: string) => {
|
||||||
const content = (await getSvgContent(url)) as string;
|
const content = (await getSvgContent(url)) as string;
|
||||||
@ -56,7 +60,7 @@
|
|||||||
|
|
||||||
// Max Categories:
|
// Max Categories:
|
||||||
let maxVisibleCategories = 1;
|
let maxVisibleCategories = 1;
|
||||||
let moreTagsOptions = false;
|
let moreTagsOptions = $state(false);
|
||||||
|
|
||||||
// Global Styles:
|
// Global Styles:
|
||||||
const globalImageStyles = 'mb-4 mt-2 h-10 select-none pointer-events-none';
|
const globalImageStyles = 'mb-4 mt-2 h-10 select-none pointer-events-none';
|
||||||
@ -156,7 +160,7 @@
|
|||||||
{#if isInFigma}
|
{#if isInFigma}
|
||||||
<button
|
<button
|
||||||
title="Insert to figma"
|
title="Insert to figma"
|
||||||
on:click={() => {
|
onclick={() => {
|
||||||
const svgHasTheme = typeof svgInfo.route !== 'string';
|
const svgHasTheme = typeof svgInfo.route !== 'string';
|
||||||
|
|
||||||
if (!svgHasTheme) {
|
if (!svgHasTheme) {
|
||||||
@ -210,7 +214,7 @@
|
|||||||
{#if svgInfo.wordmark !== undefined}
|
{#if svgInfo.wordmark !== undefined}
|
||||||
<button
|
<button
|
||||||
title={wordmarkSvg ? 'Show logo SVG' : 'Show wordmark SVG'}
|
title={wordmarkSvg ? 'Show logo SVG' : 'Show wordmark SVG'}
|
||||||
on:click={() => {
|
onclick={() => {
|
||||||
wordmarkSvg = !wordmarkSvg;
|
wordmarkSvg = !wordmarkSvg;
|
||||||
}}
|
}}
|
||||||
class={btnStyles}
|
class={btnStyles}
|
||||||
|
@ -1,11 +1,9 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { toggleMode, mode } from 'mode-watcher';
|
import { toggleMode, mode } from 'mode-watcher';
|
||||||
|
|
||||||
// Icons:
|
|
||||||
import { MoonIcon, SunIcon } from 'lucide-svelte';
|
import { MoonIcon, SunIcon } from 'lucide-svelte';
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<button on:click={toggleMode} aria-label="Toggle dark mode" class="opacity-80 hover:opacity-100">
|
<button onclick={toggleMode} aria-label="Toggle dark mode" class="opacity-80 hover:opacity-100">
|
||||||
{#if $mode === 'light'}
|
{#if $mode === 'light'}
|
||||||
<SunIcon size={20} strokeWidth={1.5} />
|
<SunIcon size={20} strokeWidth={1.5} />
|
||||||
{:else}
|
{:else}
|
||||||
|
@ -1,10 +1,17 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import type { Snippet } from 'svelte';
|
||||||
import { fly } from 'svelte/transition';
|
import { fly } from 'svelte/transition';
|
||||||
export let pathname: string = '';
|
|
||||||
|
interface TransitionProps {
|
||||||
|
pathname?: string;
|
||||||
|
children?: Snippet;
|
||||||
|
}
|
||||||
|
|
||||||
|
let { pathname = '', children }: TransitionProps = $props();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#key pathname}
|
{#key pathname}
|
||||||
<div in:fly={{ x: 0, y: 23, duration: 450 }}>
|
<div in:fly={{ x: 0, y: 23, duration: 450 }}>
|
||||||
<slot />
|
{@render children?.()}
|
||||||
</div>
|
</div>
|
||||||
{/key}
|
{/key}
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
import { buttonStyles } from '@/ui/styles';
|
import { buttonStyles } from '@/ui/styles';
|
||||||
import { cn } from '@/utils/cn';
|
import { cn } from '@/utils/cn';
|
||||||
|
|
||||||
let warning = false;
|
let warning = $state(false);
|
||||||
let warningName = 'svgl_warn_message';
|
let warningName = 'svgl_warn_message';
|
||||||
const initialValue = browser ? window.localStorage.getItem(warningName) : true;
|
const initialValue = browser ? window.localStorage.getItem(warningName) : true;
|
||||||
</script>
|
</script>
|
||||||
@ -33,7 +33,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<button
|
<button
|
||||||
class={cn(buttonStyles, 'h-10 text-sm')}
|
class={cn(buttonStyles, 'h-10 text-sm')}
|
||||||
on:click={() => {
|
onclick={() => {
|
||||||
localStorage.setItem(warningName, 'true');
|
localStorage.setItem(warningName, 'true');
|
||||||
warning = true;
|
warning = true;
|
||||||
}}
|
}}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user