Skip to content

Commit

Permalink
fix(rgbtostring): fix issue with 0 alpha rgb colors
Browse files Browse the repository at this point in the history
Fixes issue where passing 0 alpha improperly returned a non-transparent hex color.

fix #515
  • Loading branch information
bhough committed May 29, 2020
1 parent 976d5b5 commit 44de1f1
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "polished",
"version": "3.6.3",
"version": "3.6.4",
"description": "A lightweight toolset for writing styles in Javascript.",
"license": "MIT",
"author": "Brian Hough <hello@brianhough.net> (https://polished.js.org)",
Expand Down
2 changes: 1 addition & 1 deletion src/color/rgbToColorString.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default function rgbToColorString(color: RgbColor | RgbaColor): string {
&& typeof color.green === 'number'
&& typeof color.blue === 'number'
) {
if (color.alpha && typeof color.alpha === 'number') {
if (typeof color.alpha === 'number') {
return rgba({
red: color.red,
green: color.green,
Expand Down
6 changes: 6 additions & 0 deletions src/color/test/__snapshots__/rgbToColorString.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,9 @@ Object {
"background": "rgba(255,205,100,0.72)",
}
`;

exports[`rgbToColorString should convert a RgbaColor with 0 alpha to a rgba string 1`] = `
Object {
"background": "rgba(255,205,100,0)",
}
`;
11 changes: 11 additions & 0 deletions src/color/test/rgbToColorString.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ describe('rgbToColorString', () => {
}).toMatchSnapshot()
})

it('should convert a RgbaColor with 0 alpha to a rgba string', () => {
expect({
background: rgbToColorString({
red: 255,
green: 205,
blue: 100,
alpha: 0.0,
}),
}).toMatchSnapshot()
})

it('should throw an error if anything else than a RgbColor or RgbaColor is provided', () => {
// $FlowFixMe
expect(() => rgbToColorString({ red: 255, green: 1, hue: 240 })).toThrow(
Expand Down

0 comments on commit 44de1f1

Please sign in to comment.