@campxdev/shared 1.11.36 → 1.11.38

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@campxdev/shared",
3
- "version": "1.11.36",
3
+ "version": "1.11.38",
4
4
  "main": "./exports.ts",
5
5
  "scripts": {
6
6
  "start": "react-scripts start",
@@ -5,17 +5,25 @@ import {
5
5
  IconButton,
6
6
  ListItemIcon,
7
7
  MenuItem,
8
+ Stack,
8
9
  Table,
9
10
  TableCell,
10
11
  TableHead,
11
12
  TableRow,
13
+ TextField,
12
14
  Typography,
13
15
  } from '@mui/material'
14
- import { useEffect, useMemo, useState } from 'react'
16
+ import { useCallback, useEffect, useMemo, useState } from 'react'
15
17
  import { usePagination, useRowSelect, useTable } from 'react-table'
16
- import TableFooter from '../BasicTable/TableFooter'
18
+ import { debounce } from '../../../utils/debounce'
19
+ import TableStats from '../common/TableStats'
17
20
  import { SortAscIcon, SortDescIcon, SortIcon } from '../common/icons'
18
- import { StyledLimitBox, StyledLimitMenu } from '../common/styles'
21
+ import {
22
+ StyledLimitBox,
23
+ StyledLimitMenu,
24
+ StyledPagination,
25
+ StyledTableFooter,
26
+ } from '../common/styles'
19
27
  import { ColumnProps, Sort, TableProps } from '../common/types'
20
28
  import BatchActionsHeader from './BatchActionsHeader'
21
29
  import { RenderTableBody } from './RenderTableBody'
@@ -135,6 +143,12 @@ export default function ReactTable({
135
143
  hooks.visibleColumns.push((columns) => [selectColumn, ...columns])
136
144
  },
137
145
  )
146
+ const [pageInput, setPageInput] = useState<string>(String(pageIndex + 1))
147
+
148
+ const debouncedHandlePagination = useCallback(
149
+ debounce((e, value) => handlePagination(e, value), 500),
150
+ [],
151
+ )
138
152
 
139
153
  const handleSortClick = (sortBykey) => {
140
154
  setSort((prev) => {
@@ -226,14 +240,46 @@ export default function ReactTable({
226
240
  />
227
241
  </Table>
228
242
  {pagination && dataSource && !loading && (
229
- <TableFooter
230
- page={pagination.page + 1}
231
- limit={pagination.limit}
232
- totalCount={pagination.totalCount ?? 0}
233
- handlePagination={pagination.onChange}
234
- handlePageLimit={pagination.onChangeLimit}
235
- handlePageInput={pagination.handlePageInput}
236
- />
243
+ <StyledTableFooter>
244
+ <TableStats
245
+ limit={pageSize}
246
+ page={pageIndex + 1}
247
+ totalCount={pageCount}
248
+ />
249
+ <Stack direction={'row'} gap={2} alignItems={'center'}>
250
+ <StyledPagination
251
+ variant="outlined"
252
+ shape="rounded"
253
+ onChange={handlePagination}
254
+ count={Math.ceil(pageCount / pageSize)}
255
+ page={pageIndex + 1}
256
+ />
257
+ {pagination.handlePageInput && (
258
+ <Box
259
+ sx={{
260
+ '& .MuiBox-root': {
261
+ display: 'flex',
262
+ alignItems: 'center',
263
+ gap: '5px',
264
+ },
265
+ }}
266
+ >
267
+ <TextField
268
+ variant="outlined"
269
+ label={'Page :'}
270
+ size="small"
271
+ value={pageInput}
272
+ onChange={(e) => {
273
+ setPageInput(e.target.value)
274
+ debouncedHandlePagination(e, Number(e.target.value))
275
+ }}
276
+ sx={{ width: '80px' }}
277
+ />
278
+ </Box>
279
+ )}
280
+ </Stack>
281
+ <Limit pageSize={pageSize} setPageSize={setPageSize} />
282
+ </StyledTableFooter>
237
283
  )}
238
284
  </>
239
285
  )
@@ -25,7 +25,7 @@ export interface TableProps {
25
25
  totalCount: number
26
26
  onChange: (offset: number) => void
27
27
  onChangeLimit?: (v: number) => void
28
- handlePageInput?: (v: number) => void
28
+ handlePageInput?: boolean
29
29
  }
30
30
  select?: {
31
31
  enable: boolean
@@ -0,0 +1,11 @@
1
+ export function debounce(func, wait) {
2
+ let timeout
3
+ return function executedFunction(...args) {
4
+ const later = () => {
5
+ clearTimeout(timeout)
6
+ func(...args)
7
+ }
8
+ clearTimeout(timeout)
9
+ timeout = setTimeout(later, wait)
10
+ }
11
+ }