-
Notifications
You must be signed in to change notification settings - Fork 190
Expand file tree
/
Copy pathindex.tsx
More file actions
83 lines (73 loc) · 3.23 KB
/
index.tsx
File metadata and controls
83 lines (73 loc) · 3.23 KB
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
"use client";
import type * as React from "react";
export { InView } from "./InView";
export { useInView } from "./useInView";
export { useOnInViewChanged } from "./useOnInViewChanged";
export { observe } from "./observe";
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
export type ObserverInstanceCallback = (
inView: boolean,
entry: IntersectionObserverEntry,
) => void;
interface RenderProps {
inView: boolean;
entry: IntersectionObserverEntry | undefined;
// biome-ignore lint/suspicious/noExplicitAny: Ref could be anything
ref: React.RefObject<any> | ((node?: Element | null) => void);
}
export interface IntersectionOptions extends IntersectionObserverInit {
/** The IntersectionObserver interface's read-only `root` property identifies the Element or Document whose bounds are treated as the bounding box of the viewport for the element which is the observer's target. If the `root` is null, then the bounds of the actual document viewport are used.*/
root?: Element | Document | null;
/** Margin around the root. Can have values similar to the CSS margin property, e.g. `10px 20px 30px 40px` (top, right, bottom, left). */
rootMargin?: string;
/** Number between `0` and `1` indicating the percentage that should be visible before triggering. Can also be an `array` of numbers, to create multiple trigger points. */
threshold?: number | number[];
/** Only trigger the inView callback once */
triggerOnce?: boolean;
/** Skip assigning the observer to the `ref` */
skip?: boolean;
/** Set the initial value of the `inView` boolean. This can be used if you expect the element to be in the viewport to start with, and you want to trigger something when it leaves. */
initialInView?: boolean;
/** IntersectionObserver v2 - Track the actual visibility of the element */
trackVisibility?: boolean;
/** IntersectionObserver v2 - Set a minimum delay between notifications */
delay?: number;
/** Call this function whenever the in view state changes */
onChange?: (inView: boolean, entry: IntersectionObserverEntry) => void;
}
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;
}
/**
* Types specific to the PlainChildren rendering of InView
* */
export type PlainChildrenProps = IntersectionOptions & {
children?: React.ReactNode;
/**
* Render the wrapping element as this element.
* This needs to be an intrinsic element.
* If you want to use a custom element, please use the useInView
* hook to manage the ref explicitly.
* @default `'div'`
*/
as?: React.ElementType;
/** 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;
};