Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-border-distance

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-border-distance

Higher-order component (HOC) to get the distance to window border or scrollable element.

  • 0.0.7
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

React Border Distance

version

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.

react-border-distance

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).

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);

Available Props

distance: object;

An Object which contains the distance. { top: number, right: number, bottom: number, left: number } (Only available onMouseEnter)

Keywords

FAQs

Package last updated on 26 Jul 2017

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc