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

ellipsis-tooltip-react-chan

v1.2.1

Published

Hi there, this package helps in truncating the overflown text or inline element with ellipsis & shows tooltip on hover.

Downloads

624

Readme

ellipsis-tooltip-react-chan

Hi there, this package helps in truncating the overflown text or inline element with ellipsis & shows tooltip on hover. It comes into effect only when the text is overflown, else it looks like a normal element. This is dynamic i.e., when screen is minimized, more elements get truncated & it dynamically show tooltips wherever necessary. This uses react-tooltip package to display truncated content & uuid to generate unique id's for tooltips.

DEMO

CLICK HERE FOR THE DEMO

INSTALLATION

npm install --save ellipsis-tooltip-react-chan

NOTE: Type definitions already included to work with typescript

USAGE

All we need is to wrap this with any element that has a fixed width. To configure the tooltip settings, it accepts options as prop. From the below example, place refers to place of tooltip. It can be left,right,top,bottom. You can find more information about other options at react-tooltip documentation.

NOTE: The effect works only if you pass direct text or any inline or inline-block elements as children. See the examples below:

import React from 'react';
import './App.css';
import EllipsisToolTip from "ellipsis-tooltip-react-chan";

function App() {

  const options = {
    effect: "solid",
    place: "top"
  }

  return (
    <div style={{ width: "50px", margin: "5rem" }}>
      <EllipsisToolTip options={options}>
         Lorem ipsum dolor sit amet consectetur adipisicing elit. Libero, fugiat.
      </EllipsisToolTip>
    </div>
  );

}

export default App;

Span element

<EllipsisToolTip options={options}>
   <span>
       Lorem ipsum dolor sit amet consectetur.
   </span>
</EllipsisToolTip>

Anchor element

<EllipsisToolTip options={options}>
  <a href="">
    Lorem ipsum dolor sit amet consectetur
  </a>
</EllipsisToolTip>

Table cell

When you are explicitly adding the width to the columns, do not forget to apply table-layout: fixed as the table style.

<table style={{tableLayout : "fixed"}}>
  <tr>
    <td style={{maxWidth : "10vw"}}>
      <EllipsisToolTip options={options}>
        Lorem ipsum dolor sit amet consectetur
      </EllipsisToolTip>
    </td>
  </tr>
</table>

and etc.....

STYLES

When it recieves children, it wraps around an inline-block element to give the effect & inline-block elements have extra space around them. So, when placed in a table cell or CSS Grid, it gives a wired look. So we can pass style explicitly float:left as shown below to prevent this. Use this hack whenever necessary.

<tr>
  <td style={{maxWidth : "10vw"}}>
    <EllipsisToolTip style={{float: "left"}} options={options}>
      Lorem ipsum dolor sit amet consectetur
    </EllipsisToolTip>
  </td>
</tr>

By default, the font is inherited. If we want to pass any extra styles, you can make use of style prop as shown above. This doesn't affect the tooltip styles but only the wrapper I mentioned. If you wish to change the tool tip styles, you need to send the className in options. Go through the react-tooltip documentation for more information. I have briefly mentioned about styling the tooltip in my DEMO as well under TABLE/CSS GRID section. Have a look if necessary.

DYNAMIC TOOLTIP

You might run into an issue when there is state change and tool tips aren't diplaying properly, you might have to restart the react-toolip as below.

import ReactTooltip from "react-tooltip";

useEffect(() => {
        ReactTooltip.rebuild();
},[pass dependency array]);

FINAL NOTE

I am extremely glad that you thought of using this package in you project. If you like my work, I would really appreciate if you provide a star on github repo. If you stumble across any issues, kindly raise an issue for the same.