Add FormGroup component

This commit is contained in:
Thomas Gideon 2020-06-18 09:53:25 -04:00
parent e6b2e3a2ca
commit 1c03cdb809
3 changed files with 56 additions and 1 deletions

View file

@ -1,6 +1,6 @@
[package] [package]
name = "bootstrap-rs" name = "bootstrap-rs"
version = "0.2.2" version = "0.2.3"
authors = ["Thomas Gideon <cmdln@thecommandline.net>"] authors = ["Thomas Gideon <cmdln@thecommandline.net>"]
edition = "2018" edition = "2018"

53
src/form/mod.rs Normal file
View file

@ -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 {
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! {
<div class=calculate_classes("form-group", (&self.props).into())>
{ self.props.children.render() }
</div>
}
}
}
#[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! {
<div class="form-group m-3 pt-3">
<></>
</div>
};
assert_eq!(expected, form_group.view());
}
}

View file

@ -2,6 +2,7 @@ mod breadcrumb;
mod button; mod button;
mod card; mod card;
mod container; mod container;
mod form;
pub mod input; pub mod input;
mod jumbotron; mod jumbotron;
pub mod prelude; pub mod prelude;
@ -11,6 +12,7 @@ pub use self::{
button::ButtonGroup, button::ButtonGroup,
card::{Card, CardBody, CardHeader, CardText}, card::{Card, CardBody, CardHeader, CardText},
container::Container, container::Container,
form::FormGroup,
input::{Input, InputGroup, TextArea}, input::{Input, InputGroup, TextArea},
jumbotron::Jumbotron, jumbotron::Jumbotron,
}; };