diff --git a/src/components/checkbox.rs b/src/components/checkbox.rs new file mode 100644 index 0000000..615f666 --- /dev/null +++ b/src/components/checkbox.rs @@ -0,0 +1,99 @@ +use leptos::prelude::*; + +#[component] +pub fn Checkbox( + #[prop()] checked: Signal, + #[prop(into)] on_change: Callback<(), ()>, + #[prop(into)] value: String, + #[prop(default = RwSignal::new(false))] disabled: RwSignal, +) -> impl IntoView { + view! { + + } +} + +#[component] +pub fn CheckboxList( + #[prop(default = RwSignal::new(vec![]))] selected: RwSignal>, + #[prop()] items: Vec, + #[prop(default = RwSignal::new(false))] disabled: RwSignal, +) -> impl IntoView { + view! { + // Checkbox elements go in here. Each one will have a derived signal + // that checks if the name/value of that checkbox is in the selected items + // vec. If so, display as selected. If not, clear that checkbox. + + // Somehow create a derived signal?? + +
+ { + items.into_iter().map(|item| { + let is_checked = { + let item_name = item.clone(); + move || { + // Check if this checkbox should be selected + selected.get().contains(&item_name) + } + }; + + let checked_signal = Signal::derive(is_checked); + + view! { + + } + }).collect::>() + } +
+ } +} diff --git a/src/components/radio.rs b/src/components/radio.rs new file mode 100644 index 0000000..0e3168c --- /dev/null +++ b/src/components/radio.rs @@ -0,0 +1,83 @@ +use leptos::prelude::*; + +#[component] +pub fn Radio( + #[prop()] checked: Signal, + #[prop(into)] on_change: Callback<(), ()>, + #[prop(into)] value: String, + #[prop(default = RwSignal::new(false))] disabled: RwSignal, +) -> impl IntoView { + view! { + + } +} + +#[component] +pub fn RadioList( + #[prop(default = RwSignal::new(String::new()))] selected: RwSignal, + #[prop()] items: Vec, + #[prop(default = RwSignal::new(false))] disabled: RwSignal, +) -> impl IntoView { + view! { + // Checkbox elements go in here. Each one will have a derived signal + // that checks if the name/value of that checkbox is in the selected items + // vec. If so, display as selected. If not, clear that checkbox. + + // Somehow create a derived signal?? + +
+ {items + .into_iter() + .map(|item| { + let is_checked = { + let item_name = item.clone(); + move || { selected.get() == item_name } + }; + let checked_signal = Signal::derive(is_checked); + // Check if this checkbox should be selected + + view! { + + } + }) + .collect::>()} +
+ } +}