-
-
Notifications
You must be signed in to change notification settings - Fork 209
/
setLightness.js
39 lines (36 loc) · 1.07 KB
/
setLightness.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// @flow
import parseToHsl from './parseToHsl'
import toColorString from './toColorString'
import curry from '../internalHelpers/_curry'
/**
* Sets the lightness of a color to the provided value. The lightness range can be
* from 0 and 1.
*
* @example
* // Styles as object usage
* const styles = {
* background: setLightness(0.2, '#CCCD64'),
* background: setLightness(0.75, 'rgba(204,205,100,0.7)'),
* }
*
* // styled-components usage
* const div = styled.div`
* background: ${setLightness(0.2, '#CCCD64')};
* background: ${setLightness(0.75, 'rgba(204,205,100,0.7)')};
* `
*
* // CSS in JS Output
* element {
* background: "#4d4d19";
* background: "rgba(223,224,159,0.7)";
* }
*/
function setLightness(lightness: number, color: string): string {
return toColorString({
...parseToHsl(color),
lightness,
})
}
// Don’t inline this variable into export because Rollup will remove the /*#__PURE__*/ comment
const curriedSetLightness = /*#__PURE__*/ curry(setLightness) // eslint-disable-line spaced-comment
export default curriedSetLightness