-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
17 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,33 @@ | ||
<script lang="ts"> | ||
import { onMount } from 'svelte'; | ||
export let src: string; | ||
export let alt = ''; | ||
export let width = 'w-full'; | ||
export let height = 'h-full'; | ||
export let ratio = 'aspect-auto'; | ||
export let rounded = 'rounded-lg'; | ||
const base = `${width} ${height} ${ratio} ${rounded}`; | ||
const base = `${width} ${height} ${rounded}`; | ||
let loaded = false; | ||
let mounted = false; | ||
function handleLoad() { | ||
loaded = true; | ||
} | ||
onMount(() => (mounted = true)); | ||
</script> | ||
|
||
{#if !loaded} | ||
<div class="{base} aspect-square placeholder animate-pulse" /> | ||
<div class="{base} h-auto placeholder animate-pulse" /> | ||
{/if} | ||
|
||
{#if mounted} | ||
<img | ||
{src} | ||
{alt} | ||
on:load={handleLoad} | ||
class="{base} object-cover shadow-md {!loaded ? 'hidden' : ''}" | ||
/> | ||
{/if} | ||
<img | ||
{src} | ||
{alt} | ||
on:load={handleLoad} | ||
class="{base} object-cover shadow-md {!loaded ? 'hidden' : ''}" | ||
/> |