Skip to content

Commit 7a57026

Browse files
committed
feat: currentcolor (#29)
1 parent a3114a2 commit 7a57026

File tree

8 files changed

+59
-9
lines changed

8 files changed

+59
-9
lines changed

src/compiler/__tests__/@prop.test.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ test("@prop single", () => {
2121
myBackgroundColor: "#00f",
2222
},
2323
],
24+
v: [["__rn-css-color", "#f00"]],
2425
s: [1, 1],
2526
},
2627
],
@@ -51,6 +52,7 @@ test("@prop single, nested value", () => {
5152
["#00f", ["myBackgroundColor", "nested"]],
5253
],
5354
s: [1, 1],
55+
v: [["__rn-css-color", "#f00"]],
5456
},
5557
],
5658
],
@@ -79,6 +81,7 @@ test("@prop single, top level", () => {
7981
},
8082
["#00f", ["^", "myBackgroundColor"]],
8183
],
84+
v: [["__rn-css-color", "#f00"]],
8285
s: [1, 1],
8386
},
8487
],
@@ -108,6 +111,7 @@ test("@prop single, top level, nested", () => {
108111
},
109112
["#00f", ["^", "myBackgroundColor", "test"]],
110113
],
114+
v: [["__rn-css-color", "#f00"]],
111115
s: [1, 1],
112116
},
113117
],
@@ -138,6 +142,7 @@ test("@prop single, top level, nested", () => {
138142
["#00f", ["^", "myBackgroundColor", "test"]],
139143
],
140144
s: [1, 1],
145+
v: [["__rn-css-color", "#f00"]],
141146
},
142147
],
143148
],
@@ -169,6 +174,7 @@ test("@prop multiple", () => {
169174
myColor: "#f00",
170175
},
171176
],
177+
v: [["__rn-css-color", "#f00"]],
172178
s: [1, 1],
173179
},
174180
],

src/compiler/__tests__/compiler.test.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ test("hello world", () => {
1818
},
1919
],
2020
s: [1, 1],
21+
v: [["__rn-css-color", "#f00"]],
2122
},
2223
],
2324
],
@@ -128,6 +129,7 @@ test("multiple rules with same selector", () => {
128129
},
129130
],
130131
s: [2, 1],
132+
v: [["__rn-css-color", "#f00"]],
131133
},
132134
{
133135
d: [
@@ -139,6 +141,7 @@ test("multiple rules with same selector", () => {
139141
h: 1,
140142
},
141143
s: [1, 2],
144+
v: [["__rn-css-color", "#008000"]],
142145
},
143146
],
144147
],

src/compiler/attributes.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ test("multiple classes", () => {
1919
},
2020
],
2121
s: [1, 2],
22+
v: [["__rn-css-color", "#f00"]],
2223
},
2324
],
2425
],

src/compiler/compiler.types.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,16 +117,31 @@ export type StyleFunction =
117117
Record<never, never>,
118118
string, // string
119119
]
120+
| readonly [
121+
Record<never, never>,
122+
string, // string
123+
]
120124
| [
121125
Record<never, never>,
122126
string, // string
123127
StyleDescriptor, // arguments
124128
]
129+
| readonly [
130+
Record<never, never>,
131+
string, // string
132+
StyleDescriptor, // arguments
133+
]
125134
| [
126135
Record<never, never>,
127136
string, // string
128137
StyleDescriptor, // arguments
129138
1, // Should process after styles have been calculated
139+
]
140+
| readonly [
141+
Record<never, never>,
142+
string, // string
143+
StyleDescriptor, // arguments
144+
1, // Should process after styles have been calculated
130145
];
131146

132147
/****************************** Variables *******************************/

src/compiler/declarations.ts

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ const parsers: {
130130
"bottom": parseSizeDeclaration,
131131
"box-shadow": parseBoxShadow,
132132
"caret-color": parseColorOrAuto,
133-
"color": parseColorDeclaration,
133+
"color": parseFontColorDeclaration,
134134
"column-gap": parseGap,
135135
"container": parseContainer,
136136
"container-name": parseContainerName,
@@ -836,6 +836,10 @@ export function parseDeclarationUnparsed(
836836
if (property === "font-size") {
837837
builder.addDescriptor("--__rn-css-em", value);
838838
}
839+
840+
if (property === "color") {
841+
builder.addDescriptor("--__rn-css-current-color", value);
842+
}
839843
}
840844
}
841845

