Skip to main content

patternfly_yew/components/form/
section.rs

1use uuid::Uuid;
2use yew::prelude::*;
3
4/// Properties for [`FormSection`]
5#[derive(Clone, PartialEq, Properties)]
6pub struct FormSectionProperties {
7    pub title: Option<String>,
8    pub children: Html,
9}
10
11/// A group of fields on a [`Form`](crate::prelude::Form)
12#[function_component(FormSection)]
13pub fn section(props: &FormSectionProperties) -> Html {
14    let id = use_state(|| match props.title.is_some() {
15        true => Some(Uuid::new_v4().to_string()),
16        false => None,
17    });
18
19    html! (
20        <section class="pf-v6-c-form__section" role="group" aria-labelledby={(*id).clone()}>
21            if let Some(title) = &props.title {
22                <div id={(*id).clone()} class="pf-v6-c-form__section-title" aria-hidden="true">
23                    { title }
24                </div>
25            }
26            { props.children.clone() }
27        </section>
28    )
29}