use leptos::logging::log; use leptos::prelude::*; use leptos_router::components::A; use crate::components::utils; #[derive(Debug, Clone)] pub struct NavListInfo { pub text: Vec, pub id: String, pub slug: String, } #[component] fn NavListItem( #[prop(into)] name: Signal, #[prop(into)] value: Signal, #[prop(into)] text: Signal>, #[prop(into)] slug: Signal, #[prop(into)] selected: Signal, #[prop(into)] on_change: Callback<()>, ) -> impl IntoView { let linked_info = Signal::derive(move || text.get() .get(0) .cloned() .unwrap_or_default() ); let other_info = Signal::derive(move || text.get() .iter() .cloned() .skip(1) .collect::>() ); view! { } } #[component] fn NavListCheckbox( #[prop(into)] selected: Signal, #[prop(into)] on_change: Callback<()>, #[prop(into)] name: Signal, #[prop(into)] value: Signal, ) -> impl IntoView { let id = Memo::new(move |_| utils::create_unique_id(&name.get(), &value.get())); view! { } } /// # Selectable Nav-List Component /// /// This component takes a `Vec` to show a list. The list contains links that append /// the `NavListItem::slug` to the current path, and each item is selectable. The list of selected /// items is usable in this component's parent. #[component] pub fn SelectableNavList( #[prop(into)] selected: RwSignal>, #[prop(into)] items: Signal>, #[prop(into)] headers: Signal>, #[prop(into)] name: Signal, ) -> impl IntoView { let all_selected = RwSignal::new(false); let all_selected_change = move || { if all_selected.get() { log!("Unchecking all values."); all_selected.set(false); selected.set(Vec::new()); } else { log!("Checking all values."); all_selected.set(true); selected.set( items .get() .iter() .map(|info| info.id.clone()) .collect::>() ); } }; view! {
// Header block - contains evenly spaced headers and the "select all" checkbox. // Include a checkbox here that's got the same style as the items. This maintains spacing. // All headers *must* be evenly spaced, otherwise the list starts getting confusing.
{header_text}
// Items block - contains constructed items. These are selectable. } } />
} }