UNPKG

1.39 kBJavaScriptView Raw
1"use strict";
2
3exports.__esModule = true;
4exports["default"] = grayscale;
5var _parseToHsl = _interopRequireDefault(require("./parseToHsl"));
6var _toColorString = _interopRequireDefault(require("./toColorString"));
7function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
8function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
9/**
10 * Converts the color to a grayscale, by reducing its saturation to 0.
11 *
12 * @example
13 * // Styles as object usage
14 * const styles = {
15 * background: grayscale('#CCCD64'),
16 * background: grayscale('rgba(204,205,100,0.7)'),
17 * }
18 *
19 * // styled-components usage
20 * const div = styled.div`
21 * background: ${grayscale('#CCCD64')};
22 * background: ${grayscale('rgba(204,205,100,0.7)')};
23 * `
24 *
25 * // CSS in JS Output
26 * element {
27 * background: "#999";
28 * background: "rgba(153,153,153,0.7)";
29 * }
30 */
31function grayscale(color) {
32 if (color === 'transparent') return color;
33 return (0, _toColorString["default"])(_extends({}, (0, _parseToHsl["default"])(color), {
34 saturation: 0
35 }));
36}
37module.exports = exports.default;
\No newline at end of file