2023-05-27 23:55:27 +08:00
|
|
|
use super::{use_tabbar, TabbarInjectionKey};
|
2023-06-30 22:25:41 +08:00
|
|
|
use crate::components::*;
|
2023-10-17 17:25:20 +08:00
|
|
|
use crate::utils::StoredMaybeSignal;
|
2023-06-30 22:25:41 +08:00
|
|
|
use crate::{icon::*, theme::use_theme, utils::mount_style::mount_style, Theme};
|
2023-05-27 23:55:27 +08:00
|
|
|
use leptos::*;
|
|
|
|
|
|
|
|
#[component]
|
|
|
|
pub fn TabbarItem(
|
2023-10-17 17:25:20 +08:00
|
|
|
#[prop(into)] key: MaybeSignal<String>,
|
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-10-07 21:41:03 +08:00
|
|
|
mount_style("tabbar-item", include_str!("./tabbar-item.css"));
|
2023-08-29 09:11:22 +08:00
|
|
|
let theme = use_theme(Theme::light);
|
|
|
|
let tabbar = use_tabbar();
|
2023-10-17 17:25:20 +08:00
|
|
|
let key: StoredMaybeSignal<_> = key.into();
|
|
|
|
let on_click = move |_| {
|
|
|
|
tabbar.set(TabbarInjectionKey::new(key.get()));
|
2023-05-27 23:55:27 +08:00
|
|
|
};
|
|
|
|
|
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();
|
2023-11-02 22:01:48 +08:00
|
|
|
theme.with(|theme| {
|
|
|
|
let font_color = theme.common.color_primary.clone();
|
2023-11-05 16:03:58 +08:00
|
|
|
css_vars.push_str(&format!("--thaw-font-color-selected: {font_color};"));
|
2023-11-02 22:01:48 +08:00
|
|
|
});
|
2023-05-27 23:55:27 +08:00
|
|
|
css_vars
|
|
|
|
});
|
|
|
|
|
2023-10-07 21:41:03 +08:00
|
|
|
view! {
|
2023-10-08 09:28:13 +08:00
|
|
|
<div
|
2023-11-05 16:03:58 +08:00
|
|
|
class="thaw-tabbar-item"
|
|
|
|
class=("thaw-tabbar-item--selected", move || tabbar.get().value == key.get())
|
2023-10-17 17:25:20 +08:00
|
|
|
on:click=on_click
|
2023-10-08 09:28:13 +08:00
|
|
|
style=move || css_vars.get()
|
|
|
|
>
|
2023-10-02 17:04:03 +08:00
|
|
|
<OptionComp value=icon let:icon>
|
2023-11-05 16:03:58 +08:00
|
|
|
<Icon icon=icon width="22px" height="22px" class="thaw-tabbar-item__icon"/>
|
2023-06-09 22:24:39 +08:00
|
|
|
</OptionComp>
|
2023-11-05 16:03:58 +08:00
|
|
|
<div class="thaw-tabbar-item__content">{children()}</div>
|
2023-05-27 23:55:27 +08:00
|
|
|
</div>
|
|
|
|
}
|
|
|
|
}
|