Version 1, Update 72
This version introduces utility functions that allow you to set color properties using a variety of familiar encodings, including CSS hex strings and rgb()/hsl()-style function strings. The new functions include:
- figma.util.rgb(): converts a color encoding into an RGB object.
- figma.util.rgba(): converts a color encoding into an RGBA object.
- figma.util.solidPaint(): converts a color encoding into a SolidPaint object.
Examples:
const paint = {
type: 'SOLID',
color: figma.util.rgb('#FF0')
}
const layoutGrid = {
pattern: 'GRID',
sectionSize: 1,
color: figma.util.rgba('rgb(25% 25% 25%)')
}
You can alias these functions for more concise code:
const rgb = figma.util.rgb
const rgba = figma.util.rgba
const paint = {
type: 'SOLID',
color: rgb('#FF0')
}
const layoutGrid = {
pattern: 'GRID',
sectionSize: 1,
color: rgba('rgb(25% 25% 25%)')
}
A common use case is to set a node fill. Use the figma.util.solidPaint() function when you want to update the color of a fill while preserving other properties of the fill object:
if (node.fills[0].type === 'SOLID') {
node.fills = [
// Merge the original fill with a new color and opacity
figma.util.solidPaint("#FF00FF88", node.fills[0])
]
}
Other changes in this version:
- Add new assignable values for ShapeWithTextNode.shapeTypes:
TRAPEZOID,PREDEFINED_PROCESS,SHIELD,DOCUMENT_SINGLE,DOCUMENT_MULTIPLE,MANUAL_INPUT,HEXAGON,CHEVRON,PENTAGON,OCTAGON,STAR,PLUS,ARROW_LEFT,ARROW_RIGHT,SUMMING_JUNCTION,OR,SPEECH_BUBBLE,INTERNAL_STORAGE