Specifying the Content Template
The following code shows how to create a template consisting of static (text) and dynamic (the Switch UI component) content:
- import React from 'react';
- import 'devextreme/dist/css/dx.light.css';
- import { Tooltip } from 'devextreme-react/tooltip';
- import { Switch } from 'devextreme-react/switch';
- const renderContent = () => {
- return (
- <p>Static content</p>
- <Switch>
- {/* The "Switch" UI component is configured here */}
- </Switch>
- );
- }
- class App extends React.Component {
- render() {
- return (
- <div>
- <img id="image" src="https://url/to/an/image" />
- <Tooltip
- target="#image"
- showEvent="dxhoverstart"
- contentRender={renderContent}
- />
- </div>
- );
- }
- }
- export default App;
Switching Templates On the Fly
If you need to render different templates depending on a specific condition, define them inside the Tooltip container using the DevExtreme dxTemplate markup component. You can switch the templates on the fly by changing the contentTemplate property's value.
App.js
styles.css
- import React from 'react';
- import 'devextreme/dist/css/dx.light.css';
- import { Tooltip } from 'devextreme-react/tooltip';
- import { Button } from 'devextreme-react/button';
- const firstTemplate = () => {
- return (
- <p>First template</p>
- );
- }
- const secondTemplate = () => {
- return (
- <p>Second template</p>
- );
- }
- class App extends React.Component {
- constructor(props) {
- super(props);
- this.state = {
- renderContent: firstTemplate
- };
- this.changeTemplate = this.changeTemplate.bind(this);
- }
- changeTemplate() {
- this.setState({
- renderContent: this.state.renderContent === firstTemplate ? secondTemplate : firstTemplate
- });
- }
- render() {
- return (
- <div>
- <img id="image" src="https://url/to/an/image" />
- <Tooltip
- target="#image"
- showEvent="dxhoverstart"
- hideEvent="dxhoverend"
- contentRender={this.state.renderContent}
- />
- <Button
- id="buttonContainer"
- text="Change the Template"
- onClick={this.changeTemplate}
- />
- </div>
- );
- }
- }
- export default App;
- #buttonContainer {
- display: block;
- width: 200px
- }
See Also
Feel free to share topic-related thoughts here.
If you have technical questions, please create a support ticket in the DevExpress Support Center.
Thank you for the feedback!
If you have technical questions, please create a support ticket in the DevExpress Support Center.