@@ -11,7 +11,7 @@ export interface AvatarProps {
1111 * The element or component this component should render as.
1212 * @defaultValue 'span'
1313 */
14- as? : any
14+ as? : any | { root ? : any , img ? : any }
1515 src? : string
1616 alt? : string
1717 /**
@@ -37,6 +37,7 @@ export interface AvatarSlots {
3737<script setup lang="ts">
3838import { ref , computed , watch } from ' vue'
3939import { Primitive , Slot } from ' reka-ui'
40+ import { defu } from ' defu'
4041import { useAppConfig } from ' #imports'
4142import ImageComponent from ' #build/ui-image-component'
4243import { useAvatarGroup } from ' ../composables/useAvatarGroup'
@@ -46,7 +47,15 @@ import UChip from './Chip.vue'
4647
4748defineOptions ({ inheritAttrs: false })
4849
49- const props = withDefaults (defineProps <AvatarProps >(), { as: ' span' })
50+ const props = defineProps <AvatarProps >()
51+
52+ const as = computed (() => {
53+ if (typeof props .as === ' string' || typeof props .as ?.render === ' function' ) {
54+ return { root: props .as }
55+ }
56+
57+ return defu (props .as , { root: ' span' })
58+ })
5059
5160const fallback = computed (() => props .text || (props .alt || ' ' ).split (' ' ).map (word => word .charAt (0 )).join (' ' ).substring (0 , 2 ))
5261
@@ -86,13 +95,13 @@ function onError() {
8695<template >
8796 <component
8897 :is =" props.chip ? UChip : Primitive"
89- :as =" as"
98+ :as =" as.root "
9099 v-bind =" props.chip ? (typeof props.chip === 'object' ? { inset: true, ...props.chip } : { inset: true }) : {}"
91100 :class =" ui.root({ class: [props.ui?.root, props.class] })"
92101 :style =" props.style"
93102 >
94103 <component
95- :is =" ImageComponent"
104+ :is =" as.img || ImageComponent"
96105 v-if =" src && !error"
97106 :src =" src"
98107 :alt =" alt"
0 commit comments