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
//! Dialog component — modal dialog using native <dialog> element with focus trap and ESC/backdrop close.
use maud::{html, Markup};
/// Dialog rendering properties
#[derive(Clone, Debug)]
pub struct Props {
/// Unique identifier for the dialog (used by trigger to open it)
pub id: String,
/// Dialog title
pub title: String,
/// Optional description text displayed below title
pub description: Option<String>,
/// Markup content displayed in dialog body
pub children: Markup,
/// Optional footer markup (buttons/actions, rendered right-aligned)
pub footer: Option<Markup>,
/// Initial open state (default false; if true renders with open attribute for SSR)
pub open: bool,
}
impl Default for Props {
fn default() -> Self {
Self {
id: "dialog".to_string(),
title: "Dialog".to_string(),
description: None,
children: html! {},
footer: None,
open: false,
}
}
}
/// Render a dialog trigger button that opens the dialog with the given target_id
pub fn trigger(target_id: &str, label: &str) -> Markup {
html! {
button type="button"
class="mui-btn mui-btn--default mui-btn--md"
data-mui="dialog-trigger"
data-target=(target_id)
{
(label)
}
}
}
/// Render a close button for use inside the dialog (positioned absolute via CSS)
pub fn close_button(label: &str) -> Markup {
html! {
button type="button"
class="mui-dialog__close"
data-mui-close
aria-label=(label)
{
"\u{00d7}"
}
}
}
/// Render a dialog with the given properties
pub fn render(props: Props) -> Markup {
let title_id = format!("{}-title", props.id);
let desc_id = format!("{}-desc", props.id);
let has_desc = props.description.is_some();
html! {
dialog class="mui-dialog"
id=(props.id)
data-mui="dialog"
aria-labelledby=(title_id)
aria-describedby=[if has_desc { Some(desc_id.as_str()) } else { None }]
open[props.open]
{
// Close button — absolute positioned, outside header flow
(close_button("Close"))
div class="mui-dialog__header" {
h2 class="mui-dialog__title" id=(title_id) {
(props.title)
}
}
@if let Some(desc) = props.description {
p class="mui-dialog__description" id=(desc_id) {
(desc)
}
}
div class="mui-dialog__body" {
(props.children)
}
@if let Some(footer) = props.footer {
div class="mui-dialog__footer" {
(footer)
}
}
}
}
}
/// Showcase all dialog use cases
pub fn showcase() -> Markup {
html! {
div.mui-showcase__grid {
// Edit Profile dialog
{
(trigger("demo-dialog-edit-profile", "Edit Profile"))
}
{
(render(Props {
id: "demo-dialog-edit-profile".to_string(),
title: "Edit Profile".to_string(),
description: Some("Update your personal information below.".to_string()),
children: html! {
div style="display:flex;align-items:center;gap:1rem;margin-bottom:1rem;" {
div style="width:3rem;height:3rem;border-radius:50%;background:var(--mui-muted);display:flex;align-items:center;justify-content:center;font-size:1.25rem;flex-shrink:0;" {
"JD"
}
p style="font-size:0.875rem;color:var(--mui-muted-fg);" {
"Upload a new avatar from your device."
}
}
div class="mui-field" {
label class="mui-label" { "Name" }
input class="mui-input" type="text" value="Jane Doe" {}
}
div class="mui-field" {
label class="mui-label" { "Email" }
input class="mui-input" type="email" value="jane@example.com" {}
}
},
footer: Some(html! {
button class="mui-btn mui-btn--secondary mui-btn--md" data-mui-close { "Cancel" }
button class="mui-btn mui-btn--primary mui-btn--md" { "Save" }
}),
open: false,
}))
}
// Share Document dialog
{
(trigger("demo-dialog-share-doc", "Share Document"))
}
{
(render(Props {
id: "demo-dialog-share-doc".to_string(),
title: "Share Document".to_string(),
description: Some("Invite a collaborator by email address.".to_string()),
children: html! {
div class="mui-field" {
label class="mui-label" { "Email address" }
input class="mui-input" type="email" placeholder="collaborator@company.com" {}
}
div class="mui-field" {
label class="mui-label" { "Permission" }
select class="mui-select__trigger" style="width:100%;" {
option value="viewer" { "Viewer" }
option value="editor" { "Editor" }
}
}
},
footer: Some(html! {
button class="mui-btn mui-btn--secondary mui-btn--md" data-mui-close { "Cancel" }
button class="mui-btn mui-btn--primary mui-btn--md" { "Send invite" }
}),
open: false,
}))
}
}
}
}