synpad 0.1.0

A full-featured Matrix chat client built with Dioxus
use dioxus::prelude::*;

use crate::utils::room_helpers::{display_name_initials, user_color};

/// Avatar component for users and rooms.
///
/// Shows an image if `url` is provided, otherwise shows initials
/// on a colored background.
#[component]
pub fn Avatar(
    name: String,
    url: Option<String>,
    #[props(default = 36)] size: u32,
) -> Element {
    let initials = display_name_initials(&name);
    let bg_color = user_color(&name);

    rsx! {
        div {
            class: "avatar",
            style: "width: {size}px; height: {size}px; min-width: {size}px;",

            if let Some(ref src) = url {
                img {
                    class: "avatar__image",
                    src: "{src}",
                    alt: "{name}",
                    width: "{size}",
                    height: "{size}",
                }
            } else {
                div {
                    class: "avatar__fallback",
                    style: "background-color: {bg_color}; font-size: {size / 2}px;",
                    "{initials}"
                }
            }
        }
    }
}