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
//! Toggle component — two-state button (pressed/unpressed)
use maud::{html, Markup};
#[derive(Clone, Debug, Default, PartialEq)]
pub enum Size {
#[default]
Md,
Sm,
}
#[derive(Clone, Debug, Default, PartialEq)]
pub enum Variant {
#[default]
Default,
Outline,
}
#[derive(Clone, Debug)]
pub struct Props {
pub label: String,
pub pressed: bool,
pub disabled: bool,
pub id: String,
pub size: Size,
pub variant: Variant,
}
impl Default for Props {
fn default() -> Self {
Self {
label: "Toggle".to_string(),
pressed: false,
disabled: false,
id: "toggle".to_string(),
size: Size::Md,
variant: Variant::Default,
}
}
}
pub fn render(props: Props) -> Markup {
let aria_pressed = if props.pressed { "true" } else { "false" };
let size_cls = match props.size {
Size::Md => "mui-toggle--md",
Size::Sm => "mui-toggle--sm",
};
let variant_cls = match props.variant {
Variant::Default => "",
Variant::Outline => "mui-toggle--outline",
};
html! {
button type="button"
class={"mui-toggle " (size_cls) " " (variant_cls)}
aria-pressed=(aria_pressed)
id=(props.id)
data-mui="toggle"
disabled[props.disabled]
{
(props.label)
}
}
}
pub fn showcase() -> Markup {
html! {
div.mui-showcase__grid {
// Text-editor toolbar context
section {
h2 { "Text Editor Toolbar" }
p.mui-showcase__caption { "Default variant — formatting controls" }
div.mui-showcase__row {
(render(Props {
label: "B".to_string(),
pressed: true,
id: "toolbar-bold".to_string(),
..Default::default()
}))
(render(Props {
label: "I".to_string(),
pressed: false,
id: "toolbar-italic".to_string(),
..Default::default()
}))
(render(Props {
label: "U".to_string(),
pressed: false,
id: "toolbar-underline".to_string(),
..Default::default()
}))
}
p.mui-showcase__caption { "Outline variant" }
div.mui-showcase__row {
(render(Props {
label: "B".to_string(),
pressed: true,
variant: Variant::Outline,
id: "toolbar-outline-bold".to_string(),
..Default::default()
}))
(render(Props {
label: "I".to_string(),
pressed: false,
variant: Variant::Outline,
id: "toolbar-outline-italic".to_string(),
..Default::default()
}))
(render(Props {
label: "U".to_string(),
pressed: false,
variant: Variant::Outline,
id: "toolbar-outline-underline".to_string(),
..Default::default()
}))
}
}
// Sizes
section {
h2 { "Sizes" }
div.mui-showcase__row {
span.mui-showcase__label { "md" }
(render(Props {
label: "B".to_string(),
pressed: true,
id: "size-md-b".to_string(),
..Default::default()
}))
(render(Props {
label: "I".to_string(),
pressed: false,
id: "size-md-i".to_string(),
..Default::default()
}))
}
div.mui-showcase__row {
span.mui-showcase__label { "sm" }
(render(Props {
label: "B".to_string(),
pressed: true,
size: Size::Sm,
id: "size-sm-b".to_string(),
..Default::default()
}))
(render(Props {
label: "I".to_string(),
pressed: false,
size: Size::Sm,
id: "size-sm-i".to_string(),
..Default::default()
}))
}
}
// Disabled
section {
h2 { "Disabled" }
div.mui-showcase__row {
(render(Props {
label: "Off".to_string(),
disabled: true,
id: "toggle-dis-off".to_string(),
..Default::default()
}))
(render(Props {
label: "On".to_string(),
pressed: true,
disabled: true,
id: "toggle-dis-on".to_string(),
..Default::default()
}))
}
}
}
}
}