forked from caseywebdev/react-list
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.es6
152 lines (142 loc) · 3.61 KB
/
index.es6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import React from 'react';
import ReactList from 'react-list';
const renderItem = (index, key) =>
<div key={key} className={'item' + (index % 2 ? '' : ' even')}>
{index}
</div>;
renderItem.toJSON = () => renderItem.toString();
const renderSquareItem = (index, key) =>
<div key={key} className={'square-item' + (index % 2 ? '' : ' even')}>
{index}
</div>;
renderSquareItem.toJSON = () => renderSquareItem.toString();
const getHeight = index => 30 + (10 * (index % 10));
getHeight.toJSON = () => getHeight.toString();
const getWidth = index => 100 + (10 * (index % 10));
getWidth.toJSON = () => getWidth.toString();
const renderVariableHeightItem = (index, key) =>
<div
key={key}
className={'item' + (index % 2 ? '' : ' even')}
style={{lineHeight: `${getHeight(index)}px`}}
>
{index}
</div>;
renderVariableHeightItem.toJSON = () => renderVariableHeightItem.toString();
const renderVariableWidthItem = (index, key) =>
<div
key={key}
className={'item' + (index % 2 ? '' : ' even')}
style={{width: `${getWidth(index)}px`}}
>
{index}
</div>;
renderVariableWidthItem.toJSON = () => renderVariableWidthItem.toString();
const renderGridLine = (row, key) =>
<ReactList
axis='x'
key={key}
length={10000}
itemRenderer={
(column, key) => renderSquareItem(column + (10000 * row), key)
}
type='uniform'
/>;
renderGridLine.toJSON = () => renderGridLine.toString();
const examples = [
{
length: 10000,
itemRenderer: renderVariableHeightItem
},
{
axis: 'x',
length: 10000,
itemRenderer: renderVariableWidthItem
},
{
length: 10000,
itemRenderer: renderVariableHeightItem,
type: 'variable'
},
{
axis: 'x',
length: 10000,
itemRenderer: renderVariableWidthItem,
type: 'variable'
},
{
length: 10000,
itemRenderer: renderVariableHeightItem,
itemSizeGetter: getHeight,
type: 'variable'
},
{
axis: 'x',
length: 10000,
itemRenderer: renderVariableWidthItem,
itemSizeGetter: getWidth,
threshold: 0,
type: 'variable'
},
{
length: 10000,
initialIndex: 5000,
itemRenderer: renderVariableHeightItem,
itemSizeGetter: getHeight,
type: 'variable'
},
{
length: 10000,
itemRenderer: renderItem,
type: 'uniform'
},
{
axis: 'x',
length: 10000,
itemRenderer: renderItem,
type: 'uniform'
},
{
length: 10000,
itemRenderer: renderSquareItem,
type: 'uniform'
},
{
length: 10000,
initialIndex: 5000,
itemRenderer: renderItem,
type: 'uniform'
},
{
length: 10000,
itemRenderer: renderGridLine,
type: 'uniform',
useTranslate3d: true
}
];
export default class extends React.Component {
renderExamples() {
return examples.map((props, key) =>
<div key={key} className={`example axis-${props.axis}`}>
<strong>Props</strong>
<pre className='props'>{JSON.stringify(props, null, 2)}</pre>
<strong>Component</strong>
<div className='component'><ReactList {...props} /></div>
</div>
);
}
render() {
return (
<div className='index'>
<a className='banner' href='https://github.com/orgsync/react-list'>
<img
src='https://camo.githubusercontent.com/652c5b9acfaddf3a9c326fa6bde407b87f7be0f4/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6f72616e67655f6666373630302e706e67'
alt='Fork me on GitHub'
/>
</a>
<div className='header'>ReactList</div>
<div className='examples'>{this.renderExamples()}</div>
</div>
);
}
}