UNPKG

@shinyongjun/react-datepicker

Version:
33 lines 1.22 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = useElementScroll; var react_1 = require("react"); var useEventListener_1 = require("./useEventListener"); function useElementScroll(elementRef) { var _a = (0, react_1.useState)({ scrollX: 0, scrollY: 0, isAtTop: true, isAtBottom: false, hasScrollbar: false, }), scroll = _a[0], setScroll = _a[1]; var handleScroll = (0, react_1.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, }); }, []); (0, useEventListener_1.useEventListener)('scroll', handleScroll, elementRef); return scroll; } //# sourceMappingURL=useElementScroll.js.map