Avatar
An image element with a fallback for representing the user.
When to use
- Displaying a user's profile picture.
- Showing initials when no image is available.
API
Avatar::new(fallback)
Creates an avatar with fallback initials.
| Method | Type | Default | Description |
|---|---|---|---|
.src(src) | impl Into<SharedString> | — | Image source file/asset path |
When src is set, the image is rendered; otherwise the fallback initials are shown in a 40×40px ZINC_100 circle.
Usage
rust
use gpui::{Component, div, prelude::*};
use components::Avatar;
div().child(Component::new(
Avatar::new("JD").src("path/to/image.png"),
))Copy the source
crates/components/src/avatar.rs — self-contained, stateless, and free to modify.