split out item list table functionality

This commit is contained in:
jeffvli
2026-01-16 14:05:32 -08:00
parent a5fa022eb6
commit e2b20eb89b
12 changed files with 1622 additions and 1237 deletions
@@ -0,0 +1,42 @@
import { useEffect, useRef } from 'react';
interface UseTableInitialScrollProps {
initialTop?: {
behavior?: 'auto' | 'smooth';
to: number;
type: 'index' | 'offset';
};
scrollToTableIndex: (index: number, options?: { align?: 'bottom' | 'center' | 'top' }) => void;
scrollToTableOffset: (offset: number) => void;
startRowIndex?: number;
}
/**
* Hook to handle initial scroll position and scrolling to top when startRowIndex changes.
*/
export const useTableInitialScroll = ({
initialTop,
scrollToTableIndex,
scrollToTableOffset,
startRowIndex,
}: UseTableInitialScrollProps) => {
const isInitialScrollPositionSet = useRef<boolean>(false);
useEffect(() => {
if (!initialTop || isInitialScrollPositionSet.current) return;
isInitialScrollPositionSet.current = true;
if (initialTop.type === 'offset') {
scrollToTableOffset(initialTop.to);
} else {
scrollToTableIndex(initialTop.to);
}
}, [initialTop, scrollToTableIndex, scrollToTableOffset]);
// Scroll to top when startRowIndex changes
useEffect(() => {
if (startRowIndex !== undefined) {
scrollToTableOffset(0);
}
}, [startRowIndex, scrollToTableOffset]);
};