Skip to content

Commit c1031d9

Browse files
add dashed stroke support (stroke gaps are not supported)
1 parent 8dbaead commit c1031d9

4 files changed

Lines changed: 36 additions & 7 deletions

File tree

externals/design-sdk

externals/reflect-core

packages/builder-css-styles/border/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,7 @@ export function border(border: Border): CSSProperties {
3333
}
3434

3535
export function borderSide(borderSide: BorderSide): CSSProperty.Border {
36-
return `solid ${px(borderSide.width)} ${color(borderSide.color)}`;
36+
return `${borderSide.style ?? "solid"} ${px(borderSide.width)} ${color(
37+
borderSide.color
38+
)}`;
3739
}

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

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import { retrievePrimaryColor } from "@design-sdk/core/utils";
2-
import type { ReflectSceneNode, ReflectLineNode } from "@design-sdk/figma-node";
2+
import type {
3+
ReflectSceneNode,
4+
ReflectLineNode,
5+
IReflectGeometryMixin,
6+
} from "@design-sdk/figma-node";
37
import { Figma } from "@design-sdk/figma-types"; /** remove figma dependency */
4-
import { Border } from "@reflect-ui/core";
8+
import { Border, BorderStyle } from "@reflect-ui/core";
59
import { roundNumber } from "@reflect-ui/uiutils";
610

711
function fromLineNode(node: ReflectLineNode) {
@@ -11,14 +15,18 @@ function fromLineNode(node: ReflectLineNode) {
1115
}
1216
// guard invisible borders
1317
if (strokes.filter(visible).length > 0) {
18+
const _p_stroke = strokes.find(visible);
19+
1420
// generate the border, when it should exist
1521
// if width is 0, then we don't want to generate a border
1622
return node.strokeWeight
1723
? new Border({
1824
// it's a line so we only add border to a single side.
1925
top: {
20-
color: retrievePrimaryColor(strokes),
26+
color: retrievePrimaryColor([_p_stroke]),
2127
width: node.strokeWeight, // do not round number
28+
// the dashed border support is incomplete. we cannot support dashed gap since the platform does not support it.
29+
style: isDashed(node) ? BorderStyle.dashed : BorderStyle.solid,
2230
},
2331
})
2432
: undefined;
@@ -33,6 +41,8 @@ function fromNode(node: ReflectSceneNode) {
3341
if ("strokeWeight" in node) {
3442
return fromStrokes(node.strokes, {
3543
width: node.strokeWeight,
44+
// the dashed border support is incomplete. we cannot support dashed gap since the platform does not support it.
45+
dashed: isDashed(node),
3646
});
3747
}
3848
}
@@ -42,28 +52,45 @@ function fromStrokes(
4252
strokes: ReadonlyArray<Figma.Paint>,
4353
{
4454
width,
55+
dashed,
4556
}: {
4657
/**
4758
* a stroke height
4859
*/
4960
width: number;
61+
dashed: boolean;
5062
}
5163
) {
5264
// guard invisible borders
5365
if (strokes.filter(visible).length > 0) {
5466
// generate the border, when it should exist
5567
// if width is 0, then we don't want to generate a border
68+
// using the first stroke. since css3 standard does not support multiple borders (as well as flutter)
69+
const _p_stroke = strokes.find(visible);
5670
return width
5771
? Border.all({
58-
color: retrievePrimaryColor(strokes),
72+
color: retrievePrimaryColor([_p_stroke]),
5973
width: roundNumber(width),
74+
style: dashed ? BorderStyle.dashed : BorderStyle.solid,
6075
})
6176
: undefined;
6277
}
6378
}
6479

6580
const visible = (s) => s.visible;
6681

82+
/**
83+
*
84+
* returns if the node's border is dashed or not
85+
*
86+
* - when solid, the dashPattern is empty - `[]`
87+
* - when dashed, the dashPattern will be like - `[6, 6]`
88+
* @param s
89+
* @returns
90+
*/
91+
const isDashed = (s: IReflectGeometryMixin): boolean =>
92+
s.dashPattern?.length > 0;
93+
6794
export const tokenizeBorder = {
6895
fromStrokes: fromStrokes,
6996
fromNode: fromNode,

0 commit comments

Comments
 (0)