mod theme; pub use theme::NavBarTheme; use crate::{icon::*, use_theme, Theme}; use leptos::*; use thaw_components::*; use thaw_utils::{class_list, mount_style, OptionalProp}; #[slot] pub struct NavBarLeft { #[prop(optional, into)] class: OptionalProp>, children: Children, } #[slot] pub struct NavBarRight { #[prop(optional, into)] class: OptionalProp>, children: Children, } #[component] pub fn NavBar( #[prop(optional, into)] title: MaybeSignal, #[prop(optional, into)] left_arrow: MaybeSignal, #[prop(optional, into)] left_text: OptionalProp>, #[prop(optional)] nav_bar_left: Option, #[prop(optional, into)] on_click_left: Option>, #[prop(optional, into)] right_text: OptionalProp>, #[prop(optional)] nav_bar_right: Option, #[prop(optional, into)] on_click_right: Option>, #[prop(optional, into)] class: OptionalProp>, ) -> impl IntoView { mount_style("nav-bar", include_str!("./nav-bar.css")); let theme = use_theme(Theme::light); let css_vars = create_memo(move |_| { theme.with(|theme| { format!( "--thaw-background-color: {};", theme.nav_bar.background_color ) }) }); let on_click_left = move |ev| { if let Some(click_left) = on_click_left.as_ref() { click_left.call(ev); } }; let on_click_right = move |ev| { if let Some(click_right) = on_click_right.as_ref() { click_right.call(ev); } }; view! {
{if let Some(NavBarLeft { class, children }) = nav_bar_left { view! {
{children()}
} .into_view() } else if let Some(left_text) = left_text.into_option() { view! {
{move || left_text.get()}
} .into_view() } else { (move || { if left_arrow.get() { view! {
} .into() } else { None } }) .into_view() }}
{move || title.get()}
{if let Some(NavBarRight { class, children }) = nav_bar_right { view! {
{children()}
} .into() } else if let Some(right_text) = right_text.into_option() { view! {
{move || right_text.get()}
} .into() } else { None }}
} }