Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-tooltpz

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-tooltpz

💬 Flexible Tooltip Components with zero dependencies

  • 5.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
22
increased by340%
Maintainers
1
Weekly downloads
 
Created
Source

React Tooltpz

NPM version NPM license NPM total downloads NPM monthly downloads

Low-level component for creating menus, tooltips, hints, dropdown and other popups

💬 Flexible Tooltip Components with zero dependencies

  • Automatically find best position
  • With Portal
  • No extra DOM nodes
  • Tiny

Try demo

Getting Started

  • Basic Usage:

    import { useState } from 'react';
    import { Tooltip } from 'react-tooltpz';
    
    const TitleWithHoverTooltip = ({ title, tooltip }) => {
        const [opened, setOpened] = useState(false);
        const ref = useRef();
    
        return (
            <div
                ref={ref}
                onMouseEnter={() => setOpened(true)}
                onMouseLeave={() => setOpened(false)}
            >
                {title}
                {opened &&
                    <Tooltip parentRef={ref}>
                        {({ innerRef, style }) => (
                            <div ref={innerRef} style={style}>
                                {tooltip}
                            </div>
                        )}
                    </Tooltip>
                }
            </div>
        )
    };
    
    export default TitleWithHoverTooltip;
    
  • Installation:

    npm install --save react-tooltpz
    
  • Importing:

    import { Tooltip } from 'react-tooltpz';
    

    You also can import directly what you want

    import Tooltip from 'react-tooltpz/lib/Tooltip';
    import useOutsideClick from 'react-tooltpz/lib/useOutsideClick';
    

API

Tooltip

Compute a tooltip coords and render tooltip with PortalNodeContext and ZIndexContext Prefer this component instead of directly use useTooltip hook

Props

nametypedefaultdescription
parentRef{ current: { getBoundingClientRect } }requiredTooltip ref object.
It can be any object with current prop.
current prop should be null or any object with getBoundingClientRect method
innerRef{ current: { getBoundingClientRect } }-Tooltip ref object.
Similar to parentRef
zIndexnumber0Tooltip default z-index
marginnumber4Margin between parent and tooltip
position'bottom' / 'top' / 'left' / 'right''bottom'Tooltip position
align'start' / 'center' / 'end''start'Tooltip align
children({ innerRef, style }, { parentRect, tooltipRect } ) => ReactNode-Tooltip render function
styleobject-Tooltip style object
portalNodeHTMLElement-second parameter for ReadDOM.createPortal

Portal

Create a portal with PortalNodeContext. Prefer this component instead of directly use createPortal

Props

nametypedefaultdescription
childrenReactNode-first parameter for ReadDOM.createPortal
portalNodeHTMLElement-second parameter for ReadDOM.createPortal

PortalNodeContext

provide portalNode to Tooltip and Portal


ZIndexContext

provide zIndex to Tooltip


useTooltip

Compute a tooltip coords

Parameters:

  • parentRef: similar to Tooltip parentRef
  • tooltipRef: similar to Tooltip innerRef
  • options?: { margin?, position?, align? }

Returns array with:

  • coords: { top, left } | null
  • parentRect: { top, left, bottom, right, width, height } | null
  • tooltipRect: { top, left, bottom, right, width, height } | null

useOutsideClick

Handle a click outside of element with portal support

const onMouseDownOrTouchStart = useOutsideClick(onOutsideClick);

Parameters:

  • onOutsideClick?: (event): void - "onOutsideClick" handler

Returns:

  • onMouseDownOrTouchStart: (event): void - onMouseDown or onTouchStart handler

Keywords

FAQs

Package last updated on 19 Mar 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc