mirror of
https://github.com/jeffvli/feishin.git
synced 2026-06-14 23:44:01 +02:00
split out item list table functionality
This commit is contained in:
+43
@@ -0,0 +1,43 @@
|
||||
import { useEffect, useImperativeHandle, useMemo } from 'react';
|
||||
|
||||
import { ItemListHandle, ItemListStateActions } from '/@/renderer/components/item-list/types';
|
||||
|
||||
interface UseTableImperativeHandleProps {
|
||||
enableHeader: boolean;
|
||||
handleRef: React.RefObject<ItemListHandle | null>;
|
||||
internalState: ItemListStateActions;
|
||||
ref?: React.Ref<ItemListHandle>;
|
||||
scrollToTableIndex: (index: number, options?: { align?: 'bottom' | 'center' | 'top' }) => void;
|
||||
scrollToTableOffset: (offset: number) => void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook to set up the imperative handle for ItemTableList, providing scroll methods and internal state.
|
||||
*/
|
||||
export const useTableImperativeHandle = ({
|
||||
enableHeader,
|
||||
handleRef,
|
||||
internalState,
|
||||
ref,
|
||||
scrollToTableIndex,
|
||||
scrollToTableOffset,
|
||||
}: UseTableImperativeHandleProps) => {
|
||||
const imperativeHandle: ItemListHandle = useMemo(
|
||||
() => ({
|
||||
internalState,
|
||||
scrollToIndex: (index: number, options?: { align?: 'bottom' | 'center' | 'top' }) => {
|
||||
scrollToTableIndex(enableHeader ? index + 1 : index, options);
|
||||
},
|
||||
scrollToOffset: (offset: number) => {
|
||||
scrollToTableOffset(offset);
|
||||
},
|
||||
}),
|
||||
[enableHeader, internalState, scrollToTableIndex, scrollToTableOffset],
|
||||
);
|
||||
|
||||
useImperativeHandle(ref, () => imperativeHandle);
|
||||
|
||||
useEffect(() => {
|
||||
handleRef.current = imperativeHandle;
|
||||
}, [handleRef, imperativeHandle]);
|
||||
};
|
||||
Reference in New Issue
Block a user