diff options
author | jelemux <jeremias.weber@protonmail.com> | 2021-02-04 13:30:15 +0100 |
---|---|---|
committer | jelemux <jeremias.weber@protonmail.com> | 2021-02-04 13:30:15 +0100 |
commit | 69ceb1f9ec68e41029759a6fcff3168adb6df373 (patch) | |
tree | 194f21d845da5617e1c6d7fadaab380d10e472f7 /src/viewmodel/mod.rs | |
parent | 51bf8e89ce07864b70d7138bbc3958faf499cc67 (diff) | |
download | wasm-card-69ceb1f9ec68e41029759a6fcff3168adb6df373.tar.gz wasm-card-69ceb1f9ec68e41029759a6fcff3168adb6df373.tar.bz2 |
minor refactoring + comments
Diffstat (limited to 'src/viewmodel/mod.rs')
-rw-r--r-- | src/viewmodel/mod.rs | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/viewmodel/mod.rs b/src/viewmodel/mod.rs index de433de..d5d0de3 100644 --- a/src/viewmodel/mod.rs +++ b/src/viewmodel/mod.rs @@ -7,11 +7,16 @@ pub mod name; pub mod telephone; pub mod utility; + +/// Trait for types that represent the data of a vcard property used inside of a `VCardPropertyInputComponent`. pub trait VCardPropertyInputObject<C: VCardPropertyInputComponent<Self>> - where Self: Sized + where Self: Sized { + /// Function for creating a new (and empty) `VCardPropertyInputObject`. fn new() -> Self; + /// Converts each field of the `VCardPropertyInputObject` to a VCardPropertyInputField and returns them as a vector. fn get_input_fields(&self, link: &ComponentLink<C>) -> Vec<VCardPropertyInputField>; + /// Returns a `Html` representation of the `VCardPropertyInputObject`. fn render(&self, link: &ComponentLink<C>) -> Html { html!{ <div class="columns is-mobile is-multiline"> @@ -23,14 +28,19 @@ pub trait VCardPropertyInputObject<C: VCardPropertyInputComponent<Self>> </div> } } + /// Convenience function for checking if the `VCardPropertyInputObject` is empty. fn is_empty(&self) -> bool; } +/// Type for saving error messages. +/// +/// More of a placeholder for something better later on. #[derive(Debug,Clone,PartialEq)] pub struct Error { pub msg: String, } +/// Type that represents the visiual appearance of an input field. pub enum VCardPropertyInputField { Text { label: String, @@ -48,6 +58,7 @@ pub enum VCardPropertyInputField { } impl VCardPropertyInputField { + /// Returns a `Html` representation of the `VCardPropertyInputField`. pub fn render(&self) -> Html { match self { Self::Text { @@ -65,6 +76,7 @@ impl VCardPropertyInputField { } => Self::checkbox_field_input(label, id, value, onclick), } } + /// Returns an `Html` representation of a text input field with the given parameters. fn text_field_input(label: &str, id: &Option<String>, placeholder: &Option<String>, oninput: &Callback<InputData>) -> Html { html!{ <div class="field column @@ -83,6 +95,7 @@ impl VCardPropertyInputField { </div> } } + /// Returns an `Html` representation of a checkbox input field with the given parameters. fn checkbox_field_input(label: &str, id: &Option<String>, checked: &bool, onclick: &Callback<MouseEvent>) -> Html { html!{ <div class="field column |