npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-hover-text

v1.1.1

Published

All in one tooltip solution

Downloads

343

Readme

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={{
    color: "#000",
    width: "150px",
  }}
  parentClass="parent-element" // pass this prop if the tooltip should be positioned according to parent
/>;

Props

| Parameter | Type | Description | | :--------------- | :--------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | placement | string | Required. This Prop specifies where the tooltip needs to be placed. Accepted Values include top,left,bottom,right. Ex: placement="top" | | content | string or HTML | Required. 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. | | trigger | string | By default the tooltip will open on hover.If the trigger is set to "click", then the tooltip will open on click | | stylingOptions | object | This prop takes styles which can be passed as an object. Ex : stylingOptions = {width:"200px",fontSize:"10px"} | | html | boolean | This prop must be set to true, if the content for the tooltip should be HTML | | scrollElement | string | Pass 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 | | hideOnClick | boolean | If this prop is set to true, then the tooltip will close only if the user clicks on the child element of the tooltip directly. By default, the tooltip will close,if it is clicked anywhere. | | parentClass | string | If the tooltip needs to be positioned according to the parent element, specify the className of the parent element. | | ShowArrow | boolean | To show the tooltip arrow, this prop muse be set to true. By default, it is false. | | classNames | array | This prop takes an array of strings. Custom classNames can be given to the tooltip. Ex : ["custom-class1","custom-class2"] |

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

Custom styles can be passed to the tooltip using the stylingOptions prop:

stylingOptions={{
backgroundColor: "#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={{
          color: "#000",
          width: "115px",
          height:"100px"
          zIndex: 100,
          }}
          content="Bottom Tooltip">
          <button>Bottom</button>
      </HoverText>
    </>
  );
};