Table
A responsive table component for displaying data in rows and columns.
CMS Demo
See how content editors configure tables in a CMS:
Loading...
CMS ConfigurationSimulates Payload CMS table configuration with data management
Payload Block Example
// In your Payload CMS blocks config
export const TableBlock = {
slug: "table",
fields: [
{ name: "caption", type: "text", localized: true },
{
name: "columns",
type: "array",
fields: [
{ name: "header", type: "text", localized: true, required: true },
{ name: "accessor", type: "text", required: true },
],
},
{
name: "rows",
type: "array",
fields: [
{ name: "data", type: "json" },
],
},
],
}Rendering the Table
import {
Table,
TableHeader,
TableBody,
TableRow,
TableHead,
TableCell,
TableCaption,
} from "@mordecai-design-system/ui"
export function DataTable({ caption, columns, rows }) {
return (
<Table>
{caption && <TableCaption>{caption}</TableCaption>}
<TableHeader>
<TableRow>
{columns.map((col) => (
<TableHead key={col.accessor}>{col.header}</TableHead>
))}
</TableRow>
</TableHeader>
<TableBody>
{rows.map((row, i) => (
<TableRow key={i}>
{columns.map((col) => (
<TableCell key={col.accessor}>
{row.data[col.accessor]}
</TableCell>
))}
</TableRow>
))}
</TableBody>
</Table>
)
}Basic Usage
Loading...
TableData table with styled rows
Installation
pnpm add @corew500/uiUsage
import {
Table,
TableHeader,
TableBody,
TableFooter,
TableHead,
TableRow,
TableCell,
TableCaption,
} from "@mordecai-design-system/ui"<Table>
<TableCaption>A list of recent invoices.</TableCaption>
<TableHeader>
<TableRow>
<TableHead>Invoice</TableHead>
<TableHead>Status</TableHead>
<TableHead>Amount</TableHead>
</TableRow>
</TableHeader>
<TableBody>
<TableRow>
<TableCell>INV001</TableCell>
<TableCell>Paid</TableCell>
<TableCell>$250.00</TableCell>
</TableRow>
</TableBody>
</Table>Examples
With Footer
<Table>
<TableHeader>
<TableRow>
<TableHead>Product</TableHead>
<TableHead>Quantity</TableHead>
<TableHead>Price</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{items.map((item) => (
<TableRow key={item.id}>
<TableCell>{item.name}</TableCell>
<TableCell>{item.quantity}</TableCell>
<TableCell>{item.price}</TableCell>
</TableRow>
))}
</TableBody>
<TableFooter>
<TableRow>
<TableCell colSpan={2}>Total</TableCell>
<TableCell>{total}</TableCell>
</TableRow>
</TableFooter>
</Table>Sub-components
| Component | Description |
|-----------|-------------|
| Table | Root container with scroll |
| TableHeader | Header row container |
| TableBody | Body rows container |
| TableFooter | Footer row container |
| TableHead | Header cell |
| TableRow | Table row with hover states |
| TableCell | Table data cell |
| TableCaption | Table description |
Props
All Table components extend their native HTML element props (table, thead, tbody, tr, th, td).
TableRow
Use data-state="selected" to highlight a row:
<TableRow data-state="selected">
<TableCell>Selected row content</TableCell>
</TableRow>