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
90
//! Tabs control
#[cfg(feature = "yew-nested-router")]
mod router;
mod simple;

#[cfg(feature = "yew-nested-router")]
pub use router::*;
pub use simple::*;

use yew::prelude::*;

/// Properties for [`TabContentBody`]
#[derive(Clone, Debug, PartialEq, Properties)]
pub struct TabContentBodyProperties {
    #[prop_or_default]
    pub children: Html,

    #[prop_or_default]
    pub padding: bool,
}

/// Tabs component body.
///
/// This is an optional sub-components used for styling the content of a tab.
///
/// ## Properties
///
/// Defined by [`TabContentBodyProperties`].
#[function_component(TabContentBody)]
pub fn tab_content_body(props: &TabContentBodyProperties) -> Html {
    let mut class = classes!("pf-v5-c-tab-content__body");

    if props.padding {
        class.push(classes!("pf-m-padding"));
    }

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

/// Properties for [`TabContent`]
#[derive(PartialEq, Properties)]
pub struct TabContentProperties {
    #[prop_or_default]
    pub id: Option<AttrValue>,

    #[prop_or_default]
    pub hidden: bool,

    #[prop_or_default]
    pub children: Html,

    #[prop_or_default]
    pub class: Classes,

    #[prop_or_default]
    pub style: Option<AttrValue>,
}

/// Tabs component body.
///
/// > A **tab content** component should be used with the tabs component.
///
/// See: <https://www.patternfly.org/components/tab-content>
///
/// ## Properties
///
/// Defined by [`TabContentProperties`].
#[function_component(TabContent)]
pub fn tab_content(props: &TabContentProperties) -> Html {
    let mut class = Classes::from("pf-v5-c-tab-content");

    class.extend(&props.class);

    html!(
        <section
            id={props.id.clone()}
            {class}
            hidden={props.hidden}
            tabindex="0"
            role="tabpanel"
            style={props.style.clone()}
        >
            { props.children.clone() }
        </section>
    )
}