Skip to content

Commit 6e098e5

Browse files
committed
box-shadow: fix support for rgb and rgba colors
1 parent 5e64e09 commit 6e098e5

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

src/index.spec.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,6 +1198,38 @@ describe("box-shadow", () => {
11981198
});
11991199
});
12001200

1201+
it("supports rgb values", () => {
1202+
expect(
1203+
transform(`
1204+
.test {
1205+
box-shadow: 10px 20px 30px rgb(100, 100, 100);
1206+
}
1207+
`),
1208+
).toEqual({
1209+
test: {
1210+
shadowOffset: { width: 10, height: 20 },
1211+
shadowRadius: 30,
1212+
shadowColor: "rgb(100, 100, 100)",
1213+
},
1214+
});
1215+
});
1216+
1217+
it("supports rgba values", () => {
1218+
expect(
1219+
transform(`
1220+
.test {
1221+
box-shadow: 10px 20px 30px rgba(100, 100, 100, 0.5);
1222+
}
1223+
`),
1224+
).toEqual({
1225+
test: {
1226+
shadowOffset: { width: 10, height: 20 },
1227+
shadowRadius: 30,
1228+
shadowColor: "rgba(100, 100, 100, 0.5)",
1229+
},
1230+
});
1231+
});
1232+
12011233
it("trims values", () => {
12021234
expect(
12031235
transform(`

src/transforms/boxShadow.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ const removePx = val => val.replace(/(\d+)px/g, "$1");
22

33
const formatNumber = val => Number(removePx(val));
44

5-
const matchNumbers = val => val.match(/(^|\s+)\d+(px)?/g);
5+
const matchNumbers = val =>
6+
val.replace(/rgba?\(.*\)/g, "").match(/(^|\s+)\d+(px)?/g);
67

78
const isZeroOrPxValue = val => val === "0" || /\d+px/.test(val);
89

910
const filterNonNumbers = val =>
10-
val.split(" ").filter(val => isNaN(formatNumber(val)));
11+
val.split(/\s+(?![^(]*?\))/).filter(val => isNaN(formatNumber(val)));
1112

1213
const filterNumbers = nums => {
1314
if (!nums) {

0 commit comments

Comments
 (0)