Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add possibility to inject header-row-renderer + typescript type declarations #600

Merged
merged 7 commits into from
Mar 4, 2017
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
36 changes: 24 additions & 12 deletions source/Table/Table.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import React, { PropTypes, PureComponent } from 'react'
import { findDOMNode } from 'react-dom'
import Grid from '../Grid'
import defaultRowRenderer from './defaultRowRenderer'
import defaultHeaderRowRenderer from './defaultHeaderRowRenderer'
import SortDirection from './SortDirection'

/**
Expand Down Expand Up @@ -155,6 +156,20 @@ export default class Table extends PureComponent {
*/
rowRenderer: PropTypes.func,

/**
* Responsible for rendering a table row given an array of columns:
* Should implement the following interface: ({
* className: string,
* columns: any[],
* rowData: any,
* style: any,
* scrollbarWidth: number,
* height: number,
* width: number
* }): PropTypes.node
*/
headerRowRenderer: PropTypes.func,

/** Optional custom inline style to attach to table rows. */
rowStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.func]).isRequired,

Expand Down Expand Up @@ -199,6 +214,7 @@ export default class Table extends PureComponent {
onScroll: () => null,
overscanRowCount: 10,
rowRenderer: defaultRowRenderer,
headerRowRenderer: defaultHeaderRowRenderer,
rowStyle: {},
scrollToAlignment: 'auto',
scrollToIndex: -1,
Expand Down Expand Up @@ -296,18 +312,14 @@ export default class Table extends PureComponent {
style={style}
>
{!disableHeader && (
<div
className={cn('ReactVirtualized__Table__headerRow', rowClass)}
style={{
...rowStyleObject,
height: headerHeight,
overflow: 'hidden',
paddingRight: scrollbarWidth,
width: width
}}
>
{this._getRenderedHeaderRow()}
</div>
this.props.headerRowRenderer({
className: cn('ReactVirtualized__Table__headerRow', rowClass),
style: rowStyleObject,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the style parameter passed should have all of the values preset, just like we pre-append a custom rowClass. This is more inline with what we do for other *renderer props. Users can then override (if they want) specific styles or just pass them through as-is by default.

I'll make this change myself before merging, just commenting to let you know my rationale.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok good to know

height: headerHeight,
scrollbarWidth,
width,
columns: this._getRenderedHeaderRow()
})
)}

<Grid
Expand Down
25 changes: 25 additions & 0 deletions source/Table/defaultHeaderRowRenderer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/** @flow */
import React from 'react'
import type { HeaderRowRendererParams } from './types'

export default function defaultHeaderRowRenderer ({
className,
style,
height,
width,
scrollbarWidth,
columns
}: HeaderRowRendererParams) {
return <div
className={className}
style={{
...style,
height: height,
overflow: 'hidden',
paddingRight: scrollbarWidth,
width: width
}}
>
{columns}
</div>
}
1 change: 1 addition & 0 deletions source/Table/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
export default from './Table'
export defaultCellDataGetter from './defaultCellDataGetter'
export defaultCellRenderer from './defaultCellRenderer'
export defaultHeaderRowRenderer from './defaultHeaderRowRenderer.js'
export defaultHeaderRenderer from './defaultHeaderRenderer'
export defaultRowRenderer from './defaultRowRenderer'
export Table from './Table'
Expand Down
12 changes: 10 additions & 2 deletions source/Table/types.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/** @flow */

export type CellDataGetterParams = {
columnData: ?any,
dataKey: string,
Expand All @@ -14,6 +13,15 @@ export type CellRendererParams = {
rowIndex: number
};

export type HeaderRowRendererParams = {
className: string,
columns: any[],
style: any,
scrollbarWidth: number,
height: number,
width: number
};

export type HeaderRendererParams = {
columnData: ?any,
dataKey: string,
Expand All @@ -25,7 +33,7 @@ export type HeaderRendererParams = {

export type RowRendererParams = {
className: string,
columns: Array,
columns: any[],
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, why was this change required?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm I think it just slipped in when I implemented the new types, or perhaps I tried to find an easy to implement more specific type information for this array ;).
This change on it's own, is more or less a matter of taste any[] and Array should be the same in flowType.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed! I just wanted to ask in case there was a difference I was unaware of. 😄

index: number,
isScrolling: boolean,
onRowClick: ?Function,
Expand Down
1 change: 1 addition & 0 deletions source/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export {
defaultCellDataGetter as defaultTableCellDataGetter,
defaultCellRenderer as defaultTableCellRenderer,
defaultHeaderRenderer as defaultTableHeaderRenderer,
defaultHeaderRowRenderer as defaultTableHeaderRowRenderer,
defaultRowRenderer as defaultTableRowRenderer,
Table,
Column,
Expand Down