File size: 2,079 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# Table
Table is a component used to display tabular data. It is used to render semantic HTML table markup while handling accessibility. More information on accessible tables [here](http://webaim.org/techniques/tables/data).
The `compact` prop applies styling for a more compact table. It also allows for a column to occupy the largest space available by including the prop `isTitle` on a `TableItem`. Contents of the cell will have overflow faded to white.

## How to use
```js
import Table from './components/table';
import TableItem from './components/table/table-item';
import TableRow from './components/table/table-row';
function render() {
const titles = (
<TableRow isHeader>
{ [ 'One', 'Two', 'Three' ].map( ( item, i ) => (
<TableItem isHeader key={ i } isTitle={ 0 === i }>
{ item }
</TableItem>
) ) }
</TableRow>
);
const values = [
[ 1, 2, 3 ],
[ 4, 5, 6 ],
[ 7, 8, 9 ],
];
return (
<Table header={ titles } compact>
{ values.map( ( row, i ) => (
<TableRow key={ i }>
{ row.map( ( item, j ) => (
<TableItem key={ j } isTitle={ 0 === j }>
{ item }
</TableItem>
) ) }
</TableRow>
) ) }
</Table>
);
}
```
## Props `<Table/>`
- `header`: A `<TableRow />` element used to define the table's head.
- `className`: Classes added to top level element.
- `compact`: Denotes a more compact table.
## Props `<TableRow/>`
- `className`: Classes added to top level element.
- `isHeader`: Establishes row as being used for table head.
- `href`: Optional link, if set, the row becomes clickable/focusable.
## Props `<TableItem/>`
- `alignRight`: Apply `text-align: right` on an item.
- `className`: Classes added to top level element.
- `isHeader`: Establishes item as being a column header.
- `isRowHeader`: Establishes item as being a row header.
- `isTitle`: Used to specify a main cell occupying the maximum available space in `compact` mode.
|