-
-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathreact-cool-inview.d.ts
60 lines (49 loc) · 1.71 KB
/
react-cool-inview.d.ts
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
declare module "react-cool-inview" {
import type { ReactElement } from "react";
import { createElement } from "react";
export interface IntersectionObserverEntryV2
extends IntersectionObserverEntry {
readonly isVisible?: boolean;
}
export interface ScrollDirection {
readonly vertical?: "up" | "down";
readonly horizontal?: "left" | "right";
}
export interface Event<T extends HTMLElement | null = HTMLElement> {
readonly entry: IntersectionObserverEntryV2;
readonly scrollDirection: ScrollDirection;
observe: (element?: T | null) => void;
unobserve: () => void;
}
export interface OnChange<T extends HTMLElement | null = HTMLElement> {
(event: Event<T> & { inView: boolean }): void;
}
export interface OnEnter<T extends HTMLElement | null = HTMLElement> {
(event: Event<T>): void;
}
export type OnLeave<T extends HTMLElement | null = HTMLElement> = OnEnter<T>;
export interface Options<T extends HTMLElement | null> {
root?: HTMLElement | null;
rootMargin?: string;
threshold?: number | number[];
trackVisibility?: boolean;
delay?: number;
unobserveOnEnter?: boolean;
onChange?: OnChange<T>;
onEnter?: OnEnter<T>;
onLeave?: OnLeave<T>;
}
export interface Return<T extends HTMLElement | null>
extends Omit<Event<T>, "entry"> {
inView: boolean;
entry?: IntersectionObserverEntryV2;
updatePosition?: () => void;
}
export const useInView: <T extends HTMLElement | null = HTMLElement>(
options?: Options<T>
) => Return<T>;
export interface InViewProps extends Options<HTMLElement | null> {
children: ReactElement;
}
export const InView: (props: InViewProps) => ReturnType<typeof createElement>;
}