UNPKG

@intility/bifrost-react

Version:

React library for Intility's design system, Bifrost.

16 lines (15 loc) 823 B
import { RefObject } from "react"; export type ScrollDirection = "up" | "down" | "none"; /** * Listens to scroll event and reports which direction (`'up'` or `'down'`) the user is scrolling, * or `'none'` if not scrolled yet. * @param options Optional options object, with `threshold` and `elementRef` * @returns `'none'` if not scrolled yet, otherwise `'up'` or `'down'` */ export default function useScrollDirection<T extends HTMLElement>({ threshold, elementRef, }?: { /** Optional amount of pixels scrolled before changing state (default 0) */ threshold?: number; /** Optional DOM node inside a scrollable parent node or the scrollable element itself *(used to find target for scroll event listener, defaults to document root element) */ elementRef?: RefObject<T | null>; }): ScrollDirection;