Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
(event: React.PointerEvent) => {
if (trackRef.current) {
const trackRect = trackRef.current.getBoundingClientRect();
const { clientX, clientY } = event;
let diff = isVertical
? trackRect.bottom - clientY
: clientX - trackRect.left;
const length = isVertical ? trackRect.height : trackRect.width;
let percent = diff / length;
if (isReversed) {
percent = 1 - percent;
}
let nextValue = percentToValue(percent, min, max);
if (step) {
nextValue = +roundValueToStep(nextValue, step);
}
nextValue = constrainValue(nextValue, min, max);
return nextValue;
}
},
[isVertical, isReversed, max, min, step],