@primer/react
Version:
An implementation of GitHub's Primer Design System using React
35 lines (34 loc) • 983 B
JavaScript
import { c } from "react-compiler-runtime";
import { useEffect } from "react";
//#region src/hooks/useScrollFlash.ts
/**
* This hook will flash the scrollbars for a ref of a container that has scrollable overflow
* @param scrollContainerRef The ref of the scrollable content
*/
function useScrollFlash(scrollContainerRef) {
const $ = c(3);
let t0;
let t1;
if ($[0] !== scrollContainerRef) {
t0 = () => {
const scrollContainer = scrollContainerRef.current;
if (!scrollContainer) return;
const id = requestAnimationFrame(() => {
const currentScroll = scrollContainer.scrollTop;
scrollContainer.scrollTop = currentScroll < 1 ? currentScroll + 1 : currentScroll - 1;
scrollContainer.scrollTop = currentScroll;
});
return () => cancelAnimationFrame(id);
};
t1 = [scrollContainerRef];
$[0] = scrollContainerRef;
$[1] = t0;
$[2] = t1;
} else {
t0 = $[1];
t1 = $[2];
}
useEffect(t0, t1);
}
//#endregion
export { useScrollFlash as default };