Skip to content

Bugfix/box shadow #60

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 4, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 43 additions & 3 deletions src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@ it('transforms box-shadow into shadow- properties', () => runTest([
shadowOffset: { width: 10, height: 20 },
shadowRadius: 30,
shadowColor: 'red',
shadowOpacity: 1,
}));

it('transforms box-shadow without blur-radius', () => runTest([
Expand All @@ -472,14 +473,16 @@ it('transforms box-shadow without blur-radius', () => runTest([
shadowOffset: { width: 10, height: 20 },
shadowRadius: 0,
shadowColor: 'red',
shadowOpacity: 1,
}));

it('transforms box-shadow without color', () => runTest([
['box-shadow', '10px 20px red'],
['box-shadow', '10px 20px 30px'],
], {
shadowOffset: { width: 10, height: 20 },
shadowRadius: 0,
shadowColor: 'red',
shadowRadius: 30,
shadowColor: 'black',
shadowOpacity: 1,
}));

it('transforms box-shadow without blur-radius, color', () => runTest([
Expand All @@ -488,6 +491,43 @@ it('transforms box-shadow without blur-radius, color', () => runTest([
shadowOffset: { width: 10, height: 20 },
shadowRadius: 0,
shadowColor: 'black',
shadowOpacity: 1,
}));

it('transforms box-shadow with rgb color', () => runTest([
['box-shadow', '10px 20px rgb(100, 100, 100)'],
], {
shadowOffset: { width: 10, height: 20 },
shadowRadius: 0,
shadowColor: 'rgb(100, 100, 100)',
shadowOpacity: 1,
}));

it('transforms box-shadow with rgba color', () => runTest([
['box-shadow', '10px 20px rgba(100, 100, 100, 0.5)'],
], {
shadowOffset: { width: 10, height: 20 },
shadowRadius: 0,
shadowColor: 'rgba(100, 100, 100, 0.5)',
shadowOpacity: 1,
}));

it('transforms box-shadow with hsl color', () => runTest([
['box-shadow', '10px 20px hsl(120, 100%, 50%)'],
], {
shadowOffset: { width: 10, height: 20 },
shadowRadius: 0,
shadowColor: 'hsl(120, 100%, 50%)',
shadowOpacity: 1,
}));

it('transforms box-shadow with hsla color', () => runTest([
['box-shadow', '10px 20px hsla(120, 100%, 50%, 0.7)'],
], {
shadowOffset: { width: 10, height: 20 },
shadowRadius: 0,
shadowColor: 'hsla(120, 100%, 50%, 0.7)',
shadowOpacity: 1,
}));

it('transforms box-shadow enforces offset to be present', () => {
Expand Down
11 changes: 5 additions & 6 deletions src/transforms/boxShadow.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { tokens } = require('../tokenTypes');

const { NONE, SPACE, WORD, LENGTH } = tokens;
const { NONE, SPACE, COLOR, LENGTH } = tokens;

module.exports = (tokenStream) => {
let offsetX;
Expand All @@ -11,7 +11,7 @@ module.exports = (tokenStream) => {
if (tokenStream.matches(NONE)) {
tokenStream.expectEmpty();
return {
$merge: { shadowOffset: { width: 0, height: 0 }, shadowRadius: 0, shadowColor: 'black' },
$merge: { shadowOffset: { width: 0, height: 0 }, shadowRadius: 0, shadowColor: 'black', shadowOpacity: 1 },
};
}

Expand All @@ -28,10 +28,8 @@ module.exports = (tokenStream) => {
tokenStream.expect(SPACE);
blurRadius = tokenStream.expect(LENGTH);
}
} else if (color === undefined && (
tokenStream.matchesFunction() || tokenStream.matches(WORD)
)) {
color = String(tokenStream.lastValue);
} else if (tokenStream.matches(COLOR)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to check color === undefined to stop box-shadow: 0 0 0 red yellow green blue

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, should I add a test case for that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a test case and a fix for that. :)

color = tokenStream.lastValue;
} else {
tokenStream.throw();
}
Expand All @@ -45,6 +43,7 @@ module.exports = (tokenStream) => {
shadowOffset: { width: offsetX, height: offsetY },
shadowRadius: blurRadius !== undefined ? blurRadius : 0,
shadowColor: color !== undefined ? color : 'black',
shadowOpacity: 1,
};
return { $merge };
};