biji_ui/components/menubar/
root.rs1use leptos::{context::Provider, prelude::*};
2
3use crate::components::menubar::context::{MenubarContext, RootContext};
4
5#[component]
6pub fn Root(
7 children: Children,
8 #[prop(into, optional)] class: String,
9 #[prop(default = false)] allow_menu_loop: bool,
10 #[prop(default = false)] allow_item_loop: bool,
11 #[prop(default = false)] prevent_scroll: bool,
12) -> impl IntoView {
13 let menubar_ref = NodeRef::new();
14
15 let root_ctx = RootContext {
16 allow_item_loop,
17 allow_menu_loop,
18 prevent_scroll,
19 ..RootContext::default()
20 };
21 let ctx = MenubarContext {
22 menubar_ref,
23 root: RwSignal::new(root_ctx),
24 };
25
26 view! {
27 <Provider value={ctx}>
28 <div node_ref={menubar_ref} class={class}>
29 <Provider value={root_ctx}>{children()}</Provider>
30 </div>
31 </Provider>
32 }
33}