orbital_base_components/tree/
subtree.rs1use leptos::{context::Provider, prelude::*};
2use orbital_motion::{OrbitalPresence, PresenceMotion};
3
4use super::state::TreeStateInjection;
5use super::types::{SubtreeInjection, TreeItemInjection};
6
7#[slot]
8pub struct BaseTreeCollapseSlot {
9 #[prop(optional, into)]
10 pub motion_name: MaybeProp<String>,
11}
12
13#[component]
14pub fn BaseSubtree(
15 #[prop(optional, into)] class: MaybeProp<String>,
16 level: usize,
17 #[prop(optional)] base_tree_collapse: Option<BaseTreeCollapseSlot>,
18 #[prop(default = None)] subtree_children: Option<Children>,
19) -> impl IntoView {
20 let _ = base_tree_collapse;
21 let tree_item_injection = TreeItemInjection::expect_context();
22 let tree_state = TreeStateInjection::expect_context();
23 let open = tree_item_injection.open;
24 let subtree_ref = tree_item_injection.subtree_ref;
25 let size = tree_state.size;
26
27 let motion = Signal::from(PresenceMotion::collapse());
28
29 let subtree_body = view! {
30 <div
31 class=move || {
32 let mut parts = vec![
33 "orbital-tree".to_string(),
34 "orbital-subtree".to_string(),
35 format!("orbital-tree--{}", size.get().as_str()),
36 ];
37 if let Some(extra) = class.get() {
38 if !extra.is_empty() {
39 parts.push(extra);
40 }
41 }
42 parts.join(" ")
43 }
44 role="group"
45 node_ref=subtree_ref
46 >
47 <Provider value=SubtreeInjection {
48 level,
49 parent_id: Some(tree_item_injection.item_id.clone()),
50 }>{subtree_children.map(|children| children())}</Provider>
51 </div>
52 };
53
54 view! {
55 <OrbitalPresence show=open motion=motion>
56 {subtree_body}
57 </OrbitalPresence>
58 }
59}