11# React Tooltip
2+
23[ ![ npm version] ( https://img.shields.io/npm/v/react-popper-tooltip.svg?style=flat-square )] ( https://www.npmjs.com/package/react-popper-tooltip )
34[ ![ npm downloads] ( https://img.shields.io/npm/dm/react-popper-tooltip.svg?style=flat-square )] ( https://www.npmjs.com/package/react-popper-tooltip )
45[ ![ Build Status] ( https://travis-ci.com/mohsinulhaq/react-popper-tooltip.svg?branch=master )] ( https://travis-ci.com/mohsinulhaq/react-popper-tooltip )
56[ ![ Dependency Status] ( https://img.shields.io/david/mohsinulhaq/react-popper-tooltip.svg?style=flat-square )] ( https://david-dm.org/mohsinulhaq/react-popper-tooltip )
67[ ![ code style: prettier] ( https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square )] ( https://github.com/prettier/prettier )
78[ ![ codecov] ( https://codecov.io/gh/mohsinulhaq/react-popper-tooltip/branch/master/graph/badge.svg )] ( https://codecov.io/gh/mohsinulhaq/react-popper-tooltip )
89
9- React tooltip component based on [ react-popper] ( https://github.com/FezVrasta/react-popper ) , the
10- React wrapper around [ popper.js] ( https://popper.js.org/ ) library.
10+ React tooltip component based on [ react-popper] ( https://github.com/FezVrasta/react-popper ) , the React wrapper around [ popper.js] ( https://popper.js.org/ ) library.
1111
1212## Homepage
13+
1314https://mohsinulhaq.github.io/react-popper-tooltip/
1415
1516## Example
17+
1618https://codesandbox.io/s/pykkz77z5j
1719
1820### Usage
1921
2022``` bash
2123npm install react-popper-tooltip
2224```
25+
2326or
27+
2428``` bash
2529yarn add react-popper-tooltip
2630```
@@ -31,10 +35,10 @@ import {render} from 'react-dom';
3135import TooltipTrigger from ' react-popper-tooltip' ;
3236
3337const Tooltip = ({
34- getTooltipProps,
35- getArrowProps,
36- tooltipRef,
3738 arrowRef,
39+ tooltipRef,
40+ getArrowProps,
41+ getTooltipProps,
3842 placement
3943}) => (
4044 < div
@@ -47,8 +51,8 @@ const Tooltip = ({
4751 < div
4852 {... getArrowProps ({
4953 ref: arrowRef,
50- ' data-placement ' : placement ,
51- className : ' tooltip-arrow '
54+ className : ' tooltip-arrow ' ,
55+ ' data-placement ' : placement
5256 /* your props here */
5357 })}
5458 / >
@@ -69,11 +73,7 @@ const Trigger = ({getTriggerProps, triggerRef}) => (
6973);
7074
7175render (
72- < TooltipTrigger
73- placement= " right"
74- trigger= " click"
75- tooltip= {Tooltip}
76- >
76+ < TooltipTrigger placement= " right" trigger= " click" tooltip= {Tooltip}>
7777 {Trigger}
7878 < / TooltipTrigger> ,
7979 document .getElementById (' root' )
@@ -95,14 +95,14 @@ import React from 'react';
9595import TooltipTrigger from ' react-popper-tooltip' ;
9696import ' react-popper-tooltip/dist/styles.css' ;
9797
98- const Tooltip = ({tooltip, children , hideArrow ... props}) => (
98+ const Tooltip = ({children, tooltip , hideArrow, ... props}) => (
9999 < TooltipTrigger
100100 {... props}
101101 tooltip= {({
102- getTooltipProps,
103- getArrowProps,
104- tooltipRef,
105102 arrowRef,
103+ tooltipRef,
104+ getArrowProps,
105+ getTooltipProps,
106106 placement
107107 }) => (
108108 < div
@@ -111,13 +111,15 @@ const Tooltip = ({tooltip, children, hideArrow ...props}) => (
111111 className: ' tooltip-container'
112112 })}
113113 >
114- {! hideArrow && < div
115- {... getArrowProps ({
116- ref: arrowRef,
117- ' data-placement' : placement,
118- className: ' tooltip-arrow'
119- })}
120- / > }
114+ {! hideArrow && (
115+ < div
116+ {... getArrowProps ({
117+ ref: arrowRef,
118+ className: ' tooltip-arrow' ,
119+ ' data-placement' : placement
120+ })}
121+ / >
122+ )}
121123 {tooltip}
122124 < / div>
123125 )}
@@ -138,24 +140,31 @@ const Tooltip = ({tooltip, children, hideArrow ...props}) => (
138140export default Tooltip ;
139141```
140142
141- Then you can use it as shown in the example below.
143+ Then you can use it as shown in the example below.
142144
143145``` jsx
144- < Tooltip placement= " top" trigger= " click" tooltip= " Hi there!" > Click me< / Tooltip>
146+ < Tooltip placement= " top" trigger= " click" tooltip= " Hi there!" >
147+ Click me
148+ < / Tooltip>
145149```
146150
147151## Examples
152+
148153To fiddle with our example recipes, run:
154+
149155``` bash
150156> npm install
151157> npm run docs
152158```
159+
153160or
161+
154162``` bash
155163> yarn
156164> yarn docs
157165```
158- and open up [ localhost:3000] ( http://localhost:3000 ) in your browser.
166+
167+ and open up [ localhost:3000] ( http://localhost:3000 ) in your browser.
159168
160169## Props
161170
@@ -173,7 +182,6 @@ the section "[Children and tooltip functions](#children-and-tooltip-functions)".
173182This is called with an object. Read more about the properties of this object in
174183the section "[ Children and tooltip functions] ( #children-and-tooltip-functions ) ".
175184
176-
177185### defaultTooltipShown
178186
179187> ` boolean ` | defaults to ` false `
@@ -192,9 +200,9 @@ Called with the tooltip state, when the visibility of the tooltip changes
192200
193201Use this prop if you want to control the visibility state of the tooltip.
194202
195- ` react-popper-tooltip ` manages its own state internally. You can use this prop to pass the
196- visibility state of the tooltip from the outside. You will be required to keep this state up to
197- date (this is where ` onVisibilityChange ` becomes useful), but you can also control the state
203+ ` react-popper-tooltip ` manages its own state internally. You can use this prop to pass the
204+ visibility state of the tooltip from the outside. You will be required to keep this state up to
205+ date (this is where ` onVisibilityChange ` becomes useful), but you can also control the state
198206from anywhere, be that state from other components, ` redux ` , ` react-router ` , or anywhere else.
199207
200208### delayShow
@@ -214,25 +222,27 @@ Delay in hiding the tooltip (ms).
214222> ` string ` | defaults to ` right `
215223
216224The tooltip placement. Valid placements are:
225+
217226- ` auto `
218227- ` top `
219228- ` right `
220229- ` bottom `
221230- ` left `
222231
223232Each placement can have a variation from this list:
233+
224234- ` -start `
225235- ` -end `
226236
227237### trigger
228238
229- > ` string ` | defaults to ` hover `
239+ > ` string ` | defaults to ` hover `
230240
231241The event that triggers the tooltip. One of ` click ` , ` hover ` , ` right-click ` , ` none ` .
232242
233243### getTriggerRef
234244
235- > ` function(HTMLElement) => void `
245+ > ` function(HTMLElement) => void `
236246
237247Function that can be used to obtain a trigger element reference.
238248
@@ -264,10 +274,10 @@ Recommended usage with hover trigger and no arrow element
264274
265275### modifiers
266276
267- > ` object `
277+ > ` object `
268278
269- Modifiers passed directly to the underlying popper.js instance.
270- For more information, refer to Popper.js’
279+ Modifiers passed directly to the underlying popper.js instance.
280+ For more information, refer to Popper.js’
271281[ modifier docs] ( https://popper.js.org/popper-documentation.html#modifiers )
272282
273283Modifiers, applied by default:
@@ -283,8 +293,8 @@ Modifiers, applied by default:
283293## Children and tooltip functions
284294
285295This is where you render whatever you want. ` react-popper-tooltip ` uses two render props ` children `
286- and ` tooltip ` . ` Children ` prop is used to trigger the appearance of the tooltip and ` tooltip `
287- displays the tooltip itself.
296+ and ` tooltip ` . ` Children ` prop is used to trigger the appearance of the tooltip and ` tooltip `
297+ displays the tooltip itself.
288298
289299You use it like so:
290300
@@ -302,33 +312,32 @@ const tooltip = (
302312
303313> See [ the blog post about prop getters] ( https://blog.kentcdodds.com/how-to-give-rendering-control-to-users-with-prop-getters-549eaef76acf )
304314
305- These functions are used to apply props to the elements that you render.
306- It's advisable to pass all your props to that function rather than applying them on the element
315+ These functions are used to apply props to the elements that you render.
316+ It's advisable to pass all your props to that function rather than applying them on the element
307317yourself to avoid your props being overridden (or overriding the props returned). For example
308318` <button {...getTriggerProps({onClick: event => console.log(event))}>Click me</button> `
309319
310320### children function
311321
312322| property | type | description |
313323| --------------- | -------------- | --------------------------------------------------------------------- |
324+ | triggerRef | ` function ref ` | returns the react ref you should apply to the trigger element. |
314325| getTriggerProps | ` function({}) ` | returns the props you should apply to the trigger element you render. |
315- | triggerRef | ` node ` | returns the react ref you should apply to the trigger element. |
316-
317326
318327### tooltip function
319328
320- | property | type | description |
321- | --------------- | -------------- | ---------------------------------------------------------------------- |
322- | getTooltipProps | ` function({}) ` | returns the props you should apply to the tooltip element you render. |
323- | tooltipRef | ` node ` | return the react ref you should apply to the tooltip element. |
324- | getArrowProps | ` function({}) ` | return the props you should apply to the tooltip arrow element. |
325- | arrowRef | ` node ` | return the react ref you should apply to the tooltip arrow element. |
326- | placement | ` string ` | return the placement of the tooltip. |
329+ | property | type | description |
330+ | --------------- | -------------- | --------------------------------------------------------------------- |
331+ | arrowRef | ` function ref ` | return the react ref you should apply to the tooltip arrow element. |
332+ | tooltipRef | ` function ref ` | return the react ref you should apply to the tooltip element. |
333+ | getArrowProps | ` function({}) ` | return the props you should apply to the tooltip arrow element. |
334+ | getTooltipProps | ` function({}) ` | returns the props you should apply to the tooltip element you render. |
335+ | placement | ` string ` | return the dynamic placement of the tooltip. |
327336
328337## Inspiration and Thanks!
329338
330- This library is based on [ react-popper] ( https://github.com/FezVrasta/react-popper ) , the official
339+ This library is based on [ react-popper] ( https://github.com/FezVrasta/react-popper ) , the official
331340react wrapper around [ Popper.js] ( https://popper.js.org ) .
332341
333- Using of render props, prop getters and doc style of this library are heavily inspired by
342+ Using of render props, prop getters and doc style of this library are heavily inspired by
334343[ downshift] ( https://github.com/paypal/downshift ) .
0 commit comments