yew_bootstrap/component/
row.rs

1use super::Column;
2use yew::prelude::*;
3
4/// # Row container
5/// Used alongside [crate::component::Column] to create grids
6///
7/// See [crate::component::RowProps] for a listing of properties
8///
9/// ## Example
10/// ```rust
11/// use yew::prelude::*;
12/// use yew_bootstrap::component::{Column, Row};
13/// fn test() -> Html {
14///     html!{
15///         <Row class={"myclass"}>
16///             <Column lg=4><p>{ "First column" }</p></Column>
17///             <Column lg=8><p>{ "Second column" }</p></Column>
18///         </Row>
19///     }
20/// }
21/// ```
22pub struct Row {}
23
24/// # Properties for [Row]
25#[derive(Properties, Clone, PartialEq)]
26pub struct RowProps {
27    /// CSS class
28    #[prop_or_default]
29    pub class: String,
30
31    /// Event called when the element is clicked
32    #[prop_or_default]
33    pub onclick: Callback<MouseEvent>,
34
35    /// Children of type [crate::component::Column]
36    #[prop_or_default]
37    pub children: ChildrenWithProps<Column>,
38}
39
40impl Component for Row {
41    type Message = ();
42    type Properties = RowProps;
43
44    fn create(_ctx: &Context<Self>) -> Self {
45        Self {}
46    }
47
48    fn view(&self, ctx: &Context<Self>) -> Html {
49        let props = ctx.props();
50        let mut classes = Classes::new();
51        classes.push("row");
52        classes.push(props.class.clone());
53
54        html! {
55            <div
56                class={classes}
57                onclick={props.onclick.clone()}
58            >
59                { for props.children.iter() }
60            </div>
61        }
62    }
63}