mirror of
https://github.com/versia-pub/frontend.git
synced 2025-12-06 08:28:20 +01:00
feat: ✨ Make Avatar component display a loading screen while image is loading
This commit is contained in:
parent
e309c56a86
commit
7e47dafa18
|
|
@ -1,19 +1,38 @@
|
||||||
<template>
|
<template>
|
||||||
<div v-bind="$props" class="bg-dark-700 overflow-hidden flex items-center justify-center">
|
<div v-bind="$attrs" class="bg-dark-700 overflow-hidden flex items-center justify-center">
|
||||||
<Skeleton :enabled="!src" class="!h-full !w-full !rounded-none">
|
<Skeleton :enabled="!imageLoaded" class="!h-full !w-full !rounded-none">
|
||||||
<img class="cursor-pointer bg-dark-700 ring-1 w-full h-full object-cover" :src="src" :alt="alt" />
|
<img class="cursor-pointer bg-dark-700 ring-1 w-full h-full object-cover" :src="src" :alt="alt" />
|
||||||
</Skeleton>
|
</Skeleton>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import type { HTMLAttributes } from "vue";
|
|
||||||
import Skeleton from "../skeleton/Skeleton.vue";
|
import Skeleton from "../skeleton/Skeleton.vue";
|
||||||
|
|
||||||
interface Props extends /* @vue-ignore */ HTMLAttributes {
|
defineOptions({
|
||||||
|
inheritAttrs: false,
|
||||||
|
});
|
||||||
|
const props = defineProps<{
|
||||||
src?: string;
|
src?: string;
|
||||||
alt?: string;
|
alt?: string;
|
||||||
}
|
}>();
|
||||||
|
const imageLoaded = ref(false);
|
||||||
|
|
||||||
defineProps<Props>();
|
watch(
|
||||||
|
() => props.src,
|
||||||
|
(src) => {
|
||||||
|
if (!src) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load in background
|
||||||
|
const img = new Image();
|
||||||
|
img.src = src;
|
||||||
|
|
||||||
|
img.onload = () => {
|
||||||
|
imageLoaded.value = true;
|
||||||
|
};
|
||||||
|
},
|
||||||
|
{ immediate: true },
|
||||||
|
);
|
||||||
</script>
|
</script>
|
||||||
Loading…
Reference in a new issue