Skip to content

Commit e56cf3e

Browse files
authored
Merge pull request #360 from austil/master
Compute or enrich tip content
2 parents b3ed903 + 8bfbfc9 commit e56cf3e

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ className | data-class | String | | extra custom class, can use !importan
6969
delayShow | data-delay-show | Number | | `<p data-tip="tooltip" data-delay-show='1000'></p>` or `<ReactTooltip delayShow={1000} />`
7070
insecure | null | Bool | true, false | Whether to inject the style header into the page dynamically (violates CSP style-src but is a convenient default)
7171
border | data-border | Bool | true, false | Add one pixel white border
72-
getContent | null | Func or Array | () => {}, [() => {}, Interval] | Generate the tip content dynamically
72+
getContent | null | Func or Array | (dataTip) => {}, [(dataTip) => {}, Interval] | Generate the tip content dynamically
7373
afterShow | null | Func | () => {} | Function that will be called after tooltip show
7474
afterHide | null | Func | () => {} | Function that will be called after tooltip hide
7575
disable | data-tip-disable | Bool | true, false | Disable the tooltip behaviour, default is false

example/src/index.js

+21
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,27 @@ class Test extends React.Component {
248248
</div>
249249
</pre>
250250
</div>
251+
<div className="section">
252+
<h4 className='title'>Compute or enrich tip content</h4>
253+
<p className="sub-title"></p>
254+
<div className="example-jsx">
255+
<div className="side">
256+
<a data-for='enrich' data-tip='sooooo cute'>(❂‿❂)</a>
257+
</div>
258+
<div className="side">
259+
<a data-for='enrich' data-tip='really high'>(❂‿❂)</a>
260+
</div>
261+
<ReactTooltip id='enrich' getContent={(dataTip) => `This little buddy is ${dataTip}`}/>
262+
</div>
263+
<br />
264+
<pre className='example-pre'>
265+
<div>
266+
<p>{"<a data-for='enrich' data-tip='sooooo cute'>(❂‿❂)</a>\n" +
267+
"<a data-for='enrich' data-tip='really high'>(❂‿❂)</a>\n" +
268+
"<ReactTooltip id='enrich' getContent={(dataTip) => `This little buddy is ${dataTip}`}/>"}</p>
269+
</div>
270+
</pre>
271+
</div>
251272
<div className="section">
252273
<h4 className='title'>Test Scrolling</h4>
253274
<p className="sub-title"></p>

src/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,9 @@ class ReactTooltip extends React.Component {
237237
let content
238238
if (getContent) {
239239
if (Array.isArray(getContent)) {
240-
content = getContent[0] && getContent[0]()
240+
content = getContent[0] && getContent[0](this.state.originTooltip)
241241
} else {
242-
content = getContent()
242+
content = getContent(this.state.originTooltip)
243243
}
244244
}
245245

0 commit comments

Comments
 (0)