Skip to main content

euv_ui/component/toc/view/
fn.rs

1use super::*;
2
3/// A generic sticky anchor table-of-contents aligned with common docs
4/// frameworks.
5///
6/// Renders nothing when `items` is empty. The caller controls the column
7/// width and responsive visibility; the component provides the sticky inner
8/// stack.
9///
10/// # Arguments
11///
12/// - `VirtualNode<EuvTocProps>` - The props node.
13///
14/// # Returns
15///
16/// - `VirtualNode` - The TOC virtual DOM tree.
17#[component]
18pub fn euv_toc(node: VirtualNode<EuvTocProps>) -> VirtualNode {
19    let EuvTocProps { title, items }: EuvTocProps = node.try_get_props().unwrap_or_default();
20    if items.is_empty() {
21        return html! {
22            ""
23        };
24    }
25    html! {
26        div {
27            class: c_euv_toc()
28            div {
29                class: c_euv_toc_title()
30                {
31                    title
32                }
33            }
34            for item in items.iter() {
35                a {
36                    key: item.href
37                    class: if { item.level > 2u8 } {
38                        c_euv_toc_link_nested()
39                    } else {
40                        c_euv_toc_link()
41                    }
42                    href: item.href
43                    {
44                        item.text
45                    }
46                }
47            }
48        }
49    }
50}