Skip to main content

euv_ui/component/sidebar/view/
struct.rs

1use super::*;
2
3/// One node of the [`euv_sidebar`] navigation tree.
4///
5/// A node with empty `children` is a leaf link; a node with children is a
6/// collapsible group whose `link` (when set) navigates to the group index
7/// page without toggling the group.
8#[derive(Clone, Copy, CustomDebug, Data, Default, New)]
9pub struct EuvSidebarItem {
10    /// The display text.
11    #[get(type(copy))]
12    pub text: &'static str,
13    /// The leaf route; groups may link to their index page.
14    #[get(type(copy))]
15    pub link: Option<&'static str>,
16    /// Nested children (non-empty renders a collapsible group).
17    #[get(type(copy))]
18    pub children: &'static [EuvSidebarItem],
19}
20
21/// Props for the [`euv_sidebar`] component.
22///
23/// The `collapsed` signal is caller-owned so several sidebars (desktop aside
24/// and mobile drawer) can share the collapse state; `prefix` is internal and
25/// used by the recursion to key groups.
26#[derive(Clone, CustomDebug, Default)]
27pub struct EuvSidebarProps {
28    /// The current route signal (drives the active link highlight).
29    pub route_signal: Signal<String>,
30    /// The collapsed group keys.
31    pub collapsed: Signal<Vec<String>>,
32    /// The tree items.
33    pub items: &'static [EuvSidebarItem],
34    /// The group key prefix (internal recursion state, leave default).
35    pub prefix: String,
36    /// Optional navigation interceptor receiving the target link; when set it
37    /// replaces the default `Router::navigate` (used by drawers to close via
38    /// the overlay stack).
39    #[debug(skip)]
40    pub on_navigate: Option<Rc<dyn Fn(&'static str)>>,
41}
42
43/// Props of the [`euv_sidebar_item`] component.
44#[derive(Clone, CustomDebug, Default)]
45pub struct EuvSidebarItemProps {
46    /// The current route signal.
47    pub route_signal: Signal<String>,
48    /// The collapsed group keys.
49    pub collapsed: Signal<Vec<String>>,
50    /// The item to render.
51    pub item: EuvSidebarItem,
52    /// The group key prefix of the parent.
53    pub prefix: String,
54    /// Optional navigation interceptor (see [`EuvSidebarProps::on_navigate`]).
55    #[debug(skip)]
56    pub on_navigate: Option<Rc<dyn Fn(&'static str)>>,
57}