UNPKG

@kohlmannj/react-scroll-percentage

Version:

Monitor the scroll percentage of a component inside the viewport, using the IntersectionObserver API.

23 lines 1.52 kB
import { IntersectionObserverProps, IntersectionObserverRenderProps } from '@kohlmannj/react-intersection-observer'; import React, { PureComponent, ReactNode } from 'react'; import { IScrollPercentageCalculatorState } from './ScrollPercentageCalculator'; export interface IScrollPercentageObserverRenderProps extends IntersectionObserverRenderProps, IScrollPercentageCalculatorState { } export declare type ScrollPercentageObserverRenderFunction = ((fields: IScrollPercentageObserverRenderProps) => ReactNode); export interface IScrollPercentageObserverOwnProps { /** Children should be either a function or a node */ children?: ReactNode | ScrollPercentageObserverRenderFunction; /** Call this function whenever the percentage changes */ onChange?: (percentage: IScrollPercentageCalculatorState['percentage'], inView: boolean, percentageOfViewport: IScrollPercentageCalculatorState['percentageOfViewport']) => void; } export declare type ScrollPercentageObserverProps = Pick<IntersectionObserverProps, Exclude<keyof IntersectionObserverProps, 'children' | 'onChange'>> & IScrollPercentageObserverOwnProps; /** @see https://github.com/DefinitelyTyped/DefinitelyTyped/issues/28249 */ export declare class ScrollPercentageObserver extends PureComponent<ScrollPercentageObserverProps> { static defaultProps: { forwardedRef: React.RefObject<any>; threshold: number; triggerOnce: boolean; }; render(): JSX.Element; } //# sourceMappingURL=ScrollPercentageObserver.d.ts.map