Overview
TheAvatar component displays user profile pictures in a circular format. It supports image URLs, fallback to user initials, click-to-view full-size modal, and file upload functionality.
Import
Usage
Basic Avatar
Avatar with Initials Fallback
Editable Avatar
Clickable Avatar (View Full Size)
Custom Styling
Props
Image URL to display as the avatar. When provided, this takes precedence over the name fallback.
User’s name. The first letter (capitalized) displays when no
icon is provided.When
true, clicking the avatar opens a file picker for uploading a new image.Accepts: .jpg, .jpeg, .png, .gifWhen
true, clicking the avatar opens a modal showing the full-size image.Cannot be used simultaneously with
editableCallback fired when a new image is selected (when
editable={true}).Parameters:file: Base64-encoded image string, ornullif selection failed
- Validates file type (shows alert for invalid formats)
- Converts selected file to base64
- Passes the result to this callback
Custom inline styles for the avatar container. Useful for:
- Custom
backgroundColor - Text
colorfor initials fontSizefor initial letter size- Custom
width/height(default: 50px)
Features
- Image display: Shows user profile pictures with proper circular cropping
- Automatic fallback: Displays first letter of name when no image is available
- File upload: Click-to-upload with validation for image formats
- Full-size preview: Modal view for enlarged image display
- Base64 encoding: Automatically converts uploaded files for easy storage
- Customizable: Supports custom colors, sizes, and styling
Behavior
Upload Validation
Wheneditable={true}, the component:
- Opens file picker on click
- Validates file extension (
.jpg,.jpeg,.png,.gif) - Shows alert “Debes seleccionar una imagen” for invalid files
- Converts valid images to base64
- Calls
onChangewith the base64 string
Modal Display
Whenclickable={true}, the component:
- Opens a modal on click
- Displays the full-size image in a black background
- Provides a close button to dismiss the modal
Accessibility
- Uses
role="avatar"for semantic identification - Cursor changes to pointer when interactive (
editableorclickable) - Hidden file input for keyboard accessibility
Design Specifications
- Default size: 50px × 50px
- Shape: Perfect circle (border-radius: 50%)
- Background:
Color.background.primaryLow(light brand color) - Text color:
Color.text.primary - Font: Poppins, weight 500
- Initial font size: 25.45px (customizable)
Best Practices
- Always provide a
nameprop as fallback wheniconmight be unavailable - Use
editablefor profile editing interfaces - Use
clickablefor viewing user profiles or large galleries - Handle
onChangeerrors gracefully (network issues, storage limits) - Consider compressing images before upload for better performance
- Use consistent avatar sizes across your application
Related Components
- Modal - Used internally for full-size image display