File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -48,14 +48,21 @@ const calculateVisiblePages = (
4848 return pages
4949}
5050
51+ type CalculatePaginationConfig = {
52+ indexType : IndexType
53+ maxPages : number
54+ }
55+
56+ const defaultCalculatePaginationConfig : CalculatePaginationConfig = {
57+ indexType : IndexType . ONE_BASED ,
58+ maxPages : 5 ,
59+ }
60+
5161const calculatePagination = (
5262 page : number ,
5363 size : number ,
5464 total : number ,
55- config ?: {
56- indexType ?: IndexType
57- maxPages ?: number
58- }
65+ config ?: Partial < CalculatePaginationConfig >
5966) : {
6067 previous : {
6168 indexNumber : number
@@ -71,13 +78,15 @@ const calculatePagination = (
7178 isCurrent : boolean
7279 } [ ]
7380} | null => {
81+ const { indexType, maxPages } = {
82+ ...defaultCalculatePaginationConfig ,
83+ ...config ,
84+ }
85+
7486 if ( total <= size ) {
7587 return null
7688 }
7789
78- const indexType = config ?. indexType ?? IndexType . ONE_BASED
79- const maxPages = config ?. maxPages ?? 5
80-
8190 const firstPage = indexType === IndexType . ZERO_BASED ? 0 : 1
8291 const lastPage = Math . ceil ( total / size ) + ( firstPage - 1 )
8392 const isCurrentTheFirstPage = page === firstPage
You can’t perform that action at this time.
0 commit comments