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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
//! Card component — container with optional header, body, and footer.
use maud::{html, Markup};
/// Card size variant.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum Size {
/// Default padding (`1.5rem`).
#[default]
Default,
/// Compact card — reduced padding (`0.75rem`).
Sm,
}
impl Size {
/// Returns the modifier class for this size, or an empty string for the default.
pub fn as_class(self) -> &'static str {
match self {
Size::Default => "",
Size::Sm => "mui-card--sm",
}
}
}
/// Card rendering properties
#[derive(Debug, Clone)]
pub struct Props {
/// Optional card title displayed in header
pub title: Option<String>,
/// Optional card description displayed below title
pub description: Option<String>,
/// Main content markup
pub children: Markup,
/// Optional footer markup
pub footer: Option<Markup>,
/// Card size modifier.
pub size: Size,
/// Optional top-right header slot (shadcn `CardAction` equivalent).
/// When `Some`, the header becomes a 2-col grid: `(title/description) | (action)`.
pub action: Option<Markup>,
}
impl Default for Props {
fn default() -> Self {
Self {
title: None,
description: None,
children: html! {},
footer: None,
size: Size::default(),
action: None,
}
}
}
/// Render a card with the given properties.
pub fn render(props: Props) -> Markup {
let size_class = props.size.as_class();
let card_class = if size_class.is_empty() {
"mui-card".to_string()
} else {
format!("mui-card {size_class}")
};
html! {
div class=(card_class) {
@if props.title.is_some() || props.description.is_some() || props.action.is_some() {
div class="mui-card__header" {
div class="mui-card__header-text" {
@if let Some(title) = props.title {
h3 class="mui-card__title" {
(title)
}
}
@if let Some(desc) = props.description {
p class="mui-card__description" {
(desc)
}
}
}
@if let Some(action_markup) = props.action {
div class="mui-card__action" {
(action_markup)
}
}
}
}
div class="mui-card__body" {
(props.children)
}
@if let Some(footer_markup) = props.footer {
div class="mui-card__footer" {
(footer_markup)
}
}
}
}
}
/// Standalone header-action helper — renders the top-right action slot. Use when composing a
/// Card manually (without `render(Props)`), or to pass into `Props::action`.
pub fn action(children: Markup) -> Markup {
html! {
div class="mui-card__action" {
(children)
}
}
}
/// Standalone content helper — renders the card body wrapper.
pub fn content(children: Markup) -> Markup {
html! {
div class="mui-card__body" {
(children)
}
}
}
/// Standalone footer helper — renders the card footer wrapper.
pub fn footer(children: Markup) -> Markup {
html! {
div class="mui-card__footer" {
(children)
}
}
}
/// Showcase all card use cases
pub fn showcase() -> Markup {
use crate::primitives::{button, input, label, select, switch};
html! {
div.mui-showcase__grid {
// 1. Notifications card with switches
div {
p.mui-showcase__caption { "Notifications" }
(render(Props {
title: Some("Notifications".into()),
description: Some("Choose what you want to be notified about.".into()),
children: html! {
div style="display:flex;flex-direction:column;gap:1rem;" {
div style="display:flex;align-items:flex-start;justify-content:space-between;gap:1rem;" {
div {
p style="font-size:0.875rem;font-weight:500;margin:0;" { "Push Notifications" }
p style="font-size:0.8125rem;color:var(--mui-text-muted);margin:0.125rem 0 0;" {
"Send notifications to device."
}
}
(switch::render(switch::Props {
name: "card-push".into(),
id: "card-push".into(),
label: String::new(),
checked: false,
disabled: false,
aria_label: Some("Push notifications".into()),
..Default::default()
}))
}
div style="display:flex;align-items:flex-start;justify-content:space-between;gap:1rem;" {
div {
p style="font-size:0.875rem;font-weight:500;margin:0;" { "Email Notifications" }
p style="font-size:0.8125rem;color:var(--mui-text-muted);margin:0.125rem 0 0;" {
"Receive emails for activity updates."
}
}
(switch::render(switch::Props {
name: "card-email".into(),
id: "card-email".into(),
label: String::new(),
checked: true,
disabled: false,
aria_label: Some("Email notifications".into()),
..Default::default()
}))
}
}
},
footer: Some(html! {
div style="display:flex;gap:0.5rem;margin-left:auto;" {
(button::render(button::Props {
label: "Save preferences".into(),
variant: button::Variant::Primary,
size: button::Size::Md,
..Default::default()
}))
}
}),
..Default::default()
}))
}
// 2. Simple stat card
div {
p.mui-showcase__caption { "Stat card" }
(render(Props {
title: Some("Total Revenue".into()),
description: None,
children: html! {
div {
p style="font-size:1.75rem;font-weight:700;margin:0;" { "$45,231.89" }
p style="font-size:0.8125rem;color:var(--mui-text-muted);margin:0.25rem 0 0;" {
"+20.1% from last month"
}
}
},
footer: None,
..Default::default()
}))
}
// 3. Create project card with form
div {
p.mui-showcase__caption { "Create project" }
(render(Props {
title: Some("Create project".into()),
description: Some("Deploy your new project in one click.".into()),
children: html! {
div style="display:flex;flex-direction:column;gap:0.75rem;" {
div class="mui-field" {
(label::render(label::Props {
text: "Name".into(),
html_for: Some("card-project-name".into()),
..Default::default()
}))
(input::render(input::Props {
name: "project_name".into(),
id: "card-project-name".into(),
input_type: input::InputType::Text,
placeholder: "Name of your project".into(),
..Default::default()
}))
}
div class="mui-field" {
(label::render(label::Props {
text: "Framework".into(),
html_for: Some("card-framework".into()),
..Default::default()
}))
(select::render(select::Props {
name: "framework".into(),
id: "card-framework".into(),
options: vec![
select::SelectOption { value: "next".into(), label: "Next.js".into(), disabled: false },
select::SelectOption { value: "remix".into(), label: "Remix".into(), disabled: false },
select::SelectOption { value: "astro".into(), label: "Astro".into(), disabled: false },
select::SelectOption { value: "nuxt".into(), label: "Nuxt".into(), disabled: false },
],
selected: None,
placeholder: "Select a framework\u{2026}".into(),
disabled: false,
..Default::default()
}))
}
}
},
footer: Some(html! {
div style="display:flex;gap:0.5rem;justify-content:space-between;width:100%;" {
(button::render(button::Props {
label: "Cancel".into(),
variant: button::Variant::Outline,
size: button::Size::Md,
..Default::default()
}))
(button::render(button::Props {
label: "Create".into(),
variant: button::Variant::Primary,
size: button::Size::Md,
..Default::default()
}))
}
}),
..Default::default()
}))
}
// 4. Compact (Sm) card
div {
p.mui-showcase__caption { "Compact card (size: Sm)" }
(render(Props {
title: Some("Storage".into()),
description: Some("6.2 GB of 15 GB used.".into()),
size: Size::Sm,
children: html! {
div style="height:0.5rem;background:var(--mui-border);border-radius:9999px;overflow:hidden;" {
div style="width:41%;height:100%;background:var(--mui-primary, #2563eb);" {}
}
},
..Default::default()
}))
}
// 5. Card with top-right action slot
div {
p.mui-showcase__caption { "Card with action slot" }
(render(Props {
title: Some("Team members".into()),
description: Some("Manage who has access to this project.".into()),
action: Some(html! {
(button::render(button::Props {
label: "Invite".into(),
variant: button::Variant::Outline,
size: button::Size::Sm,
..Default::default()
}))
}),
children: html! {
ul style="list-style:none;padding:0;margin:0;display:flex;flex-direction:column;gap:0.5rem;" {
li style="font-size:0.875rem;" { "Alice Johnson — Owner" }
li style="font-size:0.875rem;" { "Bob Smith — Editor" }
li style="font-size:0.875rem;" { "Carol Davis — Viewer" }
}
},
..Default::default()
}))
}
}
}
}