React Border Distance
A higher-order component (HOC) to get the distance of a react element to a scrollable element or window border. Helpful for action-based overlapping content e.g. dropdown or tooltips.
Usage
The package can be installed via NPM:
npm install --save react-border-distance
Example with decorator (e.g. babel-plugin-transform-decorators-legacy):
distance
prop is only available when the mouse enters the component (onMouseEnter).
;; @Component /*...*/ { const distance = thisprops; const type = distance && distancebottom < 100 ? "dropup" : "dropdown"; return <div className=``> </div> ; }
Example without decorator (e.g. babel-plugin-transform-decorators-legacy):
;; Component /*... see above ...*/ DropDown;
Style wrapper component:
@class ... // or position: "relative" "class-name"DropDown;
Available Props
distance: object;
An Object which contains the distance.
{ top: number, right: number, bottom: number, left: number }
(Only available onMouseEnter)