Edit Component
Adding Avatar to your project is simple:
-
Make sure your project is set up with Yew. Follow their Getting Started Guide for setup instructions.
-
Add the Avatar component to your dependencies by including it in your Cargo.toml file:
cargo add avatar --features=yew
-
Import the Avatar, Image, and Fallback components into your Yew component and start using them in your app.
use avatar::yew::{Avatar, Image, Fallback};
use yew::prelude::*;
#[function_component(MyAvatar)]
pub fn my_avatar() -> Html {
html! {
<Avatar aria_label="Ferris Prophet">
<Image src="https://i.pravatar.cc/300" alt="Ferris Prophet" />
<Fallback>{"FP"}</Fallback>
</Avatar>
}
}
use avatar::yew::{Avatar, Fallback};
use avatar::Color;
use yew::prelude::*;
#[function_component(InitialsAvatar)]
pub fn initials_avatar() -> Html {
html! {
<Avatar aria_label="Ferris Prophet">
<Fallback color={Some(Color::Accent)}>{"FP"}</Fallback>
</Avatar>
}
}
use avatar::yew::{Avatar, Fallback};
use avatar::{Color, Size};
use yew::prelude::*;
#[function_component(SizedAvatars)]
pub fn sized_avatars() -> Html {
html! {
<>
<Avatar size={Size::Sm}><Fallback color={Some(Color::Success)}>{"SM"}</Fallback></Avatar>
<Avatar size={Size::Md}><Fallback color={Some(Color::Warning)}>{"MD"}</Fallback></Avatar>
<Avatar size={Size::Lg}><Fallback color={Some(Color::Danger)}>{"LG"}</Fallback></Avatar>
</>
}
}
Prevents a flash-of-fallback on fast image loads.
use avatar::yew::{Avatar, Image, Fallback};
use yew::prelude::*;
#[function_component(DelayedFallback)]
pub fn delayed_fallback() -> Html {
html! {
<Avatar aria_label="User">
<Image src="https://i.pravatar.cc/300" alt="User" />
<Fallback delay_ms={600}>{"US"}</Fallback>
</Avatar>
}
}
| Property | Type | Description | Default |
size | Size | Dimensions of the avatar. | Size::Md |
color | Color | Color theme for the fallback. | Color::Default |
variant | Variant | Default (solid) or Soft (tinted). | Variant::Default |
class | &'static str | Extra CSS classes on the root element. | "" |
style | &'static str | Extra inline CSS on the root element. | "" |
id | &'static str | id attribute on the root element. | "" |
aria_label | &'static str | Accessible name for screen readers. | "Avatar" |
tabindex | &'static str | Tab focus order. | "-1" |
container_class | &'static str | CSS class on the root <span>. | "avatar" |
container_style | &'static str | Extra inline CSS on the root <span>. | "" |
| Property | Type | Description | Default |
src | &'static str | Image source URL. | "" |
srcset | &'static str | Responsive srcset attribute. | "" |
sizes | &'static str | Responsive sizes attribute. | "" |
alt | &'static str | Alternative text (required for a11y). | "" |
class | &'static str | CSS class on the <img>. | "avatar__image" |
style | &'static str | Extra inline CSS on the <img>. | "" |
loading | &'static str | "lazy" or "eager". | "eager" |
crossorigin | &'static str | CORS setting. | "" |
decoding | &'static str | "auto", "async", or "sync". | "auto" |
referrerpolicy | &'static str | Referrer policy. | "" |
id | &'static str | id on the <img>. | "" |
width | Option<u32> | Pixel width. | None |
height | Option<u32> | Pixel height. | None |
on_load | Callback<Event> | Called when image loads. | no-op |
on_error | Callback<Event> | Called when image fails. | no-op |
| Property | Type | Description | Default |
delay_ms | u32 | Ms before fallback appears. | 0 |
color | Option<Color> | Color override. | None (inherits from Avatar) |
variant | Option<Variant> | Variant override. | None (inherits from Avatar) |
class | &'static str | CSS class on the fallback <span>. | "avatar__fallback" |
style | &'static str | Extra inline CSS on the fallback. | "" |
id | &'static str | id on the fallback <span>. | "" |
Image and Fallback must be used inside an Avatar component, they rely on its context.
- The fallback is shown until the image loads. Set
delay_ms to prevent a flash on fast connections.
- Use
Color and Variant props to match your design system.
- Looking for layered or clipped groups? Check out the Group API!
You can import Avatar RS directly into your project to customize and modify it using the opensass cli:
os add avatar yew
Edit Component
Adding Avatar to your project is simple:
-
Make sure your project is set up with Dioxus. Follow their Getting Started Guide for setup instructions.
-
Add the Avatar component to your dependencies:
cargo add avatar --features=dio
-
Import and use the Avatar, Image, and Fallback components.
use avatar::dioxus::{Avatar, Image, Fallback};
use dioxus::prelude::*;
fn MyAvatar() -> Element {
rsx! {
Avatar { aria_label: "Ferris Prophet",
Image { src: "https://i.pravatar.cc/300", alt: "Ferris Prophet" }
Fallback { "FP" }
}
}
}
use avatar::dioxus::{Avatar, Fallback};
use avatar::Color;
use dioxus::prelude::*;
fn InitialsAvatar() -> Element {
rsx! {
Avatar { aria_label: "Ferris Prophet",
Fallback { color: Color::Accent, "FP" }
}
}
}
use avatar::dioxus::{Avatar, Fallback};
use avatar::{Color, Size};
use dioxus::prelude::*;
fn SizedAvatars() -> Element {
rsx! {
Avatar { size: Size::Sm, Fallback { color: Color::Success, "SM" } }
Avatar { size: Size::Md, Fallback { color: Color::Warning, "MD" } }
Avatar { size: Size::Lg, Fallback { color: Color::Danger, "LG" } }
}
}
use avatar::dioxus::{Avatar, Image, Fallback};
use dioxus::prelude::*;
fn DelayedFallback() -> Element {
rsx! {
Avatar { aria_label: "User",
Image { src: "https://i.pravatar.cc/300", alt: "User" }
Fallback { delay_ms: 600, "US" }
}
}
}
| Property | Type | Description | Default |
size | Size | Dimensions of the avatar. | Size::Md |
color | Color | Fallback color theme. | Color::Default |
variant | Variant | Default or Soft. | Variant::Default |
class | &'static str | Extra CSS classes. | "" |
style | &'static str | Extra inline CSS. | "" |
id | &'static str | id attribute. | "" |
aria_label | &'static str | Accessible name. | "Avatar" |
tabindex | &'static str | Tab order. | "-1" |
container_class | &'static str | Class on root <span>. | "avatar" |
container_style | &'static str | Inline CSS on root <span>. | "" |
| Property | Type | Description | Default |
src | &'static str | Image URL. | "" |
srcset | &'static str | Responsive srcset. | "" |
sizes | &'static str | Responsive sizes. | "" |
alt | &'static str | Alt text (required). | "" |
class | &'static str | CSS class. | "avatar__image" |
style | &'static str | Extra inline CSS. | "" |
loading | &'static str | "lazy" or "eager". | "eager" |
crossorigin | &'static str | CORS setting. | "" |
decoding | &'static str | Decoding hint. | "auto" |
id | &'static str | id on the <img>. | "" |
width | Option<u32> | Pixel width. | None |
height | Option<u32> | Pixel height. | None |
on_load | Option<EventHandler<...>> | Load callback. | None |
on_error | Option<EventHandler<...>> | Error callback. | None |
| Property | Type | Description | Default |
delay_ms | u32 | Ms before visible. | 0 |
color | Color | Color override. | Color::Default |
variant | Variant | Variant override. | Variant::Default |
class | &'static str | CSS class. | "avatar__fallback" |
style | &'static str | Extra inline CSS. | "" |
id | &'static str | id attribute. | "" |
- Child components must be nested inside
Avatar, they rely on context.
delay_ms prevents a flash-of-fallback on fast connections.
- Looking for layered or clipped groups? Check out the Group API!
You can import Avatar RS directly into your project to customize and modify it using the opensass cli:
os add avatar dio
Edit Component
Adding Avatar to your project is simple:
-
Make sure your project is set up with Leptos. Follow their Getting Started Guide for setup instructions.
-
Add the Avatar component to your dependencies:
cargo add avatar --features=lep
-
Import and use the Avatar, Image, and Fallback components.
use avatar::leptos::{Avatar, Image, Fallback};
use leptos::prelude::*;
#[component]
fn MyAvatar() -> impl IntoView {
view! {
<Avatar aria_label="Ferris Prophet">
<Image src="https://i.pravatar.cc/300" alt="Ferris Prophet" />
<Fallback>"FP"</Fallback>
</Avatar>
}
}
use avatar::leptos::{Avatar, Fallback};
use avatar::Color;
use leptos::prelude::*;
#[component]
fn InitialsAvatar() -> impl IntoView {
view! {
<Avatar aria_label="Ferris Prophet">
<Fallback color=Color::Accent>"FP"</Fallback>
</Avatar>
}
}
use avatar::leptos::{Avatar, Fallback};
use avatar::{Color, Size};
use leptos::prelude::*;
#[component]
fn SizedAvatars() -> impl IntoView {
view! {
<Avatar size=Size::Sm><Fallback color=Color::Success>"SM"</Fallback></Avatar>
<Avatar size=Size::Md><Fallback color=Color::Warning>"MD"</Fallback></Avatar>
<Avatar size=Size::Lg><Fallback color=Color::Danger>"LG"</Fallback></Avatar>
}
}
use avatar::leptos::{Avatar, Image, Fallback};
use leptos::prelude::*;
#[component]
fn DelayedFallback() -> impl IntoView {
view! {
<Avatar aria_label="User">
<Image src="https://i.pravatar.cc/300" alt="User" />
<Fallback delay_ms=600>"US"</Fallback>
</Avatar>
}
}
| Property | Type | Description | Default |
size | Size | Dimensions of the avatar. | Size::Md |
class | &'static str | Extra CSS classes. | "" |
style | &'static str | Extra inline CSS. | "" |
id | &'static str | id attribute. | "" |
aria_label | &'static str | Accessible name. | "Avatar" |
tabindex | &'static str | Tab order. | "-1" |
container_class | &'static str | Class on root <span>. | "avatar" |
container_style | &'static str | CSS on root <span>. | "" |
| Property | Type | Description | Default |
src | &'static str | Image URL. | "" |
srcset | &'static str | Responsive srcset. | "" |
sizes | &'static str | Responsive sizes. | "" |
alt | &'static str | Alt text (required). | "" |
class | &'static str | CSS class. | "avatar__image" |
style | &'static str | Extra inline CSS. | "" |
loading | &'static str | "lazy" or "eager". | "eager" |
crossorigin | &'static str | CORS setting. | "" |
decoding | &'static str | Decoding hint. | "auto" |
id | &'static str | id on the <img>. | "" |
width | Option<u32> | Pixel width. | None |
height | Option<u32> | Pixel height. | None |
on_load | Option<Callback<web_sys::Event>> | Load callback. | None |
on_error | Option<Callback<web_sys::Event>> | Error callback. | None |
| Property | Type | Description | Default |
delay_ms | u32 | Ms before visible. | 0 |
color | Color | Color theme. | Color::Default |
variant | Variant | Default or Soft. | Variant::Default |
class | &'static str | CSS class. | "avatar__fallback" |
style | &'static str | Extra inline CSS. | "" |
id | &'static str | id attribute. | "" |
- Child components must be nested inside
Avatar, they rely on a shared RwSignal context.
- Use
delay_ms to suppress the fallback flash on fast connections.
- Looking for layered or clipped groups? Check out the Group API!
You can import Avatar RS directly into your project to customize and modify it using the opensass cli:
os add avatar lep