1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
//! Navigation Menu component — horizontal nav with dropdown content panels (mega-menu style).
use maud::{html, Markup};
/// Orientation of the navigation menu list.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum Orientation {
#[default]
Horizontal,
Vertical,
}
/// A direct navigation link.
#[derive(Clone, Debug)]
pub struct NavLink {
pub label: String,
pub href: String,
pub description: Option<String>,
}
/// A dropdown menu containing multiple links.
#[derive(Clone, Debug)]
pub struct NavMenu {
pub label: String,
pub links: Vec<NavLink>,
}
/// A navigation item: either a direct link or a dropdown menu.
#[derive(Clone, Debug)]
pub enum NavItem {
Link(NavLink),
Menu(NavMenu),
}
/// Navigation menu rendering properties.
#[derive(Clone, Debug)]
pub struct Props {
pub id: String,
pub items: Vec<NavItem>,
/// Horizontal (default) or vertical layout of the top-level list.
pub orientation: Orientation,
/// When `true` (default), dropdown content is rendered in a shared viewport panel.
/// When `false`, each trigger carries its own per-item popover wrapper.
pub viewport: bool,
}
impl Default for Props {
fn default() -> Self {
Self {
id: "nav-menu".to_string(),
items: vec![],
orientation: Orientation::Horizontal,
viewport: true,
}
}
}
/// Render a small chevron/arrow between active triggers (NavigationMenuIndicator).
///
/// Purely decorative — `aria-hidden="true"` so screen readers skip it.
pub fn indicator() -> Markup {
html! {
span class="mui-nav-menu__indicator" aria-hidden="true" { "\u{25BE}" }
}
}
/// Render a navigation menu with the given properties.
pub fn render(props: Props) -> Markup {
let list_class = match props.orientation {
Orientation::Horizontal => "mui-nav-menu__list",
Orientation::Vertical => "mui-nav-menu__list mui-nav-menu--vertical",
};
let viewport_attr = if props.viewport { "shared" } else { "per-item" };
html! {
nav class="mui-nav-menu" data-mui="nav-menu" id=(props.id) aria-label="Primary" data-viewport=(viewport_attr) {
ul class=(list_class) {
@for item in &props.items {
@match item {
NavItem::Link(link) => {
li {
a class="mui-nav-menu__link" href=(link.href) {
(link.label)
}
}
}
NavItem::Menu(menu) => {
li class="mui-nav-menu__item" data-has-content {
button class="mui-nav-menu__trigger" aria-expanded="false" aria-haspopup="true" {
(menu.label) " \u{25BE}"
}
@if props.viewport {
div class="mui-nav-menu__content" hidden {
ul class="mui-nav-menu__sub-list" {
@for link in &menu.links {
li {
a class="mui-nav-menu__sub-link" href=(link.href) {
div class="mui-nav-menu__sub-title" {
(link.label)
}
@if let Some(desc) = &link.description {
div class="mui-nav-menu__sub-desc" {
(desc)
}
}
}
}
}
}
}
} @else {
div class="mui-nav-menu__popover" data-viewport="per-item" hidden {
div class="mui-nav-menu__content" {
ul class="mui-nav-menu__sub-list" {
@for link in &menu.links {
li {
a class="mui-nav-menu__sub-link" href=(link.href) {
div class="mui-nav-menu__sub-title" {
(link.label)
}
@if let Some(desc) = &link.description {
div class="mui-nav-menu__sub-desc" {
(desc)
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
/// Showcase navigation menu examples.
pub fn showcase() -> Markup {
let items = vec![
NavItem::Menu(NavMenu {
label: "Getting Started".to_string(),
links: vec![
NavLink {
label: "Introduction".to_string(),
href: "#introduction".to_string(),
description: Some("Re-usable components built with maud and CSS.".to_string()),
},
NavLink {
label: "Installation".to_string(),
href: "#installation".to_string(),
description: Some(
"How to install dependencies and structure your app.".to_string(),
),
},
NavLink {
label: "Typography".to_string(),
href: "#typography".to_string(),
description: Some(
"Styles for headings, paragraphs, lists and more.".to_string(),
),
},
],
}),
NavItem::Menu(NavMenu {
label: "Components".to_string(),
links: vec![
NavLink {
label: "Alert".to_string(),
href: "#alert".to_string(),
description: Some("Displays a callout for important information.".to_string()),
},
NavLink {
label: "Button".to_string(),
href: "#button".to_string(),
description: Some("Triggers an action or event when clicked.".to_string()),
},
NavLink {
label: "Card".to_string(),
href: "#card".to_string(),
description: Some("Groups related content in a container.".to_string()),
},
],
}),
NavItem::Menu(NavMenu {
label: "Resources".to_string(),
links: vec![
NavLink {
label: "Documentation".to_string(),
href: "#documentation".to_string(),
description: Some("Full API reference and usage guides.".to_string()),
},
NavLink {
label: "Changelog".to_string(),
href: "#changelog".to_string(),
description: Some("Latest updates and release notes.".to_string()),
},
],
}),
NavItem::Link(NavLink {
label: "GitHub".to_string(),
href: "https://github.com".to_string(),
description: None,
}),
];
let horizontal = Props {
id: "demo-nav-menu".to_string(),
items: items.clone(),
..Props::default()
};
let vertical_items = vec![
NavItem::Menu(NavMenu {
label: "Getting Started".to_string(),
links: vec![
NavLink {
label: "Introduction".to_string(),
href: "#introduction".to_string(),
description: Some("Overview of the design system.".to_string()),
},
NavLink {
label: "Installation".to_string(),
href: "#installation".to_string(),
description: None,
},
],
}),
NavItem::Link(NavLink {
label: "Docs".to_string(),
href: "#docs".to_string(),
description: None,
}),
NavItem::Link(NavLink {
label: "GitHub".to_string(),
href: "https://github.com".to_string(),
description: None,
}),
];
let vertical = Props {
id: "demo-nav-menu-vertical".to_string(),
items: vertical_items,
orientation: Orientation::Vertical,
viewport: false,
};
html! {
div class="mui-nav-menu__showcase" {
(render(horizontal))
div class="mui-nav-menu__showcase-indicator" {
span { "Active" }
(indicator())
span { "Next" }
}
(render(vertical))
}
}
}