_is-light.scss 568 B

123456789101112131415161718192021
  1. @charset "UTF-8";
  2. /// Programatically determines whether a color is light or dark.
  3. ///
  4. /// @link http://robots.thoughtbot.com/closer-look-color-lightness
  5. ///
  6. /// @param {Color (Hex)} $color
  7. ///
  8. /// @example scss - Usage
  9. /// is-light($color)
  10. ///
  11. /// @return {Bool}
  12. @function is-light($hex-color) {
  13. $-local-red: red(rgba($hex-color, 1));
  14. $-local-green: green(rgba($hex-color, 1));
  15. $-local-blue: blue(rgba($hex-color, 1));
  16. $-local-lightness: ($-local-red * 0.2126 + $-local-green * 0.7152 + $-local-blue * 0.0722) / 255;
  17. @return $-local-lightness > 0.6;
  18. }