Skip to content

Commit a1e376d

Browse files
forabithebuilder
authored andcommitted
Add type definitions for TypeScript
1 parent 7341d83 commit a1e376d

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

index.d.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
declare module 'react-intersection-observer' {
2+
import * as React from 'react';
3+
4+
export type IntersectionObserverProps = {
5+
/** Children should be either a function or a node */
6+
children: JSX.Element | null | ((inView: boolean) => JSX.Element | null);
7+
8+
/**
9+
* The `HTMLElement` that is used as the viewport for checking visibility of
10+
* the target.
11+
* Defaults to the browser viewport if not specified or if `null`.
12+
*/
13+
root?: HTMLElement;
14+
15+
/**
16+
* Unique identifier for the root element - This is used to identify the
17+
* `IntersectionObserver` instance, so it can be reused.
18+
* If you defined a root element, without adding an `id`, it will create a new
19+
* instance for all components.
20+
*/
21+
rootId?: string;
22+
23+
/**
24+
* Margin around the root.
25+
* Can have values similar to the CSS margin property,
26+
* e.g. `"10px 20px 30px 40px"` (top, right, bottom, left).
27+
*/
28+
rootMargin?: string;
29+
30+
/**
31+
* Element tag to use for the wrapping component
32+
* @default `'div'`
33+
*/
34+
tag?: string;
35+
36+
/** Number between 0 and 1 indicating the the percentage that should be
37+
* visible before triggering. Can also be an array of numbers, to create
38+
* multiple trigger points.
39+
* @default `0`
40+
*/
41+
threshold?: number;
42+
43+
/**
44+
* Only trigger this method once
45+
* @default `false`
46+
*/
47+
triggerOnce?: boolean;
48+
49+
/** Call this function whenever the in view state changes */
50+
onChange?(inView: boolean): void;
51+
52+
/** Use `render` method to only render content when inView */
53+
render?(): JSX.Element | null;
54+
};
55+
56+
export default class IntersectionObserver extends React.Component<
57+
IntersectionObserverProps,
58+
{}
59+
> {}
60+
}

0 commit comments

Comments
 (0)