-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.ts
More file actions
44 lines (39 loc) · 1.16 KB
/
code.ts
File metadata and controls
44 lines (39 loc) · 1.16 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
figma.showUI(__html__);
figma.ui.onmessage = async (msg: { type: string; query: string }) => {
if (msg.type === "brand-search") {
try {
const res = await fetch(`http://api.logo.dev/search?q=${msg.query}`, {
headers: {
// find your secret key on the dashboard
// https://www.logo.dev/dashboard
Bearer: "Your Secret Key Here",
},
});
const data = await res.json();
console.log("have these results", data);
const nodes = [];
let lastX = 0;
for (const row of data) {
const img = await figma.createImageAsync(row.logo_url);
const node = figma.createRectangle();
const { width, height } = await img.getSizeAsync();
node.resize(width, height);
node.x = lastX;
lastX += Math.floor(width * 1.1);
node.fills = [
{
type: "IMAGE",
imageHash: img.hash,
scaleMode: "FILL",
},
];
nodes.push(node);
}
figma.currentPage.selection = nodes;
} catch (err) {
console.log("error running plugin", err);
}
console.log("done");
}
figma.closePlugin();
};