Skip to content

Instantly share code, notes, and snippets.

@t-laird
Created February 5, 2018 01:58
Show Gist options
  • Save t-laird/8f9918324c7063ed62c6a0a48beec57c to your computer and use it in GitHub Desktop.
Save t-laird/8f9918324c7063ed62c6a0a48beec57c to your computer and use it in GitHub Desktop.
//from GitPoint's color helper https://github.com/gitpoint/git-point/blob/master/src/utils/color-helpers.js
export const getFontColorByBackground = bgColor => {
const r = parseInt(bgColor.substr(0, 2), 16);
const g = parseInt(bgColor.substr(2, 2), 16);
const b = parseInt(bgColor.substr(4, 2), 16);
const yiq = (r * 299 + g * 587 + b * 114) / 1000;
return yiq >= 128 ? colors.black : colors.white;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment