UNPKG

1.76 kBJavaScriptView Raw
1"use strict";
2
3exports.__esModule = true;
4exports["default"] = void 0;
5var _curry = _interopRequireDefault(require("../internalHelpers/_curry"));
6var _parseToHsl = _interopRequireDefault(require("./parseToHsl"));
7var _toColorString = _interopRequireDefault(require("./toColorString"));
8function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
9function _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); }
10/**
11 * Sets the saturation of a color to the provided value. The saturation range can be
12 * from 0 and 1.
13 *
14 * @example
15 * // Styles as object usage
16 * const styles = {
17 * background: setSaturation(0.2, '#CCCD64'),
18 * background: setSaturation('0.75', 'rgba(204,205,100,0.7)'),
19 * }
20 *
21 * // styled-components usage
22 * const div = styled.div`
23 * background: ${setSaturation(0.2, '#CCCD64')};
24 * background: ${setSaturation('0.75', 'rgba(204,205,100,0.7)')};
25 * `
26 *
27 * // CSS in JS Output
28 * element {
29 * background: "#adad84";
30 * background: "rgba(228,229,76,0.7)";
31 * }
32 */
33function setSaturation(saturation, color) {
34 if (color === 'transparent') return color;
35 return (0, _toColorString["default"])(_extends({}, (0, _parseToHsl["default"])(color), {
36 saturation: parseFloat(saturation)
37 }));
38}
39
40// prettier-ignore
41var curriedSetSaturation = (0, _curry["default"] /* ::<number | string, string, string> */)(setSaturation);
42var _default = exports["default"] = curriedSetSaturation;
43module.exports = exports.default;
\No newline at end of file