MCPcopy
hub / github.com/styled-components/polished / readableColor

Function readableColor

src/color/readableColor.js:43–56  ·  view source on GitHub ↗
(
  color: string,
  returnIfLightColor?: string = defaultReturnIfLightColor,
  returnIfDarkColor?: string = defaultReturnIfDarkColor,
  strict?: boolean = true,
)

Source from the content-addressed store, hash-verified

41 * }
42 */
43export 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}

Callers 1

Calls 2

getLuminanceFunction · 0.70
getContrastFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…