UNPKG

react-color

Version:

A Collection of Color Pickers from Sketch, Photoshop, Chrome & more

51 lines (48 loc) 1.26 kB
export var calculateChange = function calculateChange(e, direction, hsl, container) { var containerWidth = container.clientWidth; var containerHeight = container.clientHeight; var x = typeof e.pageX === 'number' ? e.pageX : e.touches[0].pageX; var y = typeof e.pageY === 'number' ? e.pageY : e.touches[0].pageY; var left = x - (container.getBoundingClientRect().left + window.pageXOffset); var top = y - (container.getBoundingClientRect().top + window.pageYOffset); if (direction === 'vertical') { var h = void 0; if (top < 0) { h = 359; } else if (top > containerHeight) { h = 0; } else { var percent = -(top * 100 / containerHeight) + 100; h = 360 * percent / 100; } if (hsl.h !== h) { return { h: h, s: hsl.s, l: hsl.l, a: hsl.a, source: 'hsl' }; } } else { var _h = void 0; if (left < 0) { _h = 0; } else if (left > containerWidth) { _h = 359; } else { var _percent = left * 100 / containerWidth; _h = 360 * _percent / 100; } if (hsl.h !== _h) { return { h: _h, s: hsl.s, l: hsl.l, a: hsl.a, source: 'hsl' }; } } return null; };