Data
Table
Rows and columns with the right edges, heights and number alignment.
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from 'omuk-ui/table';Data
Rows and columns with the right edges, heights and number alignment.
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from 'omuk-ui/table';Change the props on the right. The table and its code follow.
| Invoice | Customer | Amount |
|---|---|---|
| INV-1042 | Northwind Trading | $1,250.00 |
| INV-1043 | Contoso Ltd | $830.50 |
| INV-1044 | Fabrikam | $12,400.00 |
| INV-1045 | Tailspin Toys | $96.00 |
| Total | $14,576.50 | |
import {
Table,
TableBody,
TableCell,
TableFooter,
TableHead,
TableHeader,
TableRow,
} from 'omuk-ui/table';
<Table containerClassName="rounded-lg inset-ring inset-ring-border">
<TableHeader>
<TableRow>
<TableHead className="pl-4">Invoice</TableHead>
<TableHead>Customer</TableHead>
<TableHead className="pr-4 text-right">Amount</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{invoices.slice(0, 4).map((invoice, index) => (
<TableRow
key={invoice.id}
data-selected={index === 1 || undefined}
>
<TableCell className="pl-4 font-medium">{invoice.id}</TableCell>
<TableCell>{invoice.customer}</TableCell>
<TableCell className="pr-4 text-right font-mono text-xs tabular-nums">
{money.format(invoice.amount)}
</TableCell>
</TableRow>
))}
</TableBody>
<TableFooter>
<TableRow>
<TableCell className="pl-4" colSpan={2}>Total</TableCell>
<TableCell className="pr-4 text-right font-mono text-xs tabular-nums">{money.format(total)}</TableCell>
</TableRow>
</TableFooter>
</Table>Numbers sit on the right, in mono at the extra-small size, so the digits line up. A row’s actions go in a menu behind an extra-small ghost button at the row’s end.
| Invoice | Customer | Status | Amount | Actions |
|---|---|---|---|---|
| INV-1042 | Northwind Trading | Paid | $1,250.00 | |
| INV-1043 | Contoso Ltd | Due | $830.50 | |
| INV-1044 | Fabrikam | Overdue | $12,400.00 | |
| INV-1045 | Tailspin Toys | Paid | $96.00 |
TableFooter holds the totals on the panel fill. TableCaption says what the table shows; it sits under the table.
| Service | Requests | Errors |
|---|---|---|
| Web app | 1,284,330 | 212 |
| Public API | 902,118 | 1,045 |
| Webhooks | 48,210 | 3 |
| Total | 2,234,658 | 1,260 |
useSelection selects as a file manager does: a click picks one row, Shift + click a range, Ctrl or Cmd + click one more. Each row’s checkbox adds or removes it, and Shift + click on a checkbox fills the range. The status line is read out as it changes.
0 of 5 selected
| Name | Size | Changed | |
|---|---|---|---|
| Brief.pdf | 240 KB | Today | |
| Budget.xlsx | 88 KB | Yesterday | |
| Logo.svg | 12 KB | 21 Nov | |
| Notes.md | 4 KB | 18 Nov | |
| Photo.jpg | 3.1 MB | 2 Nov |
The parts are the table’s own elements: Table, TableHeader, TableBody, TableFooter, TableRow, TableHead, TableCell and TableCaption. Each takes the props of its element.
From omuk-ui/selection. It takes the props below and returns props to spread: rowProps(id) on a TableRow, checkboxProps(id) on its Checkbox, allProps() on the head’s Checkbox, statusProps() on the line that counts. It also returns value, count, isSelected(id), selectAll() and clear().