From 7c4e3b162de551a72cff7969e07227600fab6401 Mon Sep 17 00:00:00 2001 From: Mitchell M Date: Wed, 19 Jun 2024 09:12:39 -0500 Subject: [PATCH] doc --- src/controls/button.rs | 6 +- src/controls/select.rs | 16 +++ src/controls/spacer.rs | 2 + src/controls/text_area.rs | 9 +- src/controls/text_input.rs | 10 +- src/form_builder.rs | 12 +- src/styles/grid_form.rs | 221 ++++++++++++++++++------------------- 7 files changed, 132 insertions(+), 144 deletions(-) diff --git a/src/controls/button.rs b/src/controls/button.rs index 40c6d8b..bb55e13 100644 --- a/src/controls/button.rs +++ b/src/controls/button.rs @@ -62,11 +62,7 @@ impl FormBuilder { let view = match show_when { Some(when) => { let when = move || when(fd.into(), cx.clone()); - view! { - - {view.clone()} - - } + view! { {view.clone()} } } None => view(), }; diff --git a/src/controls/select.rs b/src/controls/select.rs index ad1d42f..efeb4ad 100644 --- a/src/controls/select.rs +++ b/src/controls/select.rs @@ -13,7 +13,10 @@ pub struct SelectData { /// The options for the select. /// /// The first value is the string to display, the second is the value. + // TODO: maybe signal? pub options: Vec<(String, String)>, + /// The display text for the blank option, if there is one. + pub blank_option: Option, } impl ControlData for SelectData { @@ -107,4 +110,17 @@ impl ControlBuilder { } self } + + /// Adds a blank option as the first option for the select. + pub fn with_blank_option(mut self) -> Self { + self.data.blank_option = Some(String::new()); + self + } + + /// Adds a blank option as the first option for the select, + /// but sets the display string to the given value. + pub fn with_blank_option_displayed(mut self, display: impl ToString) -> Self { + self.data.blank_option = Some(display.to_string()); + self + } } diff --git a/src/controls/spacer.rs b/src/controls/spacer.rs index 3706a2a..7a0c82e 100644 --- a/src/controls/spacer.rs +++ b/src/controls/spacer.rs @@ -37,6 +37,8 @@ impl FormBuilder { impl VanityControlBuilder { /// Sets the height of the spacer. /// + /// This is a string to allow different units like "10px" or "1.25em". + /// /// This may or may not be respected based on the Style implementation. pub fn height(mut self, height: impl ToString) -> Self { self.data.height = Some(height.to_string()); diff --git a/src/controls/text_area.rs b/src/controls/text_area.rs index 0b81563..18236bb 100644 --- a/src/controls/text_area.rs +++ b/src/controls/text_area.rs @@ -9,9 +9,8 @@ use std::rc::Rc; #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] pub struct TextAreaData { pub name: String, - pub placeholder: Option, pub label: Option, - pub initial_text: String, + pub placeholder: Option, } impl ControlData for TextAreaData { @@ -70,10 +69,4 @@ impl ControlBuilder { self.data.placeholder = Some(placeholder.to_string()); self } - - /// Sets the intial_text for the text area. - pub fn initial_text(mut self, text: impl ToString) -> Self { - self.data.initial_text = text.to_string(); - self - } } diff --git a/src/controls/text_input.rs b/src/controls/text_input.rs index 95160c2..21bc551 100644 --- a/src/controls/text_input.rs +++ b/src/controls/text_input.rs @@ -9,9 +9,8 @@ use std::rc::Rc; #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct TextInputData { pub name: String, - pub placeholder: Option, pub label: Option, - pub initial_text: String, + pub placeholder: Option, pub input_type: &'static str, } @@ -21,7 +20,6 @@ impl Default for TextInputData { name: String::new(), placeholder: None, label: None, - initial_text: String::new(), input_type: "input", } } @@ -84,12 +82,6 @@ impl ControlBuilder { self } - /// Sets the intial_text for the text input. - pub fn initial_text(mut self, text: impl ToString) -> Self { - self.data.initial_text = text.to_string(); - self - } - /// Sets the text input to be the "password" type. pub fn password(mut self) -> Self { self.data.input_type = "password"; diff --git a/src/form_builder.rs b/src/form_builder.rs index d3440db..8e75e4c 100644 --- a/src/form_builder.rs +++ b/src/form_builder.rs @@ -121,11 +121,7 @@ impl FormBuilder { let view = match show_when { Some(when) => { let when = move || when(fd.into(), cx.clone()); - view! { - - {view.clone()} - - } + view! { {view.clone()} } } None => view(), }; @@ -268,11 +264,7 @@ impl FormBuilder { let view = match show_when { Some(when) => { let when = move || when(fd.into(), cx.clone()); - view! { - - {view.clone()} - - } + view! { {view.clone()} } } None => view(), }; diff --git a/src/styles/grid_form.rs b/src/styles/grid_form.rs index 6bb8f85..d519764 100644 --- a/src/styles/grid_form.rs +++ b/src/styles/grid_form.rs @@ -60,11 +60,7 @@ impl FormStyle for GridFormStyle { } fn group(&self, group: Rc>) -> View { - let view = view! { -
- {&group.data} -
- } + let view = view! {
{&group.data}
} .into_view(); self.custom_component(&group.styles, view) @@ -105,11 +101,7 @@ impl FormStyle for GridFormStyle { }; let view = view! { - } @@ -133,7 +125,13 @@ impl FormStyle for GridFormStyle { value_getter: Option>, ) -> View { let value_getter = move || value_getter.map(|g| g.get()); - view! { } + view! { + + } .into_view() } @@ -160,6 +158,7 @@ impl FormStyle for GridFormStyle { on:focusout=move |ev| { value_setter(event_target_value(&ev)); } + class="form_input" class=("form_input_invalid", move || validation_state.get().is_err()) /> @@ -178,25 +177,23 @@ impl FormStyle for GridFormStyle { ) -> View { let view = view! {
-
- - {move || validation_state.get().err()} -
- - + + {move || validation_state.get().err()}
+ } .into_view(); @@ -242,18 +239,18 @@ impl FormStyle for GridFormStyle { .collect_view(); let view = view! { -
- - {move || validation_state.get().err()} -
-
- {buttons_view} -
+
+ + {move || validation_state.get().err()} +
+
+ {buttons_view} +
} .into_view(); @@ -283,23 +280,23 @@ impl FormStyle for GridFormStyle { .collect_view(); let view = view! { -
- - {move || validation_state.get().err()} -
- - {options_view} - + {options_view} + } .into_view(); @@ -313,23 +310,23 @@ impl FormStyle for GridFormStyle { value_setter: Rc::ReturnType)>, ) -> View { let view = view! { - - } .into_view(); @@ -344,24 +341,25 @@ impl FormStyle for GridFormStyle { validation_state: Signal>, ) -> View { let view = view! { -
- - {move || validation_state.get().err()} -
- +
+ + {move || validation_state.get().err()} +
+ } .into_view(); @@ -376,28 +374,27 @@ impl FormStyle for GridFormStyle { validation_state: Signal>, ) -> View { let view = view! { -
- - {move || validation_state.get().err()} -
- ().ok(); - if let Some(value) = value { - value_setter(value); - } +
+ + {move || validation_state.get().err()} +
+ ().ok(); + if let Some(value) = value { + value_setter(value); } - - class="form_input" - /> + } + /> } .into_view();