UNPKG

@shinyongjun/react-datepicker

Version:
30 lines 1.09 kB
import { useCallback, useState } from 'react'; import { useEventListener } from './useEventListener'; export default function useElementScroll(elementRef) { var _a = useState({ scrollX: 0, scrollY: 0, isAtTop: true, isAtBottom: false, hasScrollbar: false, }), scroll = _a[0], setScroll = _a[1]; var handleScroll = useCallback(function (e) { var target = e.currentTarget; var scrollHeight = target.scrollHeight; var scrollTop = target.scrollTop; var isAtTop = scrollTop <= 0; var clientHeight = target.clientHeight; var isAtBottom = scrollHeight - scrollTop <= clientHeight + 1; var hasScrollbar = scrollHeight > clientHeight; setScroll({ scrollX: target.scrollLeft, scrollY: target.scrollTop, isAtTop: isAtTop, isAtBottom: isAtBottom, hasScrollbar: hasScrollbar, }); }, []); useEventListener('scroll', handleScroll, elementRef); return scroll; } //# sourceMappingURL=useElementScroll.js.map