-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master'
- Loading branch information
Showing
11 changed files
with
206 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,73 @@ | ||
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, | ||
intersection: IntersectionObserverEntry, | ||
) => void | ||
|
||
export type ObserverInstance = { | ||
callback: ObserverInstanceCallback | ||
element: Element | ||
inView: boolean | ||
observerId: string | ||
observer: IntersectionObserver | ||
thresholds: 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 | ||
} | ||
|
||
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'> | ||
|
||
export type InViewHookResponse = [ | ||
((node?: Element | null) => void), | ||
boolean, | ||
IntersectionObserverEntry | undefined | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.