use crate::model::*; use crate::view::weak_links::WeakComponentLink; use yew::prelude::*; use yewtil::NeqAssign; #[derive(Clone, PartialEq, Properties)] pub struct InputProps< O: 'static + VCardPropertyInputGroupObject + Clone, M: 'static + PartialEq + Clone, > { pub generated: Callback, pub weak_link: WeakComponentLink>, } #[derive(Clone, PartialEq)] pub struct PropertyGroupInputComponent< O: 'static + VCardPropertyInputGroupObject, M: 'static + PartialEq + Clone, > { pub props: InputProps, pub value: O, pub error: Option, } impl, M: 'static + PartialEq + Clone> Component for PropertyGroupInputComponent { type Message = M; type Properties = InputProps; fn create(props: ::Properties, link: yew::html::Scope) -> Self { props.weak_link.borrow_mut().replace(link); Self { props, value: O::new(), error: None, } } fn update(&mut self, msg: ::Message) -> bool { self.value.update(self.props.clone(), msg) } fn change(&mut self, props: ::Properties) -> bool { self.props.neq_assign(props) } fn view(&self) -> yew::virtual_dom::VNode { let link = self.props.weak_link.borrow().clone().unwrap(); html! {
{ self.render_error() }

{ self.value.get_title() }

{ self.value.render(&link) }
} } } impl, M: 'static + PartialEq + Clone> PropertyGroupInputComponent { /// Returns the error as `Html` fn render_error(&self) -> Html { html! { <> { if self.error.is_some() { html!{
{ self.error.clone().unwrap().msg }
} } else { html!{} } } } } }