From 1c03cdb809cf076f96e4c839ce25c020218b10f1 Mon Sep 17 00:00:00 2001 From: Thomas Gideon Date: Thu, 18 Jun 2020 09:53:25 -0400 Subject: [PATCH] Add FormGroup component --- Cargo.toml | 2 +- src/form/mod.rs | 53 +++++++++++++++++++++++++++++++++++++++++++++++++ src/lib.rs | 2 ++ 3 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 src/form/mod.rs diff --git a/Cargo.toml b/Cargo.toml index da4736a..02dcac4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bootstrap-rs" -version = "0.2.2" +version = "0.2.3" authors = ["Thomas Gideon "] edition = "2018" diff --git a/src/form/mod.rs b/src/form/mod.rs new file mode 100644 index 0000000..4d2d0d1 --- /dev/null +++ b/src/form/mod.rs @@ -0,0 +1,53 @@ +use crate::prelude::*; +use yew::prelude::*; + +pub struct FormGroup { + pub props: Props, +} + +impl Component for FormGroup { + type Message = (); + type Properties = Props; + + fn create(props: Self::Properties, _: ComponentLink) -> Self { + Self { props } + } + + fn update(&mut self, _: Self::Message) -> ShouldRender { + false + } + + fn change(&mut self, props: Self::Properties) -> ShouldRender { + render_on_change(&mut self.props, props) + } + + fn view(&self) -> Html { + html! { +
+ { self.props.children.render() } +
+ } + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test() { + let form_group = FormGroup { + props: Props { + margin: Some(Margin(Edge::All, 3)), + padding: Some(Padding(Edge::Top, 3)), + ..Props::default() + }, + }; + let expected = html! { +
+ <> +
+ }; + assert_eq!(expected, form_group.view()); + } +} diff --git a/src/lib.rs b/src/lib.rs index 57e1b0c..59f4c5a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,6 +2,7 @@ mod breadcrumb; mod button; mod card; mod container; +mod form; pub mod input; mod jumbotron; pub mod prelude; @@ -11,6 +12,7 @@ pub use self::{ button::ButtonGroup, card::{Card, CardBody, CardHeader, CardText}, container::Container, + form::FormGroup, input::{Input, InputGroup, TextArea}, jumbotron::Jumbotron, };