nova_forms/components/
group.rs

1use leptos::*;
2
3use crate::{Data, GroupContext, QueryStringPart};
4
5/// A component that binds all of its contents to a part of the form data.
6#[component]
7pub fn Group(
8    /// An optional label for the group.
9    #[prop(optional, into)] label: Option<TextProp>,
10    /// The query string that binds the group to the form data.
11    #[prop(into)] bind: QueryStringPart,
12    /// The value of the group.
13    #[prop(optional, into)] values: MaybeProp<Data>,
14     /// The value of the group.
15     #[prop(optional, into)] disabled: MaybeProp<bool>,
16    /// The children of the group.
17    children: Children
18) -> impl IntoView
19{
20    let group = GroupContext::new(bind);
21    if let Some(label) = label {
22        group.add_label(label);
23    }
24
25    create_effect(move |_| {
26        if let Some(values) = values.get() {
27            group.set_raw_value(values);
28        }
29    });
30
31    create_effect(move |_| {
32        if let Some(disabled) = disabled.get() {
33            logging::log!("group set disabled: {}", disabled);
34            group.set_disabled(disabled);
35        }
36    });
37
38    view! {
39        <Provider value=group>
40            {children()}
41        </Provider>
42    }
43}