UNPKG

1.75 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 lightness of a color to the provided value. The lightness range can be
12 * from 0 and 1.
13 *
14 * @example
15 * // Styles as object usage
16 * const styles = {
17 * background: setLightness(0.2, '#CCCD64'),
18 * background: setLightness('0.75', 'rgba(204,205,100,0.7)'),
19 * }
20 *
21 * // styled-components usage
22 * const div = styled.div`
23 * background: ${setLightness(0.2, '#CCCD64')};
24 * background: ${setLightness('0.75', 'rgba(204,205,100,0.7)')};
25 * `
26 *
27 * // CSS in JS Output
28 * element {
29 * background: "#4d4d19";
30 * background: "rgba(223,224,159,0.7)";
31 * }
32 */
33function setLightness(lightness, color) {
34 if (color === 'transparent') return color;
35 return (0, _toColorString["default"])(_extends({}, (0, _parseToHsl["default"])(color), {
36 lightness: parseFloat(lightness)
37 }));
38}
39
40// prettier-ignore
41var curriedSetLightness = (0, _curry["default"] /* ::<number | string, string, string> */)(setLightness);
42var _default = exports["default"] = curriedSetLightness;
43module.exports = exports.default;
\No newline at end of file