|
2 | 2 | import getContrast from './getContrast'
|
3 | 3 | import getLuminance from './getLuminance'
|
4 | 4 |
|
5 |
| -const defaultLightReturnColor = '#000' |
6 |
| -const defaultDarkReturnColor = '#fff' |
| 5 | +const defaultReturnIfLightColor = '#000' |
| 6 | +const defaultReturnIfDarkColor = '#fff' |
7 | 7 |
|
8 | 8 | /**
|
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 |
10 | 10 | * contrast depending on the luminosity of the given color.
|
11 | 11 | * When passing custom return colors, strict mode ensures that the
|
12 | 12 | * return color always meets or exceeds WCAG level AA or greater. If this test
|
@@ -42,15 +42,15 @@ const defaultDarkReturnColor = '#fff'
|
42 | 42 | */
|
43 | 43 | export default function readableColor(
|
44 | 44 | color: string,
|
45 |
| - lightReturnColor?: string = defaultLightReturnColor, |
46 |
| - darkReturnColor?: string = defaultDarkReturnColor, |
| 45 | + returnIfLightColor?: string = defaultReturnIfLightColor, |
| 46 | + returnIfDarkColor?: string = defaultReturnIfDarkColor, |
47 | 47 | strict?: boolean = true,
|
48 | 48 | ): 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 |
51 | 51 |
|
52 | 52 | if (!strict || getContrast(color, preferredReturnColor) >= 4.5) {
|
53 | 53 | return preferredReturnColor
|
54 | 54 | }
|
55 |
| - return isLightColor ? defaultLightReturnColor : defaultDarkReturnColor |
| 55 | + return isColorLight ? defaultReturnIfLightColor : defaultReturnIfDarkColor |
56 | 56 | }
|
0 commit comments