marlo22 / react-sticky-mouse-tooltip

React tooltip component that follow mouse cursor.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

react-sticky-mouse-tooltip

React tooltip component that follow mouse cursor. You can pass as children any HTML element or other React component.

Component functionality preview

Installation

npm install react-sticky-mouse-tooltip --save

or

yarn add react-sticky-mouse-tooltip

Example

import React from 'react';
import MouseTooltip from 'react-sticky-mouse-tooltip';

class Preview extends React.Component {
  state = {
    isMouseTooltipVisible: false,
  };

  toggleMouseTooltip = () => {
    this.setState(prevState => ({ isMouseTooltipVisible: !prevState.isMouseTooltipVisible }));
  };

  render() {
    return (
      <div>
        <button onClick={this.toggleMouseTooltip} style={buttonStyle}>
          Toggle mouse tooltip
        </button>
        <MouseTooltip
          visible={this.state.isMouseTooltipVisible}
          offsetX={15}
          offsetY={10}
        >
          <span>Follow the cursor!</span>
        </MouseTooltip>
      </div>
    );
  }
}

Attributes

Attribute Description Type Required Default value
visible Visibility of component. boolean No true
offsetX Offset along X axis. number No 0
offsetY Offset along Y axis. number No 0
className Tooltip div class name. string No -
style Styles properties of tooltip div. object No -

License

MIT

About

React tooltip component that follow mouse cursor.

License:MIT License


Languages

Language:JavaScript 97.4%Language:HTML 2.4%Language:Shell 0.2%