@abbl/material-calendar
Version:
Calendar component build with React and Material-UI
37 lines • 1.2 kB
JavaScript
import { useEffect, useState } from 'react';
export var ScrollEvent;
(function (ScrollEvent) {
ScrollEvent[ScrollEvent["UP"] = 0] = "UP";
ScrollEvent[ScrollEvent["DOWN"] = 1] = "DOWN";
})(ScrollEvent || (ScrollEvent = {}));
/**
* Hook which locks the scroll and sends callback with scroll move direction.
*
* Returns a method that accepts WheelEvent as parameter
* and handles all the logic behind the hook.
* @param props
*/
export default function useScrollLock(props) {
var _a = useState(false), scrollLocked = _a[0], setScrollLocked = _a[1];
// Unlocking the scroll after given lockDuration.
useEffect(function () {
if (scrollLocked) {
setTimeout(function () {
setScrollLocked(false);
}, props.lockDuration);
}
}, [scrollLocked]);
function handleWheelEvent(event) {
if (!scrollLocked) {
if (event.deltaY < 0) {
props.onScrollEvent(ScrollEvent.UP);
}
else {
props.onScrollEvent(ScrollEvent.DOWN);
}
setScrollLocked(true);
}
}
return handleWheelEvent;
}
//# sourceMappingURL=useScrollLock.js.map