Table
Rows and columns of data with a header, in a horizontally scrolling wrapper.
SourceStyles source@monoline/react 0.5.0Markdown for AI toolsstable
- Built on native elements
- 7 parts, named exports
- Native table elements with th scope and an optional caption.
- The scroll wrapper is focusable and named so keyboard users can scroll wide tables.
- Styles in one file:
14-table.css
Import
import '@monoline/css';
import {Table} from '@monoline/react';
Not installed yet? Pick a route.
Copies the source and its styles into your project.
npx monoline add table
Usage
import {Table, TableBody, TableCaption, TableCell, TableHead, TableHeader, TableRow} from '@monoline/react';
<Table wrapperLabel="Team">
<TableCaption>Team members</TableCaption>
<TableHeader><TableRow><TableHead>Name</TableHead><TableHead>Role</TableHead><TableHead numeric>Projects</TableHead></TableRow></TableHeader>
<TableBody>
<TableRow><TableCell>Ada Lovelace</TableCell><TableCell>Engineer</TableCell><TableCell numeric>4</TableCell></TableRow>
<TableRow><TableCell>Grace Hopper</TableCell><TableCell>Admiral</TableCell><TableCell numeric>9</TableCell></TableRow>
</TableBody>
</Table>
Anatomy
Import the parts you need and nest them like this.
import {Table, TableCaption, TableHeader, TableBody, TableRow, TableHead, TableCell} from '@monoline/react';
<Table>
<TableCaption />
<TableHeader />
<TableBody />
<TableRow />
<TableHead />
<TableCell />
</Table>
Examples
Basic
Props
TableProps
| Prop | Type | Default | Description |
|---|---|---|---|
wrapperLabel | string | – | Names the scrollable wrapper. Give it when the table can overflow. |
TableCellProps
| Prop | Type | Default | Description |
|---|---|---|---|
numeric | boolean | – | Right-aligns numbers. |
Data Attributes
State is exposed through attributes. Style it with these selectors, not with class toggles.
This component sets no state attributes.
CSS classes
| Class | Stylesheet |
|---|---|
.num | 14-table.css |
.table | 14-table.css |
.table-wrap | 14-table.css |
Customization
Style it with the kit's tokens in your own CSS, loaded after @monoline/css. Prefer the attributes above over extra classes. See Theming for every token.
app.css
.num {
border-color: var(--accent);
}
Accessibility
- Native table elements with th scope and an optional caption.
- The scroll wrapper is focusable and named so keyboard users can scroll wide tables.