Skip to content

OAvatar ​

OAvatar displays a user profile image with fallback initials or icon and optional presence status.

Usage ​

Step by step ​

  1. Import OAvatar from the ooko-ui/avatar public subpath.
  2. Provide a src URL for the user's image, or a name to generate initials.
  3. Optionally add a status to show an online/offline indicator.
  4. Adjust size, shape, color, and statusPosition to match your design.

Example ​

The rendered example and its source come from the same Vue single-file component.

AL

Interactive playground ​

Change the image, name, size, shape, color, status, and status position. The preview updates immediately.

AL

Props ​

PropTypeDefaultDescription
srcstringundefinedSource URL of the avatar image.
altstringundefinedAccessible description of the avatar image. Required when src is provided.
namestringundefinedUser name used to generate initials when no image is available.
sizeOAvatarSize"md"Visual size of the avatar.
shapeOAvatarShape"circle"Shape of the avatar container.
color"primary" | "secondary" | "info" | "success" | "warning" | "danger" | "neutral""primary"Color applied to the fallback background when no image is displayed.
statusOAvatarStatusundefinedStatus indicator displayed as an overlay badge.
statusPositionOAvatarStatusPosition"bottom-right"Position of the status badge relative to the avatar.
iconComponentundefinedVue component rendered as the fallback icon when no image or name is provided.

Events ​

EventPayloadDescription
errorEventFired when the avatar image fails to load.

Slots ​

SlotPropsDescription
defaultnoneProvides custom fallback content (e.g., initials or icon) when no image is displayed.
TypeDefinition
OAvatarShapetype OAvatarShape = "circle" | "square";
OAvatarSizetype OAvatarSize = "xs" | OokoFormControlSize | "lg" | "xl";
OAvatarStatustype OAvatarStatus = "online" | "offline" | "busy" | "away";
OAvatarStatusPositiontype OAvatarStatusPosition = "bottom-right" | "top-right" | "bottom-left" | "top-left";
OokoFormControlSizetype OokoFormControlSize = "sm" | "md";
OokoColortype OokoColor = (typeof OOKO_COLORS)[number];

CSS custom properties ​

Custom propertyDefaultDescription
--o-avatar-border-radius-circlevar(--o-radius-round)Sets the avatar corner radius for circle shape.
--o-avatar-border-radius-squarevar(--o-radius-control)Sets the avatar corner radius for square shape.
--o-avatar-fallback-border-width0Sets the avatar border width when no image is loaded.
--o-avatar-fallback-colorvar(--o-text-color-inverted)Sets the avatar fallback icon color.
--o-status-border-colorvar(--o-background-color-default)Sets the status dot border color (uses background for contrast).

Override example ​

css
:root {
  --o-avatar-border-radius-square: var(--o-radius-round);
  --o-avatar-fallback-border-width: 2px;
}

Accessibility ​

  • The avatar content has role="img" and an accessible name derived from alt, name, or a generic "User avatar" label.
  • When an image is provided, alt is required for a meaningful description; if omitted, the component uses name or the fallback label.
  • Decorative icons and initials are included in the avatar image semantics rather than announced separately.
  • The status badge is a separate, non-interactive image with an accessible label describing the status.
  • Native attributes are forwarded to the root span.

Behavior and edge cases ​

  • If src fails to load, the component automatically falls back to initials (from name) or the default/icon slot.
  • The name prop generates two-letter uppercase initials from the first two words.
  • The icon prop accepts any Vue icon component; the default slot overrides both icon and generated initials.
  • status renders a colored dot badge; statusPosition controls its corner placement.
  • Sizes: xs (24 px), sm (32 px), md (40 px), lg (48 px), xl (64 px) at the default root scale.
  • App defaults may configure color, shape, size, and statusPosition; direct props take precedence.
  • SSR-safe: image loading state and fallbacks render deterministically on the server.