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
use yew::prelude::*;

use crate::Size;

#[derive(Clone, PartialEq, Eq, Ord, PartialOrd, Copy, Debug)]
pub enum Level {
    H1,
    H2,
    H3,
    H4,
    H5,
    H6,
}

impl Default for Level {
    fn default() -> Self {
        Level::H1
    }
}

#[derive(Clone, Debug, PartialEq, Properties)]
pub struct Props {
    #[prop_or_default]
    pub children: Children,
    #[prop_or_default]
    pub level: Level,
    #[prop_or_default]
    pub size: Option<Size>,
}

#[function_component(Title)]
pub fn title(props: &Props) -> Html {
    let mut classes = Classes::from("pf-c-title");

    if let Some(size) = props.size {
        classes.push(size.as_class());
    } else {
        match props.level {
            Level::H1 => classes.push(Size::XXLarge.as_class()),
            Level::H2 => classes.push(Size::XLarge.as_class()),
            Level::H3 => classes.push(Size::Large.as_class()),
            Level::H4 => classes.push(Size::Medium.as_class()),
            Level::H5 => classes.push(Size::Medium.as_class()),
            Level::H6 => classes.push(Size::Medium.as_class()),
        }
    }

    let heading = match props.level {
        Level::H1 => html! {<h1>{ for props.children.iter() }</h1>},
        Level::H2 => html! {<h2>{ for props.children.iter() }</h2>},
        Level::H3 => html! {<h3>{ for props.children.iter() }</h3>},
        Level::H4 => html! {<h4>{ for props.children.iter() }</h4>},
        Level::H5 => html! {<h5>{ for props.children.iter() }</h5>},
        Level::H6 => html! {<h6>{ for props.children.iter() }</h6>},
    };
    html! { <div class={classes}>{heading}</div> }
}