2024-08-15 21:30:55 +00:00
|
|
|
<script lang="ts">
|
2025-01-15 19:42:54 +00:00
|
|
|
import {onMount} from "svelte"
|
2024-08-15 21:30:55 +00:00
|
|
|
import Icon from "@lib/components/Icon.svelte"
|
|
|
|
|
|
2024-10-04 00:04:00 +00:00
|
|
|
export let src = ""
|
2024-08-15 21:30:55 +00:00
|
|
|
export let size = 7
|
2024-08-23 20:33:36 +00:00
|
|
|
export let icon = "user-rounded"
|
2025-01-15 18:56:56 +00:00
|
|
|
|
2025-01-15 19:42:54 +00:00
|
|
|
let element: HTMLElement
|
|
|
|
|
|
2025-01-15 18:56:56 +00:00
|
|
|
$: rem = size * 4
|
2025-01-15 19:42:54 +00:00
|
|
|
|
|
|
|
|
onMount(() => {
|
|
|
|
|
if (src) {
|
|
|
|
|
const image = new Image()
|
|
|
|
|
|
|
|
|
|
image.addEventListener("error", () => {
|
|
|
|
|
element.querySelector(".hidden")?.classList.remove("hidden")
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
image.src = src
|
|
|
|
|
}
|
|
|
|
|
})
|
2024-08-15 21:30:55 +00:00
|
|
|
</script>
|
|
|
|
|
|
2025-01-15 18:56:56 +00:00
|
|
|
<div
|
2025-01-15 19:42:54 +00:00
|
|
|
bind:this={element}
|
|
|
|
|
class="{$$props.class} relative !flex shrink-0 items-center justify-center overflow-hidden rounded-full bg-cover bg-center"
|
|
|
|
|
style="width: {rem}px; height: {rem}px; min-width: {rem}px; background-image: url({src}); {$$props.style ||
|
|
|
|
|
''}">
|
|
|
|
|
<Icon {icon} class={src ? "hidden" : ""} size={Math.round(size * 0.8)} />
|
2025-01-15 18:56:56 +00:00
|
|
|
</div>
|