synpad 0.1.0

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

/// Tab item data.
#[derive(Clone, Debug, PartialEq)]
pub struct TabItem {
    pub id: String,
    pub label: String,
}

/// Tab navigation component.
#[component]
pub fn Tabs(
    tabs: Vec<TabItem>,
    active_tab: String,
    on_change: EventHandler<String>,
) -> Element {
    rsx! {
        div {
            class: "tabs",
            for tab in tabs.iter() {
                {
                    let tab_id = tab.id.clone();
                    let tab_label = tab.label.clone();
                    let is_active = tab.id == active_tab;
                    rsx! {
                        button {
                            class: if is_active {
                                "tabs__tab tabs__tab--active"
                            } else {
                                "tabs__tab"
                            },
                            onclick: move |_| on_change.call(tab_id.clone()),
                            "{tab_label}"
                        }
                    }
                }
            }
        }
    }
}