createComponent
info
This API is only available in Figma Design
Creates a new, empty component.
Signature
createComponent(): ComponentNode
Remarks
By default, the new node has width and height both at 100, and is parented under figma.currentPage
.
This function creates a brand new component. To turn an existing frame into a component, simply create a component and move the layers over to the new component:
Create a component
const component = figma.createComponent()
component.resizeWithoutConstraints(frame.width, frame.height)
for (const child of frame.children) {
component.appendChild(child)
}
// Note: also copy over other properties of the frame
// such as clipsContent, backgrounds, layoutGrids, etc if desired.