( color: string, returnIfLightColor?: string = defaultReturnIfLightColor, returnIfDarkColor?: string = defaultReturnIfDarkColor, strict?: boolean = true, )
| 41 | * } |
| 42 | */ |
| 43 | export default function readableColor( |
| 44 | color: string, |
| 45 | returnIfLightColor?: string = defaultReturnIfLightColor, |
| 46 | returnIfDarkColor?: string = defaultReturnIfDarkColor, |
| 47 | strict?: boolean = true, |
| 48 | ): string { |
| 49 | const isColorLight = getLuminance(color) > 0.179 |
| 50 | const preferredReturnColor = isColorLight ? returnIfLightColor : returnIfDarkColor |
| 51 | |
| 52 | if (!strict || getContrast(color, preferredReturnColor) >= 4.5) { |
| 53 | return preferredReturnColor |
| 54 | } |
| 55 | return isColorLight ? defaultReturnIfLightColor : defaultReturnIfDarkColor |
| 56 | } |
no test coverage detected
searching dependent graphs…