Skip to content

Commit 063c85d

Browse files
committed
fix(transparentize): float alpha value to 2 decimals
Ensures transparentize alpha values are floated 2 decimals. fix #548
1 parent 5e5520a commit 063c85d

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "polished",
3-
"version": "4.0.3",
3+
"version": "4.0.4",
44
"description": "A lightweight toolset for writing styles in Javascript.",
55
"license": "MIT",
66
"author": "Brian Hough <[email protected]> (https://polished.js.org)",

src/color/test/transparentize.test.js

+4
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ describe('transparentize', () => {
5454
expect(transparentize(-0.5, 'rgba(255, 0, 0, .8)')).toEqual('#f00')
5555
})
5656

57+
it('should properly round a float to 2 decimals.', () => {
58+
expect(transparentize(0.55, '#01B0BB')).toEqual('rgba(1,176,187,0.45)')
59+
})
60+
5761
it('should reduce the opacity when passed a string for amount', () => {
5862
expect(transparentize('0.1', '#fff')).toEqual('rgba(255,255,255,0.9)')
5963
})

src/color/transparentize.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function transparentize(amount: number | string, color: string): string {
3737
const alpha: number = typeof parsedColor.alpha === 'number' ? parsedColor.alpha : 1
3838
const colorWithAlpha = {
3939
...parsedColor,
40-
alpha: guard(0, 1, (alpha * 100 - parseFloat(amount) * 100) / 100),
40+
alpha: guard(0, 1, +(alpha * 100 - parseFloat(amount) * 100).toFixed(2) / 100),
4141
}
4242
return rgba(colorWithAlpha)
4343
}

0 commit comments

Comments
 (0)