bootstrap-rs/src/container.rs

49 lines
1.1 KiB
Rust
Raw Normal View History

2020-06-21 15:57:50 +00:00
use crate::{prelude::*, props::*, render};
2020-06-03 19:33:25 +00:00
use yew::prelude::*;
2020-05-28 18:09:25 +00:00
pub struct Container {
props: Props,
}
impl Component for Container {
type Properties = Props;
type Message = ();
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_if_ne(&mut self.props, props)
2020-05-28 18:09:25 +00:00
}
fn view(&self) -> Html {
2020-06-21 15:57:50 +00:00
render::render_with_prefix(&self.props, "container", render::div(&self.props.children))
2020-05-28 18:09:25 +00:00
}
}
2020-06-03 19:33:25 +00:00
#[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>
};
2021-09-06 21:17:51 +00:00
crate::test::assert_attrs_eq(expected, container.view());
2020-06-03 19:33:25 +00:00
}
}