In the latest version of TinyMCE, known as TinyMCE v5, a new functionality called tinymce.editor.ui.Registry
has been introduced. This method, named addIcon, allows users to register a new SVG icon with the editor instance it was configured for. The purpose is to provide customizable icons for various Ui components.
The registered SVG icon can be referenced by name and utilized by different TinyMCE 5 Ui elements that support icon display. It remains exclusive to the specific editor instance it was assigned to.
Parameters of the Method:
addIcon(name: String, svgData: String)
- name (String) - A unique identifier for the newly added icon.
- svgData (String) - The SVG data string used by the browser to render the SVG icon.
Implementation of the Method:
// Example code to add a basic triangle icon:
editor.ui.registry.addIcon('triangleUp', '<svg height="24" width="24"><path d="M12 0 L24 24 L0 24 Z" /></svg>');
Subsequently, you can reference this unique identifier in creating custom buttons like so:
editor.ui.registry.addButton('youtube', {
text: 'Add Video' ,
icon: 'triangleUp',
onAction: () => {
// Perform desired actions here...
}
});
Result:
https://i.sstatic.net/9bfV7.png