Hey!
I am playing with scripter and the Figma API to automate color generation
Let’s say I have this palette
const palette = {
'blue-50': '#EFF6FF',
'blue-100': '#DBEAFE',
'blue-200': '#BFDBFE',
'blue-300': '#93C5FD',
'blue-400': '#60A5FA',
'blue-500': '#3B82F6',
'blue-600': '#2563EB',
'blue-700': '#1D4ED8',
'blue-800': '#1E40AF',
'blue-900': '#1E3A8A',
}
I am able to loop thought the values with
function createPalette(){
Object.keys(palette).map(key => {
print(key)
print(palettetkey])
createFigmaStyle(key, palettetkey])
})
}
But I have a problem with my function to dynamically create Figma Styles
function createFigmaStyle(colorName: string, hexValue: Paint){
const style = figma.createPaintStyle()
style.name = colorName
//here I have an error
//Type 'string' is not assignable to type 'RGB'.
const colorRGB: RGB = hexToRGBA(hexValue, 1)
// style.type = "PAINT"
const paint: SolidPaint = {
type: "SOLID",
color: colorRGB
}
style.paints = paint
}
My question is Do Figma have an official way to convert hexa value to RGB?
because my function hexToRGBA
is a random copy paste from Stackoverflow 😅