1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
//! Split

use yew::prelude::*;

#[derive(Clone, PartialEq, Properties)]
pub struct SplitProperties {
    pub children: ChildrenWithProps<SplitItem>,
    #[prop_or_default]
    pub gutter: bool,
    #[prop_or_default]
    pub wrap: bool,
}

/// Split layout
///
/// > Use a **Split** layout to position items horizontally in a container, with one item filling the remaining horizontal space as the viewport is resized.
///
/// See: <https://www.patternfly.org/layouts/split>
///
/// ## Properties
///
/// Defined by [`SplitProperties`].
///
/// ## Children
///
/// The grid layout is supposed to contain [`crate::prelude::SplitItem`] children.
///
/// ## Example
///
/// ```rust
/// use yew::prelude::*;
/// use patternfly_yew::prelude::*;
///
/// #[function_component(Example)]
/// fn example() -> Html {
///   html!(
///     <Split gutter=true>
///       <SplitItem>{"Foo"}</SplitItem>
///       <SplitItem fill=true>{"Full Width"}</SplitItem>
///     </Split>
///   )
/// }
/// ```
#[function_component(Split)]
pub fn split(props: &SplitProperties) -> Html {
    let mut classes = Classes::from("pf-v5-l-split");

    if props.gutter {
        classes.push("pf-m-gutter");
    }

    if props.wrap {
        classes.push("pf-m-wrap");
    }

    html! (
        <div class={classes}>
            { for props.children.iter() }
        </div>
    )
}

#[derive(Clone, PartialEq, Properties)]
pub struct SplitItemProperties {
    #[prop_or_default]
    pub children: Html,
    #[prop_or_default]
    pub fill: bool,
}

/// An item in the [`Split`] layout.
///
/// ## Properties
///
/// Defined by [`SplitItemProperties`].
#[function_component(SplitItem)]
pub fn split_item(props: &SplitItemProperties) -> Html {
    let mut classes = Classes::from("pf-v5-l-split__item");

    if props.fill {
        classes.push("pf-m-fill");
    }

    html!(
        <div class={classes}>
            { props.children.clone() }
        </div>
    )
}