|
| 1 | +export function createVariables() { |
| 2 | + // Primitives |
| 3 | + const primitivesCollection = figma.variables.createVariableCollection("Primitives"); |
| 4 | + const whiteVariable = figma.variables.createVariable("white", primitivesCollection, "COLOR"); |
| 5 | + const blackVariable = figma.variables.createVariable("black", primitivesCollection, "COLOR"); |
| 6 | + const modeId = primitivesCollection.modes[0].modeId; |
| 7 | + whiteVariable.setValueForMode(modeId, figma.util.rgb("#FFFFFF")); |
| 8 | + blackVariable.setValueForMode(modeId, figma.util.rgb("#000000")); |
| 9 | + |
| 10 | + // Semantics |
| 11 | + const semanticsCollection = figma.variables.createVariableCollection("Semantics"); |
| 12 | + const lightMode = semanticsCollection.modes[0]; |
| 13 | + semanticsCollection.renameMode(lightMode.modeId, "Light"); |
| 14 | + semanticsCollection.addMode("Dark"); |
| 15 | + const darkMode = semanticsCollection.modes[1]; |
| 16 | + |
| 17 | + const textDefaultVariable = figma.variables.createVariable("text-default", semanticsCollection, "COLOR"); |
| 18 | + textDefaultVariable.setValueForMode(lightMode.modeId, { |
| 19 | + type: "VARIABLE_ALIAS", |
| 20 | + id: blackVariable.id, |
| 21 | + }); |
| 22 | + textDefaultVariable.setValueForMode(darkMode.modeId, { |
| 23 | + type: "VARIABLE_ALIAS", |
| 24 | + id: whiteVariable.id, |
| 25 | + }); |
| 26 | + |
| 27 | + const backgroundVariable = figma.variables.createVariable("background", semanticsCollection, "COLOR"); |
| 28 | + backgroundVariable.setValueForMode(lightMode.modeId, { |
| 29 | + type: "VARIABLE_ALIAS", |
| 30 | + id: whiteVariable.id, |
| 31 | + }); |
| 32 | + backgroundVariable.setValueForMode(darkMode.modeId, { |
| 33 | + type: "VARIABLE_ALIAS", |
| 34 | + id: blackVariable.id, |
| 35 | + }); |
| 36 | +} |
0 commit comments