color.js 604 B

123456789101112131415161718
  1. export const tintColor = (c, tint) => {
  2. const color = c.replace('#', '');
  3. let red = parseInt(color.slice(0, 2), 16);
  4. let green = parseInt(color.slice(2, 4), 16);
  5. let blue = parseInt(color.slice(4, 6), 16);
  6. if (tint === 0) { // when primary color is in its rgb space
  7. return [red, green, blue].join(',');
  8. } else {
  9. red += Math.round(tint * (255 - red));
  10. green += Math.round(tint * (255 - green));
  11. blue += Math.round(tint * (255 - blue));
  12. red = red.toString(16);
  13. green = green.toString(16);
  14. blue = blue.toString(16);
  15. return `#${ red }${ green }${ blue }`;
  16. }
  17. };