How to Add a Custom Button to the Floating Component Toolbar in React (on Element Selection) #6503
Replies: 1 comment 4 replies
-
You can find here an example of a toolbar extension: |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm currently integrating GrapesJS (via @grapesjs/studio-sdk/react) into my app and trying to add a custom button to the floating inline toolbar that appears on top-right of an element when it is selected in the editor canvas (the one that includes clone/delete/move icons).
I’ve tried using component.set('toolbar', [...]) inside editor.on('component:selected'), and while it works for adding buttons to the left panel toolbar, it doesn’t seem to show my custom button inside the floating contextual menu over the selected component.
Here’s the snippet I tried:
`editor.on('component:selected', (component) => {
const toolbar = component.get('toolbar') || [];
const aiButton = {
id: 'ai-edit',
className: 'fa fa-robot',
command: 'open-ai-assistant',
attributes: { title: 'Generate AI Text' }
};
if (!toolbar.find(item => item.id === 'ai-edit')) {
component.set('toolbar', [...toolbar, aiButton]);
}
});`
Beta Was this translation helpful? Give feedback.
All reactions