-
Notifications
You must be signed in to change notification settings - Fork 190
/
Copy pathindex.tsx
85 lines (73 loc) · 2.44 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import * as React from 'react';
import { InView } from './InView';
export { InView } from './InView';
export { useInView } from './useInView';
export default InView;
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
export type ObserverInstanceCallback = (
inView: boolean,
entry: IntersectionObserverEntry,
) => void;
export type ObserverInstance = {
inView: boolean;
readonly callback: ObserverInstanceCallback;
readonly element: Element;
readonly observerId: string;
readonly observer: IntersectionObserver;
readonly thresholds: ReadonlyArray<number>;
};
interface RenderProps {
inView: boolean;
entry: IntersectionObserverEntry | undefined;
ref: React.RefObject<any> | ((node?: Element | null) => void);
}
export interface IntersectionOptions extends IntersectionObserverInit {
/** Only trigger the inView callback once */
triggerOnce?: boolean;
/** Skip assigning the observer to the `ref` */
skip?: boolean;
/** IntersectionObserver v2 - Track the actual visibility of the element */
trackVisibility?: boolean;
/** IntersectionObserver v2 - Set a minimum delay between notifications */
delay?: number;
}
export interface IntersectionObserverProps extends IntersectionOptions {
/**
* Children expects a function that receives an object
* contain an `inView` boolean and `ref` that should be
* assigned to the element root.
*/
children: (fields: RenderProps) => React.ReactNode;
/** Call this function whenever the in view state changes */
onChange?: (inView: boolean, entry: IntersectionObserverEntry) => void;
}
/**
* Types specific to the PlainChildren rendering of InView
* */
export type PlainChildrenProps = IntersectionOptions & {
children: React.ReactNode;
/**
* Render the wrapping element as this element.
* @default `'div'`
*/
as?: React.ReactType<any>;
/**
* Element tag to use for the wrapping component
* @deprecated Replace with the 'as' prop
*/
tag?: React.ReactType<any>;
/** Call this function whenever the in view state changes */
onChange?: (inView: boolean, entry: IntersectionObserverEntry) => void;
} & Omit<React.HTMLProps<HTMLElement>, 'onChange'>;
/**
* The Hook response supports both array and object destructing
*/
export type InViewHookResponse = [
(node?: Element | null) => void,
boolean,
IntersectionObserverEntry | undefined,
] & {
ref: (node?: Element | null) => void;
inView: boolean;
entry?: IntersectionObserverEntry;
};