use topcoat::{
Result,
view::{Attributes, Child, StaticClass, View, class, component, view},
};
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
#[allow(dead_code)]
pub enum AvatarSize {
Sm,
#[default]
Md,
Lg,
}
impl AvatarSize {
fn classes(self) -> StaticClass {
match self {
Self::Sm => class!("size-8 text-xs"),
Self::Md => class!("size-10 text-sm"),
Self::Lg => class!("size-12 text-base"),
}
}
}
const AVATAR: StaticClass = class!("relative flex shrink-0 overflow-hidden rounded-full");
#[component]
pub async fn avatar(
#[default]
size: AvatarSize,
#[default]
mut attrs: Attributes,
#[default]
child: Child<'_>,
) -> Result<impl View> {
Ok(view! {
<span class=(class!(AVATAR, size.classes(), attrs.remove("class"))) (attrs)>
(child)
</span>
})
}
#[component]
pub async fn avatar_image(
#[into]
#[default]
alt: String,
#[default]
mut attrs: Attributes,
) -> Result<impl View> {
Ok(view! {
<img
alt=(alt)
class=(class!(
"absolute inset-0 size-full object-cover",
attrs.remove("class"),
))
(attrs)
>
})
}
#[component]
pub async fn avatar_fallback(
#[default] mut attrs: Attributes,
#[default] child: Child<'_>,
) -> Result<impl View> {
Ok(view! {
<span
class=(class!(
"flex size-full items-center justify-center bg-foreground/10 font-medium",
"text-foreground select-none",
attrs.remove("class"),
))
(attrs)
>
(child)
</span>
})
}