Skip to content

Commit f0599d1

Browse files
committed
refactor(readablecolor): update docs and function signature
Updated readableColor docs and function signature to be clearer on the purpose of each param and when to use them. re #555
1 parent afd5f1c commit f0599d1

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "polished",
3-
"version": "4.0.4",
3+
"version": "4.0.5",
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/readableColor.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
import getContrast from './getContrast'
33
import getLuminance from './getLuminance'
44

5-
const defaultLightReturnColor = '#000'
6-
const defaultDarkReturnColor = '#fff'
5+
const defaultReturnIfLightColor = '#000'
6+
const defaultReturnIfDarkColor = '#fff'
77

88
/**
9-
* Returns black or white (or optional light and dark return colors) for best
9+
* Returns black or white (or optional passed colors) for best
1010
* contrast depending on the luminosity of the given color.
1111
* When passing custom return colors, strict mode ensures that the
1212
* return color always meets or exceeds WCAG level AA or greater. If this test
@@ -42,15 +42,15 @@ const defaultDarkReturnColor = '#fff'
4242
*/
4343
export default function readableColor(
4444
color: string,
45-
lightReturnColor?: string = defaultLightReturnColor,
46-
darkReturnColor?: string = defaultDarkReturnColor,
45+
returnIfLightColor?: string = defaultReturnIfLightColor,
46+
returnIfDarkColor?: string = defaultReturnIfDarkColor,
4747
strict?: boolean = true,
4848
): string {
49-
const isLightColor = getLuminance(color) > 0.179
50-
const preferredReturnColor = isLightColor ? lightReturnColor : darkReturnColor
49+
const isColorLight = getLuminance(color) > 0.179
50+
const preferredReturnColor = isColorLight ? returnIfLightColor : returnIfDarkColor
5151

5252
if (!strict || getContrast(color, preferredReturnColor) >= 4.5) {
5353
return preferredReturnColor
5454
}
55-
return isLightColor ? defaultLightReturnColor : defaultDarkReturnColor
55+
return isColorLight ? defaultReturnIfLightColor : defaultReturnIfDarkColor
5656
}

src/color/test/readableColor.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ describe('readableColor', () => {
1010
expect(readableColor('#000')).toEqual('#fff')
1111
})
1212

13-
it('should return custom light background when passed dark color', () => {
13+
it('should return custom light color when passed a dark color', () => {
1414
expect(readableColor('black', '#001', '#ff8')).toEqual('#ff8')
1515
})
1616

17-
it('should return custom dark background when passed light color', () => {
17+
it('should return custom dark color when passed a light color', () => {
1818
expect(readableColor('white', '#001', '#ff8')).toEqual('#001')
1919
})
2020

0 commit comments

Comments
 (0)