Skip to content

Commit

Permalink
Convert Table to FunctionComponent and wrap with forwardRef (#318)
Browse files Browse the repository at this point in the history
* refactor: move docs into new /documentation folder

* refactor: introduce index rollup class for Table family

* refactor: convert Table family to FunctionComponent wrapped with refForward

* docs: add ref logger to table docs

* chore: update changelog
  • Loading branch information
alexpaxton authored Oct 2, 2019
1 parent 266ddca commit 62f1043
Show file tree
Hide file tree
Showing 13 changed files with 595 additions and 571 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Changelog

### 0.0.33
### 0.0.33 (Unreleased)

- [#319](https://github.com/influxdata/clockface/pull/319): Convert `ColorPicker` component family to `FunctionComponent` and wrap with `forwardRef`
- [#318](https://github.com/influxdata/clockface/pull/318): Convert `Table` component family to `FunctionComponent` and wrap with `forwardRef`
- [#317](https://github.com/influxdata/clockface/pull/317): Convert `Button` component family to `FunctionComponent` and wrap with `forwardRef`
- [#316](https://github.com/influxdata/clockface/pull/316): Convert `Popover` component family to `FunctionComponent` and wrap with `forwardRef`
- [#316](https://github.com/influxdata/clockface/pull/316): Convert `AppWrapper` component family to `FunctionComponent` and wrap with `forwardRef`
Expand All @@ -25,7 +26,7 @@
- [#313](https://github.com/influxdata/clockface/pull/313): [Breaking] Remove `widthPixels` prop from `Input` in favor of `style` with default width
- [#313](https://github.com/influxdata/clockface/pull/313): [Breaking] Remove `widthPixels` prop from `TextArea` in favor of `style` with default width

### 0.0.32 (Unreleased)
### 0.0.32

- [#281](https://github.com/influxdata/clockface/pull/281): Revert absolute path changes

Expand Down
File renamed without changes.
368 changes: 368 additions & 0 deletions src/Components/Table/Documentation/Table.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,368 @@
// Libraries
import React, {RefObject, createRef} from 'react'
import marked from 'marked'

// Storybook
import {storiesOf} from '@storybook/react'
import {withKnobs, select, text, boolean, object} from '@storybook/addon-knobs'
import {mapEnumKeys} from '../../../Utils/storybook'
import {jsxDecorator} from 'storybook-addon-jsx'

// Components
import {
Table,
TableRef,
TableHeaderRef,
TableHeaderCellRef,
TableBodyRef,
TableRowRef,
TableCellRef,
TableFooterRef,
} from '../'

// Types
import {
Alignment,
ComponentSize,
BorderType,
ComponentColor,
} from '../../../Types'

// Notes
import TableReadme from './Table.md'

const tableStories = storiesOf('Components|Table/Family', module)
.addDecorator(withKnobs)
.addDecorator(jsxDecorator)

tableStories.add(
'Table',
() => {
const tableRef: RefObject<TableRef> = createRef()
const tableHeaderRef: RefObject<TableHeaderRef> = createRef()
const tableHeaderCellRef: RefObject<TableHeaderCellRef> = createRef()
const tableBodyRef: RefObject<TableBodyRef> = createRef()
const tableRowRef: RefObject<TableRowRef> = createRef()
const tableCellRef: RefObject<TableCellRef> = createRef()
const tableFooterRef: RefObject<TableFooterRef> = createRef()

const logRefs = (): void => {
/* eslint-disable */
console.log('Table', tableRef.current)
console.log('TableHeader', tableHeaderRef.current)
console.log('TableHeaderCell', tableHeaderCellRef.current)
console.log('TableBody', tableBodyRef.current)
console.log('TableRow', tableRowRef.current)
console.log('TableCell', tableCellRef.current)
console.log('TableFooter', tableFooterRef.current)
/* eslint-enable */
}

return (
<div className="story--example">
<div className="story--test-buttons">
<button onClick={logRefs}>Log Ref</button>
</div>
<Table.Table
ref={tableRef}
cellPadding={
ComponentSize[
select('cellPadding', mapEnumKeys(ComponentSize), 'Small')
]
}
fontSize={
ComponentSize[
select('fontSize', mapEnumKeys(ComponentSize), 'Medium')
]
}
borders={
BorderType[select('borders', mapEnumKeys(BorderType), 'Horizontal')]
}
striped={boolean('striped', false)}
highlight={boolean('highlight', false)}
style={object('Table - width', {width: '100%'})}
>
<Table.Header ref={tableHeaderRef}>
<Table.Row ref={tableRowRef}>
<Table.HeaderCell
ref={tableHeaderCellRef}
width={text('Name - width', '30%')}
horizontalAlignment={
Alignment[
select(
'Name - horizontalAlignment',
mapEnumKeys(Alignment),
'Left'
)
]
}
>
Name
</Table.HeaderCell>
<Table.HeaderCell
width={text('Description - width', '50%')}
horizontalAlignment={
Alignment[
select(
'Description - horizontalAlignment',
mapEnumKeys(Alignment),
'Left'
)
]
}
>
Description
</Table.HeaderCell>
<Table.HeaderCell
width={text('Price - width', '20%')}
horizontalAlignment={
Alignment[
select(
'Price - horizontalAlignment',
mapEnumKeys(Alignment),
'Right'
)
]
}
>
Price
</Table.HeaderCell>
</Table.Row>
</Table.Header>
<Table.Body ref={tableBodyRef}>
<Table.Row
color={
ComponentColor[
select(
'Peach - row color',
mapEnumKeys(ComponentColor),
'Default'
)
]
}
>
<Table.Cell
ref={tableCellRef}
width={text('Name - width', '30%')}
horizontalAlignment={
Alignment[
select(
'Name - horizontalAlignment',
mapEnumKeys(Alignment),
'Left'
)
]
}
>
Peach
</Table.Cell>
<Table.Cell
width={text('Description - width', '50%')}
horizontalAlignment={
Alignment[
select(
'Description - horizontalAlignment',
mapEnumKeys(Alignment),
'Left'
)
]
}
>
A sweet fruit that makes a great pie
</Table.Cell>
<Table.Cell
width={text('Price - width', '20%')}
horizontalAlignment={
Alignment[
select(
'Price - horizontalAlignment',
mapEnumKeys(Alignment),
'Right'
)
]
}
>
$5.00
</Table.Cell>
</Table.Row>
<Table.Row
color={
ComponentColor[
select(
'Pineapple - row color',
mapEnumKeys(ComponentColor),
'Default'
)
]
}
>
<Table.Cell
width={text('Name - width', '30%')}
horizontalAlignment={
Alignment[
select(
'Name - horizontalAlignment',
mapEnumKeys(Alignment),
'Left'
)
]
}
>
Pineapple
</Table.Cell>
<Table.Cell
width={text('Description - width', '50%')}
horizontalAlignment={
Alignment[
select(
'Description - horizontalAlignment',
mapEnumKeys(Alignment),
'Left'
)
]
}
>
Tropical, highly sought after, and a requirement for a Piña
Colada
</Table.Cell>
<Table.Cell
width={text('Price - width', '20%')}
horizontalAlignment={
Alignment[
select(
'Price - horizontalAlignment',
mapEnumKeys(Alignment),
'Right'
)
]
}
>
$8.00
</Table.Cell>
</Table.Row>
<Table.Row
color={
ComponentColor[
select(
'Yuzu - row color',
mapEnumKeys(ComponentColor),
'Default'
)
]
}
>
<Table.Cell
width={text('Name - width', '30%')}
horizontalAlignment={
Alignment[
select(
'Name - horizontalAlignment',
mapEnumKeys(Alignment),
'Left'
)
]
}
>
Yuzu
</Table.Cell>
<Table.Cell
width={text('Description - width', '50%')}
horizontalAlignment={
Alignment[
select(
'Description - horizontalAlignment',
mapEnumKeys(Alignment),
'Left'
)
]
}
>
A golden citrus fruit from Japan & China with a powerful aroma
</Table.Cell>
<Table.Cell
width={text('Price - width', '20%')}
horizontalAlignment={
Alignment[
select(
'Price - horizontalAlignment',
mapEnumKeys(Alignment),
'Right'
)
]
}
>
$11.00
</Table.Cell>
</Table.Row>
<Table.Row
color={
ComponentColor[
select(
'Lychee - row color',
mapEnumKeys(ComponentColor),
'Default'
)
]
}
>
<Table.Cell
width={text('Name - width', '30%')}
horizontalAlignment={
Alignment[
select(
'Name - horizontalAlignment',
mapEnumKeys(Alignment),
'Left'
)
]
}
>
Lychee
</Table.Cell>
<Table.Cell
width={text('Description - width', '50%')}
horizontalAlignment={
Alignment[
select(
'Description - horizontalAlignment',
mapEnumKeys(Alignment),
'Left'
)
]
}
>
A light and refreshing fruit encased in a spiky shell
</Table.Cell>
<Table.Cell
width={text('Price - width', '20%')}
horizontalAlignment={
Alignment[
select(
'Price - horizontalAlignment',
mapEnumKeys(Alignment),
'Right'
)
]
}
>
$2.00
</Table.Cell>
</Table.Row>
</Table.Body>
<Table.Footer ref={tableFooterRef}>
<Table.Row>
<Table.Cell colSpan={3}>
*All fruits are shipped in padded boxes to ensure quality
</Table.Cell>
</Table.Row>
</Table.Footer>
</Table.Table>
</div>
)
},
{
readme: {
content: marked(TableReadme),
},
}
)
Loading

0 comments on commit 62f1043

Please # to comment.