newOS for Developers
Back to Overview
UserAvatar
outputuserA user avatar component with size variants, online badge, and intelligent fallback to user initials.
Source Path
apps/web/Components/User/UserAvatar.tsxPackage
@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
| Size | Dimensions | Use Case |
|---|---|---|
| sm | 32×32px | Inline mentions, compact lists |
| md | 40×40px | Default, navigation, headers |
| lg | 56×56px | Cards, profiles, prominent display |
| xl | 80×80px | Profile 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.