Skip to content

Commit eddf198

Browse files
committed
Merge pull request #206 from bvaughn/version-7
Version 7
2 parents a108d7d + c35495a commit eddf198

File tree

89 files changed

+2884
-1148
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+2884
-1148
lines changed

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.DS_Store
2-
node_modules
3-
npm-debug.log
42
build
53
coverage
4+
dist
5+
node_modules
6+
npm-debug.log

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
build
2+
codemods
23
coverage
34
docs
45
source

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
Changelog
22
------------
33

4+
# 7.0.0
5+
Version 7 changes are described in detail on the [Version 7 Roadmap wiki page](https://github.com/bvaughn/react-virtualized/wiki/Version-7-Roadmap).
6+
Upgrade instructions and [jscodeshift](https://github.com/facebook/jscodeshift) mods can also be found there.
7+
48
##### 6.3.2
59
Fixed edge-case bug in `Collection` where initial `scrollLeft` and `scrollTop` would not correctly adjust inner offsets.
610
Thanks @edulan for the contribution!

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ There are also a couple of how-to guides:
6161
* [Displaying items in reverse order](docs/reverseList.md)
6262
* [Using AutoSizer](docs/usingAutoSizer.md)
6363
* [Creating an infinite-loading list](docs/creatingAnInfiniteLoadingList.md)
64+
* [Displaying a reverse list](docs/reverseList.md)
6465

6566
Examples
6667
---------------
@@ -71,6 +72,7 @@ Here are some online demos of each component:
7172

7273
* [ArrowKeyStepper](https://bvaughn.github.io/react-virtualized/?component=ArrowKeyStepper)
7374
* [AutoSizer](https://bvaughn.github.io/react-virtualized/?component=AutoSizer)
75+
* [CellMeasurer](https://bvaughn.github.io/react-virtualized/?component=CellMeasurer)
7476
* [Collection](https://bvaughn.github.io/react-virtualized/?component=Collection)
7577
* [ColumnSizer](https://bvaughn.github.io/react-virtualized/?component=ColumnSizer)
7678
* [FlexTable](https://bvaughn.github.io/react-virtualized/?component=FlexTable)
@@ -82,6 +84,8 @@ Here are some online demos of each component:
8284
And here are some "recipe" type demos:
8385
* [Collapsable tree view](https://rawgit.com/bvaughn/react-virtualized/master/playground/tree.html)
8486
* [Full-page grid (spreadsheet)](https://rawgit.com/bvaughn/react-virtualized/master/playground/grid.html)
87+
* [Dyanmic cell measuring](https://rawgit.com/bvaughn/react-virtualized/master/playground/chat.html)
88+
* [Cell hover effects](https://rawgit.com/bvaughn/react-virtualized/master/playground/hover.html)
8589

8690
Contributions
8791
------------

codemods/6-to-7/rename-properties.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
'use strict'
2+
3+
// Renames react-virtualized version 6.x properties to be version-7 compatible
4+
module.exports = function transformer (file, api) {
5+
const jscodeshift = api.jscodeshift
6+
7+
let source = file.source
8+
9+
// Rename variable references
10+
for (var property in propertyRenameMap) {
11+
source = jscodeshift(source)
12+
.findVariableDeclarators(property)
13+
.renameTo(propertyRenameMap[property])
14+
.toSource()
15+
}
16+
17+
// Rename JSX attributes
18+
source = jscodeshift(source)
19+
.find(jscodeshift.JSXAttribute)
20+
.filter(shouldAttributeBeRenamed)
21+
.replaceWith(renameReactVirtualizedAttribute)
22+
.toSource()
23+
24+
return source
25+
}
26+
27+
const reactVirtualizedElementNames = [
28+
'ArrowKeyStepper',
29+
'AutoSizer',
30+
'Collection',
31+
'ColumnSizer',
32+
'FlexTable',
33+
'Grid',
34+
'ScrollSync',
35+
'VirtualScroll'
36+
]
37+
38+
// @param path jscodeshift.JSXAttribute
39+
const attributeBelongsToReactVirtualizedElement = path => reactVirtualizedElementNames.includes(path.parent.value.name.name)
40+
41+
// See https://github.com/bvaughn/react-virtualized/wiki/Version-7-Roadmap#clean-up-property-names
42+
const propertyRenameMap = {
43+
cellClassName: 'className',
44+
columnsCount: 'columnCount',
45+
overscanColumnsCount: 'overscanColumnCount',
46+
overscanRowsCount: 'overscanRowCount',
47+
renderCell: 'cellRenderer',
48+
renderCellRanges: 'cellRangeRenderer',
49+
rowsCount: 'rowCount'
50+
}
51+
52+
// @param path jscodeshift.JSXAttribute
53+
const shouldAttributeBeRenamed = path => attributeBelongsToReactVirtualizedElement(path) && isAttributeInPropertyRenameMap(path)
54+
55+
// @param path jscodeshift.JSXAttribute
56+
const isAttributeInPropertyRenameMap = path => propertyRenameMap.hasOwnProperty(path.value.name.name)
57+
58+
// @param path jscodeshift.JSXAttribute
59+
const renameReactVirtualizedAttribute = path => {
60+
path.value.name.name = propertyRenameMap[path.value.name.name] || path.value.name.name
61+
62+
return path.node
63+
}

docs/ArrowKeyStepper.md

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,17 @@ The appearance of this wrapper element can be customized using the `className` p
1010
### Prop Types
1111
| Property | Type | Required? | Description |
1212
|:---|:---|:---:|:---|
13-
| children | Function || Function respondible for rendering children. This function should implement the following signature: `({ onKeyDown, onSectionRendered, scrollToColumn, scrollToRow }) => PropTypes.element` |
13+
| children | Function || Function respondible for rendering children. This function should implement the following signature: `({ onSectionRendered: Function, scrollToColumn: number, scrollToRow: number }) => PropTypes.element` |
1414
| className | String | | CSS class name to attach to the wrapper `<div>`. |
15-
| columnsCount | Number || Number of columns in grid; for `FlexTable` and `VirtualScroll` this property should always be `1`. |
16-
| rowsCount | Number || Number of rows in grid. |
15+
| columnCount | Number || Number of columns in grid; for `FlexTable` and `VirtualScroll` this property should always be `1`. |
16+
| rowCount | Number || Number of rows in grid. |
1717

1818
### Children function
1919

2020
The child function is passed the following named parameters:
2121

2222
| Parameter | Type | Description |
23-
|:---|:---|:---:|
24-
| onKeyDown | Function | Key-down event handler to be attached to the DOM hierarchy. |
23+
|:---|:---|:---|
2524
| onSectionRendered | Function | Pass-through callback to be attached to child component; informs the key-stepper which range of cells are currently visible. |
2625
| scrollToColumn | Number | Specifies which column in the child component should be visible |
2726
| scrollToRow | Number | Specifies which row in the child component should be visible |
@@ -38,20 +37,18 @@ import 'react-virtualized/styles.css'; // only needs to be imported once
3837

3938
ReactDOM.render(
4039
<ArrowKeyStepper
41-
columnsCount={columnsCount}
42-
rowsCount={rowsCount}
40+
columnCount={columnCount}
41+
rowCount={rowCount}
4342
>
44-
{({ onKeyDown, onSectionRendered, scrollToColumn, scrollToRow }) => (
45-
<div onKeyDown={onKeyDown}>
46-
<Grid
47-
columnsCount={columnsCount}
48-
onSectionRendered={onSectionRendered}
49-
rowsCount={rowsCount}
50-
scrollToColumn={scrollToColumn}
51-
scrollToRow={scrollToRow}
52-
{...otherGridProps}
53-
/>
54-
</div>
43+
{({ onSectionRendered, scrollToColumn, scrollToRow }) => (
44+
<Grid
45+
columnCount={columnCount}
46+
onSectionRendered={onSectionRendered}
47+
rowCount={rowCount}
48+
scrollToColumn={scrollToColumn}
49+
scrollToRow={scrollToRow}
50+
{...otherGridProps}
51+
/>
5552
)}
5653
</ArrowKeyStepper>,
5754
document.getElementById('example')

docs/AutoSizer.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ High-order component that automatically adjusts the width and height of a single
66
### Prop Types
77
| Property | Type | Required? | Description |
88
|:---|:---|:---:|:---|
9-
| children | Function || Function respondible for rendering children. This function should implement the following signature: `({ height, width }) => PropTypes.element` |
10-
| disableHeight | Boolean | | If true the child's `height` property will not be managed |
11-
| disableWidth | Boolean | | If true the child's `width` property will not be managed |
12-
| onResize | Function | Callback to be invoked on-resize; it is passed the following named parameters: `({ height, width })` |
9+
| children | Function || Function respondible for rendering children. This function should implement the following signature: `({ height: number, width: number }) => PropTypes.element` |
10+
| disableHeight | Boolean | | Fixed `height`; if specified, the child's `height` property will not be managed |
11+
| disableWidth | Boolean | | Fixed `width`; if specified, the child's `width` property will not be managed |
12+
| onResize | Function | | Callback to be invoked on-resize; it is passed the following named parameters: `({ height: number, width: number })`. |
1313

1414
### Examples
1515

@@ -36,7 +36,7 @@ ReactDOM.render(
3636
<VirtualScroll
3737
width={width}
3838
height={height}
39-
rowsCount={list.length}
39+
rowCount={list.length}
4040
rowHeight={20}
4141
rowRenderer={
4242
index => list[index] // Could also be a DOM element

docs/CellMeasurer.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
CellMeasurer
2+
---------------
3+
4+
High-order component for automatically measuring a cell's contents by rendering it in a way that is not visible to the user.
5+
Specify a fixed width or height constraint if you only want to measure one dimension.
6+
7+
**Warning**: This HOC is fairly experimental and may change in future releases.
8+
At this time it is only intended for use with a `Grid` (not `VirtualScroll` or `FlexTable` as their item rendering and cell measuring signatures are different).
9+
Also note that in order to measure a column's width for a `Grid`, that column's content must be rendered for all rows in order to determine the maximum width.
10+
For this reason it may not be a good idea to use this HOC for `Grid`s containing a large number of both columns _and_ cells.
11+
12+
### Prop Types
13+
| Property | Type | Required? | Description |
14+
|:---|:---|:---:|:---|
15+
| cellRenderer | Function || Renders a cell given its indices. `({ columnIndex: number, rowIndex: number }): PropTypes.node` |
16+
| children | Function || Function respondible for rendering a virtualized component; `({ getColumnWidth: Function, getRowHeight: Function, resetMeasurements: Function }) => PropTypes.element` |
17+
| columnCount | number || Number of columns in the `Grid`; in order to measure a row's height, all of that row's columns must be rendered. |
18+
| container | | | A Node, Component instance, or function that returns either. If this property is not specified the document body will be used. |
19+
| height | number | | Fixed height; specify this property to measure cell-width only. |
20+
| rowCount | number || Number of rows in the `Grid`; in order to measure a column's width, all of that column's rows must be rendered. |
21+
| width | number | | Fixed width; specify this property to measure cell-height only. |
22+
23+
### Children function
24+
25+
The child function is passed the following named parameters:
26+
27+
| Parameter | Type | Description |
28+
|:---|:---|:---|
29+
| getColumnWidth | Function | Callback to set as the `columnWidth` property of a `Grid` |
30+
| getRowHeight | Function | Callback to set as the `rowHeight` property of a `Grid` |
31+
| resetMeasurements | Function | Use this function to clear cached measurements in `CellRenderer`; its size will be remeasured the next time it is requested. |
32+
33+
### Examples
34+
35+
This example shows a `Grid` with fixed column widths and dynamic row heights.
36+
For more examples check out the component [demo page](https://bvaughn.github.io/react-virtualized/?component=CellMeasurer).
37+
38+
```javascript
39+
import React from 'react';
40+
import ReactDOM from 'react-dom';
41+
import { CellMeasurer, Grid } from 'react-virtualized';
42+
import 'react-virtualized/styles.css'; // only needs to be imported once
43+
44+
ReactDOM.render(
45+
<CellMeasurer
46+
cellRenderer={cellRenderer}
47+
columnCount={columnCount}
48+
height={height}
49+
rowCount={rowCount}
50+
>
51+
{({ getColumnWidth }) => (
52+
<Grid
53+
columnCount={columnCount}
54+
columnWidth={getColumnWidth}
55+
height={height}
56+
cellRenderer={cellRenderer}
57+
rowCount={rowCount}
58+
rowHeight={fixedRowHeight}
59+
width={width}
60+
/>
61+
)}
62+
</CellMeasurer>,
63+
document.getElementById('example')
64+
);
65+
```

docs/Collection.md

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,25 @@ Collection
44
Renders scattered or non-linear data.
55
Unlike `Grid`, which renders checkerboard data, `Collection` can render arbitrarily positioned- even overlapping- data.
66

7+
**Note** that this component's measuring and layout phase is more expensive than `Grid` since it can not assume a correlation between a cell's index and position. For this reason it will take signifnicantly longer to initialize than the more linear/checkerboard components.
8+
79
### Prop Types
810
| Property | Type | Required? | Description |
911
|:---|:---|:---:|:---|
1012
| className | String | | Optional custom CSS class name to attach to root Collection element. |
1113
| cellCount | Number || Number of cells in collection. |
14+
| cellGroupRenderer | Function || Responsible for rendering a group of cells given their indices.: `({ cellSizeAndPositionGetter:Function, indices: Array<number>, cellRenderer: Function }): Array<PropTypes.node>` |
15+
| cellRenderer | Function || Responsible for rendering a cell given an row and column index: `({ index: number, isScrolling: boolean }): PropTypes.element` |
16+
| cellSizeAndPositionGetter | Function || Callback responsible for returning size and offset/position information for a given cell (index): `({ index: number }): { height: number, width: number, x: number, y: number }` |
1217
| height | Number || Height of Collection; this property determines the number of visible (vs virtualized) rows. |
1318
| noContentRenderer | Function | | Optional renderer to be rendered inside the grid when `cellCount` is 0: `(): PropTypes.node` |
14-
| onSectionRendered | Function | | Callback invoked with information about the section of the Collection that was just rendered: `(indices: Array<number>): void` |
15-
| onScroll | Function | | Callback invoked whenever the scroll offset changes within the inner scrollable region: `({ clientHeight, clientWidth, scrollHeight, scrollLeft, scrollTop, scrollWidth }): void` |
16-
| cellRenderer | Function || Responsible for rendering a cell given an row and column index: `(index: number): PropTypes.node` |
17-
| cellGroupRenderer | Function || Responsible for rendering a group of cells given their indices.: `({ cellSizeAndPositionGetter:Function, indices: Array<number>, cellRenderer: Function }): Array<PropTypes.node>` |
18-
| cellSizeAndPositionGetter | Function || Callback responsible for returning size and offset/position information for a given cell (index): `(index): { height: number, width: number, x: number, y: number }` |
19+
| onSectionRendered | Function | | Callback invoked with information about the section of the Collection that was just rendered: `({ indices: Array<number> }): void` |
20+
| onScroll | Function | | Callback invoked whenever the scroll offset changes within the inner scrollable region: `({ clientHeight: number, clientWidth: number, scrollHeight: number, scrollLeft: number, scrollTop: number, scrollWidth: number }): void` |
1921
| scrollLeft | Number | | Horizontal offset |
2022
| scrollToCell | Number | | Cell index to ensure visible (by scrolling if necessary) |
2123
| scrollTop | Number | | Vertical offset |
22-
| sectionSize | Number | | Optionally override the size of the sections a Collection's cells are split into. |
24+
| sectionSize | Number | | Optionally override the size of the sections a Collection's cells are split into. This is an advanced option and should only be used for performance tuning purposes. |
25+
| style | Object | | Optional custom inline style to attach to root Collection element. |
2326
| width | Number || Width of Collection; this property determines the number of visible (vs virtualized) columns. |
2427

2528
### Public Methods
@@ -29,7 +32,7 @@ Unlike `Grid`, which renders checkerboard data, `Collection` can render arbitrar
2932
Recomputes cell sizes and positions.
3033

3134
This function should be called if cell sizes or positions have changed but nothing else has.
32-
Since Collection only receives `cellCount` it has no way of detecting when the underlying data changes.
35+
Since Collection only receives `cellCount` (and not the underlying List or Array) it has no way of detecting when the underlying data changes.
3336

3437
### Class names
3538

@@ -62,9 +65,16 @@ const list = [
6265
ReactDOM.render(
6366
<Collection
6467
cellCount={list.length}
65-
cellRenderer={(index) => list[index].name}
66-
cellSizeAndPositionGetter={(index) => list[index]}
67-
columnsCount={list.length}
68+
cellRenderer={({ index }) => list[index].name}
69+
cellSizeAndPositionGetter={({ index }) => {
70+
const datum = list[index]
71+
return {
72+
height: datum.height,
73+
width: datum.width,
74+
x: datum.x,
75+
y: datum.y
76+
}
77+
}}
6878
height={300}
6979
width={300}
7080
/>,

docs/ColumnSizer.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ High-order component that auto-calculates column-widths for `Grid` cells.
66
### Prop Types
77
| Property | Type | Required? | Description |
88
|:---|:---|:---:|:---|
9-
| children | Function || Function respondible for rendering a virtualized Grid. This function should implement the following signature: `({ adjustedWidth, getColumnWidth, registerChild }) => PropTypes.element` |
9+
| children | Function || Function respondible for rendering a virtualized Grid. This function should implement the following signature: `({ adjustedWidth: number, getColumnWidth: Function, registerChild: Function }) => PropTypes.element` |
1010
| columnMaxWidth | Number | | Optional maximum allowed column width |
1111
| columnMinWidth | Number | | Optional minimum allowed column width |
1212
| width | Number || Width of Grid or `FlexTable` child |
@@ -16,14 +16,14 @@ High-order component that auto-calculates column-widths for `Grid` cells.
1616
The child function is passed the following named parameters:
1717

1818
| Parameter | Type | Description |
19-
|:---|:---|:---:|
19+
|:---|:---|:---|
20+
| adjustedWidth | Number | This number reflects the lesser of the overall `Grid` width or the width of all columns. Use this to make your `Grid` shrink to fit sparse content. |
2021
| getColumnWidth | Function | This function should be passed to the `Grid`'s `columnWidth` property. |
2122
| registerChild | Function | This function should be set as the child's `ref` property. It enables a set of rows to be refreshed once their data has finished loading. |
22-
| adjustedWidth | Number | This number reflects the lesser of the overall `Grid` width or the width of all columns. Use this to make your `Grid` shrink to fit sparse content. |
2323

2424
### Examples
2525

26-
This example displays a `Grid` that shrinks to fit sparse content (using the `adjustedWidth` parameter).
26+
This example displays a `Grid` that shrinks to fit sparse content (using the `adjustedWidth` parameter). An interactive demo of this component can be seen [here](https://bvaughn.github.io/react-virtualized/?component=ColumnSizer).
2727

2828
```javascript
2929
import React from 'react';
@@ -38,18 +38,18 @@ ReactDOM.render(
3838
<ColumnSizer
3939
columnMaxWidth={100}
4040
columnMinWidth={50}
41-
columnsCount={numColumns}
41+
columnCount={numColumns}
4242
width={someCalculatedWidth}
4343
>
4444
{({ adjustedWidth, getColumnWidth, registerChild }) => (
4545
<Grid
4646
ref={registerChild}
4747
columnWidth={getColumnWidth}
48-
columnsCount={numColumns}
48+
columnCount={numColumns}
4949
height={someCalculatedHeight}
50-
renderCell={someCellRenderer}
50+
cellRenderer={someCellRenderer}
5151
rowHeight={50}
52-
rowsCount={numRows}
52+
rowCount={numRows}
5353
width={adjustedWidth}
5454
/>
5555
)}

0 commit comments

Comments
 (0)