Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
react-tooltip
Advanced tools
The react-tooltip npm package is a versatile library for React that allows developers to easily add custom tooltips to their web applications. It provides a range of options for styling, positioning, and triggering tooltips, making it a convenient tool for enhancing user interface elements with additional information.
Simple Tooltips
This feature allows you to create simple tooltips with minimal configuration. By adding a 'data-tip' attribute to any React element and including the ReactTooltip component, a tooltip will appear on hover.
{"import React from 'react';\nimport ReactTooltip from 'react-tooltip';\n\nfunction App() {\n return (\n <div>\n <p data-tip='hello world'>Hover over me to see the tooltip!</p>\n <ReactTooltip />\n </div>\n );\n}\n\nexport default App;"}
Custom Styles
React-tooltip allows for custom styling of tooltips. You can specify the type (theme), effect, place, and even add custom classes for additional styling.
{"import React from 'react';\nimport ReactTooltip from 'react-tooltip';\n\nfunction App() {\n return (\n <div>\n <p data-tip='Custom styles!' data-for='customStyle'>Hover over me!</p>\n <ReactTooltip id='customStyle' type='dark' effect='solid' place='top' className='extraClass' />\n </div>\n );\n}\n\nexport default App;"}
Dynamic Content
Tooltips can display dynamic content that changes based on the application's state. This is useful for tooltips that need to update to reflect user interactions or other real-time data.
{"import React, { useState } from 'react';\nimport ReactTooltip from 'react-tooltip';\n\nfunction App() {\n const [dynamicTip, setDynamicTip] = useState('Initial tooltip content');\n\n return (\n <div>\n <p data-tip data-for='dynamicTip'>Hover over me for dynamic content!</p>\n <ReactTooltip id='dynamicTip'>{dynamicTip}</ReactTooltip>\n <button onClick={() => setDynamicTip('Updated tooltip content')}>Update Tooltip</button>\n </div>\n );\n}\n\nexport default App;"}
HTML Content
React-tooltip supports HTML content inside tooltips. This allows for more complex and styled content to be displayed within the tooltip.
{"import React from 'react';\nimport ReactTooltip from 'react-tooltip';\n\nfunction App() {\n return (\n <div>\n <p data-tip data-for='htmlContent'>Hover over me for HTML content!</p>\n <ReactTooltip id='htmlContent' dangerouslySetInnerHTML={{ __html: '<strong>HTML</strong> content' }} />\n </div>\n );\n}\n\nexport default App;"}
Tippy.js is a highly customizable tooltip and popover library powered by Popper.js. It offers a wide range of options and plugins for creating interactive tooltips and popovers. Compared to react-tooltip, Tippy.js provides more out-of-the-box animations and is not limited to React.
Rc-tooltip is a React component for tooltip functionality. It is part of the rc-components family and offers a simple API for creating and managing tooltips. While react-tooltip is more feature-rich and has a larger community, rc-tooltip is a good alternative for those already using other rc-components.
React-tippy is a React wrapper for Tippy.js, bringing its powerful tooltip capabilities to React applications. It combines the extensive features of Tippy.js with a React-friendly interface. React-tippy may be preferred by developers who want the advanced features of Tippy.js in a React-specific package.
Or see it on Github Page.
aronhelser Passive maintainer - accepting PRs and doing minor testing, but not fixing issues or doing active development.
roggervalf Active maintainer - accepting PRs and doing minor testing, fixing issues or doing active development.
huumanoid (inactive)
We would gladly accept a new maintainer to help out!
npm install react-tooltip
or
yarn add react-tooltip
1 . Require react-tooltip after installation
import ReactTooltip from 'react-tooltip';
2 . Add data-tip = "your placeholder" to your element
<p data-tip="hello world">Tooltip</p>
3 . Include react-tooltip component
<ReactTooltip />
You can import node_modules/react-tooltip/dist/index.js
into your page. Please make sure that you have already imported react
and react-dom
into your page.
Notes:
type: dark
place: top
effect: float
as default attributes. You don't have to add these options if you don't want to change the defaults<ReactTooltip />
component will be implemented on every tooltip in a same page: <ReactTooltip effect="solid" />
<a data-type="warning"></a>
will only affect this specific tooltipGlobal | Specific | Type | Values | Description |
---|---|---|---|---|
place | data-place | String | top, right, bottom, left | placement |
type | data-type | String | dark, success, warning, error, info, light | theme |
effect | data-effect | String | float, solid | behaviour of tooltip |
event | data-event | String | e.g. click | custom event to trigger tooltip |
eventOff | data-event-off | String | e.g. click | custom event to hide tooltip (only makes effect after setting event attribute) |
globalEventOff | String | e.g. click | global event to hide tooltip (global only) | |
isCapture | data-iscapture | Bool | true, false | when set to true, custom event's propagation mode will be capture |
offset | data-offset | Object | top, right, bottom, left | data-offset="{'top': 10, 'left': 10}" for specific and offset={{top: 10, left: 10}} for global |
multiline | data-multiline | Bool | true, false | support <br> , <br /> to make multiline |
className | data-class | String | extra custom class, can use !important to overwrite react-tooltip's default class | |
html | data-html | Bool | true, false | <p data-tip="<p>HTML tooltip</p>" data-html={true}></p> or <ReactTooltip html={true} /> , but see Security Note below. |
delayHide | data-delay-hide | Number | <p data-tip="tooltip" data-delay-hide='1000'></p> or <ReactTooltip delayHide={1000} /> | |
delayShow | data-delay-show | Number | <p data-tip="tooltip" data-delay-show='1000'></p> or <ReactTooltip delayShow={1000} /> | |
delayUpdate | data-delay-update | Number | <p data-tip="tooltip" data-delay-update='1000'></p> or <ReactTooltip delayUpdate={1000} /> Sets a delay in calling getContent if the tooltip is already shown and you mouse over another target | |
insecure | null | Bool | true, false | Whether to inject the style header into the page dynamically (violates CSP style-src but is a convenient default) |
border | data-border | Bool | true, false | Add one pixel white border |
textColor | data-text-color | String | e.g. red | Popup text color |
backgroundColor | data-background-color | String | e.g. yellow | Popup background color |
borderColor | data-border-color | String | e.g. green | Popup border color - enabled by the border value |
arrowColor | data-arrow-color | String | e.g. #fff | Popup arrow color - if not specified, will use the backgroundColor value |
getContent | null | Func or Array | (dataTip) => {}, [(dataTip) => {}, Interval] | Generate the tip content dynamically |
afterShow | null | Func | (evt) => {} | Function that will be called after tooltip show, with event that triggered show |
afterHide | null | Func | (evt) => {} | Function that will be called after tooltip hide, with event that triggered hide |
overridePosition | null | Func | ({left:number, top: number}, currentEvent, currentTarget, node, place, desiredPlace, effect, offset) => ({left: number, top: number}) | Function that will replace tooltip position with custom one |
disable | data-tip-disable | Bool | true, false | Disable the tooltip behaviour, default is false |
scrollHide | data-scroll-hide | Bool | true, false | Hide the tooltip when scrolling, default is true |
resizeHide | null | Bool | true, false | Hide the tooltip when resizing the window, default is true |
wrapper | null | String | div, span | Selecting the wrapper element of the react tooltip, default is div |
clickable | null | Bool | true, false | Enables tooltip to respond to mouse (or touch) events, default is false |
The html
option allows a tooltip to directly display raw HTML. This is a security risk if any of that content is supplied by the user. Any user-supplied content must be sanitized, using a package like sanitize-html. We chose not to include sanitization after discovering it increased our package size too much - we don't want to penalize people who don't use the html
option.
<ReactTooltip />
finds the tooltip via this attribute<ReactTooltip />
<ReactTooltip />
in a page but they should have different idsHide the tooltip manually, the target is optional, if no target passed in, all existing tooltips will be hidden
import ReactTooltip from 'react-tooltip'
<p ref={ref => this.fooRef = ref} data-tip='tooltip'></p>
<button onClick={() => { ReactTooltip.hide(this.fooRef) }}></button>
<ReactTooltip />
Rebinding all tooltips
Show specific tooltip manually, for example:
import ReactTooltip from 'react-tooltip'
<p ref={ref => this.fooRef = ref} data-tip='tooltip'></p>
<button onClick={() => { ReactTooltip.show(this.fooRef) }}></button>
<ReactTooltip />
The component was designed to set <ReactTooltip />
once and then use tooltip everywhere, but a lot of people get stuck when using this component in a modal. You can read the discussion here. To solve this problem:
<ReactTooltip />
outside of the <Modal>
ReactTooltip.rebuild()
when opening the modalclassName
to custom your tooltip's z-indexI suggest always putting
<ReactTooltip />
in the Highest level or smart component of Redux, so you might need these static method to control tooltip's behaviour in some situations
When you set getContent={() => { return }}
you will find the tooltip will display true
. That's because React will set the value of data-* to be 'true' automatically if there is no value to be set. So you have to set data-tip=''
in this situation.
<p data-tip='' data-for='test'></p>
<ReactTooltip id='test' getContent={() => { return null }}/>
Same for empty children, if you don't want show the tooltip when the children is empty
<p data-tip='' data-for='test'></p>
<ReactTooltip id='test'>{}</ReactTooltip>
When you render <ReactTooltip>
ahead of dynamic content, and are using data-for={id}
attributes
on new dynamic content, the tooltip will not register its event listener.
For example, you render a generic tooltip in the root of your app, then load a list of content async.
Elements in the list use the data-for={id}
attribute to bind the tooltip on hover.
Since the tooltip has already scanned for data-tip these new elements will not trigger.
One workaround for this is to trigger ReactTooltip.rebuild()
after the data load to scan for the attribute again,
to allow event wireup.
<app>
<ReactTooltip id="foo" />
<list/>
</app>
const dynamicList = (props) => {
useEffect(() => {
ReactTooltip.rebuild();
});
return(
<list>
{data.map((item)=> {
<span data-for="foo">My late bound tooltip triggered data</span>
});}
</list>
);
};
How I insert sass into react component
We welcome your contribution! Fork the repo, make some changes, submit a pull-request! Our contributing doc has some details.
MIT
FAQs
react tooltip component
The npm package react-tooltip receives a total of 1,058,169 weekly downloads. As such, react-tooltip popularity was classified as popular.
We found that react-tooltip demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
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.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.