feat(FontVirtualList): make skeleton a snippet prop
This commit is contained in:
@@ -8,7 +8,10 @@ import {
|
|||||||
Skeleton,
|
Skeleton,
|
||||||
VirtualList,
|
VirtualList,
|
||||||
} from '$shared/ui';
|
} from '$shared/ui';
|
||||||
import type { ComponentProps } from 'svelte';
|
import type {
|
||||||
|
ComponentProps,
|
||||||
|
Snippet,
|
||||||
|
} from 'svelte';
|
||||||
import { fade } from 'svelte/transition';
|
import { fade } from 'svelte/transition';
|
||||||
import { getFontUrl } from '../../lib';
|
import { getFontUrl } from '../../lib';
|
||||||
import {
|
import {
|
||||||
@@ -28,19 +31,21 @@ interface Props extends
|
|||||||
* Callback for when visible items change
|
* Callback for when visible items change
|
||||||
*/
|
*/
|
||||||
onVisibleItemsChange?: (items: UnifiedFont[]) => void;
|
onVisibleItemsChange?: (items: UnifiedFont[]) => void;
|
||||||
/**
|
|
||||||
* Weight of the font
|
|
||||||
*/
|
|
||||||
/**
|
/**
|
||||||
* Weight of the font
|
* Weight of the font
|
||||||
*/
|
*/
|
||||||
weight: number;
|
weight: number;
|
||||||
|
/**
|
||||||
|
* Skeleton snippet
|
||||||
|
*/
|
||||||
|
skeleton?: Snippet;
|
||||||
}
|
}
|
||||||
|
|
||||||
let {
|
let {
|
||||||
children,
|
children,
|
||||||
onVisibleItemsChange,
|
onVisibleItemsChange,
|
||||||
weight,
|
weight,
|
||||||
|
skeleton,
|
||||||
...rest
|
...rest
|
||||||
}: Props = $props();
|
}: Props = $props();
|
||||||
|
|
||||||
@@ -100,32 +105,25 @@ function handleNearBottom(_lastVisibleIndex: number) {
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#key isLoading}
|
<div class="relative w-full h-full">
|
||||||
<div class="relative w-full h-full" transition:fade={{ duration: 300 }}>
|
{#if skeleton && isLoading && unifiedFontStore.fonts.length === 0}
|
||||||
{#if isLoading}
|
<!-- Show skeleton only on initial load when no fonts are loaded yet -->
|
||||||
<div class="flex flex-col gap-3 sm:gap-4 p-3 sm:p-4">
|
<div transition:fade={{ duration: 300 }}>
|
||||||
{#each Array(5) as _, i}
|
{@render skeleton()}
|
||||||
<div class="flex flex-col gap-1.5 sm:gap-2 p-3 sm:p-4 border rounded-lg sm:rounded-xl border-border-subtle bg-background-40">
|
</div>
|
||||||
<div class="flex items-center justify-between mb-3 sm:mb-4">
|
{:else}
|
||||||
<Skeleton class="h-6 sm:h-8 w-1/3" />
|
<!-- VirtualList persists during pagination - no destruction/recreation -->
|
||||||
<Skeleton class="h-6 sm:h-8 w-6 sm:w-8 rounded-full" />
|
<VirtualList
|
||||||
</div>
|
items={unifiedFontStore.fonts}
|
||||||
<Skeleton class="h-24 sm:h-32 w-full" />
|
total={unifiedFontStore.pagination.total}
|
||||||
</div>
|
isLoading={isLoading}
|
||||||
{/each}
|
onVisibleItemsChange={handleInternalVisibleChange}
|
||||||
</div>
|
onNearBottom={handleNearBottom}
|
||||||
{:else}
|
{...rest}
|
||||||
<VirtualList
|
>
|
||||||
items={unifiedFontStore.fonts}
|
{#snippet children(scope)}
|
||||||
total={unifiedFontStore.pagination.total}
|
{@render children(scope)}
|
||||||
onVisibleItemsChange={handleInternalVisibleChange}
|
{/snippet}
|
||||||
onNearBottom={handleNearBottom}
|
</VirtualList>
|
||||||
{...rest}
|
{/if}
|
||||||
>
|
</div>
|
||||||
{#snippet children(scope)}
|
|
||||||
{@render children(scope)}
|
|
||||||
{/snippet}
|
|
||||||
</VirtualList>
|
|
||||||
{/if}
|
|
||||||
</div>
|
|
||||||
{/key}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user