Skip to content

Commit

Permalink
fix(transparentize): float alpha value to 2 decimals
Browse files Browse the repository at this point in the history
Ensures transparentize alpha values are floated 2 decimals.

fix #548
  • Loading branch information
bhough committed Nov 21, 2020
1 parent 5e5520a commit 063c85d
Show file tree
Hide file tree
Showing 3 changed files with 6 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": "4.0.3",
"version": "4.0.4",
"description": "A lightweight toolset for writing styles in Javascript.",
"license": "MIT",
"author": "Brian Hough <[email protected]> (https://polished.js.org)",
Expand Down
4 changes: 4 additions & 0 deletions src/color/test/transparentize.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ describe('transparentize', () => {
expect(transparentize(-0.5, 'rgba(255, 0, 0, .8)')).toEqual('#f00')
})

it('should properly round a float to 2 decimals.', () => {
expect(transparentize(0.55, '#01B0BB')).toEqual('rgba(1,176,187,0.45)')
})

it('should reduce the opacity when passed a string for amount', () => {
expect(transparentize('0.1', '#fff')).toEqual('rgba(255,255,255,0.9)')
})
Expand Down
2 changes: 1 addition & 1 deletion src/color/transparentize.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function transparentize(amount: number | string, color: string): string {
const alpha: number = typeof parsedColor.alpha === 'number' ? parsedColor.alpha : 1
const colorWithAlpha = {
...parsedColor,
alpha: guard(0, 1, (alpha * 100 - parseFloat(amount) * 100) / 100),
alpha: guard(0, 1, +(alpha * 100 - parseFloat(amount) * 100).toFixed(2) / 100),
}
return rgba(colorWithAlpha)
}
Expand Down

0 comments on commit 063c85d

Please sign in to comment.