UNPKG

1.63 kBTypeScriptView Raw
1import { PureComponent, Validator, Requireable } from 'react';
2
3export type OnScrollParams = {
4 clientHeight: number;
5 clientWidth: number;
6 scrollHeight: number;
7 scrollLeft: number;
8 scrollTop: number;
9 scrollWidth: number;
10};
11
12export type ScrollSyncChildProps = {
13 clientHeight: number;
14 clientWidth: number;
15 onScroll: (params: OnScrollParams) => void;
16 scrollHeight: number;
17 scrollLeft: number;
18 scrollTop: number;
19 scrollWidth: number;
20};
21
22export type ScrollSyncProps = {
23 /**
24 * Function responsible for rendering 2 or more virtualized components.
25 * This function should implement the following signature:
26 * ({ onScroll, scrollLeft, scrollTop }) => PropTypes.element
27 */
28 children: (props: ScrollSyncChildProps) => React.ReactNode;
29 /**
30 * PLEASE NOTE
31 * The [key: string]: any; line is here on purpose
32 * This is due to the need of force re-render of PureComponent
33 * Check the following link if you want to know more
34 * https://github.com/bvaughn/react-virtualized#pass-thru-props
35 */
36 [key: string]: any;
37};
38
39export type ScrollSyncState = {
40 clientHeight: number;
41 clientWidth: number;
42 scrollHeight: number;
43 scrollLeft: number;
44 scrollTop: number;
45 scrollWidth: number;
46};
47
48/**
49 * HOC that simplifies the process of synchronizing scrolling between two or more virtualized components.
50 */
51export class ScrollSync extends PureComponent<ScrollSyncProps, ScrollSyncState> {
52 static propTypes: {
53 children: Validator<(props: ScrollSyncChildProps) => React.ReactNode>;
54 };
55}
56
57export default ScrollSync;