Using npm modules

For more complex color/style transformation logic, it’s always good to use it from a separate npm module (or) create one.

Example

For darkening scales in CSS you can use chroma-js module

  1. import chroma from 'chroma-js'
  2. const alpha = (color) => (a) => chroma(color).alpha(a).css();
  3. const darken = alpha('#000');
  4. const shade = [
  5. darken(0),
  6. darken(1 / 8),
  7. darken(1 / 4)
  8. // More...
  9. ];
  10. const blueAlpha = [
  11. alpha(blue)(0),
  12. alpha(blue)(1 / 4),
  13. alpha(blue)(1 / 2),
  14. alpha(blue)(3 / 4),
  15. alpha(blue)(1)
  16. ];