Skip to content

Commit 8d14d1b

Browse files
authored
refactor: generate modern color syntax (#5456)
Ref #3574 (comment) Here added ColorValue to styles schema. toValue now generates modern syntax like rgb(0 0 0 / 0.5) for both color and rgb values.
1 parent d5aabf8 commit 8d14d1b

File tree

12 files changed

+305
-100
lines changed

12 files changed

+305
-100
lines changed

apps/builder/app/builder/features/style-panel/sections/backgrounds/gradient-utils.test.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ describe("formatGradientValue", () => {
7171
],
7272
});
7373
expect(formatGradientValue(gradient)).toBe(
74-
"linear-gradient(rgba(0, 0, 0, 1), rgba(255, 255, 255, 1))"
74+
"linear-gradient(rgb(0 0 0 / 1), rgb(255 255 255 / 1))"
7575
);
7676
});
7777

@@ -84,7 +84,7 @@ describe("formatGradientValue", () => {
8484
],
8585
});
8686
expect(formatGradientValue(gradient)).toBe(
87-
"repeating-linear-gradient(rgba(0, 0, 0, 1), rgba(255, 255, 255, 1))"
87+
"repeating-linear-gradient(rgb(0 0 0 / 1), rgb(255 255 255 / 1))"
8888
);
8989
});
9090

@@ -96,7 +96,7 @@ describe("formatGradientValue", () => {
9696
],
9797
});
9898
expect(formatGradientValue(gradient)).toBe(
99-
"conic-gradient(rgba(0, 0, 0, 1), rgba(255, 255, 255, 1))"
99+
"conic-gradient(rgb(0 0 0 / 1), rgb(255 255 255 / 1))"
100100
);
101101
});
102102

@@ -109,7 +109,7 @@ describe("formatGradientValue", () => {
109109
],
110110
});
111111
expect(formatGradientValue(gradient)).toBe(
112-
"repeating-conic-gradient(rgba(0, 0, 0, 1), rgba(255, 255, 255, 1))"
112+
"repeating-conic-gradient(rgb(0 0 0 / 1), rgb(255 255 255 / 1))"
113113
);
114114
});
115115

@@ -124,7 +124,7 @@ describe("formatGradientValue", () => {
124124
],
125125
});
126126
expect(formatGradientValue(gradient)).toBe(
127-
"radial-gradient(circle closest-side at center, rgba(0, 0, 0, 1), rgba(255, 255, 255, 1))"
127+
"radial-gradient(circle closest-side at center, rgb(0 0 0 / 1), rgb(255 255 255 / 1))"
128128
);
129129
});
130130

@@ -139,7 +139,7 @@ describe("formatGradientValue", () => {
139139
],
140140
});
141141
expect(formatGradientValue(gradient)).toBe(
142-
"repeating-radial-gradient(circle at center, rgba(0, 0, 0, 1), rgba(255, 255, 255, 1))"
142+
"repeating-radial-gradient(circle at center, rgb(0 0 0 / 1), rgb(255 255 255 / 1))"
143143
);
144144
});
145145
});
@@ -152,19 +152,19 @@ describe("formatGradientForType", () => {
152152

153153
test("formats solid color target", () => {
154154
expect(formatGradientForType(solidStyle, "solid")).toBe(
155-
"linear-gradient(rgba(255, 0, 0, 1) 0%, rgba(255, 0, 0, 1) 100%)"
155+
"linear-gradient(rgb(255 0 0 / 1) 0%, rgb(255 0 0 / 1) 100%)"
156156
);
157157
});
158158

159159
test("formats linear target", () => {
160160
expect(formatGradientForType(solidStyle, "linearGradient")).toBe(
161-
"linear-gradient(rgba(255, 0, 0, 1), rgba(255, 0, 0, 1))"
161+
"linear-gradient(rgb(255 0 0 / 1), rgb(255 0 0 / 1))"
162162
);
163163
});
164164

165165
test("formats conic target", () => {
166166
expect(formatGradientForType(undefined, "conicGradient")).toBe(
167-
"conic-gradient(rgba(0, 0, 0, 1) 0%, rgba(0, 0, 0, 0) 100%)"
167+
"conic-gradient(rgb(0 0 0 / 1) 0%, rgb(0 0 0 / 0) 100%)"
168168
);
169169
});
170170

@@ -174,7 +174,7 @@ describe("formatGradientForType", () => {
174174
value: "radial-gradient(circle at center, red, blue)",
175175
};
176176
expect(formatGradientForType(radialStyle, "radialGradient")).toBe(
177-
"radial-gradient(circle at center, rgba(255, 0, 0, 1), rgba(0, 0, 255, 1))"
177+
"radial-gradient(circle at center, rgb(255 0 0 / 1), rgb(0 0 255 / 1))"
178178
);
179179
});
180180

@@ -184,7 +184,7 @@ describe("formatGradientForType", () => {
184184
value: "repeating-linear-gradient(red, blue)",
185185
};
186186
expect(formatGradientForType(value, "linearGradient")).toBe(
187-
"repeating-linear-gradient(rgba(255, 0, 0, 1), rgba(0, 0, 255, 1))"
187+
"repeating-linear-gradient(rgb(255 0 0 / 1), rgb(0 0 255 / 1))"
188188
);
189189
});
190190

@@ -194,7 +194,7 @@ describe("formatGradientForType", () => {
194194
value: "repeating-conic-gradient(red, blue)",
195195
};
196196
expect(formatGradientForType(value, "conicGradient")).toBe(
197-
"repeating-conic-gradient(rgba(255, 0, 0, 1), rgba(0, 0, 255, 1))"
197+
"repeating-conic-gradient(rgb(255 0 0 / 1), rgb(0 0 255 / 1))"
198198
);
199199
});
200200

@@ -204,7 +204,7 @@ describe("formatGradientForType", () => {
204204
value: "repeating-radial-gradient(circle, red, blue)",
205205
};
206206
expect(formatGradientForType(value, "radialGradient")).toBe(
207-
"repeating-radial-gradient(circle, rgba(255, 0, 0, 1), rgba(0, 0, 255, 1))"
207+
"repeating-radial-gradient(circle, rgb(255 0 0 / 1), rgb(0 0 255 / 1))"
208208
);
209209
});
210210

@@ -214,7 +214,7 @@ describe("formatGradientForType", () => {
214214
value: "conic-gradient(red, blue)",
215215
};
216216
expect(formatGradientForType(conicStyle, "radialGradient")).toBe(
217-
"radial-gradient(rgba(255, 0, 0, 1), rgba(0, 0, 255, 1))"
217+
"radial-gradient(rgb(255 0 0 / 1), rgb(0 0 255 / 1))"
218218
);
219219
});
220220
});
@@ -225,7 +225,7 @@ describe("convertGradientToTarget", () => {
225225
conic: "conic-gradient(red 0%, blue 100%)",
226226
radial: "radial-gradient(circle, red 0%, blue 100%)",
227227
};
228-
const expectedColors = ["rgba(255, 0, 0, 1)", "rgba(0, 0, 255, 1)"];
228+
const expectedColors = ["rgb(255 0 0 / 1)", "rgb(0 0 255 / 1)"];
229229
const gradientTypes: GradientType[] = ["linear", "conic", "radial"];
230230

231231
const getStopColors = (stops: GradientStop[]) =>

0 commit comments

Comments
 (0)