use yew::prelude::*; use vcard::properties; use super::input_objects::name::*; use super::input_objects::VCardPropertyInputObject; use super::VCardPropertyInputComponent; pub struct NameView { link: ComponentLink, value: Name, oninput: Callback, errors: Vec, } pub enum Msg { UpdatePrefix(String), UpdateFirstName(String), UpdateMiddleName(String), UpdateLastName(String), UpdateSuffix(String), } #[derive(Clone, PartialEq, Properties)] pub struct Props { pub oninput: Callback, } impl VCardPropertyInputComponent for NameView { fn get_input_object(&self) -> Name { self.value.clone() } fn get_title(&self) -> String { "Name".to_string() } fn get_errors(&self) -> Vec { self.errors.clone() } } impl Component for NameView { type Message = Msg; type Properties = Props; fn create(props: ::Properties, link: yew::html::Scope) -> Self { Self { link, value: Name::new(), oninput: props.oninput, errors: vec![], } } fn update(&mut self, msg: ::Message) -> bool { match msg { Msg::UpdatePrefix(p) => self.value.prefix = p, Msg::UpdateFirstName(f) => self.value.first_name = f, Msg::UpdateMiddleName(m) => self.value.middle_name = m, Msg::UpdateLastName(l) => self.value.last_name = l, Msg::UpdateSuffix(s) => self.value.suffix = s, }; self.oninput.emit(self.value.clone()); true } fn change(&mut self, props: ::Properties) -> bool { self.oninput = props.oninput; true } fn view(&self) -> yew::virtual_dom::VNode { html!{
{ self.render_errors() }

{ self.get_title() }

{ self.get_input_object().render(&self.link) }
} } }