In TinyMCE v5, there's a new tinymce.editor.ui.Registry
method called addIcon, that registers a new SVG icon, quoting:
Registers a new SVG icon, the icon name reference can be configured by any TinyMCE 5 Ui components that can display an icon. The icon is only available to the editor instance it was configured for.
Method Parameters:
addIcon(name: String, svgData: String)
- name (String) - Unique name identifying the new icon.
- svgData (String) - The SVG data string the browser will use to render
the SVG icon.
Method Implementation:
// To add a simple triangle icon:
editor.ui.registry.addIcon('triangleUp', '<svg height="24" width="24"><path d="M12 0 L24 24 L0 24 Z" /></svg>');
Then, you can use that unique name identifier in your custom buttons, for example:
editor.ui.registry.addButton('youtube', {
text: 'Add Video' ,
icon: 'triangleUp',
onAction: () => {
// do stuff here...
}
});
Final Result: