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

react-hover-mixin

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-hover-mixin

A react mixin that will update the components state on mouse hover. Designed for tooltips, popovers, and dropdowns.

  • 1.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

react-hover-mixin

A react mixin that will update the components state on mouse hover. Designed for tooltips, popovers, and dropdowns.

var HoverMixin = require("react-hover-mixin");
...
... React.createClass({
  mixins: [HoverMixin],
  render: function(){
    return React.createElement("div", null,

      React.createElement("b", {
          onMouseEnter: this.hoverable_onMouseEnter,
          onMouseLeave: this.hoverable_onMouseLeave,
        },
        "[hover over me]"
      ),

      this.state.hover ? "I'm being hovered over!" : null

    );
  }
});

Example

$ git clone https://github.com/espeakers/react-hover-mixin.git
$ cd react-hover-mixin/
$ npm i
$ npm start

Then it will tell you which port it's hosted on so you can open it in your browser.

API

this.state.hover

true or false depending on if it's currently being hovered over.

this.hoverable_onMouseEnter | this.hoverable_onMouseLeave

These are event handlers provided by the mixin. Simply attach them to the element you wish to observe the hover state of.

For example:

...
React.createElement("div", {
    onMouseEnter: this.hoverable_onMouseEnter,
    onMouseLeave: this.hoverable_onMouseLeave
  },
  ...
),
...

child method: hoverable_onUserLeftHoverable()

This is called when the component is not hovered over anymore. (after a 500ms wait to ensure the user isn't going to just hover right over it again)

ref: "hoverable"

Set the ref to "hoverable" on the element if you want to get it's top and left position.

For example:

...
React.createElement("div", {
    ref: "hoverable",
    onMouseEnter: this.hoverable_onMouseEnter,
    onMouseLeave: this.hoverable_onMouseLeave
  },
  ...
),
...

this.state.hoverable_top | this.state.hoverable_left

The top and left position of the "hoverable" element. These are handy when trying to absolute position a tooltip or dropdown.

this.hoverable_not_relative_to_parent_bounding_rect

Set this to true if your hoverable is not relative to the parent node.

var HoverMixin = require("react-hover-mixin");
...
... React.createClass({
  mixins: [HoverMixin],

  hoverable_not_relative_to_parent_bounding_rect: true,

  render: function(){
    ...
  }
});

Installing

$ npm install --save react-hover-mixin

FYI

This project follows semantic versioning for releases.

License

MIT

Keywords

FAQs

Package last updated on 16 Nov 2015

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