diff --git a/README.md b/README.md index 35af422f..f8b90b6f 100755 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ [![npm download][download-image]][download-url] ![minified](https://badgen.net/bundlephobia/min/react-tooltip) ![minified gzip](https://badgen.net/bundlephobia/minzip/react-tooltip) + [download-image]: https://img.shields.io/npm/dm/react-tooltip.svg?style=flat-square @@ -17,7 +18,7 @@

-If you like the project, please give the project a GitHub 🌟 +If you like the project, please give the project a GitHub 🌟 ## Demo @@ -55,20 +56,23 @@ yarn add react-tooltip ## Usage +> :warning: ReactTooltip will inject the default styles into the page by default on version `5.13.0` or newer. +> The `react-tooltip/dist/react-tooltip.css` file is only for style reference and doesn't need to be imported manually anymore if you are already using `v5.13.0` or upper. + > :warning: If you were already using `react-tooltip<=5.7.5`, you'll be getting some deprecation warnings regarding the `anchorId` prop and some other features. -In versions >=5.8.0, we've introduced the `data-tooltip-id` attribute, and the `anchorSelect` prop, which are our recommended methods of using the tooltip moving forward. Check [the docs](https://react-tooltip.com/docs/getting-started) for more details. +> In versions >=5.8.0, we've introduced the `data-tooltip-id` attribute, and the `anchorSelect` prop, which are our recommended methods of using the tooltip moving forward. Check [the docs](https://react-tooltip.com/docs/getting-started) for more details. ### Using NPM package 1 . Import the CSS file to set default styling. -> :warning: You must import the CSS file or the tooltip won't show! +> :warning: If you are using a version before than `v5.13.0`, you must import the CSS file or the tooltip won't show! ```js import 'react-tooltip/dist/react-tooltip.css' ``` -This needs to be done only once. We suggest you do it on your `src/index.js` or equivalent file. +This needs to be done only once and only if you are using a version before than `5.13.0`. We suggest you do it on your `src/index.js` or equivalent file. 2 . Import `react-tooltip` after installation. @@ -123,7 +127,7 @@ You can import `node_modules/react-tooltip/dist/react-tooltip.[mode].js` into yo mode: `esm` `cjs` `umd` -Don't forget to import the CSS file from `node_modules/react-tooltip/dist/react-tooltip.css` to set default styling. This needs to be done only once in your application. +If you are using a version older than `v5.13.0` don't forget to import the CSS file from `node_modules/react-tooltip/dist/react-tooltip.css` to set default styling. This needs to be done only once in your application. Version `v5.13.0` or newer already inject the default styles into the page by default. PS: all the files have a minified version and a non-minified version. @@ -145,7 +149,7 @@ You can use [`renderToStaticMarkup()` function](https://reactjs.org/docs/react-d ```jsx import ReactDOMServer from 'react-dom/server'; [...] -I am JSX content)} > @@ -172,7 +176,7 @@ If there isn't, feel free to [submit a new issue](https://github.com/ReactToolti ### The tooltip is broken/not showing up -Make sure you've imported the default styling. You only need to do this once on your application, `App.jsx`/`App.tsx` is usually a good place to do it. +Make sure you've imported the default styling. You only need to do this once on your application and only if you are using a version before `5.13.0`, `App.jsx`/`App.tsx` is usually a good place to do it. ```jsx import 'react-tooltip/dist/react-tooltip.css' @@ -184,7 +188,7 @@ If `data-tooltip-content` and `data-tooltip-html` are both unset (or they have e ### Next.js `TypeError: f is not a function` -This problem seems to be caused by a bug related to the SWC bundler used by Next.js. +This problem seems to be caused by a bug related to the SWC bundler used by Next.js. The best way to solve this is to upgrade to `next@13.3.0` or later versions. Less ideally, if you're unable to upgrade, you can set `swcMinify: false` on your `next.config.js` file. @@ -199,7 +203,7 @@ This is specially relevant when using components that are conditionally rendered Always try to keep the `` component rendered, so if you're having issues with a tooltip you've placed inside a component which is placed/removed from the DOM dynamically, try to move the tooltip outside of it. -We usually recommend placing the tooltip component directly inside the root component of your application (usually on `App.jsx`/`App.tsx`). You can also move the `import 'react-tooltip/dist/react-tooltip.css'` there. +We usually recommend placing the tooltip component directly inside the root component of your application (usually on `App.jsx`/`App.tsx`). #### Dynamically generated anchor elements @@ -212,18 +216,12 @@ Here's a simple example on how to improve performance when using dynamically gen ```jsx // ❌ BAD
- { - myItems.map(({ id, content, tooltip }) => ( -
- {content} - -
- )) - } + {myItems.map(({ id, content, tooltip }) => ( +
+ {content} + +
+ ))}
``` @@ -268,7 +266,6 @@ Here's a simple example on how to improve performance when using dynamically gen [wwayne](https://github.com/wwayne) (inactive) - Creator of the original React Tooltip (V1.x ~ V4.x.) - We would gladly accept a new maintainer to help out! ## Contributing diff --git a/docs/docs/examples/anchor-select.mdx b/docs/docs/examples/anchor-select.mdx index de4be7a9..2332d51c 100644 --- a/docs/docs/examples/anchor-select.mdx +++ b/docs/docs/examples/anchor-select.mdx @@ -7,7 +7,6 @@ sidebar_position: 1 Using the ReactTooltip anchor select prop. import { Tooltip } from 'react-tooltip' -import 'react-tooltip/dist/react-tooltip.css' export const TooltipAnchor = ({ children, id, ...rest }) => { return ( @@ -48,7 +47,6 @@ A CSS selector for a specific id begins with a `#`. Don't forget to put it befor ```jsx import { Tooltip } from 'react-tooltip'; -import 'react-tooltip/dist/react-tooltip.css';
◕‿‿◕ ◕‿‿◕ - + #### Using class attribute @@ -74,7 +69,6 @@ A CSS selector for a specific id begins with a `.`. Don't forget to put it befor ```jsx import { Tooltip } from 'react-tooltip'; -import 'react-tooltip/dist/react-tooltip.css'; ◕‿‿◕ ◕‿‿◕ @@ -88,23 +82,12 @@ import 'react-tooltip/dist/react-tooltip.css'; ```
- - ◕‿‿◕ - - - ◕‿‿◕ - - - ◕‿‿◕ - - - ◕‿‿◕ - + ◕‿‿◕ + ◕‿‿◕ + ◕‿‿◕ + ◕‿‿◕
- + ### Complex selectors @@ -122,7 +105,6 @@ This example uses the name attribute, but it works for any HTML attribute (id, c ```jsx import { Tooltip } from 'react-tooltip'; -import 'react-tooltip/dist/react-tooltip.css'; ◕‿‿◕ ◕‿‿◕ @@ -135,23 +117,12 @@ import 'react-tooltip/dist/react-tooltip.css'; ```
- - ◕‿‿◕ - - - ◕‿‿◕ - - - ◕‿‿◕ - - - ◕‿‿◕ - + ◕‿‿◕ + ◕‿‿◕ + ◕‿‿◕ + ◕‿‿◕
- + #### Child selector @@ -165,7 +136,6 @@ Often you can just use a class selector or something else much simpler. ```jsx import { Tooltip } from 'react-tooltip'; -import 'react-tooltip/dist/react-tooltip.css';
◕‿‿◕ @@ -183,7 +153,7 @@ import 'react-tooltip/dist/react-tooltip.css'; /> ``` -
@@ -199,4 +169,4 @@ import 'react-tooltip/dist/react-tooltip.css'; \ No newline at end of file +/> diff --git a/docs/docs/examples/basic-examples.mdx b/docs/docs/examples/basic-examples.mdx index c32af94e..6907f822 100644 --- a/docs/docs/examples/basic-examples.mdx +++ b/docs/docs/examples/basic-examples.mdx @@ -7,7 +7,6 @@ sidebar_position: 0 Some basic examples of how to use the ReactTooltip component. import { Tooltip } from 'react-tooltip' -import 'react-tooltip/dist/react-tooltip.css' export const TooltipAnchor = ({ children, id, ...rest }) => { return ( @@ -38,7 +37,6 @@ export const TooltipAnchor = ({ children, id, ...rest }) => { ```jsx import { Tooltip } from 'react-tooltip'; -import 'react-tooltip/dist/react-tooltip.css'; ◕‿‿◕ @@ -49,7 +47,15 @@ import 'react-tooltip/dist/react-tooltip.css'; ``` -
+
◕‿‿◕ @@ -61,25 +67,20 @@ import 'react-tooltip/dist/react-tooltip.css'; ### Props - #### Using anchor element `id` ```jsx import { Tooltip } from 'react-tooltip'; -import 'react-tooltip/dist/react-tooltip.css' ◕‿‿◕ - ``` ◕‿‿◕ - + #### Using anchor elements `className` @@ -91,21 +92,25 @@ Check the [Anchor select examples](./anchor-select.mdx) for more complex use cas ```jsx import { Tooltip } from 'react-tooltip'; -import 'react-tooltip/dist/react-tooltip.css' ◕‿‿◕ ◕‿‿◕ - ``` -
+
◕‿‿◕ ◕‿‿◕
- + diff --git a/docs/docs/examples/children.mdx b/docs/docs/examples/children.mdx index 5435e04e..efb51221 100644 --- a/docs/docs/examples/children.mdx +++ b/docs/docs/examples/children.mdx @@ -7,7 +7,6 @@ sidebar_position: 1 Using children for setting the ReactTooltip content. import { Tooltip } from 'react-tooltip' -import 'react-tooltip/dist/react-tooltip.css' export const TooltipAnchor = ({ children, id, ...rest }) => { return ( @@ -41,7 +40,6 @@ This is useful for setting a placeholder for the tooltip content. ```jsx import { Tooltip } from 'react-tooltip'; -import 'react-tooltip/dist/react-tooltip.css'; ◕‿‿◕ diff --git a/docs/docs/examples/content.mdx b/docs/docs/examples/content.mdx index 1efb6921..f4af61ef 100644 --- a/docs/docs/examples/content.mdx +++ b/docs/docs/examples/content.mdx @@ -7,7 +7,6 @@ sidebar_position: 1 Setting the ReactTooltip content. import { Tooltip } from 'react-tooltip' -import 'react-tooltip/dist/react-tooltip.css' export const TooltipAnchor = ({ children, id, ...rest }) => { return ( @@ -34,12 +33,10 @@ export const TooltipAnchor = ({ children, id, ...rest }) => { ) } - ### Using `data-tooltip-content` anchor element attribute ```jsx import { Tooltip } from 'react-tooltip'; -import 'react-tooltip/dist/react-tooltip.css'; ``` - + ◕‿‿◕ @@ -62,17 +56,13 @@ import 'react-tooltip/dist/react-tooltip.css'; ```jsx import { Tooltip } from 'react-tooltip'; -import 'react-tooltip/dist/react-tooltip.css'; ◕‿‿◕ - ``` ◕‿‿◕ - + diff --git a/docs/docs/examples/delay.mdx b/docs/docs/examples/delay.mdx index cbaf49c3..f4e3a9b1 100644 --- a/docs/docs/examples/delay.mdx +++ b/docs/docs/examples/delay.mdx @@ -7,7 +7,6 @@ sidebar_position: 1 Delay showing/hiding the ReactTooltip component. import { Tooltip } from 'react-tooltip' -import 'react-tooltip/dist/react-tooltip.css' export const TooltipAnchor = ({ children, id, ...rest }) => { return ( @@ -38,7 +37,6 @@ export const TooltipAnchor = ({ children, id, ...rest }) => { ```jsx import { Tooltip } from 'react-tooltip'; -import 'react-tooltip/dist/react-tooltip.css'; { return ( @@ -50,10 +49,9 @@ This is the default event option, so it doesn't have to be manually set. ```jsx import { Tooltip } from 'react-tooltip'; -import 'react-tooltip/dist/react-tooltip.css'; ◕‿‿◕ -◕‿‿◕ - + ### Using `click` @@ -77,10 +71,9 @@ Clicking anywhere outside the anchor element will close the tooltip. ```jsx import { Tooltip } from 'react-tooltip'; -import 'react-tooltip/dist/react-tooltip.css'; ◕‿‿◕ -◕‿‿◕ - + diff --git a/docs/docs/examples/html.mdx b/docs/docs/examples/html.mdx index 6cf330aa..783a7b24 100644 --- a/docs/docs/examples/html.mdx +++ b/docs/docs/examples/html.mdx @@ -7,7 +7,6 @@ sidebar_position: 1 Using HTML content in ReactTooltip component. import { Tooltip } from 'react-tooltip' -import 'react-tooltip/dist/react-tooltip.css' export const TooltipAnchor = ({ children, id, ...rest }) => { return ( @@ -44,7 +43,6 @@ You can also use [`renderToStaticMarkup()`](https://reactjs.org/docs/react-dom-s ```jsx import { Tooltip } from 'react-tooltip'; -import 'react-tooltip/dist/react-tooltip.css'; - ### Using `html` prop :::info @@ -74,17 +71,16 @@ You should probably pass the content as children to the tooltip instead. ```jsx import { Tooltip } from 'react-tooltip'; -import 'react-tooltip/dist/react-tooltip.css'; ◕‿‿◕ - ``` ◕‿‿◕ - diff --git a/docs/docs/examples/multiline.mdx b/docs/docs/examples/multiline.mdx index cff7c08a..377f2954 100644 --- a/docs/docs/examples/multiline.mdx +++ b/docs/docs/examples/multiline.mdx @@ -7,7 +7,6 @@ sidebar_position: 1 Multiline content in ReactTooltip component. import { Tooltip } from 'react-tooltip' -import 'react-tooltip/dist/react-tooltip.css' export const TooltipAnchor = ({ children, id, ...rest }) => { return ( @@ -42,10 +41,8 @@ You can also use [`renderToStaticMarkup()`](https://reactjs.org/docs/react-dom-s ::: - ```jsx import { Tooltip } from 'react-tooltip'; -import 'react-tooltip/dist/react-tooltip.css'; - ### Using tooltip children and JSX ```jsx import { Tooltip } from 'react-tooltip'; -import 'react-tooltip/dist/react-tooltip.css'; ◕‿‿◕ diff --git a/docs/docs/examples/offset.mdx b/docs/docs/examples/offset.mdx index f28a49c9..2f7c9007 100644 --- a/docs/docs/examples/offset.mdx +++ b/docs/docs/examples/offset.mdx @@ -7,7 +7,6 @@ sidebar_position: 1 Offset option for the ReactTooltip component. import { Tooltip } from 'react-tooltip' -import 'react-tooltip/dist/react-tooltip.css' export const TooltipAnchor = ({ children, id, ...rest }) => { return ( @@ -38,7 +37,6 @@ export const TooltipAnchor = ({ children, id, ...rest }) => { ```jsx import { Tooltip } from 'react-tooltip'; -import 'react-tooltip/dist/react-tooltip.css'; ◕‿‿◕ ◕‿‿◕ @@ -49,11 +47,21 @@ import 'react-tooltip/dist/react-tooltip.css'; ```
- ◕‿‿◕ - ◕‿‿◕ - ◕‿‿◕ - ◕‿‿◕ - ◕‿‿◕ + + ◕‿‿◕ + + + ◕‿‿◕ + + + ◕‿‿◕ + + + ◕‿‿◕ + + + ◕‿‿◕ +
@@ -61,7 +69,6 @@ import 'react-tooltip/dist/react-tooltip.css'; ```jsx import { Tooltip } from 'react-tooltip'; -import 'react-tooltip/dist/react-tooltip.css'; ◕‿‿◕ ◕‿‿◕ - + diff --git a/docs/docs/examples/place.mdx b/docs/docs/examples/place.mdx index e68603e3..ab823a6e 100644 --- a/docs/docs/examples/place.mdx +++ b/docs/docs/examples/place.mdx @@ -8,7 +8,6 @@ Changing the placement for the ReactTooltip component. import { useState } from 'react'; import { Tooltip } from 'react-tooltip' -import 'react-tooltip/dist/react-tooltip.css' export const TooltipAnchor = ({ children, id, ...rest }) => { return ( @@ -41,7 +40,6 @@ The `place` prop and the `data-tooltip-place` attribute accept the following val ```jsx import { Tooltip } from 'react-tooltip'; -import 'react-tooltip/dist/react-tooltip.css'; ◕‿‿◕ @@ -60,7 +58,6 @@ import 'react-tooltip/dist/react-tooltip.css'; ```jsx import { Tooltip } from 'react-tooltip'; -import 'react-tooltip/dist/react-tooltip.css'; const PLACES = ['top', 'right', 'bottom', 'left'] const [place, setPlace] = useState(0) diff --git a/docs/docs/examples/provider-wrapper.mdx b/docs/docs/examples/provider-wrapper.mdx index a78683af..e93922f9 100644 --- a/docs/docs/examples/provider-wrapper.mdx +++ b/docs/docs/examples/provider-wrapper.mdx @@ -13,7 +13,6 @@ This has been deprecated. Use the `data-tooltip-id` attribute, or the `anchorSel ::: import { Tooltip, TooltipProvider, TooltipWrapper } from 'react-tooltip' -import 'react-tooltip/dist/react-tooltip.css' export const TooltipAnchor = ({ children, id, ...rest }) => { return ( @@ -40,11 +39,7 @@ export const TooltipAnchor = ({ children, id, ...rest }) => { } export const WithProvider = ({ children }) => { - return ( - - {children} - - ) + return {children} } ### Setting up `` @@ -54,8 +49,7 @@ For simplicity, just wrap your whole application with the provider. ```jsx // this is usually the `src/App.jsx` (or `src/App.tsx`) file -import { TooltipProvider } from 'react-tooltip'; -import 'react-tooltip/dist/react-tooltip.css'; +import { TooltipProvider } from 'react-tooltip' function App() { return ( @@ -65,14 +59,13 @@ function App() { ) } -export default App; +export default App ``` ### Using `` ```jsx import { Tooltip, TooltipWrapper } from 'react-tooltip'; -import 'react-tooltip/dist/react-tooltip.css'; ◕‿‿◕ @@ -87,14 +80,10 @@ import 'react-tooltip/dist/react-tooltip.css';
- - ◕‿‿◕ - + ◕‿‿◕ - - ◕‿‿◕ - + ◕‿‿◕ @@ -112,7 +101,6 @@ If you need to use multiple tooltips, each with multiple anchors, use the toolti ```jsx import { Tooltip, TooltipWrapper } from 'react-tooltip'; -import 'react-tooltip/dist/react-tooltip.css'; ◕‿‿◕ @@ -133,24 +121,16 @@ import 'react-tooltip/dist/react-tooltip.css';
- - ◕‿‿◕ - + ◕‿‿◕ - - ◕‿‿◕ - + ◕‿‿◕ - - ◕‿‿◕ - + ◕‿‿◕ - - ◕‿‿◕ - + ◕‿‿◕ diff --git a/docs/docs/examples/render.mdx b/docs/docs/examples/render.mdx index 92721a5f..f5517adc 100644 --- a/docs/docs/examples/render.mdx +++ b/docs/docs/examples/render.mdx @@ -7,7 +7,6 @@ sidebar_position: 1 Using the ReactTooltip render prop to render dynamic content based on the active anchor element. import { Tooltip } from 'react-tooltip' -import 'react-tooltip/dist/react-tooltip.css' export const TooltipAnchor = ({ children, id, ...rest }) => { return ( @@ -40,7 +39,7 @@ The `render` prop can be used to render the tooltip content dynamically based on The function signature is as follows: ```ts -(render: { content: string | null; activeAnchor: HTMLElement | null }) => ChildrenType +;(render: { content: string | null; activeAnchor: HTMLElement | null }) => ChildrenType ``` - `content` is available for quick access to the `data-tooltip-content` attribute on the anchor element @@ -49,24 +48,23 @@ The function signature is as follows: ```jsx import { Tooltip } from 'react-tooltip'; -import 'react-tooltip/dist/react-tooltip.css'; - ◕‿‿◕ - ◕‿‿◕ - @@ -86,21 +84,21 @@ import 'react-tooltip/dist/react-tooltip.css';
◕‿‿◕ ◕‿‿◕ @@ -111,11 +109,8 @@ import 'react-tooltip/dist/react-tooltip.css'; render={({ content, activeAnchor }) => ( The element #{content} is currently active. -
- Relevant attribute:{' '} - { - activeAnchor?.getAttribute('data-some-relevant-attr') || 'not set' - } +
+ Relevant attribute: {activeAnchor?.getAttribute('data-some-relevant-attr') || 'not set'}
)} /> diff --git a/docs/docs/examples/state.mdx b/docs/docs/examples/state.mdx index 479593fc..d92f8b13 100644 --- a/docs/docs/examples/state.mdx +++ b/docs/docs/examples/state.mdx @@ -8,7 +8,6 @@ Controlled state example for the ReactTooltip component. import { useState } from 'react' import { Tooltip } from 'react-tooltip' -import 'react-tooltip/dist/react-tooltip.css' export const TooltipAnchor = ({ children, id, background, ...rest }) => { return ( @@ -51,7 +50,6 @@ It is just a demonstration, and you can come up with use cases as complex as you ```jsx import { useState } from 'react'; import { Tooltip } from 'react-tooltip'; -import 'react-tooltip/dist/react-tooltip.css'; const [isOpen, setIsOpen] = useState(false) @@ -89,34 +87,19 @@ export const ControlledStateExample = () => { const [isOpen, setIsOpen] = useState(false) return ( <> - setIsOpen(true)} - > + setIsOpen(true)}> ◕‿‿◕ - setIsOpen(true)} - > + setIsOpen(true)}> ◕‿‿◕ - setIsOpen(true)} - > + setIsOpen(true)}> ◕‿‿◕ - setIsOpen(true)} - > + setIsOpen(true)}> ◕‿‿◕ - setIsOpen(true)} - > + setIsOpen(true)}> ◕‿‿◕ { > ◕‿‿◕ - + ) } diff --git a/docs/docs/examples/styling.mdx b/docs/docs/examples/styling.mdx index d6c1a21f..836448a0 100644 --- a/docs/docs/examples/styling.mdx +++ b/docs/docs/examples/styling.mdx @@ -9,7 +9,6 @@ How to customize tooltip styles in ReactTooltip styles. Tooltip arrow inherits its background color from tooltip (its parent). import { Tooltip } from 'react-tooltip' -import 'react-tooltip/dist/react-tooltip.css' import CodeBlock from '@theme/CodeBlock' import TooltipStyles from '!!raw-loader!../../../src/components/Tooltip/styles.module.css' @@ -43,7 +42,6 @@ You can add styles into the tooltip with inline styling. ```jsx import { Tooltip } from 'react-tooltip' -import 'react-tooltip/dist/react-tooltip.css'
``` -
+
◕‿‿◕ - +
### Classes @@ -74,7 +70,6 @@ Using CSS Specificity you can add a class with more specificity than the default ```jsx import { Tooltip } from 'react-tooltip' -import 'react-tooltip/dist/react-tooltip.css'