thaw/src/mobile/nav_bar/mod.rs

57 lines
2 KiB
Rust
Raw Normal View History

2023-06-10 13:00:41 +08:00
use crate::{utils::mount_style::mount_style, components::*};
2023-06-04 17:14:41 +08:00
use leptos::*;
use leptos_icons::*;
use stylers::style_sheet_str;
2023-06-04 17:32:33 +08:00
use web_sys::MouseEvent;
2023-06-04 17:14:41 +08:00
#[component]
pub fn NavBar(
cx: Scope,
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 {
let class_name = mount_style("nav-bar", || style_sheet_str!("./src/mobile/nav_bar/nav-bar.css"));
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-06-04 17:14:41 +08:00
view! { cx, class=class_name,
<div class="melt-nav-bar">
2023-06-10 13:00:41 +08:00
<If cond=MaybeSignal::derive(cx, move || left_arrow.get() || !left_text.get().is_empty())>
<Then slot>
<div class="melt-nav-bar__left" on:click=onclick_left>
<If cond=left_arrow>
<Then slot>
<Icon icon=AiIcon::AiLeftOutlined/>
</Then>
</If>
{ left_text.get() }
</div>
</Then>
</If>
2023-06-04 17:14:41 +08:00
<div class="melt-nav-bar__center">
{ move || title.get() }
</div>
2023-06-10 13:00:41 +08:00
<If cond=MaybeSignal::derive(cx, move || !right_text.get().is_empty())>
<Then slot>
<div class="melt-nav-bar__right" on:click=onclick_right>
{ right_text.get() }
</div>
</Then>
</If>
2023-06-04 17:14:41 +08:00
</div>
}
}