From 5d16c36231fb78f32e2e1b46e25f96cd995ffb91 Mon Sep 17 00:00:00 2001 From: Samandar Turg'unboev Date: Mon, 2 Jun 2025 15:57:24 +0500 Subject: [PATCH] pagination --- .../ui-kit/BasePagination/index.tsx | 42 ++++++++++++++++--- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/src/components/ui-kit/BasePagination/index.tsx b/src/components/ui-kit/BasePagination/index.tsx index 729f559..9041037 100644 --- a/src/components/ui-kit/BasePagination/index.tsx +++ b/src/components/ui-kit/BasePagination/index.tsx @@ -1,6 +1,7 @@ import * as React from 'react'; import Pagination from '@mui/material/Pagination'; import Stack from '@mui/material/Stack'; +import { Divider } from '@mui/material'; interface BasePaginationProps { page: number; @@ -10,15 +11,40 @@ interface BasePaginationProps { } export default function BasePagination({ page, pageSize, totalCount, onChange }: BasePaginationProps) { + const [inputValue, setInputValue] = React.useState(page); + + React.useEffect(() => { + setInputValue(page); + }, [page]); + + React.useEffect(() => { + const handler = setTimeout(() => { + const maxPage = Math.ceil(totalCount / pageSize); + let newPage = inputValue; + + if (inputValue === 0) { + newPage = 1; // Agar 0 kiritsa, 1 page ga o‘tsin + } else if (inputValue > maxPage) { + newPage = maxPage; // Max page dan oshsa, max page ga o‘tsin + } + + if (newPage !== page) { + onChange(newPage); + } + }, 1000); + + return () => clearTimeout(handler); + }, [inputValue, page, totalCount, pageSize, onChange]); + return ( - + }> onChange(newPage)} - variant='outlined' - shape='rounded' - color='primary' + variant="outlined" + shape="rounded" + color="primary" sx={{ '.Mui-selected': { backgroundColor: theme => theme.palette.primary.main, @@ -26,6 +52,12 @@ export default function BasePagination({ page, pageSize, totalCount, onChange }: }, }} /> + setInputValue(Number(e.target.value))} + /> ); -} +} \ No newline at end of file