1- # @tippy .js/react
1+ <p align =" center " >
2+ <img src =" https://github.com/atomiks/tippy.js-react/raw/master/logo.png " alt =" Logo " width =" 295 " >
3+ </p >
24
3- React component for [ Tippy.js] ( https://github.com/atomiks/tippyjs ) 4.
5+ <h1 align =" center " >Tippy.js for React</h1 >
6+
7+ React component for [ Tippy.js] ( https://github.com/atomiks/tippyjs ) 4. Tippy.js
8+ is a highly customizable tooltip and popover library powered by Popper.js. This
9+ wrapper lets you use it declaratively in React.
410
511## Installation
612
@@ -65,12 +71,47 @@ function App() {
6571}
6672```
6773
74+ ` styled-components ` v4 does this for you automatically, so it should be seamless
75+ when using the ` styled ` constructor.
76+
6877## Native props
6978
7079See the [ Tippy.js docs] ( https://atomiks.github.io/tippyjs/all-options/ )
7180
7281## React-specific props
7382
83+ > Note: these examples are using the new
84+ > [ React Hooks API] ( https://reactjs.org/docs/hooks-intro.html ) . It isn't
85+ > required to use this library – the props will work as expected in class
86+ > components too.
87+
88+ ### ` className?: string `
89+
90+ A React-alternative to the ` theme ` prop. The className gets added to the tooltip
91+ element's class list as expected, without adding ` -theme ` as a suffix.
92+
93+ ``` jsx
94+ function App () {
95+ return (
96+ < Tippy content= " Tooltip" className= " hello world" >
97+ < button / >
98+ < / Tippy>
99+ )
100+ }
101+ ```
102+
103+ Rendered DOM:
104+
105+ ``` html
106+ <div class =" tippy-popper" >
107+ <div class =" tippy-tooltip dark-theme hello world" >
108+ <!-- inner elements -->
109+ </div >
110+ </div >
111+ ```
112+
113+ See [ themes] ( https://atomiks.github.io/tippyjs/themes/ ) for more information.
114+
74115### ` isEnabled?: boolean `
75116
76117Prop to control the ` tippy.enable() ` / ` tippy.disable() ` instance methods. Use
@@ -80,7 +121,7 @@ this when you want to temporarily disable a tippy from showing.
80121function App () {
81122 const [isEnabled , setIsEnabled ] = useState (true )
82123 return (
83- < Tippy content= " test " isEnabled= {isEnabled}>
124+ < Tippy content= " Tooltip " isEnabled= {isEnabled}>
84125 < button / >
85126 < / Tippy>
86127 )
@@ -97,27 +138,30 @@ UI events.
97138function App () {
98139 const [isVisible , setIsVisible ] = useState (true )
99140 return (
100- < Tippy content= " test " isVisible= {isVisible}>
141+ < Tippy content= " Tooltip " isVisible= {isVisible}>
101142 < button / >
102143 < / Tippy>
103144 )
104145}
105146```
106147
107- > ** Note 1 ** : You should also set the ` hideOnClick ` prop to ` false ` if you don't
148+ > ** Note** : You should also set the ` hideOnClick ` prop to ` false ` if you don't
108149> want the tippy to hide when the user clicks on the document somewhere.
109150
110151### ` onCreate?: (tip: Instance) => void `
111152
112153Callback invoked when the Tippy instance has been created. Use this when you
113154need to store the Tippy instance on the component.
114155
156+ This should only be done for advanced (imperative) manipulation of the tippy
157+ instance – in most cases using props should suffice.
158+
115159``` jsx
116160function App () {
117161 const tippyInstance = useRef ()
118162 return (
119163 < Tippy
120- content= " test "
164+ content= " Tooltip "
121165 onCreate= {instance => (tippyInstance .current = instance)}
122166 >
123167 < button / >
0 commit comments