thaw/src/mobile/nav_bar/mod.rs

52 lines
1.8 KiB
Rust
Raw Normal View History

2023-06-30 22:25:41 +08:00
use crate::{components::*, icon::*, utils::mount_style::mount_style};
2023-06-04 17:14:41 +08:00
use leptos::*;
2023-06-04 17:32:33 +08:00
use web_sys::MouseEvent;
2023-06-04 17:14:41 +08:00
#[component]
pub fn NavBar(
2023-06-10 13:00:41 +08:00
#[prop(optional, into)] title: MaybeSignal<&'static str>,
2023-06-04 17:14:41 +08:00
#[prop(optional, into)] left_arrow: MaybeSignal<bool>,
2023-06-10 13:00:41 +08:00
#[prop(optional, into)] left_text: MaybeSignal<&'static str>,
2023-06-04 17:32:33 +08:00
#[prop(optional, into)] click_left: Option<SignalSetter<MouseEvent>>,
2023-06-10 13:00:41 +08:00
#[prop(optional, into)] right_text: MaybeSignal<&'static str>,
2023-06-04 17:32:33 +08:00
#[prop(optional, into)] click_right: Option<SignalSetter<MouseEvent>>,
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-06-04 17:14:41 +08:00
2023-06-04 17:32:33 +08:00
let onclick_left = move |ev| {
if let Some(click_left) = click_left {
click_left.set(ev);
}
};
let onclick_right = move |ev| {
if let Some(click_right) = click_right {
click_right.set(ev);
}
};
2023-10-07 21:41:03 +08:00
view! {
2023-06-04 17:14:41 +08:00
<div class="melt-nav-bar">
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>
<div class="melt-nav-bar__left" on:click=onclick_left>
<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-08 09:28:13 +08:00
{left_text.get()}
2023-06-10 13:00:41 +08:00
</div>
</Then>
</If>
2023-10-08 09:28:13 +08:00
<div class="melt-nav-bar__center">{move || title.get()}</div>
<If cond=MaybeSignal::derive(move || !right_text.get().is_empty())>
2023-06-10 13:00:41 +08:00
<Then slot>
<div class="melt-nav-bar__right" on:click=onclick_right>
2023-10-08 09:28:13 +08:00
{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
}