biji_ui/components/accordion/
root.rs

1use leptos::{context::Provider, prelude::*};
2
3use super::context::{AccordionContext, RootContext};
4
5#[component]
6pub fn Root(
7    children: Children,
8    #[prop(into, optional)] class: String,
9    #[prop(default = false)] allow_loop: bool,
10) -> impl IntoView {
11    let accordion_ref = NodeRef::new();
12    let root_ctx = RootContext {
13        allow_loop,
14        ..RootContext::default()
15    };
16    let ctx = AccordionContext {
17        root: RwSignal::new(root_ctx),
18        accordion_ref,
19    };
20
21    view! {
22        <Provider value={ctx}>
23            <div node_ref={accordion_ref} class={class}>
24                <Provider value={root_ctx}>{children()}</Provider>
25            </div>
26        </Provider>
27    }
28}