-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.ts
More file actions
27 lines (20 loc) · 871 Bytes
/
code.ts
File metadata and controls
27 lines (20 loc) · 871 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// import figma types
import { rgbToHex } from "./utils/rgbToHex";
import { VariableResolvedDataEnum } from "./types/types";
const getLocalVariableCollections = async () => {
const variableJSON = {} as Record<string, string>;
const colorVariables = await figma.variables.getLocalVariablesAsync(VariableResolvedDataEnum.COLOR);
await Promise.all(
colorVariables.map(async (colorVariable) => {
const { name, valuesByMode } = await figma.variables.getVariableByIdAsync(colorVariable.id) as any;
const modeIds = Object.keys(valuesByMode);
const value = valuesByMode[modeIds[0]];
if (typeof value.r === "number") {
variableJSON[name] = rgbToHex({ r: value.r, g: value.g, b: value.b, a: value.a });
}
})
);
console.log(variableJSON);
}
getLocalVariableCollections();
figma.closePlugin();