Standardize props

This commit is contained in:
Thomas Gideon 2020-06-03 15:33:25 -04:00
parent 96b6152d7b
commit c833bb1957
17 changed files with 358 additions and 252 deletions

View file

@ -1,16 +1,10 @@
use crate::prelude::*;
use yew::{html::Children, prelude::*};
use yew::prelude::*;
pub struct Container {
props: Props,
}
#[derive(Properties, Clone, PartialEq)]
pub struct Props {
#[prop_or_default]
pub children: Children,
}
impl Component for Container {
type Properties = Props;
type Message = ();
@ -29,9 +23,31 @@ impl Component for Container {
fn view(&self) -> Html {
html! {
<div class="container">
<div class=calculate_classes("container", (&self.props).into())>
{ self.props.children.render() }
</div>
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test() {
let container = Container {
props: Props {
margin: Some(Margin(Edge::All, 3)),
padding: Some(Padding(Edge::Top, 3)),
..Props::default()
},
};
let expected = html! {
<div class="container m-3 pt-3">
<></>
</div>
};
assert_eq!(expected, container.view());
}
}