refactor(client): extract useClientPagination hook and clean up Select prop
- Replace duplicated page/rowsPerPage state in Team, Notifications and Status Pages tables with a shared useClientPagination hook - Drop unused placeholderColor prop from Select; placeholder always uses secondary text - Restore LAYOUT.MD constant for the account menu item gap
This commit is contained in:
1 parent
25735df0c6
commit
897204ead3
6 files changed
+57
-109
No files matched your search
@@ -0,0 +1,37 @@
|
||||
import { useState } from "react";
|
||||
|
||||
export const useClientPagination = <T>(rows: T[], initialRowsPerPage = 10) => {
|
||||
const [page, setPage] = useState(0);
|
||||
const [rowsPerPage, setRowsPerPage] = useState(initialRowsPerPage);
|
||||
|
||||
const handlePageChange = (
|
||||
_e: React.MouseEvent<HTMLButtonElement> | null,
|
||||
newPage: number
|
||||
) => {
|
||||
setPage(newPage);
|
||||
};
|
||||
|
||||
const handleRowsPerPageChange = (
|
||||
e: React.ChangeEvent<HTMLTextAreaElement | HTMLInputElement>
|
||||
) => {
|
||||
setPage(0);
|
||||
setRowsPerPage(Number(e.target.value));
|
||||
};
|
||||
|
||||
const pagedRows = rows.slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage);
|
||||
|
||||
return {
|
||||
page,
|
||||
rowsPerPage,
|
||||
pagedRows,
|
||||
paginationProps: {
|
||||
component: "div" as const,
|
||||
count: rows.length,
|
||||
page,
|
||||
rowsPerPage,
|
||||
onPageChange: handlePageChange,
|
||||
onRowsPerPageChange: handleRowsPerPageChange,
|
||||
itemsOnPage: pagedRows.length,
|
||||
},
|
||||
};
|
||||
};
|
||||
Reference in new issue
Block a user