
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
react-border-distance
Advanced tools
Higher-order component (HOC) to get the distance to window border or scrollable element.
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.
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).
import React from "react";
import borderDistance from "react-border-distance";
@borderDistance()
class DropDown extends React.Component {
/*...*/
render() {
const { distance } = this.props;
const type = distance && distance.bottom < 100
? "dropup"
: "dropdown";
return(
<div className={`${type}`}>
</div>
);
}
}
Example without decorator (e.g. babel-plugin-transform-decorators-legacy):
import React from "react";
import borderDistance from "react-border-distance";
class DropDown extends React.Component {
/*... see above ...*/
}
export default borderDistance()(DropDown);
Style wrapper component:
@borderDistance({ position: "relative" }, "class-name")
class ...
// or
export default borderDistance({ position: "relative" }, "class-name")(DropDown);
distance: object;
An Object which contains the distance.
{ top: number, right: number, bottom: number, left: number }
(Only available onMouseEnter)
FAQs
Higher-order component (HOC) to get the distance to window border or scrollable element.
We found that react-border-distance demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.