mirror of
https://github.com/coracle-social/flotilla.git
synced 2025-12-10 10:57:04 +00:00
Tweak avatar again
This commit is contained in:
@@ -1,18 +1,32 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import {onMount} from "svelte"
|
||||||
import Icon from "@lib/components/Icon.svelte"
|
import Icon from "@lib/components/Icon.svelte"
|
||||||
|
|
||||||
export let src = ""
|
export let src = ""
|
||||||
export let size = 7
|
export let size = 7
|
||||||
export let icon = "user-rounded"
|
export let icon = "user-rounded"
|
||||||
|
|
||||||
|
let element: HTMLElement
|
||||||
|
|
||||||
$: rem = size * 4
|
$: rem = size * 4
|
||||||
|
|
||||||
|
onMount(() => {
|
||||||
|
if (src) {
|
||||||
|
const image = new Image()
|
||||||
|
|
||||||
|
image.addEventListener("error", () => {
|
||||||
|
element.querySelector(".hidden")?.classList.remove("hidden")
|
||||||
|
})
|
||||||
|
|
||||||
|
image.src = src
|
||||||
|
}
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
class="{$$props.class} relative !flex shrink-0 items-center justify-center overflow-hidden rounded-full"
|
bind:this={element}
|
||||||
style="width: {rem}px; height: {rem}px; min-width: {rem}px; {$$props.style || ''}">
|
class="{$$props.class} relative !flex shrink-0 items-center justify-center overflow-hidden rounded-full bg-cover bg-center"
|
||||||
<Icon {icon} size={Math.round(size * 0.8)} />
|
style="width: {rem}px; height: {rem}px; min-width: {rem}px; background-image: url({src}); {$$props.style ||
|
||||||
<div
|
''}">
|
||||||
class="absolute left-0 top-0 h-full w-full bg-cover bg-center"
|
<Icon {icon} class={src ? "hidden" : ""} size={Math.round(size * 0.8)} />
|
||||||
style="background-image: url({src})" />
|
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user