File size: 442 Bytes
8a37e0a
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import type { ListRange } from 'react-virtuoso';

/**
 * Gets the alignment for react-virtuoso's scrollToIndex function.
 * @param index The index of the item.
 * @param range The range of items currently visible.
 * @returns
 */
export const getScrollToIndexAlign = (index: number, range: ListRange): 'start' | 'end' => {
  if (index > (range.endIndex - range.startIndex) / 2 + range.startIndex) {
    return 'end';
  }
  return 'start';
};