@primer/react
Version:
An implementation of GitHub's Primer Design System using React
36 lines (33 loc) • 1.01 kB
JavaScript
import { c } from 'react-compiler-runtime';
import { useEffect } from 'react';
/**
* 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 currentScroll = scrollContainer.scrollTop;
const maxScroll = scrollContainer.scrollHeight;
const altScroll = currentScroll < Math.min(1, maxScroll) ? currentScroll + 1 : currentScroll - 1;
scrollContainer.scrollTop = altScroll;
scrollContainer.scrollTop = currentScroll;
};
t1 = [scrollContainerRef];
$[0] = scrollContainerRef;
$[1] = t0;
$[2] = t1;
} else {
t0 = $[1];
t1 = $[2];
}
useEffect(t0, t1);
}
export { useScrollFlash as default };