2023-01-06 11:44:50 -08:00
|
|
|
import { useEffect, useRef } from 'react';
|
|
|
|
|
import { useInView } from 'framer-motion';
|
|
|
|
|
|
|
|
|
|
export const useFixedTableHeader = () => {
|
|
|
|
|
const intersectRef = useRef<HTMLDivElement | null>(null);
|
|
|
|
|
const tableContainerRef = useRef<HTMLDivElement | null>(null);
|
|
|
|
|
|
|
|
|
|
const isNotPastTableIntersection = useInView(intersectRef, {
|
2023-01-08 02:18:05 -08:00
|
|
|
margin: '-63px 0px 0px 0px',
|
2023-01-06 11:44:50 -08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const tableInView = useInView(tableContainerRef, {
|
|
|
|
|
margin: '-128px 0px 0px 0px',
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
2023-01-06 14:49:41 -08:00
|
|
|
const header = document.querySelector('main .ag-header');
|
|
|
|
|
const root = document.querySelector('main .ag-root');
|
2023-01-06 11:44:50 -08:00
|
|
|
|
|
|
|
|
if (isNotPastTableIntersection || !tableInView) {
|
|
|
|
|
header?.classList.remove('ag-header-fixed');
|
|
|
|
|
root?.classList.remove('ag-header-fixed-margin');
|
|
|
|
|
} else {
|
|
|
|
|
header?.classList.add('ag-header-fixed');
|
|
|
|
|
root?.classList.add('ag-header-fixed-margin');
|
|
|
|
|
}
|
|
|
|
|
}, [isNotPastTableIntersection, tableInView]);
|
|
|
|
|
|
|
|
|
|
return { intersectRef, tableContainerRef };
|
|
|
|
|
};
|