vael-ui v0.5.7

Data display

Layout

Avatar

A circular or square image, or initials, that represents a person or an entity. Use it beside names in lists, comments and headers.

Install

import { Avatar } from 'vael-ui'

Playground

AL

Placement, behaviour and animation

Usage
<script setup lang="ts">
import { Avatar } from 'vael-ui'
</script>

<template>
  <Avatar name="Ada Lovelace" />
</template>

Props

NameTypeDefaultDescription
srcstringImage URL. Falls back to the default slot or initials until it loads, or if it fails.
altstringImage alt text; defaults to name.
namestringPerson's name, used for the fallback initials and as the default alt.
size'sm' | 'md' | 'lg''md'Avatar size.
shape'circle' | 'square''circle'Round or rounded-square frame.
badgePlacement'top-start' | 'top-end' | 'bottom-start' | 'bottom-end''bottom-end'Which corner the #badge slot sits on.
motionAvatarMotionHow it moves: its parts' appearance, like the image fading in over the fallback ({ initial: { image: { opacity: 0 } } }). false turns its own animation off.
uiPartial<Record<'root' | 'image' | 'fallback' | 'badge', UiPartValue>>Class and style overrides for each part.

Events

NameTypeDescription
load(event: Event)Fires when the image loads.
error(event: Event)Fires when the image fails to load.

Slots

NameTypeDescription
defaultanyFallback content shown while there's no loaded image; defaults to the initials of name.
badgeanyOverlay on the avatar's edge, e.g. a Badge; position it with badgePlacement.

Exposed

NameTypeDescription
elHTMLElement | nullRoot element.
imgElHTMLImageElement | nullImage element (null without src).
partsRecord<string, HTMLElement | HTMLElement[] | null>Its elements by part name, for your own animation; a repeated part is an array.

Motion New

Avatar: its parts' appearance, like the image fading in over the fallback.

<Avatar
  :motion="{ initial: { root: { opacity: 0, y: 4 } } }"
/>
NameTypeDescription
initialexitrootimagefallbackbadgeSets where each part comes in from and leaves to: any CSS property, plus x, y and blur. A plain number is px, or degrees for rotate.
enterleave(parts, context) => animationAnimates the parts with GSAP, motion or element.animate(). Return the animation and the component waits for it, and stops it if interrupted.
springdurationeasing{ damping, response } | number | stringTimes all of it: a spring, or a duration in ms with an easing. Never both.
falsebooleanTurns its motion off, for an animation of your own on its exposed elements.

Accessibility

It has no keyboard interaction of its own.

  • The image takes its alt from alt, then name. Without either, alt is empty and screen readers skip the image.
  • The fallback (the initials or your default slot) is plain text. It shows while the image loads, or after it fails, and the hidden image is aria-hidden, so the avatar is read once.
  • Avatar has no role and no keyboard handling. Content in the #badge slot is not hidden from screen readers.