Skip to main content

Table

Quick start

Hover table component can be used to organise and display data. Here's a quick start guide to get started with the table component.

Importing Component

import {
Table,
TableCaption,
Thead,
Th,
Tbody,
Tr,
Td,
Tfoot
} from "@hover-design/react";

Code Snippets and Examples

Basic Table
<Table addBorder>
<TableCaption>Calories and proteins data</TableCaption>
<Thead>
<Tr>
<Th>Food</Th>
<Th>Protein</Th>
<Th>Calories</Th>
</Tr>
</Thead>
<Tbody>
<Tr>
<Td>Almonds</Td>
<Td alignContent="right">21g</Td>
<Td alignContent="right">579</Td>
</Tr>
<Tr>
<Td>Eggs</Td>
<Td alignContent="right">13g</Td>
<Td alignContent="right">143</Td>
</Tr>
<Tr>
<Td>Peanuts</Td>
<Td alignContent="right">25g</Td>
<Td alignContent="right">607</Td>
</Tr>
<Tr>
<Td>Yogurt</Td>
<Td alignContent="right">6g</Td>
<Td alignContent="right">70</Td>
</Tr>
</Tbody>
</Table>
Calories and proteins data
FoodProteinCalories
Almonds21g579
Eggs13g143
Peanuts25g607
Yogurt6g70
Striped Table
<Table addBorder striped>
<TableCaption>Calories and proteins data</TableCaption>
<Thead>
<Tr>
<Th>Food</Th>
<Th>Protein</Th>
<Th>Calories</Th>
</Tr>
</Thead>
<Tbody>
<Tr>
<Td>Almonds</Td>
<Td alignContent="right">21g</Td>
<Td alignContent="right">579</Td>
</Tr>
<Tr>
<Td>Eggs</Td>
<Td alignContent="right">13g</Td>
<Td alignContent="right">143</Td>
</Tr>
<Tr>
<Td>Peanuts</Td>
<Td alignContent="right">25g</Td>
<Td alignContent="right">607</Td>
</Tr>
<Tr>
<Td>Yogurt</Td>
<Td alignContent="right">6g</Td>
<Td alignContent="right">70</Td>
</Tr>
</Tbody>
</Table>
Calories and proteins data
FoodProteinCalories
Almonds21g579
Eggs13g143
Peanuts25g607
Yogurt6g70
Customized table
<Table
addBorder
borderColor="#ccc"
striped
stripeColor="#f9f9f9"
borderRadius="8px"
horizontalSpacing="100px"
rowHeight="1.5"
alignContent="center"
alignHeading="center"
>
<TableCaption>Calories and proteins data</TableCaption>
<Thead backgroundColor="#eee">
<Tr>
<Th>Food</Th>
<Th>Protein</Th>
<Th>Calories</Th>
</Tr>
</Thead>
<Tbody>
<Tr>
<Td>Almonds</Td>
<Td>21g</Td>
<Td>579</Td>
</Tr>
<Tr>
<Td>Eggs</Td>
<Td>13g</Td>
<Td>143</Td>
</Tr>
<Tr>
<Td>Peanuts</Td>
<Td>25g</Td>
<Td>607</Td>
</Tr>
<Tr>
<Td>Yogurt</Td>
<Td>6g</Td>
<Td>70</Td>
</Tr>
</Tbody>
</Table>
Calories and proteins data
FoodProteinCalories
Almonds21g579
Eggs13g143
Peanuts25g607
Yogurt6g70

Props Reference

Table

AttributesValuesDefault ValueOptional ?
childrenReactNode-No
addBordertrue | falsefalseYes
borderRadiusstring4pxYes
borderColorstringblackYes
alignContentleft | center | rightleftYes
alignHeadingleft | center | rightleftYes
cellPaddingstring10pxYes
stripedtrue | falsefalseYes
stripeColorstring#EEEYes
rowHeightstring1Yes
horizontalSpacingstring0Yes
overrideTableClassstring-Yes
overrideTableContainerClassstring-Yes
wrapperStyleCSS Style Object-Yes
wrapperClassNamestring-Yes

The table component renders a div that wraps the table to not allow the table to overflow the parent, this can be customized by sending a class to overrideTableContainerClass

TableCaption

AttributesValuesDefault ValueOptional ?
childrenReact.ReactNodeundefinedNo
placementtop | bottombottomYes

Thead

AttributesValuesDefault ValueOptional ?
childrenReact.ReactNodeundefinedNo
backgroundColorstring'#DDD'Yes

Tbody

AttributesValuesDefault ValueOptional ?
childrenReact.ReactNodeundefinedNo

Tr

AttributesValuesDefault ValueOptional ?
childrenReact.ReactNodeundefinedNo

Th

AttributesValuesDefault ValueOptional ?
childrenReact.ReactNodeundefinedNo
alignHeadingleft | center | right-Yes

Td

AttributesValuesDefault ValueOptional ?
childrenReact.ReactNodeundefinedNo
alignContentleft | center | right-Yes

Tfoot

AttributesValuesDefault ValueOptional ?
childrenReact.ReactNodeundefinedNo
backgroundColorstring#DDDYes