React Diagram - Diagram Tools

The DevExtreme Diagram ships with configurable tool panels and menus. The following image highlights these visual elements:

DevExtreme Diagram tools

To configure Diagram tools, implement the following properties:

To specify which commands a tool panel or menu displays, define the element's commands[] array (for instance, mainToolbar.commands[]). To add predefined commands, specify only the name property:

App.tsx
  • import { Diagram, MainToolbar, Command } from 'devextreme-react/diagram';
  •  
  • function App() {
  • return (
  • <Diagram>
  • <MainToolbar visible={true}>
  • <Command name="undo" />
  • <Command name="redo" />
  • <Command name="fontName" />
  • <Command name="fontSize" />
  • <Command name="bold" />
  • <Command name="italic" />
  • <Command name="underline" />
  • </MainToolbar>
  • </Diagram>
  • )
  • }

The Diagram component supports custom commands within tool panels and menus. To define a custom command item, specify a string command.name value (different from Command type values) and implement the onCustomCommand handler. You can also specify custom command icons and text. The following code snippet demonstrates a custom command that imports an empty value into the Diagram to clear component content:

App.tsx
  • import { Diagram, MainToolbar, Command, type DiagramTypes } from 'devextreme-react/diagram';
  •  
  • function handleCustomCommand(e: DiagramTypes.CustomCommandEvent) {
  • if(e.name === 'clear') {
  • e.component.import('');
  • }
  • }
  •  
  • function App() {
  • return (
  • <Diagram onCustomCommand={handleCustomCommand}>
  • <MainToolbar visible={true}>
  • <Command
  • name="clear"
  • icon="deletetable"
  • />
  • </MainToolbar>
  • </Diagram>
  • )
  • }

View Demo