thaw/src/mobile/tabbar/tabbar_item.rs

41 lines
1.4 KiB
Rust
Raw Normal View History

2023-05-27 23:55:27 +08:00
use super::{use_tabbar, TabbarInjectionKey};
2023-06-30 22:25:41 +08:00
use crate::components::*;
use crate::{icon::*, theme::use_theme, utils::mount_style::mount_style, Theme};
2023-05-27 23:55:27 +08:00
use leptos::*;
use stylers::style_sheet_str;
#[component]
pub fn TabbarItem(
#[prop(into)] name: MaybeSignal<&'static str>,
2023-06-09 22:24:39 +08:00
#[prop(optional, into)] icon: Option<Icon>,
2023-05-27 23:55:27 +08:00
children: Children,
) -> impl IntoView {
2023-06-30 22:25:41 +08:00
let class_name = mount_style("tabbar-item", || {
style_sheet_str!("./src/mobile/tabbar/tabbar-item.css")
});
2023-08-29 09:11:22 +08:00
let theme = use_theme(Theme::light);
let tabbar = use_tabbar();
2023-05-27 23:55:27 +08:00
let onclick_select = move |_| {
tabbar.set(TabbarInjectionKey::new(name.get().to_string()));
};
2023-08-29 09:11:22 +08:00
let css_vars = create_memo(move |_| {
2023-05-27 23:55:27 +08:00
let mut css_vars = String::new();
let theme = theme.get();
let font_color = theme.common.color_primary.clone();
css_vars.push_str(&format!("--font-color-selected: {font_color};"));
css_vars
});
2023-08-29 09:11:22 +08:00
view! { class=class_name,
2023-05-27 23:55:27 +08:00
<div class="melt-tabbar-item" class=("melt-tabbar-item--selected", move || tabbar.get().value == name.get()) on:click=onclick_select style=move || css_vars.get()>
2023-06-09 22:24:39 +08:00
<OptionComp value=icon bind:icon>
<Icon icon=icon width="22px" height="22px" class="melt-tabbar-item__icon"/>
</OptionComp>
2023-05-27 23:55:27 +08:00
<div class="melt-tabbar-item__content">
2023-08-29 09:11:22 +08:00
{ children() }
2023-05-27 23:55:27 +08:00
</div>
</div>
}
}