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-lightweight-tooltip

v1.0.0

Published

A lightweight React.js tooltip component

Downloads

15,036

Readme

build status npm version bitHound Score Dependency Status

A lightweight React.js tooltip component

Demo

Check it out

Features

  • Shows onMouseEnter and hides onMouseLeave on devices with mouse
  • Shows onTouchStart and hides “on touch outside” on devices with touch screen
  • Uses inline-styles for easy composing of specialized components
  • Can contain rich content (composed of components)
  • Works well on a long lists (eg. financial transactions)
  • Is relatively small (~130 lines of ES6 code incl. default inline-styles)
  • Has no external dependencies except React and ReactDOM
  • Includes TypeScript typings

Installation

npm install react-lightweight-tooltip --save

Basic Usage

Import tooltip component

import {Tooltip} from 'react-lightweight-tooltip';

Use tooltip component

<Tooltip content="Yes, the default one">Simple black tooltip</Tooltip>

Advanced Usage

The props

children

The children represent the element(s) the tooltip is wrapped around.

content

The content is the actual content of the tooltip. It can be string or array of React Elements.

Note that each React Element in the array has to have its unique key prop.

<Tooltip
  content={
    [
      'This repo is hosted on ',
      <a href="https://github.com" key="githublink" target="_blank">Github</a>,
    ]
  }>
  Tooltip with a link
</Tooltip>

styles

The styles prop is used to override the default styles of the tooltip. When passed to the component, the component merges them with its default styles.

This is especaially handy when writing specialized components.

const greenRoundedStyle = {
  content: {
    backgroundColor: 'green',
    color: '#000',
  },
  tooltip: {
    backgroundColor: 'green',
    borderRadius: '10px',
  },
  arrow: {
    borderTop: 'solid green 5px',
  },
};

const GreenRoundedTooltip = () => {
  return (
    <Tooltip
      content={
        [
          'This repo is hosted on ',
          <a href="https://github.com" key="githublink" target="_blank">Github</a>,
        ]
      }
      styles={greenRoundedStyle}>
      Green tooltip with rounded corners and a link
    </Tooltip>
  );
}

export default GreenRoundedTooltip;

Custom Styling

You can easily override the default styles by passing your own styles to the styles prop. When your styles get passed, the component merges them with its default styles.

The default styles are the following:

{
  wrapper: {
    position: 'relative',
    display: 'inline-block',
    zIndex: '98',
    color: '#555',
    cursor: 'help',
  },
  tooltip: {
    position: 'absolute',
    zIndex: '99',
    background: '#000',
    bottom: '100%',
    left: '50%',
    marginBottom: '10px',
    padding: '5px',
    WebkitTransform: 'translateX(-50%)',
    msTransform: 'translateX(-50%)',
    OTransform: 'translateX(-50%)',
    transform: 'translateX(-50%)',
  },
  content: {
    background: '#000',
    color: '#fff',
    fontSize: '.8em',
    padding: '.3em 1em',
    whiteSpace: 'nowrap',
  },
  arrow: {
    position: 'absolute',
    width: '0',
    height: '0',
    bottom: '-5px',
    left: '50%',
    marginLeft: '-5px',
    borderLeft: 'solid transparent 5px',
    borderRight: 'solid transparent 5px',
    borderTop: 'solid #000 5px',
  },
  gap: {
    position: 'absolute',
    width: '100%',
    height: '20px',
    bottom: '-20px',
  },
}

TODO

  • [ ] Improve demo: dispay examples and code only, make it responsive
  • [ ] Improve docs: tooltip style/dom explanation
  • [ ] Improve tests (let me think...)
  • [ ] Write typings

Acknowledgements

Special thanks to @no23reason for his help with the “on touch outside” handling. This project uses the react-component-boilerplate.

License

react-lightweight-tooltip is available under MIT license. See LICENSE for more details.