Skip to content

Commit 2160662

Browse files
committed
Add first color to borders.
1 parent f5c2108 commit 2160662

File tree

7 files changed

+64
-14
lines changed

7 files changed

+64
-14
lines changed

packages/backend/src/common/retrieveUI/retrieveColors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ const convertSolidColor = (
6868
const kind = "solid";
6969
const hex = rgbTo6hex(fill.color);
7070
const hexNearestColor = tailwindNearestColor(hex);
71-
exported = tailwindSolidColor(fill, kind);
71+
exported = tailwindSolidColor(fill.color, fill.opacity, kind);
7272
colorName = tailwindColors[hexNearestColor];
7373
} else if (framework === "SwiftUI") {
7474
exported = swiftuiColor(fill.color, opacity);

packages/backend/src/flutter/builderImpl/flutterColor.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,16 @@ export const flutterColorFromFills = (
1212
const fill = retrieveTopFill(fills);
1313

1414
if (fill && fill.type === "SOLID") {
15-
const opacity = fill.opacity ?? 1.0;
16-
return flutterColor(fill.color, opacity);
15+
return flutterColor(fill.color, fill.opacity ?? 1.0);
16+
} else if (
17+
fill &&
18+
(fill.type === "GRADIENT_LINEAR" ||
19+
fill.type === "GRADIENT_ANGULAR" ||
20+
fill.type === "GRADIENT_RADIAL")
21+
) {
22+
if (fill.gradientStops.length > 0) {
23+
return flutterColor(fill.gradientStops[0].color, fill.opacity ?? 1.0);
24+
}
1725
}
1826

1927
return "";

packages/backend/src/html/builderImpl/htmlColor.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,20 @@ export const htmlColorFromFills = (
1313
// if fill isn't visible, it shouldn't be painted.
1414
return htmlColor(fill.color, fill.opacity);
1515
}
16+
if (
17+
fill &&
18+
(fill.type === "GRADIENT_LINEAR" ||
19+
fill.type === "GRADIENT_ANGULAR" ||
20+
fill.type === "GRADIENT_RADIAL" ||
21+
fill.type === "GRADIENT_DIAMOND")
22+
) {
23+
if (fill.gradientStops.length > 0) {
24+
return htmlColor(
25+
fill.gradientStops[0].color,
26+
fill.opacity
27+
);
28+
}
29+
}
1630

1731
return "";
1832
};

packages/backend/src/html/htmlDefaultBuilder.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@ export class HtmlDefaultBuilder {
9090
formatWithJSX(
9191
"border",
9292
this.isJSX,
93-
[sliceNum(weight), color, borderStyle].filter((d) => d).join(" ")
93+
[`${sliceNum(weight)}px`, color, borderStyle]
94+
.filter((d) => d)
95+
.join(" ")
9496
)
9597
);
9698
} else {

packages/backend/src/swiftui/builderImpl/swiftuiColor.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ import { sliceNum } from "../../common/numToAutoFixed";
66
export const swiftUISolidColor = (fill: Paint): string => {
77
if (fill && fill.type === "SOLID") {
88
return swiftuiColor(fill.color, fill.opacity ?? 1.0);
9+
} else if (
10+
fill &&
11+
(fill.type === "GRADIENT_LINEAR" ||
12+
fill.type === "GRADIENT_ANGULAR" ||
13+
fill.type === "GRADIENT_RADIAL")
14+
) {
15+
if (fill.gradientStops.length > 0) {
16+
return swiftuiColor(fill.gradientStops[0].color, fill.opacity ?? 1.0);
17+
}
918
}
1019

1120
return "";

packages/backend/src/tailwind/builderImpl/tailwindColor.ts

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,39 @@ export const tailwindColorFromFills = (
1313

1414
const fill = retrieveTopFill(fills);
1515
if (fill && fill.type === "SOLID") {
16-
return tailwindSolidColor(fill, kind);
16+
return tailwindSolidColor(fill.color, fill.opacity, kind);
17+
} else if (
18+
fill &&
19+
(fill.type === "GRADIENT_LINEAR" ||
20+
fill.type === "GRADIENT_ANGULAR" ||
21+
fill.type === "GRADIENT_RADIAL" ||
22+
fill.type === "GRADIENT_DIAMOND")
23+
) {
24+
if (fill.gradientStops.length > 0) {
25+
return tailwindSolidColor(
26+
fill.gradientStops[0].color,
27+
fill.opacity,
28+
kind
29+
);
30+
}
1731
}
18-
1932
return "";
2033
};
2134

22-
export const tailwindSolidColor = (fill: SolidPaint, kind: string): string => {
23-
const opacity = fill.opacity ?? 1.0;
24-
35+
export const tailwindSolidColor = (
36+
color: RGB,
37+
opacity: number | undefined,
38+
kind: string
39+
): string => {
2540
// example: text-opacity-50
2641
// ignore the 100. If opacity was changed, let it be visible.
2742
const opacityProp =
28-
opacity !== 1.0 ? `${kind}-opacity-${nearestOpacity(opacity)}` : null;
43+
opacity !== 1.0
44+
? `${kind}-opacity-${nearestOpacity(opacity ?? 1.0)}`
45+
: null;
2946

3047
// example: text-red-500
31-
const colorProp = `${kind}-${getTailwindFromFigmaRGB(fill.color)}`;
48+
const colorProp = `${kind}-${getTailwindFromFigmaRGB(color)}`;
3249

3350
// if fill isn't visible, it shouldn't be painted.
3451
return [colorProp, opacityProp].filter((d) => d).join(" ");

packages/plugin-ui/src/PluginUI.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ type PluginUIProps = {
3535
contrastWhite: number;
3636
contrastBlack: number;
3737
}[];
38-
gradients: { cssPreview: string; exportedValue: string }[];
38+
gradients: { cssPreview: string; exportValue: string }[];
3939
};
4040

4141
export const PluginUI = (props: PluginUIProps) => {
@@ -443,7 +443,7 @@ export const ColorsPanel = (props: {
443443
export const GradientsPanel = (props: {
444444
gradients: {
445445
cssPreview: string;
446-
exportedValue: string;
446+
exportValue: string;
447447
}[];
448448
onColorClick: (color: string) => void;
449449
}) => {
@@ -471,7 +471,7 @@ export const GradientsPanel = (props: {
471471
}`}
472472
style={{ background: gradient.cssPreview }}
473473
onClick={() => {
474-
handleButtonClick(gradient.exportedValue, idx);
474+
handleButtonClick(gradient.exportValue, idx);
475475
}}
476476
></button>
477477
))}

0 commit comments

Comments
 (0)