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
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
//! `data::table_full` — data table with search box, filter chips, bulk
//! action dropdown, selectable rows, and per-row action menu.
//!
//! Composes: `card`, `input`, `button`, `badge`, `native_select`. The
//! table itself is rendered directly (not via `data_table` primitive)
//! because the block needs control over the status pills and the
//! per-row action column.
//!
//! The block is server-rendered HTML — search/filter/bulk actions
//! submit to the `action` URL and your handler re-renders the list.
//! Works without JS.
use maud::{html, Markup};
use crate::primitives::{badge, button, card, input, native_select};
#[derive(Clone, Debug, Default)]
pub struct Props {
/// Page title shown above the card.
pub title: String,
/// Short description under the title.
pub subtitle: Option<String>,
/// URL that both the filter form + bulk-action form submit to.
pub action: String,
/// Current value of the search box (preserved across submits).
pub search_value: String,
pub columns: Vec<Column>,
pub filters: Vec<Filter>,
pub rows: Vec<Row>,
/// Bulk actions shown in a dropdown — disabled until at least one
/// row is selected (the checkbox-counter JS is up to the consumer;
/// this block ships the dropdown wired to POST with selected ids).
pub bulk_actions: Vec<BulkAction>,
/// Summary text shown under the table — e.g. "Showing 25 of 1,284".
pub pagination_summary: Option<String>,
/// URL for the primary action (e.g. "Create customer") at the top
/// right of the card.
pub primary_action: Option<PrimaryAction>,
}
#[derive(Clone, Debug)]
pub struct Column {
pub label: String,
}
#[derive(Clone, Debug)]
pub struct Filter {
/// Display name ("Status", "Plan").
pub label: String,
/// Submitted form field name.
pub name: String,
pub options: Vec<(String, String)>,
pub selected: Option<String>,
}
#[derive(Clone, Debug)]
pub struct Row {
/// Stable identifier — submitted as part of bulk action form.
pub id: String,
/// Cells in the same order as `columns`. Last cell can use a
/// `RowCell::Status` to render a colored badge.
pub cells: Vec<RowCell>,
/// Optional URL to view this row. When set, the first cell is
/// rendered as a link.
pub view_href: Option<String>,
}
#[derive(Clone, Debug)]
pub enum RowCell {
Text(String),
/// Two-line cell: primary + secondary text (name + email pattern).
Stacked {
primary: String,
secondary: String,
},
Status {
label: String,
variant: StatusVariant,
},
Markup(Markup),
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum StatusVariant {
Success,
Warning,
Danger,
Neutral,
}
#[derive(Clone, Debug)]
pub struct BulkAction {
pub value: String,
pub label: String,
/// `true` means the action is destructive — shown with a warning
/// tint. Consumer is still responsible for the confirm dialog.
pub destructive: bool,
}
#[derive(Clone, Debug)]
pub struct PrimaryAction {
pub label: String,
pub href: String,
}
pub fn render(props: Props) -> Markup {
let col_count = props.columns.len();
html! {
div class="mui-block mui-block--data" {
(card::render(card::Props {
children: html! {
// Header row — title + primary action
div class="mui-block--data__header" {
div {
h2 class="mui-block--data__title" { (props.title) }
@if let Some(s) = &props.subtitle {
p class="mui-block--data__subtitle" { (s) }
}
}
@if let Some(action) = &props.primary_action {
a href=(action.href)
class="mui-btn mui-btn--primary mui-btn--sm"
style="text-decoration:none;" {
(action.label)
}
}
}
// Filter + search row
form action=(props.action) method="get"
class="mui-block--data__filters" {
div class="mui-block--data__search" {
(input::render(input::Props {
name: "q".into(),
id: "mui-block-data-q".into(),
input_type: crate::primitives::input::InputType::Search,
placeholder: "Search\u{2026}".into(),
value: props.search_value.clone(),
..Default::default()
}))
}
@for (idx, f) in props.filters.iter().enumerate() {
div class="mui-block--data__filter" {
(native_select::render(native_select::NativeSelectProps {
name: f.name.clone(),
id: format!("mui-block-data-filter-{}", idx),
options: f.options.iter().map(|(v, l)| native_select::NativeOption {
value: v.clone(),
label: l.clone(),
disabled: false,
}).collect(),
selected: f.selected.clone(),
placeholder: Some(f.label.clone()),
disabled: false,
}))
}
}
(button::render(button::Props {
label: "Apply".into(),
variant: button::Variant::Outline,
size: button::Size::Md,
button_type: "submit",
..Default::default()
}))
}
// Bulk action row (rendered even when empty so the UI
// doesn't shift when rows get selected)
@if !props.bulk_actions.is_empty() {
form action=(props.action) method="post"
class="mui-block--data__bulk" {
span class="mui-block--data__bulk-label" {
"With selected: "
}
(native_select::render(native_select::NativeSelectProps {
name: "bulk_action".into(),
id: "mui-block-data-bulk".into(),
options: props.bulk_actions.iter().map(|a| native_select::NativeOption {
value: a.value.clone(),
label: a.label.clone(),
disabled: false,
}).collect(),
selected: None,
placeholder: Some("Choose an action\u{2026}".into()),
disabled: false,
}))
(button::render(button::Props {
label: "Run".into(),
variant: button::Variant::Outline,
size: button::Size::Md,
button_type: "submit",
..Default::default()
}))
}
}
// Table
div class="mui-block--data__table-wrap" {
table class="mui-block--data__table" {
thead {
tr {
th class="mui-block--data__select-col" {
input type="checkbox"
class="mui-block--data__select-all"
aria-label="Select all rows";
}
@for c in &props.columns {
th { (c.label) }
}
th class="mui-block--data__actions-col" aria-label="Row actions" {}
}
}
tbody {
@if props.rows.is_empty() {
tr class="mui-block--data__empty" {
td colspan=((col_count + 2).to_string()) {
"No results. Adjust the filters above or "
@if let Some(action) = &props.primary_action {
a href=(action.href) class="mui-block--auth__footer-link" {
(action.label.to_lowercase())
}
"."
} @else {
"clear the search."
}
}
}
}
@for row in &props.rows {
tr {
td class="mui-block--data__select-col" {
input type="checkbox"
name="ids"
value=(row.id)
aria-label="Select row";
}
@for (idx, cell) in row.cells.iter().enumerate() {
td {
@match cell {
RowCell::Text(s) => {
@if idx == 0 && row.view_href.is_some() {
a href=(row.view_href.as_deref().unwrap_or("#"))
class="mui-block--data__row-link" {
(s)
}
} @else {
(s)
}
}
RowCell::Stacked { primary, secondary } => {
div class="mui-block--data__stacked" {
@if idx == 0 && row.view_href.is_some() {
a href=(row.view_href.as_deref().unwrap_or("#"))
class="mui-block--data__row-link mui-block--data__stacked-primary" {
(primary)
}
} @else {
span class="mui-block--data__stacked-primary" {
(primary)
}
}
span class="mui-block--data__stacked-secondary" {
(secondary)
}
}
}
RowCell::Status { label, variant } => {
(badge::render(badge::Props {
label: label.clone(),
variant: match variant {
StatusVariant::Success => badge::Variant::Success,
StatusVariant::Warning => badge::Variant::Warning,
StatusVariant::Danger => badge::Variant::Danger,
StatusVariant::Neutral => badge::Variant::Secondary,
},
..Default::default()
}))
}
RowCell::Markup(m) => { (m) }
}
}
}
td class="mui-block--data__actions-col" {
@if let Some(href) = &row.view_href {
a href=(href) class="mui-block--data__row-action" {
"View \u{2192}"
}
}
}
}
}
}
}
}
@if let Some(summary) = &props.pagination_summary {
p class="mui-block--data__pagination-summary" { (summary) }
}
},
..Default::default()
}))
}
}
}
pub fn preview() -> Markup {
render(Props {
title: "Customers".into(),
subtitle: Some("Manage your customer roster. Search, filter, and act in bulk.".into()),
action: "/customers".into(),
search_value: String::new(),
columns: vec![
Column {
label: "Customer".into(),
},
Column {
label: "Plan".into(),
},
Column {
label: "MRR".into(),
},
Column {
label: "Status".into(),
},
Column {
label: "Signed up".into(),
},
],
filters: vec![
Filter {
label: "Plan".into(),
name: "plan".into(),
options: vec![
("".into(), "All plans".into()),
("starter".into(), "Starter".into()),
("pro".into(), "Pro".into()),
("enterprise".into(), "Enterprise".into()),
],
selected: None,
},
Filter {
label: "Status".into(),
name: "status".into(),
options: vec![
("".into(), "All statuses".into()),
("active".into(), "Active".into()),
("trial".into(), "Trial".into()),
("past_due".into(), "Past due".into()),
("churned".into(), "Churned".into()),
],
selected: Some("active".into()),
},
],
rows: vec![
Row {
id: "c-001".into(),
cells: vec![
RowCell::Stacked {
primary: "Acme Corp".into(),
secondary: "billing@acme.com".into(),
},
RowCell::Text("Enterprise".into()),
RowCell::Text("$2,490".into()),
RowCell::Status {
label: "Active".into(),
variant: StatusVariant::Success,
},
RowCell::Text("Jan 14, 2024".into()),
],
view_href: Some("/customers/c-001".into()),
},
Row {
id: "c-002".into(),
cells: vec![
RowCell::Stacked {
primary: "Globex".into(),
secondary: "finance@globex.io".into(),
},
RowCell::Text("Pro".into()),
RowCell::Text("$790".into()),
RowCell::Status {
label: "Active".into(),
variant: StatusVariant::Success,
},
RowCell::Text("Mar 02, 2025".into()),
],
view_href: Some("/customers/c-002".into()),
},
Row {
id: "c-003".into(),
cells: vec![
RowCell::Stacked {
primary: "Initech".into(),
secondary: "ap@initech.co".into(),
},
RowCell::Text("Pro".into()),
RowCell::Text("$790".into()),
RowCell::Status {
label: "Past due".into(),
variant: StatusVariant::Warning,
},
RowCell::Text("Apr 11, 2025".into()),
],
view_href: Some("/customers/c-003".into()),
},
Row {
id: "c-004".into(),
cells: vec![
RowCell::Stacked {
primary: "Hooli".into(),
secondary: "ops@hooli.xyz".into(),
},
RowCell::Text("Starter".into()),
RowCell::Text("$0".into()),
RowCell::Status {
label: "Trial".into(),
variant: StatusVariant::Neutral,
},
RowCell::Text("Apr 14, 2026".into()),
],
view_href: Some("/customers/c-004".into()),
},
Row {
id: "c-005".into(),
cells: vec![
RowCell::Stacked {
primary: "Piedmont Labs".into(),
secondary: "hello@piedmont.dev".into(),
},
RowCell::Text("Enterprise".into()),
RowCell::Text("$4,990".into()),
RowCell::Status {
label: "Churned".into(),
variant: StatusVariant::Danger,
},
RowCell::Text("Jun 22, 2024".into()),
],
view_href: Some("/customers/c-005".into()),
},
],
bulk_actions: vec![
BulkAction {
value: "export".into(),
label: "Export CSV".into(),
destructive: false,
},
BulkAction {
value: "tag".into(),
label: "Add tag".into(),
destructive: false,
},
BulkAction {
value: "cancel".into(),
label: "Cancel subscription".into(),
destructive: true,
},
],
pagination_summary: Some("Showing 5 of 1,284 customers".into()),
primary_action: Some(PrimaryAction {
label: "New customer".into(),
href: "/customers/new".into(),
}),
})
}