mirror of
https://github.com/pheralb/svgl.git
synced 2025-03-12 16:10:34 +08:00
⚙️ Add loadMore button.
This commit is contained in:
parent
05e4b1dfb3
commit
f8aa92e2c9
@ -17,6 +17,7 @@
|
|||||||
type="text"
|
type="text"
|
||||||
{placeholder}
|
{placeholder}
|
||||||
autocomplete="off"
|
autocomplete="off"
|
||||||
|
autofocus={true}
|
||||||
class="w-full border-b border-neutral-300 bg-white p-3 pl-11 placeholder-neutral-500 focus:outline-none focus:ring-1 focus:ring-neutral-300 dark:border-neutral-800 dark:bg-neutral-900 dark:focus:ring-neutral-700"
|
class="w-full border-b border-neutral-300 bg-white p-3 pl-11 placeholder-neutral-500 focus:outline-none focus:ring-1 focus:ring-neutral-300 dark:border-neutral-800 dark:bg-neutral-900 dark:focus:ring-neutral-700"
|
||||||
bind:value={searchTerm}
|
bind:value={searchTerm}
|
||||||
on:input
|
on:input
|
||||||
|
@ -10,22 +10,28 @@
|
|||||||
import { flyAndScale } from '@/utils/flyAndScale';
|
import { flyAndScale } from '@/utils/flyAndScale';
|
||||||
|
|
||||||
// Icons:
|
// Icons:
|
||||||
import { CopyIcon, DownloadIcon, LinkIcon, PackageIcon, PaintBucket, ChevronsRight } from 'lucide-svelte';
|
import {
|
||||||
|
CopyIcon,
|
||||||
|
DownloadIcon,
|
||||||
|
LinkIcon,
|
||||||
|
PackageIcon,
|
||||||
|
PaintBucket,
|
||||||
|
ChevronsRight
|
||||||
|
} from 'lucide-svelte';
|
||||||
|
|
||||||
// Main Card:
|
// Main Card:
|
||||||
import CardSpotlight from './cardSpotlight.svelte';
|
import CardSpotlight from './cardSpotlight.svelte';
|
||||||
import { DropdownMenu } from 'bits-ui';
|
import { DropdownMenu } from 'bits-ui';
|
||||||
|
|
||||||
// Figma
|
// Figma
|
||||||
import { onMount } from "svelte";
|
import { onMount } from 'svelte';
|
||||||
import { copyToClipboard as figmaCopyToClipboard } from '@/figma/copy-to-clipboard';
|
import { copyToClipboard as figmaCopyToClipboard } from '@/figma/copy-to-clipboard';
|
||||||
import { insertSVG as figmaInsertSVG } from '@/figma/insert-svg';
|
import { insertSVG as figmaInsertSVG } from '@/figma/insert-svg';
|
||||||
|
|
||||||
|
|
||||||
// Props:
|
// Props:
|
||||||
export let svgInfo: iSVG;
|
export let svgInfo: iSVG;
|
||||||
|
|
||||||
let isInFigma = false
|
let isInFigma = 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';
|
||||||
@ -69,7 +75,7 @@
|
|||||||
[MIMETYPE]: getSvgContent(url, true)
|
[MIMETYPE]: getSvgContent(url, true)
|
||||||
};
|
};
|
||||||
|
|
||||||
if(isInFigma) {
|
if (isInFigma) {
|
||||||
const content = (await getSvgContent(url, false)) as string;
|
const content = (await getSvgContent(url, false)) as string;
|
||||||
figmaCopyToClipboard(content);
|
figmaCopyToClipboard(content);
|
||||||
} else {
|
} else {
|
||||||
@ -90,7 +96,7 @@
|
|||||||
const insertSVG = async (url?: string) => {
|
const insertSVG = async (url?: string) => {
|
||||||
const content = (await getSvgContent(url, false)) as string;
|
const content = (await getSvgContent(url, false)) as string;
|
||||||
figmaInsertSVG(content);
|
figmaInsertSVG(content);
|
||||||
}
|
};
|
||||||
|
|
||||||
// Icon Stroke & Size:
|
// Icon Stroke & Size:
|
||||||
let iconStroke = 1.8;
|
let iconStroke = 1.8;
|
||||||
@ -157,7 +163,6 @@
|
|||||||
</button>
|
</button>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
|
|
||||||
<button
|
<button
|
||||||
title="Copy to clipboard"
|
title="Copy to clipboard"
|
||||||
on:click={() => {
|
on:click={() => {
|
||||||
@ -211,7 +216,9 @@
|
|||||||
<p>Light & Dark variants</p>
|
<p>Light & Dark variants</p>
|
||||||
</DropdownMenu.Item>
|
</DropdownMenu.Item>
|
||||||
<DropdownMenu.Item
|
<DropdownMenu.Item
|
||||||
title="Download only {document.documentElement.classList.contains('dark') ? 'dark' : 'light'} variant"
|
title="Download only {document.documentElement.classList.contains('dark')
|
||||||
|
? 'dark'
|
||||||
|
: 'light'} variant"
|
||||||
class="flex h-10 select-none items-center rounded-md py-3 pl-3 pr-1.5 text-sm font-medium cursor-pointer hover:bg-neutral-100 dark:hover:bg-neutral-700/40"
|
class="flex h-10 select-none items-center rounded-md py-3 pl-3 pr-1.5 text-sm font-medium cursor-pointer hover:bg-neutral-100 dark:hover:bg-neutral-700/40"
|
||||||
on:click={() => {
|
on:click={() => {
|
||||||
const svgHasTheme = typeof svgInfo.route !== 'string';
|
const svgHasTheme = typeof svgInfo.route !== 'string';
|
||||||
|
@ -40,7 +40,7 @@
|
|||||||
>
|
>
|
||||||
<div class="md:px-6 md:py-6">
|
<div class="md:px-6 md:py-6">
|
||||||
<nav
|
<nav
|
||||||
class="flex items-center space-x-1 overflow-y-auto border-b border-neutral-300 dark:border-neutral-700/40 md:mb-3 md:flex-col md:space-x-0 md:space-y-1 md:overflow-y-visible px-5 md:px-0 pb-2 pt-3 md:pt-0"
|
class="flex items-center space-x-1 overflow-y-auto md:mb-3 md:flex-col md:space-x-0 md:space-y-1 md:overflow-y-visible px-5 md:px-0 pb-2 pt-3 md:pt-0"
|
||||||
>
|
>
|
||||||
<a
|
<a
|
||||||
href="/"
|
href="/"
|
||||||
@ -66,20 +66,6 @@
|
|||||||
</a>
|
</a>
|
||||||
{/each}
|
{/each}
|
||||||
</nav>
|
</nav>
|
||||||
<a
|
|
||||||
href="https://twitter.com/pheralb_"
|
|
||||||
target="_blank"
|
|
||||||
class="group mt-5 md:flex hidden items-center space-x-2 duration-100 hover:text-dark dark:text-neutral-400 dark:hover:text-white"
|
|
||||||
>
|
|
||||||
<Heart color="#991b1b" size={18} weight={'duotone'} />
|
|
||||||
<div class="flex items-center space-x-1">
|
|
||||||
<p class="text-muted text-sm">Created by pheralb</p>
|
|
||||||
<ArrowUpRight
|
|
||||||
size={14}
|
|
||||||
class="transition-transform duration-300 group-hover:-translate-y-[1px]"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</a>
|
|
||||||
</div>
|
</div>
|
||||||
</aside>
|
</aside>
|
||||||
<div class="ml-0 md:ml-56 pb-6">
|
<div class="ml-0 md:ml-56 pb-6">
|
||||||
|
@ -14,9 +14,11 @@
|
|||||||
import NotFound from '@/components/notFound.svelte';
|
import NotFound from '@/components/notFound.svelte';
|
||||||
|
|
||||||
// Icons:
|
// Icons:
|
||||||
import { ArrowDownUpIcon, ArrowUpDownIcon } from 'lucide-svelte';
|
import { ArrowDown, ArrowDownUpIcon, ArrowUpDownIcon } from 'lucide-svelte';
|
||||||
|
|
||||||
let sorted: boolean = false;
|
let sorted: boolean = false;
|
||||||
|
let isFirstLoad: boolean = true;
|
||||||
|
let showAll: boolean = false;
|
||||||
|
|
||||||
// Search:
|
// Search:
|
||||||
let searchTerm = '';
|
let searchTerm = '';
|
||||||
@ -29,12 +31,22 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const loadSvgs = () => {
|
||||||
|
if (isFirstLoad || showAll) {
|
||||||
|
filteredSvgs = allSvgs;
|
||||||
|
isFirstLoad = false;
|
||||||
|
} else {
|
||||||
|
filteredSvgs = allSvgs.slice(0, 30);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Search svgs:
|
// Search svgs:
|
||||||
const searchSvgs = () => {
|
const searchSvgs = () => {
|
||||||
return (filteredSvgs = allSvgs.filter((svg: iSVG) => {
|
loadSvgs();
|
||||||
|
filteredSvgs = allSvgs.filter((svg: iSVG) => {
|
||||||
let svgTitle = svg.title.toLowerCase();
|
let svgTitle = svg.title.toLowerCase();
|
||||||
return svgTitle.includes(searchTerm.toLowerCase());
|
return svgTitle.includes(searchTerm.toLowerCase());
|
||||||
}));
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// Clear search:
|
// Clear search:
|
||||||
@ -66,6 +78,8 @@
|
|||||||
return b.id! - a.id!;
|
return b.id! - a.id!;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
loadSvgs();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svelte:head>
|
<svelte:head>
|
||||||
@ -97,10 +111,24 @@
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<Grid>
|
<Grid>
|
||||||
{#each filteredSvgs as svg}
|
{#each filteredSvgs.slice(0, showAll ? undefined : 30) as svg}
|
||||||
<SvgCard svgInfo={svg} />
|
<SvgCard svgInfo={svg} />
|
||||||
{/each}
|
{/each}
|
||||||
</Grid>
|
</Grid>
|
||||||
|
{#if filteredSvgs.length > 30 && !showAll}
|
||||||
|
<div class="flex items-center justify-center mt-4">
|
||||||
|
<button
|
||||||
|
class="flex items-center space-x-2 rounded-md border border-neutral-300 p-2 duration-100 hover:bg-neutral-200 dark:border-neutral-700 dark:hover:bg-neutral-700/40"
|
||||||
|
on:click={() => (showAll = true)}
|
||||||
|
>
|
||||||
|
<ArrowDown size={16} strokeWidth={2} />
|
||||||
|
<span>Load All SVGs</span>
|
||||||
|
<span class="opacity-70">
|
||||||
|
({filteredSvgs.length - 30} more)
|
||||||
|
</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
{#if filteredSvgs.length === 0}
|
{#if filteredSvgs.length === 0}
|
||||||
<NotFound notFoundTerm={searchTerm} />
|
<NotFound notFoundTerm={searchTerm} />
|
||||||
{/if}
|
{/if}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user