Bedform UIMessages
Table
Present structured data in rows and columns.
Table
*
string
*
Usage
import { Table } from "@bedform/ui/table";
export function WorldsTable() {
return (
<Table variant="striped">
<table>
<caption>Available worlds</caption>
<thead>
<tr>
<th scope="col">World</th>
<th scope="col">Players</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Mountains</th>
<td>4 / 10</td>
</tr>
<tr>
<th scope="row">Village</th>
<td>8 / 20</td>
</tr>
</tbody>
</table>
</Table>
);
}Table renders a scrollable div around a native table, which you write yourself.
Sorting
Put a button with the ore-table-sort class inside a header with aria-sort. Its value identifies the column.
<th scope="col" aria-sort={sort.column === "players" ? sort.direction : "none"}>
<button className="ore-table-sort" type="button" value="players">
Players
<span className="ore-table-sort-indicator" aria-hidden="true" />
</button>
</th>The sort event provides the column and the next direction. Your application sorts the data.
const [sort, setSort] = useState<OreTableSortDetail>({
column: "",
direction: "none",
});
<Table onSort={(event) => setSort(event.detail)}>ā¦</Table>;OreTableSortDetail is exported from @bedform/ui.
API
Table accepts every div attribute and forwards its ref to the div.
| Prop | Type | Default |
|---|---|---|
onSort | (event: CustomEvent<OreTableSortDetail>) => void | ā |
variant | "plain" | "striped" | "plain" |
| Event | Detail |
|---|---|
sort | { column: string; direction: "none" | "ascending" | "descending" } |
Public classes
| Class | Purpose |
|---|---|
.ore-table | Table container and controller root |
.ore-table-row-header-column | Row-header column width |
.ore-table-data-column | Data column width |
.ore-table-corner | Empty top-left corner cell |
.ore-table-sort | Sortable header button |
.ore-table-sort-indicator | Ascending and descending indicator |
CSS variables
The horizontally scrollable table also accepts all Scrollbar CSS variables.
| Variable | Purpose |
|---|---|
--ore-table-unit | Base size unit |
--ore-table-border | Cell border color |
--ore-table-header-background | Header cell background |
--ore-table-row-background | Row background |
--ore-table-row-background-alternate | Alternate striped row background |
--ore-table-foreground | Table text color |
--ore-table-sort-inactive | Inactive sort indicator color |
Accessibility
Keep the native table structure, add a caption, and use scope on headers.
Sorting updates aria-sort. Announce results when there are no changes.