Table
Anatomy
A flexible HTML table primitive with support for striped rows, hover states, compact sizing, and rich cell content.
maud_ui::primitives::table
Props
Generated from public Rust fields. Defaults are evaluated from the implementation.
| Prop | Type | Default | Description |
|---|---|---|---|
headers | Vec<String> | [] | No description |
rows | Vec<Vec<String>> | [] | No description |
rich_rows | Vec<Vec<CellMarkup>> | [] | No description |
footer_row | Vec<CellMarkup> | [] | No description |
striped | bool | false | No description |
hoverable | bool | false | No description |
compact | bool | false | No description |
caption | Option<String> | None | No description |
right_align_cols | Vec<usize> | [] | Numeric columns: right-aligned, tabular numerals in headers, body and footer. |
hide_cols_sm | Vec<usize> | [] | Column indices dropped at 40rem and below. A five-column row that merely squeezes on a phone becomes unreadable; naming the columns that carry the least signal lets the table shed them instead. Emits data-hide-sm on the matching th/td. |
Examples
Compact row actions — fixed height, verb stays together
With badges, right-aligned amounts, and footer total
| Invoice | Status | Method | Amount |
|---|---|---|---|
| INV001 | Paid | Credit Card | $250.00 |
| INV002 | Pending | PayPal | $150.00 |
| INV003 | Unpaid | Bank Transfer | $350.00 |
| INV004 | Paid | Credit Card | $450.00 |
| INV005 | Paid | PayPal | $550.00 |
| Total | $1,750.00 |
Striped + hoverable
| Invoice | Status | Method | Amount |
|---|---|---|---|
| INV001 | Paid | Credit Card | $250.00 |
| INV002 | Pending | PayPal | $150.00 |
| INV003 | Unpaid | Bank Transfer | $350.00 |
| INV004 | Paid | Credit Card | $450.00 |
| INV005 | Paid | PayPal | $550.00 |
Compact — tabular amounts align in plain rows too
| Invoice | Status | Method | Amount |
|---|---|---|---|
| INV001 | Paid | Credit Card | $250.00 |
| INV002 | Pending | PayPal | $150.00 |
| INV003 | Unpaid | Bank Transfer | $350.00 |
| INV004 | Paid | Credit Card | $450.00 |
| INV005 | Paid | PayPal | $550.00 |
Usage and composition
Description
Table renders semantic HTML tables with built-in support for headers, body rows, and footer rows. Cells can contain plain text or rich Markup content (including nested components like badges). Tables support visual modifiers for better readability and UX patterns.
Import
use maud_ui::primitives::table;
Example
use maud::{html, Markup};
use maud_ui::primitives::table::{Props, CellMarkup, render};
let headers = vec![
"Invoice".to_string(),
"Status".to_string(),
"Amount".to_string(),
];
let rows = vec![
vec!["INV001".to_string(), "Paid".to_string(), "$250.00".to_string()],
vec!["INV002".to_string(), "Pending".to_string(), "$150.00".to_string()],
];
let table = render(Props {
headers,
rows,
striped: true,
hoverable: true,
right_align_cols: vec![2],
..Default::default()
});
CellMarkup
Helper struct for rich (Markup-based) table cells.
| Method | Signature | Description |
|---|---|---|
text(s: &str) | Self | Create a left-aligned text cell |
right(s: &str) | Self | Create a right-aligned text cell |
markup(m: Markup, align_right: bool) | Self | Create a cell with custom Markup (e.g., badges, buttons) |
Variants
Striped
Alternating row background colors improve readability for wide tables.
render(Props {
striped: true,
..Default::default()
})
Hoverable
Row background highlights on hover and when a row action receives keyboard focus.
render(Props {
hoverable: true,
..Default::default()
})
Compact
Reduced padding for dense data displays.
render(Props {
compact: true,
..Default::default()
})
Rich Cells (with Markup)
Embed components like badges, buttons, or custom HTML inside cells.
use maud_ui::primitives::{table, badge};
let rich_rows = vec![
vec![
CellMarkup::text("INV001"),
CellMarkup::markup(
badge::render(badge::Props {
label: "Paid".into(),
variant: badge::Variant::Success,
..Default::default()
}),
false,
),
CellMarkup::right("$250.00"),
],
];
render(Props {
headers: vec!["Invoice".into(), "Status".into(), "Amount".into()],
rich_rows,
..Default::default()
})
With Footer
Totals or summary rows with optional right alignment for numbers.
let footer_row = vec![
CellMarkup::text("Total"),
CellMarkup::text(""),
CellMarkup::right("$1,750.00"),
];
render(Props {
footer_row,
..Default::default()
})
With Caption
Semantic table captions improve accessibility and provide context.
render(Props {
caption: Some("A list of your recent invoices.".into()),
..Default::default()
})
Related
- Data Table — Complex tables with sorting, filtering, and pagination
- Badge — Status indicators often embedded in table cells
- Typography — Text styling inside cells
Shadcn Reference
Maud-ui table is a HTML-semantic wrapper for shadcn's <Table> component pattern.
Accessibility
- Semantic HTML: Uses
<thead>,<tbody>,<tfoot>, and column headers withscope="col". - Caption: Use the
captionfield for a semantic table title, visible to screen readers. - Right Alignment: Declare numeric columns in
right_align_colsfor visual alignment; numeric styling does not change the spoken value. - Hover/Striping: Visual indicators (hover, striped) reinforce row boundaries but are not required for understanding.