Skip to content

Instantly share code, notes, and snippets.

@auduongtuan
Last active October 19, 2021 03:30
Show Gist options
  • Select an option

  • Save auduongtuan/5e7b2138a4123e4c6e059b7ce78a8119 to your computer and use it in GitHub Desktop.

Select an option

Save auduongtuan/5e7b2138a4123e4c6e059b7ce78a8119 to your computer and use it in GitHub Desktop.
Batch create Color styles in Figma
const colors = {B5: "#F2F8FF", B10: "#D6EBFF", B20: "#B2D7FC", B30: "#75B4F6", B40: "#4294EE", B50: "#1671E0", B60: "#0058CC", B70: "#0041B3", B80: "#0041B3", B90: "#00257A", B100: "#00155C", R5: "#FFF4F2", R10: "#FFDDD6", R20: "#FCBEB2", R30: "#F68A75", R40: "#EE5B42", R50: "#E03116", R60: "#CC1700", R70: "#B31000", R80: "#8F0800", R90: "#7A0400", R100: "#5C0000", Y5: "#FFFBF2", Y10: "#FFF3D6", Y20: "#FCE4B3", Y30: "#F6CC76", Y40: "#EEB443", Y50: "#E09916", Y60: "#CC7F00", Y70: "#B36B00", Y80: "#8F5000", Y90: "#7A4100", Y100: "#5C2E00", C5: "#F2FFFF", C10: "#D6FFFF", C20: "#B2FBFC", C30: "#75F4F6", C40: "#42E8EE", C50: "#16D5E0", C60: "#00BACC", C70: "#009CB3", C80: "#00768F", C90: "#005F7A", C100: "#00435C", P5: "#F7F2FF", P10: "#E7D6FF", P20: "#D1B2FC", P30: "#BB91F6", P40: "#995FED", P50: "#6416E0", P60: "#4A00CC", P70: "#3C00B3", P80: "#2C008F", P90: "#22007A", P100: "#17005C", G5: "#F6FFF2", G10: "#E5FFD6", G20: "#CBFCB3", G30: "#A0F07D", G40: "#88E063", G50: "#6ECC4E", G60: "#45B027", G70: "#2F8F1D", G80: "#197A0F", G90: "#0C660A", G100: "#08520B", N0: "#F9F9F9", N5: "#F0F0F1", N10: "#E1E1E3", N20: "#D2D2D6", N30: "#B4B4BB", N40: "#9696A0", N50: "#757585", N60: "#59596A", N70: "#494957", N80: "#393944", N90: "#292931", N100: "#18181D", Black: "#000000", White: "#FFFFFF"};
const colorFullName = {
R: "Red",
B: "Blue",
G: "Green",
Y: "Yellow",
C: "Cyan",
P: "Purple",
N: "Neutral"
}
function hexToRgb(hex: string) : RGB {
let result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
if(result) {
return {
r: parseInt(result[1], 16) / 255,
g: parseInt(result[2], 16) / 255,
b: parseInt(result[3], 16) / 255
}
} else {
return {r: 0, g:0, b:0}
}
}
for (const name in colors) {
let rgbcolor = hexToRgb(colors[name]);
let group
const style = figma.createPaintStyle()
if(name.length <= 4) {
group = colorFullName[name[0]]
} else {
group = "Mono"
}
style.name = `${group}/${name}`
style.paints = [
{type: "SOLID", color: rgbcolor}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment