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

v2.0.2

Published

React simple tooltip - ts/js. (Fetch, click, hover...)

Downloads

338

Readme


Description

It is wrap the tooltip for the element. (Customize tooltip - html/css/complex)

Append the tooltip outside the root. (portal element).


Usage

Install the package

npm install --save react-tooltip-z

Import the module in the place you want to use:

import { Tooltip } from "react-tooltip-z";
// import { Tooltip, useTooltipContext } from "react-tooltip-z";

Snippet

simple
<Tooltip
    // tooltipContent={'This is simple tooltip'}
    tooltipContent={<b>This is jsx<br /> Tooltip</b>} // or Component
    tooltipClassName="my-class"
    placement="right"
    // trigger="click"
    // onClick={() => alert('event active')} // myClick()
>
    <button>this is children</button>
</Tooltip>
simple: trigger=manual (with api)
// here is the sample, please update it exactly with your source

const [sync, setSync] = useState(false)
// fetch api // do something
fetchApi() {
    if (sync) {
        setSync(false)
        return
    }

    fetch('api').then(....).then(rs => {
        setTodo(todo)
        setSync(true)
    })
}

<Tooltip
    tooltipContent={<div>{todo.title}e<br />fds</div>}
    trigger="manual"
    placement='right'
    showSync={sync} // manual simple
>
    <button>Tooltip of todo</button>
</Tooltip>

<button onClick={fetchApi}>Fetch</button>
More complex (with api + useTooltipContext)
// here is the sample, please update it exactly with your source

import { Tooltip, useTooltipContext } from "react-tooltip-z";

// ListData.js
<ul>
    {
        post.map(item => {
            return (
                <Tooltip
                    tagName="li"  // wrap all child
                    trigger="manual"
                    placement="right"
                >
                    <ListDataItem {...} />
                </Tooltip>
            )
        })
    }
</ul>

// ListDataItem.js
// use TooltipContext to update tooltip
const { showTooltip, hideTooltip, isShow, tooltipId} = useTooltipContext()

// do something and show tooltip
fetchApi() {
    showTooltip('tooltip data after fetch.')
}

<div
    onClick={fetchApi}
    onMouseLeave={hideTooltip}
>
    This is list data item index.
</div>

props (mains)

| props | type | description | |----------------------|-------------------------------|-----------------------------------------------------------------------| | tagName | String | If you wrap all children component, use this | | tooltipClassName | String | | | tooltipContent | String/Component/ jsx | Tooltip data | | placement | top/right/left/bottom | it relies on the element's height, width and position to display. | | trigger | hover/click/manual | Default hover | | backgroundColor | String | Default #282727 | | tooltipColor | String | Default #ffffff | | delayShow | Number (250) minisecond | Time delay show tooltip | | display | fade/zoom | Animate tooltip | | limitWidth | Boolean | Fix max-width: 200px. Default: true. | | onShown | function | Event after show | | onHidden | function | Event after hide | | showSync | Boolean | Simple trigger = manual | | open | Boolean | Show tooltip | | hideIfResize | Boolean | hide tooltip if resize screen (Default true) | | hideIfScroll | Boolean | hide tooltip if scroll screen (Default false) | | centerArrow | Boolean | Show arrow and tooltip on center element (Default false) | | forceHide | any | when change forceHide, tooltip will be forced hidden (Default null) | | ...props | other | Other props of child elements |

top || right || bottom || left || placement

Note

`...props` here are the props added to the child components. (You should add on child)

`showSync` or `useTooltipContext`: should be used when trigger = `manual`
  • placement: if the position of the tooltip goes beyond the screen. It try will move to the right position to be visible.

RUN

LIVE EXAMPLE

License

MIT