diff --git a/types/react-visibility-sensor/index.d.ts b/types/react-visibility-sensor/index.d.ts index 9e8776cb8f..80cda84d19 100644 --- a/types/react-visibility-sensor/index.d.ts +++ b/types/react-visibility-sensor/index.d.ts @@ -1,6 +1,7 @@ -// Type definitions for react-visibility-sensor 3.11 +// Type definitions for react-visibility-sensor 5.0 // Project: https://github.com/joshwnj/react-visibility-sensor#readme // Definitions by: Rasmus Bergström +// Gabriel Cangussu // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.8 @@ -15,8 +16,15 @@ interface Shape { right?: number; } +interface ChildFunctionArg { + isVisible: boolean | null; + visibilityRect: Shape; +} + +type ChildFunction = (arg: ChildFunctionArg) => React.ReactNode; + interface Props { - onChange: (isVisible: boolean, visibilityRect?: Shape) => void; + onChange?: (isVisible: boolean) => void; active?: boolean; partialVisibility?: boolean; offset?: Shape; @@ -29,10 +37,9 @@ interface Props { resizeCheck?: boolean; resizeDelay?: number; resizeThrottle?: number; + containment?: HTMLElement; delayedCall?: boolean; - children?: ( - args: { isVisible: boolean; visibilityRect?: Shape } - ) => React.ReactNode; + children?: React.ReactElement | ChildFunction; } declare const ReactVisibilitySensor: React.StatelessComponent; diff --git a/types/react-visibility-sensor/react-visibility-sensor-tests.tsx b/types/react-visibility-sensor/react-visibility-sensor-tests.tsx index 9dca0efb34..a78189da71 100644 --- a/types/react-visibility-sensor/react-visibility-sensor-tests.tsx +++ b/types/react-visibility-sensor/react-visibility-sensor-tests.tsx @@ -8,7 +8,7 @@ const shape = { top: num, left: num, bottom: num, right: num }; const component = ( {}} + onChange={(bool) => {}} active={bool} partialVisibility={bool} offset={shape} @@ -21,7 +21,15 @@ const component = ( resizeCheck={bool} resizeDelay={num} resizeThrottle={num} - delayedCall={bool}> - {({ isVisible: bool, visibilityRect: shape }) =>
} + delayedCall={bool} + containment={window.document.body} + > +
+ +); + +const componentWithFunctionAsChild = ( + + {({ isVisible, visibilityRect }) =>
} );