Playground

Table

Rows and columns of data with a header, in a horizontally scrolling wrapper.

  • 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

PropTypeDefaultDescription
wrapperLabelstring–Names the scrollable wrapper. Give it when the table can overflow.

TableCellProps

PropTypeDefaultDescription
numericboolean–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

ClassStylesheet
.num14-table.css
.table14-table.css
.table-wrap14-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.