Permalink
Cannot retrieve contributors at this time
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
18 lines (15 sloc)
661 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; |