Skip to content

Compute or enrich tip content #360

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ className | data-class | String | | extra custom class, can use !importan
delayShow | data-delay-show | Number | | `<p data-tip="tooltip" data-delay-show='1000'></p>` or `<ReactTooltip delayShow={1000} />`
insecure | null | Bool | true, false | Whether to inject the style header into the page dynamically (violates CSP style-src but is a convenient default)
border | data-border | Bool | true, false | Add one pixel white border
getContent | null | Func or Array | () => {}, [() => {}, Interval] | Generate the tip content dynamically
getContent | null | Func or Array | (dataTip) => {}, [(dataTip) => {}, Interval] | Generate the tip content dynamically
afterShow | null | Func | () => {} | Function that will be called after tooltip show
afterHide | null | Func | () => {} | Function that will be called after tooltip hide
disable | data-tip-disable | Bool | true, false | Disable the tooltip behaviour, default is false
Expand Down
21 changes: 21 additions & 0 deletions example/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,27 @@ class Test extends React.Component {
</div>
</pre>
</div>
<div className="section">
<h4 className='title'>Compute or enrich tip content</h4>
<p className="sub-title"></p>
<div className="example-jsx">
<div className="side">
<a data-for='enrich' data-tip='sooooo cute'>(❂‿❂)</a>
</div>
<div className="side">
<a data-for='enrich' data-tip='really high'>(❂‿❂)</a>
</div>
<ReactTooltip id='enrich' getContent={(dataTip) => `This little buddy is ${dataTip}`}/>
</div>
<br />
<pre className='example-pre'>
<div>
<p>{"<a data-for='enrich' data-tip='sooooo cute'>(❂‿❂)</a>\n" +
"<a data-for='enrich' data-tip='really high'>(❂‿❂)</a>\n" +
"<ReactTooltip id='enrich' getContent={(dataTip) => `This little buddy is ${dataTip}`}/>"}</p>
</div>
</pre>
</div>
<div className="section">
<h4 className='title'>Test Scrolling</h4>
<p className="sub-title"></p>
Expand Down
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,9 @@ class ReactTooltip extends React.Component {
let content
if (getContent) {
if (Array.isArray(getContent)) {
content = getContent[0] && getContent[0]()
content = getContent[0] && getContent[0](this.state.originTooltip)
} else {
content = getContent()
content = getContent(this.state.originTooltip)
}
}

Expand Down