Tables display a collection of structured data and typically have the ability to sort, filter, and paginate data. Good data tables allows the user to scan, analyze, compare, filter, and sort information to derive insights and commit actions.
Table shift and alignment attributes can work in conjunction with each other, as well as be applied to the table header (not just the table body).
Use table size "sm"
when data density is a priority. Smaller row height enables the user to view more data without the need for scrolling.
Table can leverage the max-width property. Learn more in our visual guidelines.
import React from 'react' import Table from 'playbook-ui' const TableSm = (props) => { return ( <Table size="sm" > <thead> <tr> <th>{'Column 1'}</th> <th>{'Column 2'}</th> <th>{'Column 3'}</th> <th>{'Column 4'}</th> <th>{'Column 5'}</th> </tr> </thead> <tbody> <tr> <td>{'Value 1'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> <td>{'Value 4'}</td> <td>{'Value 5'}</td> </tr> <tr> <td>{'Value 1'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> <td>{'Value 4'}</td> <td>{'Value 5'}</td> </tr> <tr> <td>{'Value 1'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> <td>{'Value 4'}</td> <td>{'Value 5'}</td> </tr> </tbody> </Table> ) } export default TableSm
Use table size "md"
to add padding around each row to increase reading comfortability.
import React from 'react' import Table from 'playbook-ui' const TableMd = (props) => { return ( <Table size="md" > <thead> <tr> <th>{'Column 1'}</th> <th>{'Column 2'}</th> <th>{'Column 3'}</th> <th>{'Column 4'}</th> <th>{'Column 5'}</th> </tr> </thead> <tbody> <tr> <td>{'Value 1'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> <td>{'Value 4'}</td> <td>{'Value 5'}</td> </tr> <tr> <td>{'Value 1'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> <td>{'Value 4'}</td> <td>{'Value 5'}</td> </tr> <tr> <td>{'Value 1'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> <td>{'Value 4'}</td> <td>{'Value 5'}</td> </tr> </tbody> </Table> ) } export default TableMd
Use table size "lg"
to add padding around each row to maximize reading comfortability.
import React from 'react' import Table from 'playbook-ui' const TableLg = (props) => { return ( <Table size="lg" > <thead> <tr> <th>{'Column 1'}</th> <th>{'Column 2'}</th> <th>{'Column 3'}</th> <th>{'Column 4'}</th> <th>{'Column 5'}</th> </tr> </thead> <tbody> <tr> <td>{'Value 1'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> <td>{'Value 4'}</td> <td>{'Value 5'}</td> </tr> <tr> <td>{'Value 1'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> <td>{'Value 4'}</td> <td>{'Value 5'}</td> </tr> <tr> <td>{'Value 1'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> <td>{'Value 4'}</td> <td>{'Value 5'}</td> </tr> </tbody> </Table> ) } export default TableLg
React: Use sticky
on a table to allow the table header to be fixed in place when the user scrolls up and down on the page.
Rails: Pass sticky: true
to props.
If the table header is not sticking in the right place you will need to pass a inline top
style to the thead
.
React Example: <thead style={{ top: "-16px" }}>
Rails Example: <thead style="top: -16px">
Sticky may not work if any parent/ancestor of the sticky element has any of the overflow
properties set. Additionally, specifying a height on the overflowing container provides measurement for this feature to work properly. In some cases, it may be necessary to set the same parent/ancestor container to position: static
as well.
import React from "react" import Table from 'playbook-ui' const TableSticky = (props) => ( <Table sticky > <thead> <tr> <th>{'Column 1'}</th> <th>{'Column 2'}</th> <th>{'Column 3'}</th> <th>{'Column 4'}</th> <th>{'Column 5'}</th> </tr> </thead> <tbody> <tr> <td>{'Value 1'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> <td>{'Value 4'}</td> <td>{'Value 5'}</td> </tr> <tr> <td>{'Value 1'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> <td>{'Value 4'}</td> <td>{'Value 5'}</td> </tr> <tr> <td>{'Value 1'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> <td>{'Value 4'}</td> <td>{'Value 5'}</td> </tr> <tr> <td>{'Value 1'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> <td>{'Value 4'}</td> <td>{'Value 5'}</td> </tr> <tr> <td>{'Value 1'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> <td>{'Value 4'}</td> <td>{'Value 5'}</td> </tr> <tr> <td>{'Value 1'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> <td>{'Value 4'}</td> <td>{'Value 5'}</td> </tr> <tr> <td>{'Value 1'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> <td>{'Value 4'}</td> <td>{'Value 5'}</td> </tr> <tr> <td>{'Value 1'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> <td>{'Value 4'}</td> <td>{'Value 5'}</td> </tr> <tr> <td>{'Value 1'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> <td>{'Value 4'}</td> <td>{'Value 5'}</td> </tr> <tr> <td>{'Value 1'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> <td>{'Value 4'}</td> <td>{'Value 5'}</td> </tr> </tbody> </Table> ) export default TableSticky
Pass our textAlign
global prop to any table.row
subcomponent to change the text alignment of all cells within that row.
The header/ first row is the default, followed by the second row being centered, and then the last row shifted to the right.
import React from 'react' import Table from 'playbook-ui' const TableAlignmentRow = (props) => { return ( <Table > <Table.Head> <Table.Row> <Table.Header>{'Column 1'}</Table.Header> <Table.Header>{'Column 2'}</Table.Header> <Table.Header>{'Column 3'}</Table.Header> <Table.Header>{'Column 4'}</Table.Header> <Table.Header>{'Column 5'}</Table.Header> </Table.Row> </Table.Head> <Table.Body> <Table.Row> <Table.Cell>{'Value 1'}</Table.Cell> <Table.Cell>{'Value 2'}</Table.Cell> <Table.Cell>{'Value 3'}</Table.Cell> <Table.Cell>{'Value 4'}</Table.Cell> <Table.Cell>{'Value 5'}</Table.Cell> </Table.Row> <Table.Row textAlign="center"> <Table.Cell>{'Value 1'}</Table.Cell> <Table.Cell>{'Value 2'}</Table.Cell> <Table.Cell>{'Value 3'}</Table.Cell> <Table.Cell>{'Value 4'}</Table.Cell> <Table.Cell>{'Value 5'}</Table.Cell> </Table.Row> <Table.Row textAlign="right"> <Table.Cell>{'Value 1'}</Table.Cell> <Table.Cell>{'Value 2'}</Table.Cell> <Table.Cell>{'Value 3'}</Table.Cell> <Table.Cell>{'Value 4'}</Table.Cell> <Table.Cell>{'Value 5'}</Table.Cell> </Table.Row> </Table.Body> </Table> ) } export default TableAlignmentRow
Pass our textAlign
global prop to any table.cell
subcomponent to change the text alignment of individual cells, or apply this prop persistently to align entire columns.
In the table above the "Rating" column contents is centered and the "Money" column contents is right aligned.
import React from 'react' import Table from 'playbook-ui' const TableAlignmentColumn = (props) => { return ( <Table > <Table.Head> <Table.Row> <Table.Header>{'Column 1'}</Table.Header> <Table.Header>{'Column 2'}</Table.Header> <Table.Header>{'Column 3'}</Table.Header> <Table.Header textAlign="center">{'Rating'}</Table.Header> <Table.Header textAlign="right">{'Money'}</Table.Header> </Table.Row> </Table.Head> <Table.Body> <Table.Row> <Table.Cell>{'Value 1'}</Table.Cell> <Table.Cell>{'Value 2'}</Table.Cell> <Table.Cell>{'Value 3'}</Table.Cell> <Table.Cell textAlign="center">{'3'}</Table.Cell> <Table.Cell textAlign="right">{'$57.32'}</Table.Cell> </Table.Row> <Table.Row> <Table.Cell>{'Value 1'}</Table.Cell> <Table.Cell>{'Value 2'}</Table.Cell> <Table.Cell>{'Value 3'}</Table.Cell> <Table.Cell textAlign="center">{'2'}</Table.Cell> <Table.Cell textAlign="right">{'$5,657.08'}</Table.Cell> </Table.Row> <Table.Row> <Table.Cell>{'Value 1'}</Table.Cell> <Table.Cell>{'Value 2'}</Table.Cell> <Table.Cell>{'Value 3'}</Table.Cell> <Table.Cell textAlign="center">{'4'}</Table.Cell> <Table.Cell textAlign="right">{'$358.77'}</Table.Cell> </Table.Row> </Table.Body> </Table> ) } export default TableAlignmentColumn
Pass our verticalAlign
global prop to any table.row
subcomponent to change the vertical alignment of all cells within that row.
import React from 'react' import Table from 'playbook-ui' const TableAlignmentShiftRow = (props) => { return ( <Table> <Table.Head> <Table.Row> <Table.Header>{'Column 1'}</Table.Header> <Table.Header>{'Column 2'}</Table.Header> <Table.Header>{'Column 3'}</Table.Header> <Table.Header>{'Column 4'}</Table.Header> <Table.Header>{'Column 5'}</Table.Header> </Table.Row> </Table.Head> <Table.Body> <Table.Row> <Table.Cell> {'Value 1a'} <br /> {'Value 1a'} <br /> {'Value 1a'} </Table.Cell> <Table.Cell>{'Value 2a'}</Table.Cell> <Table.Cell>{'Value 3a'}</Table.Cell> <Table.Cell>{'Value 4a'}</Table.Cell> <Table.Cell>{'Value 5a'}</Table.Cell> </Table.Row> <Table.Row verticalAlign="middle"> <Table.Cell> {'Value 1b'} <br /> {'Value 1b'} <br /> {'Value 1b'} </Table.Cell> <Table.Cell>{'Value 2b'}</Table.Cell> <Table.Cell>{'Value 3b'}</Table.Cell> <Table.Cell>{'Value 4b'}</Table.Cell> <Table.Cell>{'Value 5b'}</Table.Cell> </Table.Row> <Table.Row verticalAlign="bottom"> <Table.Cell> {'Value 1c'} <br /> {'Value 1c'} <br /> {'Value 1c'} </Table.Cell> <Table.Cell>{'Value 2c'}</Table.Cell> <Table.Cell>{'Value 3c'}</Table.Cell> <Table.Cell>{'Value 4c'}</Table.Cell> <Table.Cell>{'Value 5c'}</Table.Cell> </Table.Row> </Table.Body> </Table> ) } export default TableAlignmentShiftRow
Pass our verticalAlign
global prop to any table.cell
subcomponent to change the text alignment of individual cells, or apply this prop persistently to align entire columns.
The first table shifts "Total" down, whereas the second table shifts the "Espresso Drinks" column contents up.
import React from 'react' import Table from 'playbook-ui' const TableAlignmentShiftData = (props) => { return ( <div> <Table marginBottom="md" > <Table.Head> <Table.Row> <Table.Header> </Table.Header> <Table.Header>{'Price'}</Table.Header> </Table.Row> </Table.Head> <Table.Body> <Table.Row> <Table.Cell verticalAlign="bottom">{'Total'}</Table.Cell> <Table.Cell> {'$12'} <br /> {'$46'} <br /> {'$25'} <br /> {'-------'} <br /> {'$83'} </Table.Cell> </Table.Row> </Table.Body> </Table> <Table > <Table.Head> <Table.Row> <Table.Header>{'Espresso Drinks'}</Table.Header> <Table.Header>{'Ingredients'}</Table.Header> </Table.Row> </Table.Head> <Table.Body> <Table.Row> <Table.Cell verticalAlign="top">{'Cappuccino'} </Table.Cell> <Table.Cell> {'Steamed Milk'} <br /> {'Milk Foam'} </Table.Cell> </Table.Row> <Table.Row> <Table.Cell verticalAlign="top"> {'Macchiato'} </Table.Cell> <Table.Cell verticalAlign="top"> {'Espresso'} <br /> {'Steamed Milk'} </Table.Cell> </Table.Row> <Table.Row> <Table.Cell> {'Mocha'} </Table.Cell> <Table.Cell> {'Hot Chocolate'} <br /> {'Steamed Milk'} </Table.Cell> </Table.Row> </Table.Body> </Table> </div> ) } export default TableAlignmentShiftData
Side highlight can take product, status, and category colors. To view full list of colors, visit token colors.
Note: Only use category colors for categories. Do not mix it with product or status colors.
import React from 'react' import Table from 'playbook-ui' const TableSideHighlight = (props) => { return ( <div> <Table size="sm" > <thead> <tr> <th>{'Product colors'}</th> <th>{'Column 2'}</th> <th>{'Column 3'}</th> <th>{'Column 4'}</th> <th>{'Column 5'}</th> </tr> </thead> <tbody> <Table.Row sideHighlightColor="product_1_highlight" > <td>{'Product 1'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> <td>{'Value 4'}</td> <td>{'Value 5'}</td> </Table.Row> <Table.Row sideHighlightColor="product_2_highlight" > <td>{'Product 2'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> <td>{'Value 4'}</td> <td>{'Value 5'}</td> </Table.Row> <Table.Row sideHighlightColor="product_3_highlight" > <td>{'Product 3'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> <td>{'Value 4'}</td> <td>{'Value 5'}</td> </Table.Row> <Table.Row sideHighlightColor="none" > <td>{'None'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> <td>{'Value 4'}</td> <td>{'Value 5'}</td> </Table.Row> </tbody> </Table> <br /> <Table size="sm" > <thead> <tr> <th>{'Status colors'}</th> <th>{'Column 2'}</th> <th>{'Column 3'}</th> <th>{'Column 4'}</th> <th>{'Column 5'}</th> </tr> </thead> <tbody> <Table.Row sideHighlightColor="success" > <td>{'Success'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> <td>{'Value 4'}</td> <td>{'Value 5'}</td> </Table.Row> <Table.Row sideHighlightColor="warning" > <td>{'Warning'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> <td>{'Value 4'}</td> <td>{'Value 5'}</td> </Table.Row> <Table.Row sideHighlightColor="error" > <td>{'Error'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> <td>{'Value 4'}</td> <td>{'Value 5'}</td> </Table.Row> <Table.Row sideHighlightColor="none" > <td>{'None'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> <td>{'Value 4'}</td> <td>{'Value 5'}</td> </Table.Row> </tbody> </Table> <br /> <Table size="sm" > <thead> <tr> <th>{'Category Colors'}</th> <th>{'Column 2'}</th> <th>{'Column 3'}</th> <th>{'Column 4'}</th> <th>{'Column 5'}</th> </tr> </thead> <tbody> <Table.Row sideHighlightColor="category_1" > <td>{'Category Color 1'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> <td>{'Value 4'}</td> <td>{'Value 5'}</td> </Table.Row> <Table.Row sideHighlightColor="category_2" > <td>{'Category Color 2'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> <td>{'Value 4'}</td> <td>{'Value 5'}</td> </Table.Row> <Table.Row sideHighlightColor="category_3" > <td>{'Category Color 3'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> <td>{'Value 4'}</td> <td>{'Value 5'}</td> </Table.Row> <Table.Row sideHighlightColor="none" > <td>{'None'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> <td>{'Value 4'}</td> <td>{'Value 5'}</td> </Table.Row> </tbody> </Table> </div> ) } export default TableSideHighlight
import React from 'react' import Table from 'playbook-ui' const TableContainer = (props) => { return ( <Table container={false} size="md" > <thead> <tr> <th>{'Column 1'}</th> <th>{'Column 2'}</th> <th>{'Column 3'}</th> <th>{'Column 4'}</th> <th>{'Column 5'}</th> </tr> </thead> <tbody> <tr> <td>{'Value 1'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> <td>{'Value 4'}</td> <td>{'Value 5'}</td> </tr> <tr> <td>{'Value 1'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> <td>{'Value 4'}</td> <td>{'Value 5'}</td> </tr> <tr> <td>{'Value 1'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> <td>{'Value 4'}</td> <td>{'Value 5'}</td> </tr> </tbody> </Table> ) } export default TableContainer
import React from 'react' import Table from 'playbook-ui' const TableDisableHover = (props) => { return ( <Table disableHover size="md" > <thead> <tr> <th>{'Column 1'}</th> <th>{'Column 2'}</th> <th>{'Column 3'}</th> <th>{'Column 4'}</th> <th>{'Column 5'}</th> </tr> </thead> <tbody> <tr> <td>{'Value 1'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> <td>{'Value 4'}</td> <td>{'Value 5'}</td> </tr> <tr> <td>{'Value 1'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> <td>{'Value 4'}</td> <td>{'Value 5'}</td> </tr> <tr> <td>{'Value 1'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> <td>{'Value 4'}</td> <td>{'Value 5'}</td> </tr> </tbody> </Table> ) } export default TableDisableHover
import React from 'react' import Table from 'playbook-ui' const TableMultiline = (props) => { return ( <Table size="sm" > <thead> <tr> <th>{'Column 1'}</th> <th>{'Column 2'}</th> <th>{'Column 3'}</th> <th>{'Column 4'}</th> <th>{'Column 5'}</th> </tr> </thead> <tbody> <tr> <td> {'Value 1'} <br /> {'Value 1'} <br /> {'Value 1'} </td> <td>{'Value 2'}</td> <td> {'Value 3'} <br /> {'Value 3'} </td> <td>{'Value 4'}</td> <td>{'Value 5'}</td> </tr> <tr> <td> {'Value 1'} <br /> {'Value 1'} <br /> {'Value 1'} </td> <td>{'Value 2'}</td> <td> {'Value 3'} <br /> {'Value 3'} </td> <td>{'Value 4'}</td> <td>{'Value 5'}</td> </tr> <tr> <td> {'Value 1'} <br /> {'Value 1'} <br /> {'Value 1'} </td> <td>{'Value 2'}</td> <td> {'Value 3'} <br /> {'Value 3'} </td> <td>{'Value 4'}</td> <td>{'Value 5'}</td> </tr> </tbody> </Table> ) } export default TableMultiline
import React from 'react' import Table from 'playbook-ui' const TableSingleLine = (props) => { return ( <Table singleLine size="sm" > <thead> <tr> <th>{'Column 1'}</th> <th>{'Column 2'}</th> <th>{'Column 3'}</th> <th>{'Column 4'}</th> <th>{'Column 5'}</th> </tr> </thead> <tbody> <tr> <td> {'Value 1'} <br /> {'Value 1'} <br /> {'Value 1'} </td> <td>{'Value 2'}</td> <td> {'Value 3'} <br /> {'Value 3'} </td> <td>{'Value 4'}</td> <td>{'Value 5'}</td> </tr> <tr> <td> {'Value 1'} <br /> {'Value 1'} <br /> {'Value 1'} </td> <td>{'Value 2'}</td> <td> {'Value 3'} <br /> {'Value 3'} </td> <td>{'Value 4'}</td> <td>{'Value 5'}</td> </tr> <tr> <td> {'Value 1'} <br /> {'Value 1'} <br /> {'Value 1'} </td> <td>{'Value 2'}</td> <td> {'Value 3'} <br /> {'Value 3'} </td> <td>{'Value 4'}</td> <td>{'Value 5'}</td> </tr> </tbody> </Table> ) } export default TableSingleLine
Tighter spacing in first- and last-child cells of each row for data-heavy tables.
import React from 'react' import Table from 'playbook-ui' const TableDataTable = (props) => { return ( <Table dataTable > <thead> <tr> <th>{'Column 1'}</th> <th>{'Column 2'}</th> <th>{'Column 3'}</th> <th>{'Column 4'}</th> <th>{'Column 5'}</th> </tr> </thead> <tbody> <tr> <td>{'Value 1'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> <td>{'Value 4'}</td> <td>{'Value 5'}</td> </tr> <tr> <td>{'Value 1'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> <td>{'Value 4'}</td> <td>{'Value 5'}</td> </tr> <tr> <td>{'Value 1'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> <td>{'Value 4'}</td> <td>{'Value 5'}</td> </tr> </tbody> </Table> ) } export default TableDataTable
import React from 'react' import Table from 'playbook-ui' import Title from 'playbook-ui' const TableResponsiveTable = (props) => { return ( <div> <Title size={4} text="Not Responsive" /> <Table responsive="none" > <thead> <tr> <th>{'Column 1'}</th> <th>{'Column 2'}</th> <th>{'Column 3'}</th> <th>{'Column 4'}</th> <th>{'Column 5'}</th> </tr> </thead> <tbody> <tr> <td>{'Value 1'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> <td>{'Value 4'}</td> <td>{'Value 5'}</td> </tr> </tbody> </Table> <br /> <br /> <Title size={4} text="Collapse Mobile" /> <Table collapse="sm" > <thead> <tr> <th>{'Column 1'}</th> <th>{'Column 2'}</th> <th>{'Column 3'}</th> <th>{'Column 4'}</th> <th>{'Column 5'}</th> </tr> </thead> <tbody> <tr> <td>{'Value 1'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> <td>{'Value 4'}</td> <td>{'Value 5'}</td> </tr> </tbody> </Table> <br /> <br /> <Title size={4} text="Collapse Tablet" /> <Table collapse="md" > <thead> <tr> <th>{'Column 1'}</th> <th>{'Column 2'}</th> <th>{'Column 3'}</th> <th>{'Column 4'}</th> <th>{'Column 5'}</th> </tr> </thead> <tbody> <tr> <td>{'Value 1'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> <td>{'Value 4'}</td> <td>{'Value 5'}</td> </tr> </tbody> </Table> <br /> <br /> <Title size={4} text="Collapse Desktop" /> <Table collapse="lg" > <thead> <tr> <th>{'Column 1'}</th> <th>{'Column 2'}</th> <th>{'Column 3'}</th> <th>{'Column 4'}</th> <th>{'Column 5'}</th> </tr> </thead> <tbody> <tr> <td>{'Value 1'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> <td>{'Value 4'}</td> <td>{'Value 5'}</td> </tr> </tbody> </Table> </div> ) } export default TableResponsiveTable
If there is one button on each row of the table, ideally, it should use the secondary
variant and be placed at the end of the row
import React from 'react' import Table from 'playbook-ui' import Button from 'playbook-ui' const TableOneAction = (props) => { return ( <Table size="sm" > <thead> <tr> <th>{'Column 1'}</th> <th>{'Column 2'}</th> <th>{'Column 3'}</th> <th>{'Column 4'}</th> <th>{''}</th> </tr> </thead> <tbody> <tr> <td>{'Value 1'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> <td>{'Value 4'}</td> <td align="right"> {' '} <Button onClick={() => alert('button clicked!')} text="Action" variant="secondary" /> {' '} </td> </tr> <tr> <td>{'Value 1'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> <td>{'Value 4'}</td> <td align="right"> {' '} <Button onClick={() => alert('button clicked!')} text="Action" variant="secondary" /> {' '} </td> </tr> <tr> <td>{'Value 1'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> <td>{'Value 4'}</td> <td align="right"> {' '} <Button onClick={() => alert('button clicked!')} text="Action" variant="secondary" /> {' '} </td> </tr> </tbody> </Table> ) } export default TableOneAction
If there are two actions on each of the row, one should ideally one should use the secondary
variant and the other use the link
variant. The button using the secondary
variant should be placed at the end.
import React from 'react' import Table from 'playbook-ui' import Button from 'playbook-ui' const TableOneAction = (props) => { return ( <Table size="sm" > <thead> <tr> <th>{'Column 1'}</th> <th>{'Column 2'}</th> <th>{'Column 3'}</th> <th>{'Column 4'}</th> <th>{''}</th> </tr> </thead> <tbody> <tr> <td>{'Value 1'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> <td>{'Value 4'}</td> <td align="right"> <Button onClick={() => alert('button clicked!')} paddingLeft="none" text="Tertiary Action" variant="link" /> <Button onClick={() => alert('button clicked!')} text="Secondary Action" variant="secondary" /> </td> </tr> <tr> <td>{'Value 1'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> <td>{'Value 4'}</td> <td align="right"> <Button onClick={() => alert('button clicked!')} paddingLeft="none" text="Tertiary Action" variant="link" /> <Button onClick={() => alert('button clicked!')} text="Secondary Action" variant="secondary" /> </td> </tr> <tr> <td>{'Value 1'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> <td>{'Value 4'}</td> <td align="right"> <Button onClick={() => alert('button clicked!')} paddingLeft="none" text="Tertiary Action" variant="link" /> <Button onClick={() => alert('button clicked!')} text="Secondary Action" variant="secondary" /> </td> </tr> </tbody> </Table> ) } export default TableOneAction
If there are more than two actions on each row, then they should be contained in secondary circle icon button with the ellipsis-h
icon (horizontal ellipsis) at the end of the row
import React from 'react' import Table from 'playbook-ui' import CircleIconButton from 'playbook-ui' const TableTwoPlusActions = (props) => { return ( <Table size="sm" > <thead> <tr> <th>{'Column 1'}</th> <th>{'Column 2'}</th> <th>{'Column 3'}</th> <th>{'Column 4'}</th> <th>{''}</th> </tr> </thead> <tbody> <tr> <td>{'Value 1'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> <td>{'Value 4'}</td> <td align="right"> {' '} <CircleIconButton icon="ellipsis-h" variant="secondary" /> </td> </tr> <tr> <td>{'Value 1'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> <td>{'Value 4'}</td> <td align="right"> {' '} <CircleIconButton icon="ellipsis-h" variant="secondary" /> </td> </tr> <tr> <td>{'Value 1'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> <td>{'Value 4'}</td> <td align="right"> {' '} <CircleIconButton icon="ellipsis-h" variant="secondary" /> </td> </tr> </tbody> </Table> ) } export default TableTwoPlusActions
If the button is towards the middle of the table, it should likely use button variant link
import React from 'react' import Table from 'playbook-ui' import Button from 'playbook-ui' const TableActionMiddle = (props) => { return ( <Table size="sm" > <thead> <tr> <th>{'Column 1'}</th> <th>{'Column 2'}</th> <th>{'Column 3'}</th> <th>{'Column 4'}</th> <th>{'Column 5'}</th> </tr> </thead> <tbody> <tr> <td>{'Value 1'}</td> <td>{'Value 2'}</td> <td> {' '} <Button onClick={() => alert('button clicked!')} paddingLeft="none" text="Action" variant="link" /> </td> <td>{'Value 4'}</td> <td>{'Value 5'}</td> </tr> <tr> <td>{'Value 1'}</td> <td>{'Value 2'}</td> <td> {' '} <Button onClick={() => alert('button clicked!')} paddingLeft="none" text="Action" variant="link" /> </td> <td>{'Value 4'}</td> <td>{'Value 5'}</td> </tr> <tr> <td>{'Value 1'}</td> <td>{'Value 2'}</td> <td> {' '} <Button onClick={() => alert('button clicked!')} paddingLeft="none" text="Action" variant="link" /> </td> <td>{'Value 4'}</td> <td>{'Value 5'}</td> </tr> </tbody> </Table> ) } export default TableActionMiddle
Icon buttons are great to use if space is limited. If the icon isn’t VERY self explanatory (for example pencil/pen for edit, trashcan for delete) then it should use a tooltip explaining what the action does. The tooltip shouldn’t be longer than a few words and essentially serves as a replacement for what the button would say if it weren’t an icon
import React from 'react' import Table from 'playbook-ui' import CircleIconButton from 'playbook-ui' import Flex from 'playbook-ui' import FlexItem from 'playbook-ui' const TableIconButtons = (props) => { return ( <Table size="sm" > <thead> <tr> <th>{'Column 1'}</th> <th>{'Column 2'}</th> <th>{'Column 3'}</th> <th>{'Column 4'}</th> <th>{''}</th> </tr> </thead> <tbody> <tr> <td>{'Value 1'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> <td>{'Value 4'}</td> <td align="right"> <Flex justifyContent="end" orientation="row" > <FlexItem> <CircleIconButton icon="trash-alt" variant="link" /> </FlexItem> <FlexItem> <CircleIconButton icon="pencil" variant="secondary" /> </FlexItem> </Flex> </td> </tr> <tr> <td>{'Value 1'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> <td>{'Value 4'}</td> <td align="right"> <Flex justifyContent="end" orientation="row" > <FlexItem> <CircleIconButton icon="trash-alt" variant="link" /> </FlexItem> <FlexItem> <CircleIconButton icon="pencil" variant="secondary" /> </FlexItem> </Flex> </td> </tr> <tr> <td>{'Value 1'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> <td>{'Value lk'}</td> <td align="right"> <Flex justifyContent="end" orientation="row" > <FlexItem> <CircleIconButton icon="trash-alt" variant="link" /> </FlexItem> <FlexItem> <CircleIconButton icon="pencil" variant="secondary" /> </FlexItem> </Flex> </td> </tr> </tbody> </Table> ) } export default TableIconButtons
import React from 'react' import Table from 'playbook-ui' import Background from 'playbook-ui' const TableWithBackgroundKit = (props) => { return ( <div> <div> <Table > <thead> <tr> <th>{'Column 1'}</th> <th>{'Column 2'}</th> <th>{'Column 3'}</th> </tr> </thead> <tbody> <tr> <td>{'Value 1'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> </tr> <Background backgroundColor="error_subtle" tag='tr' > <td>{'Value 1'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> </Background> <tr> <td>{'Value 1'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> </tr> <tr> <td>{'Value 1'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> </tr> <Background backgroundColor="warning_subtle" tag='tr' > <td>{'Value 1'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> </Background> <tr> <td>{'Value 1'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> </tr> </tbody> </Table> </div> <div> <Table paddingTop="sm" > <colgroup> <Background backgroundColor="error_subtle" tag='col' /> <Background backgroundColor="card_light" tag='col' /> <Background backgroundColor="warning_subtle" tag='col' /> </colgroup> <Background backgroundColor="card_light" tag='thead' > <tr> <th>{'Column 1'}</th> <th>{'Column 2'}</th> <th>{'Column 3'}</th> </tr> </Background> <tbody> <tr> <td>{'Value 1'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> </tr> <tr> <td>{'Value 1'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> </tr> <tr> <td>{'Value 1'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> </tr> <tr> <td>{'Value 1'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> </tr> <tr> <td>{'Value 1'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> </tr> <tr> <td>{'Value 1'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> </tr> </tbody> </Table> </div> </div> ) } export default TableWithBackgroundKit
import React from 'react' import Table from 'playbook-ui' const TableVerticalBorder = (props) => { return ( <Table size="sm" verticalBorder > <thead> <tr> <th>{'Column 1'}</th> <th>{'Column 2'}</th> <th>{'Column 3'}</th> <th>{'Column 4'}</th> <th>{'Column 5'}</th> </tr> </thead> <tbody> <tr> <td>{'Value 1'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> <td>{'Value 4'}</td> <td>{'Value 5'}</td> </tr> <tr> <td>{'Value 1'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> <td>{'Value 4'}</td> <td>{'Value 5'}</td> </tr> <tr> <td>{'Value 1'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> <td>{'Value 4'}</td> <td>{'Value 5'}</td> </tr> </tbody> </Table> ) } export default TableVerticalBorder
Optionally pass the striped
(boolean, defaults to false) prop to set odd rows to a contrasting background color. This helps with readability on larger tables with lots of data.
import React from "react" import Table from 'playbook-ui' const TableStriped = (props) => ( <Table striped > <thead> <tr> <th>{'Column 1'}</th> <th>{'Column 2'}</th> <th>{'Column 3'}</th> <th>{'Column 4'}</th> <th>{'Column 5'}</th> </tr> </thead> <tbody> <tr> <td>{'Value 1'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> <td>{'Value 4'}</td> <td>{'Value 5'}</td> </tr> <tr> <td>{'Value 1'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> <td>{'Value 4'}</td> <td>{'Value 5'}</td> </tr> <tr> <td>{'Value 1'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> <td>{'Value 4'}</td> <td>{'Value 5'}</td> </tr> <tr> <td>{'Value 1'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> <td>{'Value 4'}</td> <td>{'Value 5'}</td> </tr> <tr> <td>{'Value 1'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> <td>{'Value 4'}</td> <td>{'Value 5'}</td> </tr> </tbody> </Table> ) export default TableStriped
You can optionally build your table using our sub-components, which map to their respective html table elements:
Table.Head
= thead
Table.Body
= tbody
Table.Row
= tr
Table.Header
= th
Table.Cell
= td
import React from 'react' import Table from 'playbook-ui' const TableWithSubcomponents = (props) => { return ( <Table size="sm" > <Table.Head> <Table.Row> <Table.Header>{'Column 1'}</Table.Header> <Table.Header>{'Column 2'}</Table.Header> <Table.Header>{'Column 3'}</Table.Header> <Table.Header>{'Column 4'}</Table.Header> <Table.Header>{'Column 5'}</Table.Header> </Table.Row> </Table.Head> <Table.Body> <Table.Row> <Table.Cell>{'Value 1'}</Table.Cell> <Table.Cell>{'Value 2'}</Table.Cell> <Table.Cell>{'Value 3'}</Table.Cell> <Table.Cell>{'Value 4'}</Table.Cell> <Table.Cell>{'Value 5'}</Table.Cell> </Table.Row> <Table.Row> <Table.Cell>{'Value 1'}</Table.Cell> <Table.Cell>{'Value 2'}</Table.Cell> <Table.Cell>{'Value 3'}</Table.Cell> <Table.Cell>{'Value 4'}</Table.Cell> <Table.Cell>{'Value 5'}</Table.Cell> </Table.Row> <Table.Row> <Table.Cell>{'Value 1'}</Table.Cell> <Table.Cell>{'Value 2'}</Table.Cell> <Table.Cell>{'Value 3'}</Table.Cell> <Table.Cell>{'Value 4'}</Table.Cell> <Table.Cell>{'Value 5'}</Table.Cell> </Table.Row> </Table.Body> </Table> ) } export default TableWithSubcomponents
Optionally build your table with divs by passing div
to the tag
prop of all* your sub-components.
*NOTE: The tag
prop defaults to table
, which returns html elements. If divs are desired, sub-components must be used and all table elements, including the initial kit call, must use div
as their tag
in order for the table to render properly.
import React from 'react' import Table from 'playbook-ui' const TableWithSubcomponentsAsDivs = (props) => { return ( <Table size="sm" tag="div" > <Table.Head tag="div"> <Table.Row tag="div"> <Table.Header tag="div">{'Column 1'}</Table.Header> <Table.Header tag="div">{'Column 2'}</Table.Header> <Table.Header tag="div">{'Column 3'}</Table.Header> <Table.Header tag="div">{'Column 4'}</Table.Header> <Table.Header tag="div">{'Column 5'}</Table.Header> </Table.Row> </Table.Head> <Table.Body tag="div"> <Table.Row tag="div"> <Table.Cell tag="div">{'Value 1'}</Table.Cell> <Table.Cell tag="div">{'Value 2'}</Table.Cell> <Table.Cell tag="div">{'Value 3'}</Table.Cell> <Table.Cell tag="div">{'Value 4'}</Table.Cell> <Table.Cell tag="div">{'Value 5'}</Table.Cell> </Table.Row> <Table.Row tag="div"> <Table.Cell tag="div">{'Value 1'}</Table.Cell> <Table.Cell tag="div">{'Value 2'}</Table.Cell> <Table.Cell tag="div">{'Value 3'}</Table.Cell> <Table.Cell tag="div">{'Value 4'}</Table.Cell> <Table.Cell tag="div">{'Value 5'}</Table.Cell> </Table.Row> <Table.Row> <Table.Cell tag="div">{'Value 1'}</Table.Cell> <Table.Cell tag="div">{'Value 2'}</Table.Cell> <Table.Cell tag="div">{'Value 3'}</Table.Cell> <Table.Cell tag="div">{'Value 4'}</Table.Cell> <Table.Cell tag="div">{'Value 5'}</Table.Cell> </Table.Row> </Table.Body> </Table> ) } export default TableWithSubcomponentsAsDivs
Pass any of our spacing tokens to the outerPadding
/ outer_padding
prop to customize a table's outer padding (both the left padding of the first column and the right padding of the last column).
import React from 'react' import Table from 'playbook-ui' import Button from 'playbook-ui' const TableOuterPadding = (props) => { return ( <Table outerPadding="sm" size="sm" > <thead> <tr> <th>{'Column 1'}</th> <th>{'Column 2'}</th> <th>{'Column 3'}</th> <th>{'Column 4'}</th> <th>{''}</th> </tr> </thead> <tbody> <tr> <td>{'Value 1'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> <td>{'Value 4'}</td> <td align="right"> {' '} <Button onClick={() => alert('button clicked!')} text="Action" variant="secondary" /> {' '} </td> </tr> <tr> <td>{'Value 1'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> <td>{'Value 4'}</td> <td align="right"> {' '} <Button onClick={() => alert('button clicked!')} text="Action" variant="secondary" /> {' '} </td> </tr> <tr> <td>{'Value 1'}</td> <td>{'Value 2'}</td> <td>{'Value 3'}</td> <td>{'Value 4'}</td> <td align="right"> {' '} <Button onClick={() => alert('button clicked!')} text="Action" variant="secondary" /> {' '} </td> </tr> </tbody> </Table> ) } export default TableOuterPadding