Skip to content
Permalink
main
Switch branches/tags
Go to file
 
 
Cannot retrieve contributors at this time
// taken from:
// https://github.com/styled-components/polished/blob/0764c982551b487469043acb56281b0358b3107b/src/color/getContrast.js
import getLuminance from './getLuminance';
/**
* Returns the contrast ratio between two colors based on
* [W3's recommended equation for calculating contrast](http://www.w3.org/TR/WCAG20/#contrast-ratiodef).
*/
function getContrast(color1: string, color2: string): number {
const luminance1 = getLuminance(color1);
const luminance2 = getLuminance(color2);
return luminance1 > luminance2
? (luminance1 + 0.05) / (luminance2 + 0.05)
: (luminance2 + 0.05) / (luminance1 + 0.05);
}
export default getContrast;