Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
341 changes: 341 additions & 0 deletions docs/docs/components/table.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,341 @@
# 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,
Flex,
} from "@hover-design/react";
import { resetTableStyles } from "../../src/components/examples/resetTableStyles.css.ts";
import "../../src/components/examples/global.styles.css.ts";

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

### Code Snippets and Examples

##### Basic Table

```jsx
<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>
```

<div className={resetTableStyles}>
<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>
</div>

##### Striped Table

```jsx
<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>
```

<div className={resetTableStyles}>
<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>
</div>

##### Customized table

```jsx
<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>
```

<div className={resetTableStyles}>
<Table
addBorder
borderColor="#ccc"
striped
stripeColor="#f9f9f9"
borderRadius="8px"
horizontalSpacing="100px"
alignContent="center"
alignHeading="center"
rowHeight="1.5"
>
<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>
</div>

### Props Reference

#### Table

| Attributes | Values | Default Value | Optional ? |
| :-------------------------- | :-----------------------------------: | :-----------: | ---------: |
| children | `ReactNode` | - | No |
| addBorder | `true` &#124; `false` | `false` | Yes |
| borderRadius | `string` | `4px` | Yes |
| borderColor | `string` | `black` | Yes |
| alignContent | `left` &#124; `center` &#124; `right` | `left` | Yes |
| alignHeading | `left` &#124; `center` &#124; `right` | `left` | Yes |
| cellPadding | `string` | `10px` | Yes |
| striped | `true` &#124; `false` | `false` | Yes |
| stripeColor | `string` | `#EEE` | Yes |
| rowHeight | `string` | `1` | Yes |
| horizontalSpacing | `string` | `0` | Yes |
| overrideTableClass | `string` | - | Yes |
| overrideTableContainerClass | `string` | - | 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

| Attributes | Values | Default Value | Optional ? |
| :--------- | :-------------------: | :-----------: | ---------: |
| children | `React.ReactNode` | undefined | No |
| placement | `top` &#124; `bottom` | `bottom` | Yes |

#### Thead

| Attributes | Values | Default Value | Optional ? |
| :-------------- | :---------------: | :-----------: | ---------: |
| children | `React.ReactNode` | undefined | No |
| backgroundColor | `string` | '#DDD' | Yes |

#### Tbody

| Attributes | Values | Default Value | Optional ? |
| :--------- | :---------------: | :-----------: | ---------: |
| children | `React.ReactNode` | undefined | No |

#### Tr

| Attributes | Values | Default Value | Optional ? |
| :--------- | :---------------: | :-----------: | ---------: |
| children | `React.ReactNode` | undefined | No |

#### Th

| Attributes | Values | Default Value | Optional ? |
| :----------- | :-----------------------------------: | :-----------: | ---------: |
| children | `React.ReactNode` | undefined | No |
| alignHeading | `left` &#124; `center` &#124; `right` | - | Yes |

#### Td

| Attributes | Values | Default Value | Optional ? |
| :----------- | :-----------------------------------: | :-----------: | ---------: |
| children | `React.ReactNode` | undefined | No |
| alignContent | `left` &#124; `center` &#124; `right` | - | Yes |

#### Tfoot

| Attributes | Values | Default Value | Optional ? |
| :-------------- | :---------------: | :-----------: | ---------: |
| children | `React.ReactNode` | undefined | No |
| backgroundColor | `string` | `#DDD` | Yes |
20 changes: 20 additions & 0 deletions docs/src/components/examples/global.styles.css.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { globalStyle } from "@vanilla-extract/css";
import { resetTableStyles } from "./resetTableStyles.css";

globalStyle(
`${resetTableStyles} td, ${resetTableStyles} th, ${resetTableStyles} tr`,
{
border: "none",
}
);

globalStyle(
`${resetTableStyles} tr:nth-child(even), ${resetTableStyles} thead`,
{
backgroundColor: "transparent",
}
);

globalStyle(`${resetTableStyles} table`, {
marginBottom: 0,
});
3 changes: 3 additions & 0 deletions docs/src/components/examples/resetTableStyles.css.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { style } from "@vanilla-extract/css";

export const resetTableStyles = style({});
2 changes: 1 addition & 1 deletion lib/src/components/Table/Table.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const [tableThemeClass, tableThemeVars]: ITableThemeVars = createTheme({
contentAlignment: "left",
customCellPadding: "10px",
customStripeColor: "#eee",
customHorizontalSpacing: "0",
});

export const tableContainerDefaults = style({
Expand All @@ -29,4 +30,3 @@ export const tableContainerDefaults = style({
export const tableDefaults = style({
borderCollapse: "collapse",
});

11 changes: 11 additions & 0 deletions lib/src/components/Table/Table.global.styles.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,14 @@ globalStyle(`${tableDefaults} td`, {
globalStyle(`${tableDefaults}.striped tr:nth-child(even)`, {
backgroundColor: tableThemeVars.customStripeColor,
});

globalStyle(`${tableDefaults} thead th, ${tableDefaults} tbody td`, {
paddingRight: tableThemeVars.customHorizontalSpacing,
});

globalStyle(
`${tableDefaults} thead th:last-child, ${tableDefaults} tbody td:last-child`,
{
paddingRight: tableThemeVars.customCellPadding,
}
);
Loading