aboutsummaryrefslogtreecommitdiff
path: root/src/components/SmartList/SmartList.js
blob: 975cbbd9b7dc6179851deebe9bd4436bcffa4ca9 (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
import React from 'react';

import { FixedSizeList } from 'react-window';
import AutoSizer from 'react-virtualized-auto-sizer';

import { makeStyles } from '@material-ui/core';


const useStyles = makeStyles(theme => ({
  root: {
    scrollbarColor: `${theme.palette.primary.dark} ${theme.palette.primary.light}`,
  }
}));


const SmartList = ({ itemSize, itemCount, renderItem }) => {
  const classes = useStyles();

  return (
    <div style={{ flex: '1 1 auto'}}>
      <AutoSizer>
        {({ width, height }) => (
          <FixedSizeList
            height={height}
            width={width}
            itemSize={itemSize}
            itemCount={itemCount}
            className={classes.root}
          >
            {renderItem}
          </FixedSizeList>
        )}
      </AutoSizer>
    </div>
  );
};


export default SmartList;