@@ -940,6 +944,8 @@ export function parseUnparsed(
940944
return true;
941945
} else if (tokenOrValue === "false") {
942946
return false;
947+
} else if (tokenOrValue === "currentcolor") {
948+
return [{}, "var", "__rn-css-current-color"] as const;
943949
} else {
944950
return tokenOrValue;
945951
}
@@ -1033,6 +1039,8 @@ export function parseUnparsed(
10331039
if (value === "inherit") {
10341040
builder.addWarning("value", value);
10351041
return;
1042+
} else if (value === "currentcolor") {
1043+
return [{}, "var", "__rn-css-current-color"] as const;
10361044
}
10371045

10381046
if (value === "true") {
@@ -1324,11 +1332,26 @@ export function parseColorOrAuto(
13241332
}
13251333
}
13261334

1335+
export function parseFontColorDeclaration(
1336+
declaration: Extract<Declaration, { value: CssColor }>,
1337+
builder: StylesheetBuilder,
1338+
) {
1339+
parseColorDeclaration(declaration, builder);
1340+
1341+
builder.addDescriptor(
1342+
"--__rn-css-color",
1343+
parseColor(declaration.value, builder),
1344+
);
1345+
}
1346+
13271347
export function parseColorDeclaration(
1328-
declaration: { value: CssColor },
1348+
declaration: Extract<Declaration, { value: CssColor }>,
13291349
builder: StylesheetBuilder,
13301350
) {
1331-
return parseColor(declaration.value, builder);
1351+
builder.addDescriptor(
1352+
declaration.property,
1353+
parseColor(declaration.value, builder),
1354+
);
13321355
}
13331356

13341357
export function parseColor(cssColor: CssColor, builder: StylesheetBuilder) {
@@ -1345,8 +1368,7 @@ export function parseColor(cssColor: CssColor, builder: StylesheetBuilder) {
13451368

13461369
switch (cssColor.type) {
13471370
case "currentcolor":
1348-
builder.addWarning("value", cssColor.type);
1349-
return;
1371+
return [{}, "var", "__rn-css-current-color"] as const;
13501372
case "light-dark":
13511373
// TODO: Handle light-dark colors
13521374
return;

src/compiler/inheritance.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ test("nested classes", () => {
2323
{
2424
cq: [{ n: "my-class" }],
2525
d: [{ color: "#f00" }],
26+
v: [["__rn-css-color", "#f00"]],
2627
s: [1, 2],
2728
},
2829
],
@@ -63,6 +64,7 @@ test("multiple tiers classes", () => {
6364
{
6465
cq: [{ n: "one" }, { n: "two" }],
6566
d: [{ color: "#f00" }],
67+
v: [["__rn-css-color", "#f00"]],
6668
s: [1, 3],
6769
},
6870
],
@@ -109,6 +111,7 @@ test("tiers with multiple classes", () => {
109111
},
110112
],
111113
d: [{ color: "#f00" }],
114+
v: [["__rn-css-color", "#f00"]],
112115
s: [1, 4],
113116
},
114117
],

src/runtime/native/__tests__/grouping.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ test("groups", () => {
3737
test("group - active", () => {
3838
registerCSS(
3939
`.group\\/item:active .my-class {
40-
color: red;
40+
background-color: red;
4141
}`,
4242
);
4343

@@ -54,7 +54,7 @@ test("group - active", () => {
5454

5555
fireEvent(parent, "pressIn");
5656

57-
expect(child.props.style).toStrictEqual({ color: "#f00" });
57+
expect(child.props.style).toStrictEqual({ backgroundColor: "#f00" });
5858
});
5959

6060
test.skip("group - active (animated)", () => {

src/runtime/native/__tests__/media-query.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ test("not all", () => {
149149
// It is the same as max-width: 639px
150150
registerCSS(`
151151
@media not all and (min-width: 640px) {
152-
.my-class { color: red; }
152+
.my-class { background-color: red; }
153153
}`);
154154
// Make larger than 640
155155
act(() => {
@@ -173,7 +173,7 @@ test("not all", () => {
173173
});
174174

175175
expect(component.props.style).toStrictEqual({
176-
color: "#f00",
176+
backgroundColor: "#f00",
177177
});
178178
});
179179

0 commit comments

Comments
 (0)