Compare commits

..
2 changed files with 8 additions and 19 deletions
+7 -18
View File
@@ -95,10 +95,7 @@ export type ElementProps<TableRowData extends object | CustomRowConfig, TableRow
selectionBehavior?: 'replace' | 'toggle'; selectionBehavior?: 'replace' | 'toggle';
onRowAction?: (key: TableRowKey, row: TableRowData) => void; onRowAction?: (key: TableRowKey, row: TableRowData) => void;
slotEmpty?: React.ReactNode; slotEmpty?: React.ReactNode;
viewMoreConfig?: { initialNumRowsToShow?: number;
initialNumRowsToShow: number;
numRowsPerPage?: number;
};
// collection: TableCollection<string>; // collection: TableCollection<string>;
// children: React.ReactNode; // children: React.ReactNode;
}; };
@@ -128,7 +125,7 @@ export const Table = <TableRowData extends object, TableRowKey extends Key>({
selectionMode = 'single', selectionMode = 'single',
selectionBehavior = 'toggle', selectionBehavior = 'toggle',
slotEmpty, slotEmpty,
viewMoreConfig, initialNumRowsToShow,
// shouldRowRender, // shouldRowRender,
// collection, // collection,
@@ -144,18 +141,8 @@ export const Table = <TableRowData extends object, TableRowKey extends Key>({
style, style,
}: ElementProps<TableRowData, TableRowKey> & StyleProps) => { }: ElementProps<TableRowData, TableRowKey> & StyleProps) => {
const [selectedKeys, setSelectedKeys] = useState(new Set<TableRowKey>()); const [selectedKeys, setSelectedKeys] = useState(new Set<TableRowKey>());
const [numRowsToShow, setNumRowsToShow] = useState(viewMoreConfig?.initialNumRowsToShow); const [numRowsToShow, setNumRowsToShow] = useState(initialNumRowsToShow);
const enableViewMore = viewMoreConfig !== undefined; const enableViewMore = numRowsToShow !== undefined;
const onViewMoreClick = () => {
if (!viewMoreConfig) return;
const { numRowsPerPage } = viewMoreConfig;
if (numRowsPerPage) {
setNumRowsToShow((prev) => (prev ?? 0) + numRowsPerPage);
} else {
setNumRowsToShow(data.length);
}
};
const currentBreakpoints = useBreakpoints(); const currentBreakpoints = useBreakpoints();
const shownColumns = columns.filter( const shownColumns = columns.filter(
@@ -231,7 +218,9 @@ export const Table = <TableRowData extends object, TableRowKey extends Key>({
} }
numColumns={shownColumns.length} numColumns={shownColumns.length}
onViewMoreClick={ onViewMoreClick={
enableViewMore && numRowsToShow! < data.length ? onViewMoreClick : undefined enableViewMore && numRowsToShow < data.length
? () => setNumRowsToShow(data.length)
: undefined
} }
// shouldRowRender={shouldRowRender} // shouldRowRender={shouldRowRender}
hideHeader={hideHeader} hideHeader={hideHeader}
@@ -121,7 +121,7 @@ export const TradingRewardHistoryTable = ({
selectionBehavior="replace" selectionBehavior="replace"
withOuterBorder={withOuterBorder} withOuterBorder={withOuterBorder}
withInnerBorders={withInnerBorders} withInnerBorders={withInnerBorders}
viewMoreConfig={{ initialNumRowsToShow: 5, numRowsPerPage: 10 }} initialNumRowsToShow={5}
withScrollSnapColumns withScrollSnapColumns
withScrollSnapRows withScrollSnapRows
/> />