Line data Source code
1 16 : <template>
2 : <span
3 : :class="
4 : cn(
5 : 'inline-flex aspect-square items-center justify-center overflow-hidden rounded-full bg-muted',
6 : size === 'large' ? 'size-12' : 'size-8'
7 : )
8 : "
9 : >
10 : <img
11 : v-if="hasAvatar"
12 : :src="photoUrl ?? undefined"
13 : :alt="label"
14 : :aria-label="label"
15 : class="size-full object-cover"
16 : @error="handleImageError"
17 : />
18 : <i
19 : v-else
20 : data-testid="avatar-icon"
21 : :aria-label="label"
22 : :class="cn('icon-[lucide--user]', iconClass)"
23 : />
24 : </span>
25 : </template>
26 :
27 : <script setup lang="ts">
28 : import { cn } from '@comfyorg/tailwind-utils'
29 : import { computed, ref, watch } from 'vue'
30 :
31 : const {
32 : photoUrl,
33 : label,
34 : iconClass = 'size-4',
35 : size = 'normal'
36 : } = defineProps<{
37 : photoUrl?: string | null
38 : label: string
39 : iconClass?: string
40 : size?: 'normal' | 'large'
41 : }>()
42 :
43 17 : const imageError = ref(false)
44 17 : const handleImageError = () => {
45 0 : imageError.value = true
46 : }
47 17 : const hasAvatar = computed(() => photoUrl && !imageError.value)
48 :
49 17 : watch(
50 : () => photoUrl,
51 : () => {
52 0 : imageError.value = false
53 : }
54 : )
55 : </script>
|