Introduction

Tooltip that always stays on top of the screen was created using the React portal feature.

Install

# npm
npm i -D tata-react-tooltip
 
# yarn
yarn add -D tata-react-tooltip
 
# pnpm
pnpm add -D tata-react-tooltip

Usage

import { Tooltip } from 'tata-react-tooltip';
import { useRef } from 'react';
 
const ref = useRef<HTMLDivElement>(null);

Default

<Tooltip
  direction="right"
  parentRef={ref}
  message="hello tooltip!"
>
  <div ref={ref} className="hello">
    Hello Tooltip!
  </div>
</Tooltip>

Dialog

<Tooltip
  dialog
  direction="right"
  parentRef={ref}
  message="hello tooltip!"
>
  <div ref={ref} className="hello">
    Hello Tooltip!
  </div>
</Tooltip>

Custom Style

<Tooltip
  direction="right"
  parentRef={ref}
  message="hello tooltip!"
  bgColor='#9667E9'
  tailColor='#9667E9'
  tailBorderColor='#9667E9'
  customStyle={{ fontSize: '0.9rem', fontWeight: '600' }}
>
  <div ref={ref} className="hello">
    Hello Tooltip!
  </div>
</Tooltip>

API

*: required

PropertyDescriptionTypeDefault
*parentRefParent element's refRefObject<any>-
messageTooltip messagestring-
directionTooltip's relative placement to the parenttltoptrrtrightrbblbottombrltleftlbtop
customStyleCustom CSS styles for the tooltipCSSProperties-
leaveDelayDelay before tooltip disappears (milliseconds)number-
enterDelayDelay before tooltip appears (milliseconds)number-
colorTooltip text colorstring-
bgColorTooltip background colorstring#333
tailColorTooltip tail colorstring#333
tailBorderColorTooltip tail border colorstring#333
hideTailHide tooltip tailbooleanfalse
dialogDisplay tooltip as dialog boxbooleanfalse
dialogIconIcon for dialog tooltipReactNode<WarnIcon />
dialogBtnTextButton text for dialog tooltipstringYES
customTooltipCustom component to replace default tooltipReactNode-