|
1 | 1 | <script lang="ts"> |
2 | 2 | import { cls } from '@layerstack/tailwind'; |
| 3 | + import type { Component } from 'svelte'; |
3 | 4 |
|
4 | 5 | let { |
5 | 6 | component, |
6 | 7 | example, |
7 | 8 | aspect = 'initial', |
8 | 9 | background = false, |
9 | 10 | viewTransitionName = null, |
| 11 | + fallbackIcon, |
10 | 12 | class: className |
11 | 13 | }: { |
12 | 14 | component: string; |
13 | 15 | example: string; |
14 | 16 | aspect?: 'initial' | 'video' | 'square' | 'screenshot'; |
15 | 17 | background?: boolean; |
16 | 18 | viewTransitionName?: string | null; |
| 19 | + fallbackIcon?: Component; |
17 | 20 | class?: string; |
18 | 21 | } = $props(); |
19 | 22 |
|
| 23 | + let hasError = $state(false); |
| 24 | +
|
20 | 25 | const basePath = $derived(`/screenshots/${component}/${example}`); |
21 | 26 |
|
22 | 27 | const sizes = [ |
|
41 | 46 | )} |
42 | 47 | style:view-transition-name={viewTransitionName} |
43 | 48 | > |
44 | | - {#each ['light', 'dark'] as mode} |
45 | | - {#each sizes as size} |
46 | | - <img |
47 | | - src="{basePath}-{mode}-{size.width}.webp" |
48 | | - alt="{component} - {example}" |
49 | | - class={cls( |
50 | | - 'w-full h-full object-scale-down object-center p-2', |
51 | | - mode === 'light' ? size.light : 'hidden ' + size.dark |
52 | | - )} |
53 | | - loading="lazy" |
54 | | - /> |
| 49 | + {#if hasError && fallbackIcon} |
| 50 | + {@const FallbackIcon = fallbackIcon} |
| 51 | + <div class="w-full h-full flex items-center justify-center text-surface-content/30"> |
| 52 | + <FallbackIcon class="size-12" /> |
| 53 | + </div> |
| 54 | + {:else if !hasError} |
| 55 | + {#each ['light', 'dark'] as mode (mode)} |
| 56 | + {#each sizes as size (size.width)} |
| 57 | + <img |
| 58 | + src="{basePath}-{mode}-{size.width}.webp" |
| 59 | + alt="{component} - {example}" |
| 60 | + class={cls( |
| 61 | + 'w-full h-full object-scale-down object-center p-2', |
| 62 | + mode === 'light' ? size.light : 'hidden ' + size.dark |
| 63 | + )} |
| 64 | + loading="lazy" |
| 65 | + onerror={() => (hasError = true)} |
| 66 | + /> |
| 67 | + {/each} |
55 | 68 | {/each} |
56 | | - {/each} |
| 69 | + {/if} |
57 | 70 | </div> |
0 commit comments