Avatar
Features
- Automatic and manual control over when the image renders.
 - Fallback part accepts any children.
 - Optionally delay fallback rendering to avoid content flashing.
 
Installation
Install the component from your command line.
$ npm add reka-uiAnatomy
Import all parts and piece them together.
<script setup>
import { AvatarImage, AvatarRoot } from 'reka-ui'
</script>
<template>
  <AvatarRoot>
    <AvatarImage />
    <AvatarFallback />
  </AvatarRoot>
</template>API Reference
Root
Contains all the parts of an avatar
| Prop | Default | Type | 
|---|---|---|
as | 'span' | AsTag | ComponentThe element or component this component should render as. Can be overwritten by   | 
asChild | booleanChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details.  | 
Image
The image to render. By default it will only render when it has loaded. You can use the @loadingStatusChange handler if you need more control.
| Prop | Default | Type | 
|---|---|---|
as | 'img' | AsTag | ComponentThe element or component this component should render as. Can be overwritten by   | 
asChild | booleanChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details.  | |
referrerPolicy | '' | 'no-referrer' | 'no-referrer-when-downgrade' | 'origin' | 'origin-when-cross-origin' | 'same-origin' | 'strict-origin' | 'strict-origin-when-cross-origin' | 'unsafe-url' | |
src* | string | 
| Emit | Payload | 
|---|---|
loadingStatusChange | [value: ImageLoadingStatus]A callback providing information about the loading status of the image.   | 
Fallback
An element that renders when the image hasn't loaded. This means whilst it's loading, or if there was an error. If you notice a flash during loading, you can provide a delayMs prop to delay its rendering so it only renders for those with slower connections. For more control, use the @loadingStatusChange emit on AvatarImage.
| Prop | Default | Type | 
|---|---|---|
as | 'span' | AsTag | ComponentThe element or component this component should render as. Can be overwritten by   | 
asChild | booleanChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details.  | |
delayMs | 0 | numberUseful for delaying rendering so it only appears for those with slower connections.  | 
Examples
Clickable Avatar with tooltip
You can compose the Avatar with a Tooltip to display extra information.
<script setup>
import { AvatarImage, AvatarRoot, TooltipArrow, TooltipRoot, TooltipTrigger } from 'reka-ui'
</script>
<template>
  <TooltipRoot>
    <TooltipTrigger>
      <AvatarRoot>…</AvatarRoot>
    </TooltipTrigger>
    <TooltipContent side="top">
      Tooltip content
      <TooltipArrow />
    </TooltipContent>
  </TooltipRoot>
</template>