| 1 |
# @patternfly/react-table |
| 2 |
|
| 3 |
This package provides Table PatternFly components based on [PatternFly][patternfly] |
| 4 |
|
| 5 |
### Installing |
| 6 |
|
| 7 |
```sh |
| 8 |
yarn add @patternfly/react-table |
| 9 |
``` |
| 10 |
|
| 11 |
or |
| 12 |
|
| 13 |
```sh |
| 14 |
npm install @patternfly/react-table --save |
| 15 |
``` |
| 16 |
|
| 17 |
## Usage |
| 18 |
|
| 19 |
It's strongly advised to use the PatternFly base CSS in your whole project, or some components may diverge in appearance: |
| 20 |
|
| 21 |
```js |
| 22 |
import '@patternfly/react-core/dist/styles/base.css'; |
| 23 |
``` |
| 24 |
|
| 25 |
#### Example component usage |
| 26 |
|
| 27 |
```ts |
| 28 |
import { Table, Thead, Tr, Th, Td, Tbody } from '@patternfly/react-table'; |
| 29 |
|
| 30 |
export const ComposableTableBasic = () => { |
| 31 |
const repositories = [ |
| 32 |
{ name: 'one', branches: 'two', prs: 'three' }, |
| 33 |
{ name: 'one - 2', branches: null, prs: null }, |
| 34 |
{ name: 'one - 3', branches: 'two - 3', prs: 'three - 3' } |
| 35 |
]; |
| 36 |
|
| 37 |
const columnNames = { |
| 38 |
name: 'Repositories', |
| 39 |
branches: 'Branches', |
| 40 |
prs: 'Pull requests' |
| 41 |
}; |
| 42 |
|
| 43 |
return ( |
| 44 |
<Table> |
| 45 |
<Thead> |
| 46 |
<Tr> |
| 47 |
<Th>{columnNames.name}</Th> |
| 48 |
<Th>{columnNames.branches}</Th> |
| 49 |
<Th>{columnNames.prs}</Th> |
| 50 |
</Tr> |
| 51 |
</Thead> |
| 52 |
<Tbody> |
| 53 |
{repositories.map(repo => ( |
| 54 |
<Tr key={repo.name}> |
| 55 |
<Td dataLabel={columnNames.name}>{repo.name}</Td> |
| 56 |
<Td dataLabel={columnNames.branches}>{repo.branches}</Td> |
| 57 |
<Td dataLabel={columnNames.prs}>{repo.prs}</Td> |
| 58 |
</Tr> |
| 59 |
))} |
| 60 |
</Tbody> |
| 61 |
</Table> |
| 62 |
); |
| 63 |
} |
| 64 |
export default SimpleTable; |
| 65 |
``` |
| 66 |
|
| 67 |
## Contribution |
| 68 |
|
| 69 |
This library makes use of the babel plugin from [@patternfly/react-styles](../react-styles/README.md) to enable providing the CSS alongside the components. This removes the need for consumers to use (style|css|sass)-loaders. For an example of using CSS from core you can reference [Button.js](./src/components/Button/Button.js). For any CSS not provided by core please use the `StyleSheet.create` utility from [@patternfly/react-styles](../react-styles/README.md). This will prevent collisions with any consumers, and allow the CSS to be bundled with the component. |
| 70 |
|
| 71 |
### Documentation |
| 72 |
|
| 73 |
A comprehensive list of components and detailed usage of each can be found on the [PatternFly react docs][docs] website |
| 74 |
You can also find how each component is meant to be used from a design perspective on the [PatternFly core][patternfly] website. |
| 75 |
|
| 76 |
Note: All commands below assume you are on the root directory in this repository. |
| 77 |
|
| 78 |
### Install & run locally |
| 79 |
|
| 80 |
Run to install all the dependencies, build and run the site locally. |
| 81 |
|
| 82 |
```sh |
| 83 |
yarn install && yarn start |
| 84 |
``` |
| 85 |
|
| 86 |
### Testing |
| 87 |
|
| 88 |
Testing is done at the root of this repo. To only run the @patternfly/react-table tests: |
| 89 |
|
| 90 |
``` |
| 91 |
yarn test packages/react-table |
| 92 |
``` |
| 93 |
|
| 94 |
[patternfly]: https://github.com/patternfly/patternfly |
| 95 |
[docs]: https://react-staging.patternfly.org/ |