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
};
- assert_eq!(expected, comp.view());
+ crate::test::assert_attrs_eq(expected, comp.view());
}
}
diff --git a/src/container.rs b/src/container.rs
index 58954b5..731d550 100644
--- a/src/container.rs
+++ b/src/container.rs
@@ -43,6 +43,6 @@ mod tests {
};
- assert_eq!(expected, container.view());
+ crate::test::assert_attrs_eq(expected, container.view());
}
}
diff --git a/src/input/mod.rs b/src/input/mod.rs
index 14f0519..03cf5e4 100644
--- a/src/input/mod.rs
+++ b/src/input/mod.rs
@@ -6,9 +6,14 @@ use self::props::Props;
pub use self::{group::InputGroup, textarea::TextArea};
use crate::{prelude::*, render};
use std::fmt::{Display, Formatter, Result as FmtResult};
+use std::{
+ borrow::Cow,
+ fmt::{Display, Formatter, Result as FmtResult},
+};
#[cfg(feature = "validate")]
use validator::ValidationErrors;
use yew::prelude::*;
+use yew::{html::IntoOptPropValue, prelude::*};
#[derive(Clone, PartialEq)]
pub enum InputType {
@@ -19,6 +24,18 @@ pub enum InputType {
Color,
}
+impl IntoOptPropValue> for &InputType {
+ fn into_opt_prop_value(self) -> Option> {
+ match self {
+ InputType::Text => Some(Cow::from("text")),
+ InputType::Date => Some(Cow::from("date")),
+ InputType::DateTime => Some(Cow::from("datetime-local")),
+ InputType::Checkbox => Some(Cow::from("checkbox")),
+ InputType::Color => Some(Cow::from("color")),
+ }
+ }
+}
+
impl Display for InputType {
fn fmt(&self, f: &mut Formatter) -> FmtResult {
match self {
@@ -78,9 +95,9 @@ impl Component for Input {
let html = html! {
};
render::render_with_prefix(&self.props, prefix, html)
diff --git a/src/input/textarea.rs b/src/input/textarea.rs
index 16eed41..65d8b54 100644
--- a/src/input/textarea.rs
+++ b/src/input/textarea.rs
@@ -40,16 +40,14 @@ impl Component for TextArea {
#[cfg(not(feature = "validate"))]
fn view(&self) -> Html {
- let prefix = vec!["form-control", &valid_as_class(&self.props.valid)];
- let html = {
- html! {
+ let prefix = vec!["form-control", valid_as_class(&self.props.valid)];
+ let html = html! {
- }
};
render::render_with_prefix(&self.props, prefix, html)
}
diff --git a/src/lib.rs b/src/lib.rs
index 90fd99a..6ece964 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -20,3 +20,18 @@ pub use self::{
input::{Input, InputGroup, TextArea},
jumbotron::Jumbotron,
};
+
+#[cfg(test)]
+pub(crate) mod test {
+ use yew::virtual_dom::VNode;
+
+ pub(crate) fn assert_attrs_eq(expected: VNode, comp: VNode) {
+ match (expected, comp) {
+ (VNode::VTag(mut expected), VNode::VTag(mut comp)) => assert_eq!(
+ expected.attributes.get_mut_index_map(),
+ comp.attributes.get_mut_index_map()
+ ),
+ _ => panic!("One or both components were not tags!"),
+ }
+ }
+}
diff --git a/src/prelude/border.rs b/src/prelude/border.rs
index e8f1566..514909c 100644
--- a/src/prelude/border.rs
+++ b/src/prelude/border.rs
@@ -1,15 +1,15 @@
use super::{Color, Edge};
-use crate::props::IntoBsClass;
+use yew::Classes;
#[derive(Clone, PartialEq)]
pub struct Border(pub Edge, pub Color);
-impl IntoBsClass for Border {
- fn as_classname(&self) -> String {
- let edge = match self.0 {
+impl From<&&Border> for Classes {
+ fn from(border: &&Border) -> Classes {
+ let edge = match border.0 {
Edge::All => "border".to_owned(),
- _ => self.0.with_prefix("border"),
+ _ => border.0.with_prefix("border"),
};
- format!("{} {}", edge, self.1.with_prefix("border"))
+ Classes::from(format!("{} {}", edge, border.1.with_prefix("border")))
}
}
diff --git a/src/prelude/color.rs b/src/prelude/color.rs
index bc0b12a..cbbd786 100644
--- a/src/prelude/color.rs
+++ b/src/prelude/color.rs
@@ -1,3 +1,5 @@
+use yew::html::ImplicitClone;
+
#[derive(Clone, PartialEq)]
pub enum Color {
Primary,
@@ -12,6 +14,8 @@ pub enum Color {
Unset,
}
+impl ImplicitClone for Color {}
+
impl Default for Color {
fn default() -> Self {
Self::Unset
diff --git a/src/prelude/margin.rs b/src/prelude/margin.rs
index 01cc816..190c089 100644
--- a/src/prelude/margin.rs
+++ b/src/prelude/margin.rs
@@ -1,10 +1,10 @@
-use crate::props::IntoBsClass;
+use yew::Classes;
#[derive(Debug, Clone, PartialEq)]
pub struct Margin(pub super::Edge, pub usize);
-impl IntoBsClass for Margin {
- fn as_classname(&self) -> String {
- format!("m{}-{}", self.0, self.1)
+impl From<&&Margin> for Classes {
+ fn from(margin: &&Margin) -> Classes {
+ Classes::from(format!("m{}-{}", margin.0, margin.1))
}
}
diff --git a/src/prelude/mod.rs b/src/prelude/mod.rs
index 3d3be8f..3c53db8 100644
--- a/src/prelude/mod.rs
+++ b/src/prelude/mod.rs
@@ -15,9 +15,9 @@ use yew::prelude::*;
/// edit or correct as needed.
pub struct InputString>(pub S);
-impl> Into