-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.js
More file actions
115 lines (115 loc) · 5.48 KB
/
code.js
File metadata and controls
115 lines (115 loc) · 5.48 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// This plugin will open a window to prompt the user to enter a number, and
// it will then create that many rectangles on the screen.
// This file holds the main code for the plugins. It has access to the *document*.
// You can access browser APIs in the <script> tag inside "ui.html" which has a
// full browser environment (see documentation).
// This shows the HTML page in "ui.html".
console.log(figma.command);
if (figma.command === 'setting') {
figma.showUI(__html__);
figma.ui.onmessage = msg => {
figma.closePlugin();
};
}
else {
const baseColor = figma.command === 'createDoc1' ? { type: "SOLID", color: { r: 0.4274, g: 0.6941, b: 0.3333 } } : figma.command === 'createDoc2' ? { type: "SOLID", color: { r: 0.8980, g: 0.2901, b: 0.4 } } : { type: "SOLID", color: { r: 0.3137, g: 0.5333, b: 0.8666 } };
const titleColor = { type: "SOLID", color: { r: 1, g: 1, b: 1 } };
const contentColor = { type: "SOLID", color: { r: 0.1176, g: 0.1176, b: 0.1176 } };
const titleTextString = figma.command === 'createDoc1' ? '仕様捕捉のタイトルを入力' : figma.command === 'createDoc2' ? '一時メモのタイトルを入力' : '【ステータス】チケット番号 課題名';
const subTitleTextString = 'サブタイトル1';
const contentsTextString = 'AutoLayoutなのでメモとサブタイトルは増やすことができます';
Promise.all([figma.loadFontAsync({ family: "Noto Sans JP", style: "Bold" }), figma.loadFontAsync({ family: "Noto Sans JP", style: "Regular" })]).then(() => {
const textTitle = figma.createText();
textTitle.fontName = {
family: 'Noto Sans JP',
style: 'Bold'
};
textTitle.fontSize = 40;
textTitle.characters = titleTextString;
textTitle.fills = [titleColor];
const textSubTitle = figma.createText();
textSubTitle.fontName = {
family: 'Noto Sans JP',
style: 'Bold'
};
textSubTitle.fontSize = 24;
textSubTitle.characters = subTitleTextString;
textSubTitle.fills = [contentColor];
const textContents = figma.createText();
textContents.fontName = {
family: 'Noto Sans JP',
style: 'Regular'
};
textContents.fontSize = 24;
textContents.characters = contentsTextString;
textContents.fills = [contentColor];
const frameTitle = figma.createFrame();
frameTitle.layoutMode = 'HORIZONTAL';
frameTitle.primaryAxisAlignItems = 'MIN';
frameTitle.counterAxisAlignItems = 'MIN';
frameTitle.horizontalPadding = 20;
frameTitle.verticalPadding = 8;
frameTitle.itemSpacing = 8;
frameTitle.primaryAxisSizingMode = 'FIXED';
frameTitle.counterAxisSizingMode = 'AUTO';
frameTitle.layoutAlign = 'STRETCH';
frameTitle.fills = [baseColor];
frameTitle.appendChild(textTitle);
const frameContents = figma.createFrame();
frameContents.layoutMode = 'VERTICAL';
frameContents.primaryAxisAlignItems = 'MIN';
frameContents.counterAxisAlignItems = 'MIN';
frameContents.horizontalPadding = 20;
frameContents.verticalPadding = 20;
frameContents.itemSpacing = 12;
frameContents.primaryAxisSizingMode = 'AUTO';
frameContents.counterAxisSizingMode = 'FIXED';
frameContents.layoutAlign = 'STRETCH';
frameContents.appendChild(textSubTitle);
frameContents.appendChild(textContents);
const frameDoc = figma.createFrame();
frameDoc.layoutMode = 'VERTICAL';
frameDoc.primaryAxisAlignItems = 'MIN';
frameDoc.counterAxisAlignItems = 'MIN';
frameDoc.horizontalPadding = 0;
frameDoc.verticalPadding = 0;
frameDoc.itemSpacing = 0;
frameDoc.strokes = [baseColor];
frameDoc.strokeWeight = 5;
frameDoc.cornerRadius = 20;
frameDoc.clipsContent = true;
frameDoc.primaryAxisSizingMode = 'AUTO';
frameDoc.counterAxisSizingMode = 'AUTO';
frameDoc.x = figma.viewport.center.x;
frameDoc.y = figma.viewport.center.y;
frameDoc.appendChild(frameContents);
frameDoc.insertChild(0, frameTitle);
const nodes = [];
figma.currentPage.appendChild(frameDoc);
nodes.push(frameDoc);
figma.currentPage.selection = nodes;
figma.viewport.scrollAndZoomIntoView(nodes);
}).finally(() => {
figma.closePlugin();
});
}
// Calls to "parent.postMessage" from within the HTML page will trigger this
// callback. The callback will be passed the "pluginMessage" property of the
// posted message.
// figma.ui.onmessage = msg => {
// // One way of distinguishing between different types of messages sent from
// // your HTML page is to use an object with a "type" property like this.
// if (msg.type === 'createDoc1') {
// const nodes: SceneNode[] = [];
// for (let i = 0; i < msg.count; 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.