aboutsummaryrefslogtreecommitdiff
path: root/src/lib/SmartList/SmartList.tsx
blob: 22cd3b28534ee753b8e878bb9d737460498cee77 (plain)
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
import React from 'react';
import { FixedSizeList } from 'react-window';
import AutoSizer from 'react-virtualized-auto-sizer';


interface RenderPropTypes {
  index: number;
  style: React.CSSProperties;
}

interface PropTypes {
  itemSize: number;
  itemCount: number;
  renderItem: React.FC<RenderPropTypes>;
}

interface Size {
  height: number;
  width: number;
}


const SmartList: React.FC<PropTypes> = ({ itemSize, itemCount, renderItem }) => {

  const ResizedList: React.FC<Size> = ({ width, height}) => (
    <FixedSizeList
      height={height}
      width={width}
      itemSize={itemSize}
      itemCount={itemCount}
    >
      {renderItem}
    </FixedSizeList>
  );

  return (
    <div style={{ flex: '1 1 auto', overflow: 'hidden' }}>
      <AutoSizer children={ResizedList} />
    </div>
  );
};


export default SmartList;