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::*;
|
|
|
|
|
|
|
|
#[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-10-09 10:28:22 +08:00
|
|
|
#[prop(optional, into)] click_left: Option<Callback<ev::MouseEvent>>,
|
2023-06-10 13:00:41 +08:00
|
|
|
#[prop(optional, into)] right_text: MaybeSignal<&'static str>,
|
2023-10-09 10:28:22 +08:00
|
|
|
#[prop(optional, into)] click_right: Option<Callback<ev::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-10-11 09:28:44 +08:00
|
|
|
let on_click_left = move |ev| {
|
2023-10-09 20:56:30 +08:00
|
|
|
if let Some(click_left) = 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-09 20:56:30 +08:00
|
|
|
if let Some(click_right) = 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! {
|
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>
|
2023-10-11 09:28:44 +08:00
|
|
|
<div class="melt-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-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>
|
2023-10-11 09:28:44 +08:00
|
|
|
<div class="melt-nav-bar__right" on:click=on_click_right>
|
|
|
|
{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
|
|
|
}
|