2019-09-13 12:37:46 +00:00
|
|
|
/* eslint-disable react/display-name */
|
2020-10-16 13:16:01 +00:00
|
|
|
import React, { memo } from "react";
|
|
|
|
import PropTypes from "prop-types";
|
|
|
|
import CustomScrollbarsVirtualList from "../scrollbar/custom-scrollbars-virtual-list";
|
|
|
|
import { FixedSizeList as List, areEqual } from "react-window";
|
|
|
|
import AutoSizer from "react-virtualized-auto-sizer";
|
2021-02-09 14:50:25 +00:00
|
|
|
import StyledRowContainer from "./styled-row-container";
|
2019-08-29 13:02:11 +00:00
|
|
|
|
|
|
|
class RowContainer extends React.PureComponent {
|
2021-03-12 09:59:32 +00:00
|
|
|
renderRow = memo(({ data, index, style }) => {
|
|
|
|
return <div style={style}>{data[index]}</div>;
|
|
|
|
}, areEqual);
|
2019-08-29 13:02:11 +00:00
|
|
|
|
|
|
|
render() {
|
2020-10-16 13:16:01 +00:00
|
|
|
const {
|
|
|
|
manualHeight,
|
|
|
|
itemHeight,
|
|
|
|
children,
|
|
|
|
useReactWindow,
|
|
|
|
id,
|
|
|
|
className,
|
|
|
|
style,
|
|
|
|
} = this.props;
|
2019-08-29 13:02:11 +00:00
|
|
|
|
|
|
|
const renderList = ({ height, width }) => (
|
|
|
|
<List
|
|
|
|
className="List"
|
|
|
|
height={height}
|
|
|
|
width={width}
|
|
|
|
itemSize={itemHeight}
|
|
|
|
itemCount={children.length}
|
|
|
|
itemData={children}
|
|
|
|
outerElementType={CustomScrollbarsVirtualList}
|
|
|
|
>
|
2019-09-13 12:37:46 +00:00
|
|
|
{this.renderRow}
|
2019-08-29 13:02:11 +00:00
|
|
|
</List>
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
2020-10-16 13:16:01 +00:00
|
|
|
<StyledRowContainer
|
|
|
|
id={id}
|
|
|
|
className={className}
|
|
|
|
style={style}
|
|
|
|
manualHeight={manualHeight}
|
|
|
|
useReactWindow={useReactWindow}
|
|
|
|
>
|
2021-03-12 09:59:32 +00:00
|
|
|
{useReactWindow ? <AutoSizer>{renderList}</AutoSizer> : children}
|
2019-08-29 13:02:11 +00:00
|
|
|
</StyledRowContainer>
|
|
|
|
);
|
|
|
|
}
|
2019-09-10 06:01:34 +00:00
|
|
|
}
|
2019-08-29 13:02:11 +00:00
|
|
|
|
|
|
|
RowContainer.propTypes = {
|
2021-03-10 10:44:54 +00:00
|
|
|
/** Height of one Row element. Required for scroll to work properly */
|
2019-08-29 13:02:11 +00:00
|
|
|
itemHeight: PropTypes.number,
|
2021-03-10 10:44:54 +00:00
|
|
|
/** Allows you to set fixed block height for Row */
|
2019-08-29 13:02:11 +00:00
|
|
|
manualHeight: PropTypes.string,
|
2021-03-10 10:44:54 +00:00
|
|
|
/** Child elements */
|
2019-11-14 12:25:54 +00:00
|
|
|
children: PropTypes.any.isRequired,
|
2021-03-10 10:44:54 +00:00
|
|
|
/** Use react-window for efficiently rendering large lists */
|
2019-12-03 12:54:46 +00:00
|
|
|
useReactWindow: PropTypes.bool,
|
2021-03-10 10:44:54 +00:00
|
|
|
/** Accepts class */
|
2019-12-03 12:54:46 +00:00
|
|
|
className: PropTypes.string,
|
2021-03-10 10:44:54 +00:00
|
|
|
/** Accepts id */
|
2019-12-03 12:54:46 +00:00
|
|
|
id: PropTypes.string,
|
2021-03-10 10:44:54 +00:00
|
|
|
/** Accepts css style */
|
2020-10-16 13:16:01 +00:00
|
|
|
style: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
|
2019-08-29 13:02:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
RowContainer.defaultProps = {
|
|
|
|
itemHeight: 50,
|
2019-12-03 12:54:46 +00:00
|
|
|
useReactWindow: true,
|
2020-10-16 13:16:01 +00:00
|
|
|
id: "rowContainer",
|
2019-08-29 13:02:11 +00:00
|
|
|
};
|
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
export default RowContainer;
|