polished
Version:
A lightweight toolset for writing styles in Javascript.
42 lines (39 loc) • 1.19 kB
Flow
// @flow
import parseToHsl from './parseToHsl'
import toColorString from './toColorString'
import curry from '../internalHelpers/_curry'
/**
* Changes the hue of the color. Hue is a number between 0 to 360. The first
* argument for adjustHue is the amount of degrees the color is rotated around
* the color wheel, always producing a positive hue value.
*
* @example
* // Styles as object usage
* const styles = {
* background: adjustHue(180, '#448'),
* background: adjustHue('180', 'rgba(101,100,205,0.7)'),
* }
*
* // styled-components usage
* const div = styled.div`
* background: ${adjustHue(180, '#448')};
* background: ${adjustHue('180', 'rgba(101,100,205,0.7)')};
* `
*
* // CSS in JS Output
* element {
* background: "#888844";
* background: "rgba(136,136,68,0.7)";
* }
*/
function adjustHue(degree: number | string, color: string): string {
if (color === 'transparent') return color
const hslColor = parseToHsl(color)
return toColorString({
...hslColor,
hue: hslColor.hue + parseFloat(degree),
})
}
// prettier-ignore
const curriedAdjustHue = curry/* ::<number | string, string, string> */(adjustHue)
export default curriedAdjustHue