Table
@codeui/solid v0.3.0
Style native HTML tables with Inkstone.
When to use
Use Table to present data in rows and columns. Add a caption to name the table and use header cells to identify rows or columns.
Live demo
import { Table, TableScrollArea, type TableProps } from "@codeui/solid";
export default function ExportFormats(props: Pick<TableProps, "size" | "striped">) {
return (
<TableScrollArea aria-label="Export formats">
<Table size={props.size} striped={props.striped}>
<caption>Export formats</caption>
<thead>
<tr>
<th scope="col">Format</th>
<th scope="col">Use</th>
<th scope="col" style={{ "text-align": "end" }}>
Scale
</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">PNG</th>
<td>High-resolution screenshots</td>
<td style={{ "text-align": "end" }}>2×</td>
</tr>
<tr>
<th scope="row">JPEG</th>
<td>Smaller files for sharing</td>
<td style={{ "text-align": "end" }}>1×</td>
</tr>
<tr>
<th scope="row">SVG</th>
<td>Scalable artwork</td>
<td style={{ "text-align": "end" }}>Any</td>
</tr>
</tbody>
</Table>
</TableScrollArea>
);
}Anatomy
| Format | Use | Scale |
|---|---|---|
| PNG | High-resolution screenshots | 2× |
| JPEG | Smaller files for sharing | 1× |
| SVG | Scalable artwork | Any |
Tap a part to outline it in the demo.
- 01Table
tableclasses.root - 02TableScrollArea
table-scroll-areaclasses.scrollArea
| Export | Renders | classes key | data-cui | Role |
|---|---|---|---|---|
Table | table | root | table | Table |
TableScrollArea | div | scrollArea | table-scroll-area | Region when named |
Use native caption, thead, tbody, tfoot, tr, th, and td inside Table. The table stylesheet applies to these elements.
Variants
Size
import ExportFormats from "./basic";
export default function CompactTable() {
return <ExportFormats size="sm" />;
}size="sm" reduces cell padding. Use the default md when you have room for more space between rows.
Striped rows
import ExportFormats from "./basic";
export default function StripedTable() {
return <ExportFormats striped />;
}Set striped to give alternating body rows a neutral fill.
Ready API
Import Table and TableScrollArea from @codeui/solid or @codeui/solid/table.
Table
Pass native table attributes such as id and aria-describedby to Table.
Use class or classes.root to extend the table styles. Add classes directly to cells for column-specific styles.
| Prop | Type | Default |
|---|---|---|
size | "sm" | "md" | "md" |
striped | boolean | false |
TableScrollArea
Wrap Table in TableScrollArea when the columns may exceed the available width. Give the scroll area a name with aria-label or aria-labelledby, so keyboard users can identify it.
Use class or classes.scrollArea to extend the scroll area styles.
Styles export
tableStyles
Load @codeui/styles/theme.css and @codeui/styles/table.css when you use the styles outside Solid. Import tableStyles from @codeui/styles/table. Apply tableStyles.root() to a native table and tableStyles.scrollArea() to its scroll container.
Set data-size="sm" for compact cells and data-striped="true" for alternating row fills. The Markdown table in Ready API uses the same stylesheet.
Accessibility
Add scope="col" to column headers and scope="row" to row headers. Use a caption when the table needs a visible name. Keep interactive content in native controls so it stays in the page's tab order.
SSR notes
Table and TableScrollArea render their native HTML, classes, and attributes on the server.