forked from bernaferrari/FigmaToCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhtmlSize.ts
More file actions
46 lines (41 loc) · 1.23 KB
/
Copy pathhtmlSize.ts
File metadata and controls
46 lines (41 loc) · 1.23 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
import { formatWithJSX } from "./../../common/parseJSX";
import { AltSceneNode } from "../../altNodes/altMixins";
import { nodeWidthHeight } from "../../common/nodeWidthHeight";
export const htmlSize = (node: AltSceneNode, isJSX: boolean): string => {
return htmlSizePartial(node, isJSX).join("");
};
export const htmlSizePartial = (
node: AltSceneNode,
isJsx: boolean
): [string, string] => {
const size = nodeWidthHeight(node, false);
let w = "";
if (typeof size.width === "number") {
w += formatWithJSX("width", isJsx, size.width);
} else if (size.width === "full") {
if (
node.parent &&
"layoutMode" in node.parent &&
node.parent.layoutMode === "HORIZONTAL"
) {
w += formatWithJSX("flex", isJsx, "1 1 0%");
} else {
w += formatWithJSX("width", isJsx, "100%");
}
}
let h = "";
if (typeof size.height === "number") {
h += formatWithJSX("height", isJsx, size.height);
} else if (typeof size.height === "string") {
if (
node.parent &&
"layoutMode" in node.parent &&
node.parent.layoutMode === "VERTICAL"
) {
h += formatWithJSX("flex", isJsx, "1 1 0%");
} else {
h += formatWithJSX("height", isJsx, "100%");
}
}
return [w, h];
};