From dd6df30370b777111fba8f3b41e5d389faffcc86 Mon Sep 17 00:00:00 2001 From: Thomas Gideon Date: Mon, 6 Sep 2021 17:17:51 -0400 Subject: [PATCH] Upgrade yew --- Cargo.toml | 4 ++-- src/alert/bus.rs | 6 +++--- src/alert/mod.rs | 22 ++++++++++++++++------ src/breadcrumb/item.rs | 2 +- src/button/mod.rs | 30 +++++++++++++++++++++++++++--- src/card/body.rs | 2 +- src/card/header.rs | 2 +- src/container.rs | 2 +- src/input/mod.rs | 21 +++++++++++++++++++-- src/input/textarea.rs | 8 +++----- src/lib.rs | 15 +++++++++++++++ src/prelude/border.rs | 12 ++++++------ src/prelude/color.rs | 4 ++++ src/prelude/margin.rs | 8 ++++---- src/prelude/mod.rs | 6 +++--- src/prelude/padding.rs | 8 ++++---- src/props.rs | 42 ++++++++++++++++-------------------------- src/render.rs | 6 +++--- 18 files changed, 129 insertions(+), 71 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5912900..134a09c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bootstrap-rs" -version = "0.4.0" +version = "0.5.0" authors = ["Thomas Gideon "] edition = "2018" @@ -11,7 +11,7 @@ crate-type = ["cdylib", "rlib"] validate = [ "validator" ] [dependencies] -yew = "~0.17.2" +yew = "^0.18.0" log = "~0.4.8" serde_json = "^1.0.40" serde = "^1.0.98" diff --git a/src/alert/bus.rs b/src/alert/bus.rs index da80067..ac81475 100644 --- a/src/alert/bus.rs +++ b/src/alert/bus.rs @@ -17,10 +17,10 @@ pub enum Request { Clear, } -impl Into> for &Request { - fn into(self) -> Option<(Color, String)> { +impl From<&Request> for Option<(Color, String)> { + fn from(request: &Request) -> Option<(Color, String)> { use Request::*; - match self { + match request { Primary(alert) => Some((Color::Primary, alert.clone())), Secondary(alert) => Some((Color::Secondary, alert.clone())), Success(alert) => Some((Color::Success, alert.clone())), diff --git a/src/alert/mod.rs b/src/alert/mod.rs index 64e8412..8443070 100644 --- a/src/alert/mod.rs +++ b/src/alert/mod.rs @@ -11,6 +11,8 @@ use yew::prelude::*; pub struct Alert { link: ComponentLink, props: Props, + prefix: String, + prefixed_color: String, } impl Component for Alert { @@ -18,7 +20,12 @@ impl Component for Alert { type Message = (); fn create(props: Self::Properties, link: ComponentLink) -> Self { - Self { link, props } + Self { + link, + props, + prefix: String::from("alert"), + prefixed_color: String::default(), + } } fn update(&mut self, _: Self::Message) -> ShouldRender { @@ -27,6 +34,9 @@ impl Component for Alert { } fn change(&mut self, props: Self::Properties) -> ShouldRender { + if props.color != self.props.color { + self.prefixed_color = props.color.with_prefix(&self.prefix); + } render_if_ne(&mut self.props, props) } @@ -45,10 +55,10 @@ impl Component for Alert { }; - render::render_with_prefix( - &self.props, - vec!["alert", &self.props.color.with_prefix("alert")], - html, - ) + render::render_with_prefix(&self.props, vec![&self.prefix, &self.prefixed_color], html) } + + fn rendered(&mut self, _first_render: bool) {} + + fn destroy(&mut self) {} } diff --git a/src/breadcrumb/item.rs b/src/breadcrumb/item.rs index 3d0b1d0..962728d 100644 --- a/src/breadcrumb/item.rs +++ b/src/breadcrumb/item.rs @@ -133,6 +133,6 @@ mod tests { > }; - assert_eq!(expected, item.view()); + crate::test::assert_attrs_eq(expected, item.view()); } } diff --git a/src/button/mod.rs b/src/button/mod.rs index 2444c9f..20c243b 100644 --- a/src/button/mod.rs +++ b/src/button/mod.rs @@ -5,8 +5,11 @@ mod toolbar; use self::props::Props; pub use self::{group::ButtonGroup, toolbar::ButtonToolbar}; use crate::{prelude::*, render}; -use std::fmt::{Display, Formatter, Result}; -use yew::prelude::*; +use std::{ + borrow::Cow, + fmt::{Display, Formatter, Result}, +}; +use yew::{html::IntoOptPropValue, prelude::*}; #[derive(Clone, PartialEq)] pub enum ButtonType { @@ -15,6 +18,27 @@ pub enum ButtonType { Reset, } +impl IntoOptPropValue> for ButtonType { + fn into_opt_prop_value(self) -> Option> { + match self { + Self::Button => Some(Cow::from("button")), + Self::Submit => Some(Cow::from("submit")), + Self::Reset => Some(Cow::from("reset")), + } + } +} + +impl IntoOptPropValue> for &ButtonType { + fn into_opt_prop_value(self) -> Option> { + use ButtonType::*; + match self { + Button => Some(Cow::from("button")), + Submit => Some(Cow::from("submit")), + Reset => Some(Cow::from("reset")), + } + } +} + impl Default for ButtonType { fn default() -> Self { ButtonType::Button @@ -57,7 +81,7 @@ impl Component for Button { fn view(&self) -> Html { let html = html! {