From 5a03734b6767fed04c0913384584d8f59dc597ea Mon Sep 17 00:00:00 2001 From: jelemux Date: Tue, 24 Nov 2020 21:58:51 +0100 Subject: add traits for viewmodel and view --- src/view/input_objects/mod.rs | 106 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 src/view/input_objects/mod.rs (limited to 'src/view/input_objects/mod.rs') diff --git a/src/view/input_objects/mod.rs b/src/view/input_objects/mod.rs new file mode 100644 index 0000000..7c0fdff --- /dev/null +++ b/src/view/input_objects/mod.rs @@ -0,0 +1,106 @@ +use vcard::properties; +use yew::prelude::*; +use super::VCardPropertyInputComponent; + +pub mod address; +pub mod birthday; +pub mod name; +pub mod photo; +pub mod telephone; +pub mod utility; + +pub trait VCardPropertyInputObject> + where Self: Sized +{ + fn new() -> Self; + fn get_input_fields(&self, link: &ComponentLink) -> Vec; + fn render(&self, link: &ComponentLink) -> Html { + html!{ +
+ { + for self.get_input_fields(link).iter().map(|field| + field.render() + ) + } +
+ } + } + fn to_vcard_property(&self) -> Result; +} + +#[derive(Debug)] +pub struct VCardPropertyInputError { + msg: String, +} + +pub enum VCardPropertyInputField { + Text { + label: String, + id: Option, + placeholder: Option, + oninput: Callback, + value: String, + }, + CheckBox { + label: String, + id: Option, + onclick: Callback, + value: bool, + }, +} + +impl VCardPropertyInputField { + pub fn render(&self) -> Html { + match self { + Self::Text { + label, + id, + placeholder, + oninput, + value: _, + } => Self::text_field_input(label, id, placeholder, oninput), + Self::CheckBox { + label, + id, + onclick, + value, + } => Self::checkbox_field_input(label, id, value, onclick), + } + } + fn text_field_input(label: &str, id: &Option, placeholder: &Option, oninput: &Callback) -> Html { + html!{ +
+ +
+ +
+
+ } + } + fn checkbox_field_input(label: &str, id: &Option, checked: &bool, onclick: &Callback) -> Html { + html!{ +
+ +
+ } + } +} \ No newline at end of file -- cgit v1.2.3