@@ -8,7 +8,7 @@ React tooltip component based on [react-popper](https://github.com/FezVrasta/rea
88React wrapper around [ popper.js] ( https://popper.js.org/ ) library.
99
1010## Example
11- https://codesandbox.io/s/v04l1ky2rl
11+ https://codesandbox.io/s/pykkz77z5j
1212
1313### Usage
1414
@@ -23,24 +23,51 @@ import TooltipTrigger from 'react-popper-tooltip';
2323
2424render (
2525 < TooltipTrigger
26- tooltip= {({ getTooltipProps, arrowProps, arrowPlacement }) => (
27- < div className= " tooltip" {... getTooltipProps ()}>
26+ placement= " right"
27+ trigger= " click"
28+ tooltip= {({
29+ getTooltipProps,
30+ getArrowProps,
31+ tooltipRef,
32+ arrowRef,
33+ placement
34+ }) => (
35+ < div
36+ {... getTooltipProps ({
37+ ref: tooltipRef,
38+ className: ' tooltip-container'
39+ /* your props here */
40+ })}
41+ >
2842 < div
29- data- placement= {arrowPlacement}
30- className= " arrow"
31- {... arrowProps}
43+ {... getArrowProps ({
44+ ref: arrowRef,
45+ ' data-placement' : placement,
46+ className: ' tooltip-arrow'
47+ /* your props here */
48+ })}
3249 / >
33- { tooltip}
50+ < div className = " tooltip-body " > Hello, World ! < / div >
3451 < / div>
3552 )}
3653 >
37- {({ getTriggerProps }) => < span {... getTriggerProps ()}> {children}< / span> }
54+ {({ getTriggerProps, triggerRef }) => (
55+ < div
56+ {... getTriggerProps ({
57+ ref: triggerRef,
58+ className: ' trigger'
59+ /* your props here */
60+ })}
61+ >
62+ Click Me!
63+ < / div>
64+ )}
3865 < / TooltipTrigger> ,
3966 document .getElementById (' root' )
4067);
4168```
4269
43- ` TooltipTrigger ` is the only component exposed by the package. It's just a positioning engine. What to render is left completely to the user, which can be provided using render props.
70+ ` TooltipTrigger ` is the only component exposed by the package. It's just a positioning engine. What to render is left completely to the user, which can be provided using render props. Your props should be passed through ` getTriggerProps ` , ` getTooltipProps ` and ` getArrowProps ` .
4471
4572Read more about [ render prop] ( https://cdb.reacttraining.com/use-a-render-prop-50de598f11ce ) pattern if you're not familiar with this approach.
4673
@@ -52,25 +79,46 @@ If you would like our opinionated container and arrow styles for your tooltip fo
5279
5380``` jsx
5481import React from ' react' ;
55- import TooltipTrigger from " react-popper-tooltip" ;
82+ import TooltipTrigger from ' react-popper-tooltip' ;
5683import ' react-popper-tooltip/dist/styles.css' ;
5784
5885const Tooltip = ({ tooltip, children, ... props }) => (
5986 < TooltipTrigger
6087 {... props}
61- tooltip= {({ getTooltipProps, tooltipRef, arrowStyle, arrowRef, arrowPlacement }) => (
62- < div className= " tooltip-container" ref= {tooltipRef} {... getTooltipProps ()}>
88+ tooltip= {({
89+ getTooltipProps,
90+ getArrowProps,
91+ tooltipRef,
92+ arrowRef,
93+ placement
94+ }) => (
95+ < div
96+ {... getTooltipProps ({
97+ ref: tooltipRef,
98+ className: ' tooltip-container'
99+ })}
100+ >
63101 < div
64- className= " tooltip-arrow"
65- ref= {arrowRef}
66- style= {arrowStyle}
67- data- placement= {arrowPlacement}
102+ {... getArrowProps ({
103+ ref: arrowRef,
104+ ' data-placement' : placement,
105+ className: ' tooltip-arrow'
106+ })}
68107 / >
69108 {tooltip}
70109 < / div>
71110 )}
72111 >
73- {({ getTriggerProps, triggerRef }) => < span ref= {triggerRef} {... getTriggerProps ()}> {children}< / span> }
112+ {({ getTriggerProps, triggerRef }) => (
113+ < span
114+ {... getTriggerProps ({
115+ ref: triggerRef,
116+ className: ' trigger'
117+ })}
118+ >
119+ {children}
120+ < / span>
121+ )}
74122 < / TooltipTrigger>
75123);
76124
@@ -80,7 +128,7 @@ export default Tooltip;
80128Then you can use it as shown in the example below.
81129
82130``` jsx
83- < Tooltip tooltip = " Hi there! " placement= " top" trigger= " click" > Click me< / Tooltip>
131+ < Tooltip placement= " top" trigger= " click" tooltip = " Hi there! " > Click me< / Tooltip>
84132```
85133
86134## Props
@@ -211,20 +259,20 @@ yourself to avoid your props being overridden (or overriding the props returned)
211259### children function
212260
213261| property | type | description |
214- | ----------------- | ---------------- | ----------------------------------------------------------------------- |
262+ | --------------- | -------------- | --------------------------------------------------------------------- |
215263| getTriggerProps | ` function({}) ` | returns the props you should apply to the trigger element you render. |
216264| triggerRef | ` node ` | returns the react ref you should apply to the trigger element. |
217265
218266
219267### tooltip function
220268
221- | property | type | description |
222- | ----------------- | ---------------- | ----------------------------------------------------------------------- |
223- | getTooltipProps | ` function({}) ` | returns the props you should apply to the tooltip element you render. |
224- | tooltipRef | ` node ` | return the react ref you should apply to the tooltip element. |
225- | arrowStyle | ` object ` | return the styles you should apply to the tooltip arrow style attr. |
226- | arrowRef | ` node ` | return the react ref you should apply to the tooltip arrow you render.|
227- | placement | ` string ` | return the placement of the tooltip arrow element. |
269+ | property | type | description |
270+ | --------------- | -------------- | ---------------------------------------------------------------------- |
271+ | getTooltipProps | ` function({}) ` | returns the props you should apply to the tooltip element you render. |
272+ | tooltipRef | ` node ` | return the react ref you should apply to the tooltip element. |
273+ | arrowStyle | ` object ` | return the styles you should apply to the tooltip arrow style attr. |
274+ | arrowRef | ` node ` | return the react ref you should apply to the tooltip arrow you render. |
275+ | placement | ` string ` | return the placement of the tooltip arrow element. |
228276
229277## Inspiration and Thanks!
230278
0 commit comments