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

/// Properties for [`FormSection`]
#[derive(Clone, PartialEq, Properties)]
pub struct FormSectionProperties {
    pub title: Option<String>,
    pub children: Html,
}

/// A group of fields on a [`Form`](crate::prelude::Form)
#[function_component(FormSection)]
pub fn section(props: &FormSectionProperties) -> Html {
    let id = use_state(|| match props.title.is_some() {
        true => Some(Uuid::new_v4().to_string()),
        false => None,
    });

    html! (
        <section class="pf-v5-c-form__section" role="group" aria-labelledby={(*id).clone()}>

            if let Some(title) = &props.title {
                <div id={(*id).clone()} class="pf-v5-c-form__section-title" aria-hidden="true">
                    { title }
                </div>
            }

            { props.children.clone() }
        </section>
    )
}