newOS for Developers

Back to Overview

UserAvatar

outputuser

A user avatar component with size variants, online badge, and intelligent fallback to user initials.

Source Path
apps/web/Components/User/UserAvatar.tsx
Package

@newos/web

Props Interface

interface UserAvatarProps {
  user?: UserReadPublicResponse;   // User data with username/picture
  size?: "sm" | "md" | "lg" | "xl"; // Size variant (default: "md")
  showBadge?: boolean;              // Show status badge
  fallbackText?: string;            // Custom fallback initials
  imageUrl?: string;                // Override image URL
  onClick?: () => void;             // Click handler
  className?: string;               // Additional classes
}

Size Reference

SizeDimensionsUse Case
sm32×32pxInline mentions, compact lists
md40×40pxDefault, navigation, headers
lg56×56pxCards, profiles, prominent display
xl80×80pxProfile pages, hero sections

Key Features

Intelligent Fallback

Automatically generates initials from username when image is unavailable. Falls back to first 2 characters of username, uppercased.

Status Badge

Optional online/status indicator badge with size-appropriate positioning.

Gradient Background

Fallback avatars use a subtle gradient background that adapts to light/dark mode.

Related Components