-
Notifications
You must be signed in to change notification settings - Fork 835
/
virtual-list.js
55 lines (51 loc) · 1.47 KB
/
virtual-list.js
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
// @flow
import React from 'react';
import {withStyle} from 'styletron-react';
import {StatefulMenu, OptionList, StyledList} from 'baseui/menu';
import List from 'react-virtualized/dist/commonjs/List';
import AutoSizer from 'react-virtualized/dist/commonjs/AutoSizer';
const ITEMS = [...new Array(1500)].map((_, index) => ({
label: `item number: ${index + 1}`,
}));
const Container = withStyle(StyledList, {height: '500px'});
const VirtualList = React.forwardRef((props, ref) => {
const children = React.Children.toArray(props.children);
return (
<Container {...props} ref={ref}>
<AutoSizer>
{({width}) => (
<List
role={props.role}
height={500}
rowCount={props.children.length}
rowHeight={36}
rowRenderer={({index, key, style}) => (
<OptionList
key={key}
style={style}
{...children[index].props}
overrides={{
ListItem: {
style: {
paddingTop: 0,
paddingBottom: 0,
display: 'flex',
alignItems: 'center',
},
},
}}
/>
)}
width={width}
/>
)}
</AutoSizer>
</Container>
);
});
export default () => (
<StatefulMenu
items={ITEMS}
overrides={{List: {component: VirtualList}}}
/>
);