use leptos::*; use leptos_meta::Style; use leptos_router::{use_location, use_navigate}; use thaw::*; #[component] pub fn SiteHeader() -> impl IntoView { let theme = use_rw_theme(); let theme_name = create_memo(move |_| { theme.with(|theme| { if theme.name == *"light" { "Dark".to_string() } else { "Light".to_string() } }) }); let change_theme = Callback::new(move |_| { if theme_name.get_untracked() == "Light" { theme.set(Theme::light()); } else { theme.set(Theme::dark()); } }); let style = create_memo(move |_| { theme.with(|theme| format!("border-bottom: 1px solid {}", theme.common.border_color)) }); let search_value = create_rw_signal(String::new()); let search_all_options = store_value(gen_search_all_options()); let search_options = create_memo(move |_| { let search_value = search_value.get(); if search_value.is_empty() { return vec![]; } fn match_value(pattern: &str, value: String) -> bool { if pattern.is_empty() { return true; } if value.is_empty() { return false; } if pattern.chars().next() == value.chars().next() { return match_value(pattern.split_at(1).1, value.split_at(1).1.to_string()); } match_value(pattern, value.split_at(1).1.to_string()) } search_all_options.with_value(|options| { let search_value = search_value.to_lowercase().replace([' ', '-'], ""); let search_value = if search_value.len() > 20 { search_value.split_at(20).0 } else { &search_value }; options .iter() .filter(|option| { let label = option.label.to_lowercase().replace([' ', '-'], ""); match_value(search_value, label) }) .cloned() .collect() }) }); let on_search_select = move |path: String| { let navigate = use_navigate(); navigate(&path, Default::default()); }; let auto_complete_ref = create_component_ref::(); let handle = window_event_listener(ev::keydown, move |event| { let key = event.key(); if key == *"/" { if let Some(auto_complete_ref) = auto_complete_ref.get_untracked() { event.prevent_default(); auto_complete_ref.focus(); } } }); on_cleanup(move || handle.remove()); let menu_value = use_menu_value(change_theme); view! {
"Thaw UI"