Skip to main content
Sipilov_Ivan
February 10, 2023
Solved

Where im my ts code I should declare "command" to map function to the commands from manifest.json?

I want to add submenu for my plugin. I added all items to manifest, like this doc suggests:

figma.com

But there is no example or doc of where these commands should be declare in my plugin code to map them with my plugin functions.

Huge thanks in advance!

This topic has been closed for replies.
tank666
tank666Solution
February 11, 2023
if (figma.command === 'menu command string') {
    // do something
}

Please see this plugin example:

github.com
UX/UI designer. Figma expert. Creator and developer of plugins and widgets for Figma and FigJam. Check out my resources in Figma Community: figma.com/@tank

6 replies

tank666
tank666Solution
February 11, 2023
if (figma.command === 'menu command string') {
    // do something
}

Please see this plugin example:

github.com
UX/UI designer. Figma expert. Creator and developer of plugins and widgets for Figma and FigJam. Check out my resources in Figma Community: figma.com/@tank
Sipilov_Ivan
February 16, 2023

Hey, thx a lot @tank666

Can you suggest where exactly to declare the if statement? I tried to put it at the same place where I check figma ui message to perform operations based on the UI input. But it doesn’t seams to work.

tank666
February 16, 2023

Add this condition outside the figma.ui.

UX/UI designer. Figma expert. Creator and developer of plugins and widgets for Figma and FigJam. Check out my resources in Figma Community: figma.com/@tank
Sipilov_Ivan
February 16, 2023

Yep, that worked with console log, thx. But all my logic and functions for the plugin leaves inside the figma.ui. Can you suggest any solution, how to use it all and not dublicate the hole plugin code?

tank666
February 16, 2023

Just declare your functions in the global scope and then call them in the right places.

UX/UI designer. Figma expert. Creator and developer of plugins and widgets for Figma and FigJam. Check out my resources in Figma Community: figma.com/@tank
Sipilov_Ivan
February 16, 2023

Yep, I guess that is the only way. Thank you once again.