-
-
Notifications
You must be signed in to change notification settings - Fork 209
/
lighten.js
41 lines (38 loc) · 1.09 KB
/
lighten.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
40
41
// @flow
import parseToHsl from './parseToHsl'
import toColorString from './toColorString'
import guard from '../internalHelpers/_guard'
import curry from '../internalHelpers/_curry'
/**
* Returns a string value for the lightened color.
*
* @example
* // Styles as object usage
* const styles = {
* background: lighten(0.2, '#CCCD64'),
* background: lighten(0.2, 'rgba(204,205,100,0.7)'),
* }
*
* // styled-components usage
* const div = styled.div`
* background: ${lighten(0.2, '#FFCD64')};
* background: ${lighten(0.2, 'rgba(204,205,100,0.7)')};
* `
*
* // CSS in JS Output
*
* element {
* background: "#e5e6b1";
* background: "rgba(229,230,177,0.7)";
* }
*/
function lighten(amount: number, color: string): string {
const hslColor = parseToHsl(color)
return toColorString({
...hslColor,
lightness: guard(0, 1, hslColor.lightness + amount),
})
}
// Don’t inline this variable into export because Rollup will remove the /*#__PURE__*/ comment
const curriedLighten = /*#__PURE__*/ curry(lighten) // eslint-disable-line spaced-comment
export default curriedLighten