UNPKG

@talend/react-components

Version:
71 lines 2.03 kB
import PropTypes from 'prop-types'; import { InfiniteLoader } from 'react-virtualized'; import VList from '../VList'; import { useListContext } from '../context'; import { debounce } from "lodash"; import { jsx as _jsx } from "react/jsx-runtime"; const DEFAULT_THRESHOLD = 5; const DEFAULT_MIN_BATCH_SIZE = 20; const DEFAULT_DEBOUNCE_DELAY = 0; function LazyLoadingList(props) { const { rowCount, threshold, minimumBatchSize, loadMoreRows, debounceDelay, onRowsRendered: parentOnRowsRendered, ...rest } = props; const { collection } = useListContext(); const isRowLoaded = ({ index }) => collection && collection[index]; let loadMoreRowsCallback = loadMoreRows; if (loadMoreRowsCallback && debounceDelay) { loadMoreRowsCallback = debounce(loadMoreRowsCallback, debounceDelay); } return /*#__PURE__*/_jsx(InfiniteLoader, { isRowLoaded: isRowLoaded, loadMoreRows: loadMoreRowsCallback, minimumBatchSize: minimumBatchSize, rowCount: rowCount, threshold: threshold, children: ({ onRowsRendered, registerChild }) => { function combinedOnRowsRendered(...args) { if (parentOnRowsRendered) { parentOnRowsRendered(...args); } onRowsRendered(...args); } return /*#__PURE__*/_jsx(VList, { registerChild: registerChild, onRowsRendered: combinedOnRowsRendered, rowCount: rowCount, ...rest }); } }); } LazyLoadingList.defaultProps = { threshold: DEFAULT_THRESHOLD, minimumBatchSize: DEFAULT_MIN_BATCH_SIZE, debounceDelay: DEFAULT_DEBOUNCE_DELAY }; if (process.env.NODE_ENV !== 'production') { LazyLoadingList.propTypes = { loadMoreRows: PropTypes.func.isRequired, onRowsRendered: PropTypes.func, rowCount: PropTypes.number, threshold: PropTypes.number, minimumBatchSize: PropTypes.number, debounceDelay: PropTypes.number }; } export default LazyLoadingList; //# sourceMappingURL=LazyLoadingList.component.js.map