A container for displaying display data in a tabular format.
A table consists of the following components:
Table
table tag.TableThead
thead tag to wrap table headers.TableTbody
tbody tag to wrap the table's main data.TableTr
tr tag - a table row.TableTh
th tag - a table header.TableTd
td tag - a table cell.The components can be imported via:
To build a table, use the Pluma components like you would the native HTML elements. For example:
| Name | Genus | Species |
|---|---|---|
| Australian Magpie | Gymnorhina | tibicen |
| Galah | Eolophus | roseicapilla |
| Rainbow lorikeet | Trichoglossus | moluccanus |
Note: It is required to provide a caption argument, which renders a visually hidden caption tag within the table.
This caption is used by assistive technologies to provide context to the table.
The TableTh component will automatically receive a scope attribute of col or row,
depending on whether it is nested within Thead or Tbody:
| Name | Genus | Species |
|---|---|---|
| Australian Magpie | Gymnorhina | tibicen |
The table can render in a few differently styled variants.
isBorderless will remove borders between table rows:
| Name | Genus | Species |
|---|---|---|
| Australian Magpie | Gymnorhina | tibicen |
| Galah | Eolophus | roseicapilla |
| Rainbow lorikeet | Trichoglossus | moluccanus |
isStriped will apply alternating background colors to rows:
| Name | Genus | Species |
|---|---|---|
| Australian Magpie | Gymnorhina | tibicen |
| Galah | Eolophus | roseicapilla |
| Rainbow lorikeet | Trichoglossus | moluccanus |
shouldHighlightOnHover will apply a background color when hovering over a row:
| Name | Genus | Species |
|---|---|---|
| Australian Magpie | Gymnorhina | tibicen |
| Galah | Eolophus | roseicapilla |
| Rainbow lorikeet | Trichoglossus | moluccanus |
Sometimes, you may need to conditionally enable the hover style only on specific rows.
In this case, you can pass the shouldHighlightOnHover prop to the TableTr component directly:
| Name | Genus | Species |
|---|---|---|
| Australian Magpie | Gymnorhina | tibicen |
| Galah | Eolophus | roseicapilla |
| Rainbow lorikeet | Trichoglossus | moluccanus |
The component accepts a layout prop, which can be set to fixed to
set table-layout: fixed on the table.
| Name | Genus | Species |
|---|---|---|
| Australian Magpie | Gymnorhina | tibicen |
| Galah | Eolophus | roseicapilla |
| Rainbow lorikeet | Trichoglossus | moluccanus |
The TableTh component accepts an onClick prop. When present,
the header will render a button, which will call the provided callback when clicked.
Additionally, the isActive prop to apply a different text color to the header,
to indicate that the column is currently "active".
These props can be used when making tables sortable, and clicking headers should invoke the sorting functionality.
| Australian Magpie | Gymnorhina | tibicen |
| Galah | Eolophus | roseicapilla |
| Rainbow lorikeet | Trichoglossus | moluccanus |
Note: The table component itself does not perform any sorting at this time. These props are utilities to make it easier to customize the table to include sorting.
PlumaTable extends BoxA caption for the table for assistive technologies, but hidden visually.
Whether to disable the border style between table rows
Whether to render table rows with alternating background colors
Default:auto
The layout of the table
Whether hovering over the rows should highlight them (change their background color)
PlumaTableTh extends BoxWhether this column is active (for example, when sorting on this column). Changes the color of the column header's text.
Whether the cell is clickable. When provided, the cell will render a button, and will have additional hover styles applied. Can be used when implementing click-to-sort functionality, for example.
PlumaTableTr extends BoxWhether to disable the border style on this row
Whether hovering over this row should highlight it (change its background color)
PlumaTableTd extends BoxWhether the cell should have extra padding depending on nesting level.