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_provider`] component.
44///
45/// The provider holds the state the sidebar and its groups share, so a
46/// caller can fold the tree without reaching into the sidebar itself.
47#[derive(Clone, CustomDebug, Default)]
48pub struct EuvSidebarProviderProps {
49    /// The collapsed groups.
50    pub collapsed: Signal<Vec<String>>,
51}
52
53/// Props of the [`euv_sidebar_item`] component.
54#[derive(Clone, CustomDebug, Default)]
55pub struct EuvSidebarItemProps {
56    /// The current route signal.
57    pub route_signal: Signal<String>,
58    /// The collapsed group keys.
59    pub collapsed: Signal<Vec<String>>,
60    /// The item to render.
61    pub item: EuvSidebarItem,
62    /// The group key prefix of the parent.
63    pub prefix: String,
64    /// Optional navigation interceptor (see [`EuvSidebarProps::on_navigate`]).
65    #[debug(skip)]
66    pub on_navigate: Option<Rc<dyn Fn(&'static str)>>,
67}
68
69/// Props of the [`euv_sidebar_header`] component.
70///
71/// The header holds whatever the caller puts in it and takes no settings
72/// of its own.
73#[derive(Clone, CustomDebug, Default)]
74pub struct EuvSidebarHeaderProps {}
75
76/// Props of the [`euv_sidebar_content`] component.
77///
78/// The content is the scrollable middle of the sidebar and takes no
79/// settings of its own.
80#[derive(Clone, CustomDebug, Default)]
81pub struct EuvSidebarContentProps {}
82
83/// Props of the [`euv_sidebar_footer`] component.
84///
85/// The footer holds whatever the caller puts in it and takes no settings
86/// of its own.
87#[derive(Clone, CustomDebug, Default)]
88pub struct EuvSidebarFooterProps {}
89
90/// Props of the [`euv_sidebar_group`] component.
91///
92/// The group holds a caption and its rows and takes no settings of its
93/// own.
94#[derive(Clone, CustomDebug, Default)]
95pub struct EuvSidebarGroupProps {}
96
97/// Props of the [`euv_sidebar_group_label`] component.
98///
99/// The caption of a group holds its name and takes no settings of its own.
100#[derive(Clone, CustomDebug, Default)]
101pub struct EuvSidebarGroupLabelProps {}
102
103/// Props of the [`euv_sidebar_group_action`] component.
104///
105/// The control at the end of a caption takes no settings of its own: what
106/// it does is the caller's business, and it reports through the click
107/// handler of the button.
108#[derive(Clone, CustomDebug, Default)]
109pub struct EuvSidebarGroupActionProps {}
110
111/// Props of the [`euv_sidebar_group_content`] component.
112///
113/// The rows of a group take no settings of their own.
114#[derive(Clone, CustomDebug, Default)]
115pub struct EuvSidebarGroupContentProps {}
116
117/// Props of the [`euv_sidebar_menu`] component.
118///
119/// The menu holds the rows and takes no settings of its own.
120#[derive(Clone, CustomDebug, Default)]
121pub struct EuvSidebarMenuProps {}
122
123/// Props of the [`euv_sidebar_menu_item`] component.
124///
125/// A row of the menu holds its button and takes no settings of its own.
126#[derive(Clone, CustomDebug, Default)]
127pub struct EuvSidebarMenuItemProps {}
128
129/// Props of the [`euv_sidebar_menu_button`] component.
130///
131/// The row of a menu item is the clickable part of it. The reference
132/// renders a link when the row leads somewhere and a button when it only
133/// acts, so the target route decides which of the two it is.
134#[derive(Clone, CustomDebug, Default)]
135pub struct EuvSidebarMenuButtonProps {
136    /// Whether the row is the one the reader is on.
137    ///
138    /// The state travels in the `data-active` attribute, so the styling of
139    /// the row can be driven from the markup alone.
140    pub is_active: bool,
141    /// The route the row leads to.
142    ///
143    /// An empty route renders a button instead of a link.
144    pub href: &'static str,
145}
146
147/// Props of the [`euv_sidebar_menu_action`] component.
148///
149/// The control at the end of a menu row takes no settings of its own.
150#[derive(Clone, CustomDebug, Default)]
151pub struct EuvSidebarMenuActionProps {}
152
153/// Props of the [`euv_sidebar_menu_badge`] component.
154///
155/// The count at the end of a menu row takes no settings of its own: the
156/// count itself is what the caller puts in it.
157#[derive(Clone, CustomDebug, Default)]
158pub struct EuvSidebarMenuBadgeProps {}
159
160/// Props of the [`euv_sidebar_menu_sub`] component.
161///
162/// The nested list of rows takes no settings of its own.
163#[derive(Clone, CustomDebug, Default)]
164pub struct EuvSidebarMenuSubProps {}
165
166/// Props of the [`euv_sidebar_menu_sub_item`] component.
167///
168/// A row of a nested menu takes no settings of its own.
169#[derive(Clone, CustomDebug, Default)]
170pub struct EuvSidebarMenuSubItemProps {}
171
172/// Props of the [`euv_sidebar_menu_sub_button`] component.
173///
174/// A nested row behaves like a row of the menu itself: it carries the
175/// active state and leads to a route.
176#[derive(Clone, CustomDebug, Default)]
177pub struct EuvSidebarMenuSubButtonProps {
178    /// Whether the row is the one the reader is on.
179    pub is_active: bool,
180    /// The route the row leads to.
181    ///
182    /// An empty route renders a button instead of a link.
183    pub href: &'static str,
184}
185
186/// Props of the [`euv_sidebar_menu_skeleton`] component.
187///
188/// The placeholder that stands in for a row while it loads can carry an
189/// icon in front of its text, the way the reference does.
190#[derive(Clone, CustomDebug, Default)]
191pub struct EuvSidebarMenuSkeletonProps {
192    /// Whether the placeholder carries an icon.
193    pub show_icon: bool,
194}
195
196/// Props of the [`euv_sidebar_input`] component.
197///
198/// The search field of the sidebar carries the placeholder that tells the
199/// reader what to search for.
200#[derive(Clone, CustomDebug, Default)]
201pub struct EuvSidebarInputProps {
202    /// The placeholder text of the field.
203    pub placeholder: &'static str,
204}
205
206/// Props of the [`euv_sidebar_inset`] component.
207///
208/// The main area beside the sidebar takes no settings of its own.
209#[derive(Clone, CustomDebug, Default)]
210pub struct EuvSidebarInsetProps {}
211
212/// Props of the [`euv_sidebar_rail`] component.
213///
214/// The edge that opens and closes the sidebar takes no settings of its
215/// own.
216#[derive(Clone, CustomDebug, Default)]
217pub struct EuvSidebarRailProps {}
218
219/// Props of the [`euv_sidebar_separator`] component.
220///
221/// The rule that divides one band of the sidebar from the next takes no
222/// settings of its own.
223#[derive(Clone, CustomDebug, Default)]
224pub struct EuvSidebarSeparatorProps {}
225
226/// Props of the [`euv_sidebar_trigger`] component.
227///
228/// The button that opens and closes the sidebar reports the state it
229/// leaves the sidebar in, so the reader can tell an open sidebar from a
230/// closed one.
231#[derive(Clone, CustomDebug, Default)]
232pub struct EuvSidebarTriggerProps {
233    /// Whether the sidebar is open.
234    pub expanded: bool,
235}