thaw/thaw/src/mobile/nav_bar/mod.rs

74 lines
2.5 KiB
Rust
Raw Normal View History

2023-11-01 14:04:12 +08:00
mod theme;
2023-10-17 17:25:20 +08:00
use crate::{
components::*,
icon::*,
2023-11-01 14:04:12 +08:00
use_theme,
utils::{class_list::class_list, mount_style, StoredMaybeSignal},
2023-11-01 14:04:12 +08:00
Theme,
2023-10-17 17:25:20 +08:00
};
2023-06-04 17:14:41 +08:00
use leptos::*;
2023-11-01 14:04:12 +08:00
pub use theme::NavBarTheme;
2023-06-04 17:14:41 +08:00
#[component]
pub fn NavBar(
2023-10-17 17:25:20 +08:00
#[prop(optional, into)] title: MaybeSignal<String>,
2023-06-04 17:14:41 +08:00
#[prop(optional, into)] left_arrow: MaybeSignal<bool>,
2023-10-17 17:25:20 +08:00
#[prop(optional, into)] left_text: MaybeSignal<String>,
#[prop(optional, into)] on_click_left: Option<Callback<ev::MouseEvent>>,
#[prop(optional, into)] right_text: MaybeSignal<String>,
#[prop(optional, into)] on_click_right: Option<Callback<ev::MouseEvent>>,
#[prop(optional, into)] class: MaybeSignal<String>,
2023-06-04 17:14:41 +08:00
) -> impl IntoView {
2023-10-07 21:41:03 +08:00
mount_style("nav-bar", include_str!("./nav-bar.css"));
2023-11-01 14:04:12 +08:00
let theme = use_theme(Theme::light);
let css_vars = create_memo(move |_| {
theme.with(|theme| {
format!(
2023-11-05 16:03:58 +08:00
"--thaw-background-color: {};",
2023-11-01 14:04:12 +08:00
theme.nav_bar.background_color
)
})
});
2023-10-17 17:25:20 +08:00
let title: StoredMaybeSignal<_> = title.into();
let left_text: StoredMaybeSignal<_> = left_text.into();
let right_text: StoredMaybeSignal<_> = right_text.into();
2023-06-04 17:14:41 +08:00
2023-10-11 09:28:44 +08:00
let on_click_left = move |ev| {
2023-10-17 17:25:20 +08:00
if let Some(click_left) = on_click_left.as_ref() {
2023-10-09 10:28:22 +08:00
click_left.call(ev);
2023-06-04 17:32:33 +08:00
}
2023-10-11 09:28:44 +08:00
};
2023-10-09 20:56:30 +08:00
2023-10-11 09:28:44 +08:00
let on_click_right = move |ev| {
2023-10-17 17:25:20 +08:00
if let Some(click_right) = on_click_right.as_ref() {
2023-10-09 10:28:22 +08:00
click_right.call(ev);
2023-06-04 17:32:33 +08:00
}
2023-10-11 09:28:44 +08:00
};
2023-06-04 17:32:33 +08:00
2023-10-07 21:41:03 +08:00
view! {
<div class=class_list!["thaw-nav-bar", move || class.get()] style=move || css_vars.get()>
2023-10-08 09:28:13 +08:00
<If cond=MaybeSignal::derive(move || left_arrow.get() || !left_text.get().is_empty())>
2023-06-10 13:00:41 +08:00
<Then slot>
2023-11-05 16:03:58 +08:00
<div class="thaw-nav-bar__left" on:click=on_click_left>
2023-06-10 13:00:41 +08:00
<If cond=left_arrow>
<Then slot>
2023-06-30 22:25:41 +08:00
<Icon icon=Icon::from(AiIcon::AiLeftOutlined)/>
2023-06-10 13:00:41 +08:00
</Then>
</If>
2023-10-11 09:28:44 +08:00
{move || left_text.get()}
2023-06-10 13:00:41 +08:00
</div>
</Then>
</If>
2023-11-05 16:03:58 +08:00
<div class="thaw-nav-bar__center">{move || title.get()}</div>
2023-10-08 09:28:13 +08:00
<If cond=MaybeSignal::derive(move || !right_text.get().is_empty())>
2023-06-10 13:00:41 +08:00
<Then slot>
2023-11-05 16:03:58 +08:00
<div class="thaw-nav-bar__right" on:click=on_click_right>
2023-10-11 09:28:44 +08:00
{move || right_text.get()}
2023-06-10 13:00:41 +08:00
</div>
</Then>
2023-06-30 22:25:41 +08:00
</If>
2023-06-04 17:14:41 +08:00
</div>
}
2023-06-30 22:25:41 +08:00
}