1.0.8 • Published 3 months ago

react-hover-text v1.0.8

Weekly downloads
-
License
ISC
Repository
-
Last release
3 months ago

React Hover Text

A all-in-one library for all kind of tooltip

Features

  • Customize the tooltip using props and place the tooltip on Top,Bottom,Left and Right.
  • Auto detection of the space available and opens itself in the opposite direction
  • Change the background color,text color,width,height using props.
  • Trigger the tooltip on either click or on hover.
  • Add HTML as content for the tooltip.

Usage

import HoverText from "react-hover-text";
//props used by Tooltip
<HoverText
  placement="top" // Pass this prop to define where the tooltip needs to be placed
  content="Hello World" // The content that needs to be shown on the tooltip
  stylingOptions={{
    bgColor: "#fff",
    color: "#000",
    width: "150px",
  }}
  parentClass="parent-element" // pass this prop if the tooltip should be positioned according to parent
/>;

Props

ParameterTypeDescription
placementstringRequired. This Prop specifies where the tooltip needs to be placed. Accepted Values include top,left,bottom,right. Ex: placement="top"
contentstring or HTMLRequired. This Prop specifies the text that needs to appear on the tooltip. Ex: content="hello world". Note: For adding Html elements as the content, set the html prop to true.
triggerstringBy default the tooltip will open on hover.If the trigger is set to "click", then the tooltip will open on click
stylingOptionsobjectThe styling options like bgColor,color,width,height can be passed as object for this prop
htmlbooleanThis prop must be set to true, if the content for the tooltip should be HTML
scrollElementstringPass the classname of the element on which overflow:scroll property is applied. This prop will be needed if tooltip is added inside an element that will scroll
hideOnClickbooleanIf this value is set to true, then the tooltip will close only if the user clicks on the tooltip directly. By default, the tooltip will close,if it is clicked anywhere.
parentClassstringIf the tooltip needs to be positioned according to the parent element, specify the className of the parent element.

Important

If the tooltip is added inside an element that will scroll, the below function needs to be called from the utils file along with the parameters. This function must be called inside the function that handles the scrolling for the element.

import { tooltipScroll } from "react-hover-text/dist/utils";
tooltipScroll(targetElementClass, scrollParentElementClass, scrollElementClass);

/**
 * tooltipScroll
 * @param {string} targetElementClass - This class is the target element, that makes the tooltip visible.
 * @param {string} scrollParentElementClass - This class is the parent of the scrolling element.
 * @param {string} scrollElementClass - This class is the element on which the overflow:scroll property is applied.
 */

Example (Scrolling tooltip)

// Example given below
handleScroll(){
  tooltipScroll(".table-row-tooltip .btn-download", ".home-table", ".asc-custom-table-wrapper");
}

Styling Options

The styling Options supported on the tooltip are as follows : width, height, zIndex, bgColor, color. The prop need to be passed as follows in the below given format :

stylingOptions={{
bgColor: "#fff",
color: "#000",
width: "115px",
height:"100px"
zIndex: 100,
}}

Example

import HoverText from "react-hover-text";

export const App = () => {
  return (
    <>
      <HoverText placement="top" content="Top Tooltip">
        <button>Top</button>
      </HoverText>

      <HoverText
        placement="bottom"
        stylingOptions={{
          bgColor: "#fff",
          color: "#000",
          width: "115px",
          height:"100px"
          zIndex: 100,
          }}
          content="Bottom Tooltip">
          <button>Bottom</button>
      </HoverText>
    </>
  );
};
1.0.8

3 months ago

1.0.7

3 months ago

1.0.6

3 months ago

1.0.5

3 months ago

1.0.4

8 months ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago