feat(Avatar): use NuxtImg component when available

Resolves nuxt/ui#2078
This commit is contained in:
Benjamin Canac
2024-11-07 13:01:51 +01:00
parent 0454124b3c
commit f1a14dd87c
3 changed files with 20 additions and 5 deletions

View File

@@ -15,9 +15,9 @@ type AvatarVariants = VariantProps<typeof avatar>
export interface AvatarProps extends Pick<AvatarFallbackProps, 'delayMs'> {
/**
* The element or component this component should render as.
* @defaultValue 'img'
* @defaultValue 'span'
*/
as?: string | object
as?: any
src?: string
alt?: string
icon?: string
@@ -36,10 +36,11 @@ import { AvatarRoot, AvatarImage, AvatarFallback, useForwardProps } from 'radix-
import { reactivePick } from '@vueuse/core'
import { useAvatarGroup } from '../composables/useAvatarGroup'
import UIcon from './Icon.vue'
import ImageComponent from '#build/ui-image-component'
defineOptions({ inheritAttrs: false })
const props = defineProps<AvatarProps>()
const props = withDefaults(defineProps<AvatarProps>(), { as: 'span' })
const fallbackProps = useForwardProps(reactivePick(props, 'delayMs'))
@@ -54,10 +55,10 @@ const ui = computed(() => avatar({
</script>
<template>
<AvatarRoot :class="ui.root({ class: [props.class, props.ui?.root] })">
<AvatarRoot :as="as" :class="ui.root({ class: [props.class, props.ui?.root] })">
<AvatarImage
v-if="src"
:as="as"
:as="ImageComponent"
:src="src"
:alt="alt"
v-bind="$attrs"