How to create custom shapes using template binding in React Diagram
The Syncfusion® React Diagram supports rendering custom HTML content within nodes using template binding. This allows you to create nodes with dynamic HTML elements such as buttons, forms, or other content.
To define a node with custom HTML content, set the shape
property of the node to HTML. Specify the template content using the nodeTemplate
function. Here’s how:
function App() {
return (
<DiagramComponent
id="container"
nodes={[{
id: 'node1',
offsetX: 100,
offsetY: 100,
width: 100,
height: 100,
}]}
nodeTemplate={diagramTemplate.bind(this)}
getNodeDefaults={(obj) => {
obj.shape = {type: 'HTML'};
obj.backgroundColor = '#6BA5D7';
return obj;
}}
>
</DiagramComponent>
);
}
Define the Custom HTML Template:
Implement the nodeTemplate
function to define the custom HTML content within the node.
function diagramTemplate() {
return (
<div>
<button onClick={nodeBtnClick}>Button</button>
</div>
);
}
Sample: Click Here
Conclusion
I hope you enjoyed learning about How to create custom shapes using template binding in React Diagram. You can refer to our React Diagram feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our React Diagram example to understand how to create and manipulate data. For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our other controls. If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!