I’m very new to Figma Plugin Development and I’m just trying to get a sense of how information flows from code.ts into ui.html and back. One such thing I’ll need to be able to do in the future is interact with components. Here’s what I’m trying
I’ve made some headway. I don’t need to importComponentByKeyAsync the currentSelection is an array of Nodes currently selected, and you can traverse that object to see its properties. But the documentation for how to update properties is lacking in clarity. https://www.figma.com/plugin-docs/editing-properties/. I’ve read in other threads that you have to clone something and rewrite it to the node… but its all still very abstract. Does anyone have code showing how to change properties of a ComponentNode?
The documentation seems to say that it’s up to me to implement a clone function. The property I want to edit is selection[0].reactions.transition.duration. Which property do I clone… selection[0].reactions… or selection[0].reactions.transition?
Just like you change properties of any JS object. component.name = "new component name" for example would change the name property of the component (or any other node).
However, for more complex properties that are stored as arrays and objects, you will notice that we marked all the properties in those objects as readonly . That means that the following, which you may naturally be inclined to try, won’t work:
// error: object is not extensible
figma.currentPage.selection.push(otherNode)
// error: Cannot assign to read only property 'r' of object
node.fills[0].color.r = 10