UNPKG

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