-
Notifications
You must be signed in to change notification settings - Fork 317
/
code.ts
72 lines (56 loc) · 2.47 KB
/
code.ts
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// runs this code if the plugin is run in Figma
if (figma.editorType === 'figma') {
// This plugin creates 5 rectangles on the screen.
const numberOfRectangles = 5
// This file holds the main code for the plugins. It has access to the *document*.
// You can access browser APIs such as the network by creating a UI which contains
// a full browser environment (see documentation).
const nodes: SceneNode[] = [];
for (let i = 0; i < numberOfRectangles; i++) {
const rect = figma.createRectangle();
rect.x = i * 150;
rect.fills = [{type: 'SOLID', color: {r: 1, g: 0.5, b: 0}}];
figma.currentPage.appendChild(rect);
nodes.push(rect);
}
figma.currentPage.selection = nodes;
figma.viewport.scrollAndZoomIntoView(nodes);
// Make sure to close the plugin when you're done. Otherwise the plugin will
// keep running, which shows the cancel button at the bottom of the screen.
figma.closePlugin();
}
// runs this code if the plugin is run in FigJam
if (figma.editorType === 'figjam') {
// This plugin creates 5 shapes with text on the screen, and adds a connector in between each one.
const numberOfShapes = 5
// This file holds the main code for the plugin. It has access to the *document*.
// You can access browser APIs such as the network by creating a UI which contains
// a full browser environment (see documentation).
const nodes: SceneNode[] = [];
for (let i = 0; i < numberOfShapes; i++) {
const shape = figma.createShapeWithText();
shape.shapeType = 'ROUNDED_RECTANGLE'
// You can set shapeType to one of: 'SQUARE' | 'ELLIPSE' | 'ROUNDED_RECTANGLE' | 'DIAMOND' | 'TRIANGLE_UP' | 'TRIANGLE_DOWN' | 'PARALLELOGRAM_RIGHT' | 'PARALLELOGRAM_LEFT'
shape.x = i * 400;
shape.fills = [{type: 'SOLID', color: {r: 1, g: 0.5, b: 0}}];
figma.currentPage.appendChild(shape);
nodes.push(shape);
}
for (let i = 0; i < (numberOfShapes - 1); i++) {
const connector = figma.createConnector();
connector.strokeWeight = 8
connector.connectorStart = {
endpointNodeId: nodes[i].id,
magnet: 'AUTO',
};
connector.connectorEnd = {
endpointNodeId: nodes[i+1].id,
magnet: 'AUTO',
};
}
figma.currentPage.selection = nodes;
figma.viewport.scrollAndZoomIntoView(nodes);
// Make sure to close the plugin when you're done. Otherwise the plugin will
// keep running, which shows the cancel button at the bottom of the screen.
figma.closePlugin();
}