Last active
October 14, 2020 11:07
-
-
Save upalexgill/8bce3acbbec24a8ef24ab4185f223728 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| const color = "rgb(0, 0, 0)" | |
| const rgb = colour.match(/\d+/g) // rgb: [0: 0, 1: 0, 2: 0] | |
| const getContrastColour = rgb => { | |
| // http://www.w3.org/TR/AERT#color-contrast | |
| const brightness = Math.round( | |
| (parseInt(rgb[0], 10) * 299 + | |
| parseInt(rgb[1], 10) * 587 + | |
| parseInt(rgb[2], 10) * 114) / | |
| 1000 | |
| ) | |
| const contrastColour = brightness > 125 ? "#000" : "#fff" | |
| return contrastColour | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment