Skip to content

Commit 8dbaead

Browse files
add proper line support - fixes the border side handling of the line node
1 parent 949b969 commit 8dbaead

4 files changed

Lines changed: 44 additions & 7 deletions

File tree

externals/reflect-core

packages/designto-token/main.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -314,11 +314,9 @@ function handle_by_types(
314314
break;
315315

316316
case nodes.ReflectSceneNodeType.line:
317-
// FIXME: this is a temporary fallback. line should be handled with unique handler. (using rect's handler instead.)
318-
tokenizedTarget = tokenizeContainer.fromRectangle(node as any);
317+
tokenizedTarget = tokenizeContainer.fromLine(node as any);
318+
// tokenizedTarget = tokenizeDivider.fromLine(_line);
319319
break;
320-
// const _line = node as nodes.ReflectLineNode;
321-
// tokenizedTarget = tokenizeDivider.fromLine(_line);
322320

323321
default:
324322
console.error(`${node["type"]} is not yet handled by "@designto/token"`);

packages/designto-token/token-border/index.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,30 @@
11
import { retrievePrimaryColor } from "@design-sdk/core/utils";
2-
import { ReflectSceneNode } from "@design-sdk/figma-node";
2+
import type { ReflectSceneNode, ReflectLineNode } from "@design-sdk/figma-node";
33
import { Figma } from "@design-sdk/figma-types"; /** remove figma dependency */
44
import { Border } from "@reflect-ui/core";
55
import { roundNumber } from "@reflect-ui/uiutils";
66

7+
function fromLineNode(node: ReflectLineNode) {
8+
const strokes = node.strokes;
9+
if (!strokes || strokes.length === 0) {
10+
return undefined;
11+
}
12+
// guard invisible borders
13+
if (strokes.filter(visible).length > 0) {
14+
// generate the border, when it should exist
15+
// if width is 0, then we don't want to generate a border
16+
return node.strokeWeight
17+
? new Border({
18+
// it's a line so we only add border to a single side.
19+
top: {
20+
color: retrievePrimaryColor(strokes),
21+
width: node.strokeWeight, // do not round number
22+
},
23+
})
24+
: undefined;
25+
}
26+
}
27+
728
function fromNode(node: ReflectSceneNode) {
829
if ("strokes" in node) {
930
if (!node.strokes || node.strokes.length === 0) {
@@ -29,7 +50,7 @@ function fromStrokes(
2950
}
3051
) {
3152
// guard invisible borders
32-
if (strokes.filter((s) => s.visible).length > 0) {
53+
if (strokes.filter(visible).length > 0) {
3354
// generate the border, when it should exist
3455
// if width is 0, then we don't want to generate a border
3556
return width
@@ -41,7 +62,10 @@ function fromStrokes(
4162
}
4263
}
4364

65+
const visible = (s) => s.visible;
66+
4467
export const tokenizeBorder = {
4568
fromStrokes: fromStrokes,
4669
fromNode: fromNode,
70+
fromLineNode: fromLineNode,
4771
};

packages/designto-token/token-container/index.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,20 @@ function fromRectangle(rect: nodes.ReflectRectangleNode): core.Container {
2323
return container;
2424
}
2525

26+
function fromLine(line: nodes.ReflectLineNode): core.Container {
27+
const container = new core.Container({
28+
key: keyFromNode(line),
29+
width: line.width,
30+
height: 0,
31+
boxShadow: line.shadows as BoxShadowManifest[],
32+
border: tokenizeBorder.fromLineNode(line),
33+
});
34+
35+
container.x = line.x;
36+
container.y = line.y;
37+
return container;
38+
}
39+
2640
function fromEllipse(ellipse: nodes.ReflectEllipseNode): core.Container {
2741
const container = new core.Container({
2842
key: keyFromNode(ellipse),
@@ -45,4 +59,5 @@ function fromEllipse(ellipse: nodes.ReflectEllipseNode): core.Container {
4559
export const tokenizeContainer = {
4660
fromRectangle: fromRectangle,
4761
fromEllipse: fromEllipse,
62+
fromLine: fromLine,
4863
};

0 commit comments

Comments
 (0)