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
//! Switch component — maud-ui Wave 2
use maud::{html, Markup};
#[derive(Clone, Debug)]
pub struct Props {
pub name: String,
pub id: String,
pub label: String,
pub checked: bool,
pub disabled: bool,
/// Explicit accessible name. Required when `label` is empty (e.g., when
/// the switch sits next to an external label or description block).
/// Falls back to `label` if not set.
pub aria_label: Option<String>,
}
impl Default for Props {
fn default() -> Self {
Self {
name: "switch".to_string(),
id: "switch".to_string(),
label: "Toggle".to_string(),
checked: false,
disabled: false,
aria_label: None,
}
}
}
pub fn render(props: Props) -> Markup {
let aria_checked = if props.checked { "true" } else { "false" };
let value = if props.checked { "true" } else { "false" };
let accessible_name = props
.aria_label
.clone()
.unwrap_or_else(|| props.label.clone());
html! {
span class="mui-switch-wrap" {
@if props.disabled {
button type="button" class="mui-switch" role="switch"
aria-checked=(aria_checked)
aria-label=(accessible_name)
id=(props.id.clone())
data-mui="switch"
data-name=(props.name.clone())
disabled {
span class="mui-switch__thumb" aria-hidden="true";
}
} @else {
button type="button" class="mui-switch" role="switch"
aria-checked=(aria_checked)
aria-label=(accessible_name)
id=(props.id.clone())
data-mui="switch"
data-name=(props.name.clone()) {
span class="mui-switch__thumb" aria-hidden="true";
}
}
input type="hidden" name=(props.name.clone()) value=(value)
class="mui-switch__value" aria-hidden="true";
@if !props.label.is_empty() {
label for=(props.id) class="mui-switch__label" {
(props.label)
}
}
}
}
}
pub fn showcase() -> Markup {
html! {
div.mui-showcase__grid {
// Realistic settings panel
section {
h2 { "Notification Settings" }
div style="display:flex;flex-direction:column;gap:1rem;max-width:28rem;" {
// Marketing emails — off
div style="display:flex;align-items:flex-start;justify-content:space-between;gap:1rem;" {
div {
label for="sw-marketing" style="font-size:0.875rem;font-weight:500;color:var(--mui-text);display:block;" {
"Marketing emails"
}
span style="font-size:0.8125rem;color:var(--mui-text-muted);" {
"Receive emails about new products, features, and more."
}
}
(render(Props {
name: "marketing".to_string(),
id: "sw-marketing".to_string(),
label: String::new(),
checked: false,
disabled: false,
aria_label: Some("Marketing emails".to_string()),
}))
}
// Push notifications — on
div style="display:flex;align-items:flex-start;justify-content:space-between;gap:1rem;" {
div {
label for="sw-push" style="font-size:0.875rem;font-weight:500;color:var(--mui-text);display:block;" {
"Push notifications"
}
span style="font-size:0.8125rem;color:var(--mui-text-muted);" {
"Receive notifications directly on your device."
}
}
(render(Props {
name: "push".to_string(),
id: "sw-push".to_string(),
label: String::new(),
checked: true,
disabled: false,
aria_label: Some("Push notifications".to_string()),
}))
}
// Airplane mode — disabled
div style="display:flex;align-items:flex-start;justify-content:space-between;gap:1rem;opacity:0.6;" {
div {
label for="sw-airplane" style="font-size:0.875rem;font-weight:500;color:var(--mui-text);display:block;" {
"Airplane mode"
}
span style="font-size:0.8125rem;color:var(--mui-text-muted);" {
"Managed by your organization."
}
}
(render(Props {
name: "airplane".to_string(),
id: "sw-airplane".to_string(),
label: String::new(),
checked: false,
disabled: true,
aria_label: Some("Airplane mode".to_string()),
}))
}
}
}
// Simple inline states
section {
h2 { "States" }
div.mui-showcase__row {
(render(Props {
name: "demo-off".to_string(),
id: "demo-off".to_string(),
label: "Off".to_string(),
checked: false,
disabled: false,
aria_label: None,
}))
(render(Props {
name: "demo-on".to_string(),
id: "demo-on".to_string(),
label: "On".to_string(),
checked: true,
disabled: false,
aria_label: None,
}))
(render(Props {
name: "demo-disabled".to_string(),
id: "demo-disabled".to_string(),
label: "Disabled".to_string(),
checked: false,
disabled: true,
aria_label: None,
}))
(render(Props {
name: "demo-locked".to_string(),
id: "demo-locked".to_string(),
label: "Locked on".to_string(),
checked: true,
disabled: true,
aria_label: None,
}))
}
}
}
}
}