@@ -10,10 +10,8 @@ import {
1010 Pagination ,
1111 PaginationContent ,
1212 PaginationItem ,
13- PaginationLink ,
1413 PaginationPrevious ,
1514 PaginationNext ,
16- PaginationEllipsis ,
1715} from '@/components/auth0/shared/pagination' ;
1816import {
1917 Select ,
@@ -44,12 +42,12 @@ export const defaultLabels: DataPaginationLabels = {
4442 showing : 'Showing' ,
4543 to : 'to' ,
4644 of : 'of' ,
47- results : 'results ' ,
45+ results : '' ,
4846 totalResults : 'total results' ,
49- show : 'Show ' ,
47+ show : '' ,
5048 perPage : 'per page' ,
51- previous : 'Previous ' ,
52- next : 'Next ' ,
49+ previous : '' ,
50+ next : '' ,
5351 goToPage : 'Go to page {page}' ,
5452 goToPrevious : 'Go to previous page' ,
5553 goToNext : 'Go to next page' ,
@@ -66,6 +64,7 @@ export interface RegularPaginationState {
6664
6765export interface CheckpointPaginationState {
6866 pageSize : number ;
67+ currentPage ?: number ;
6968 totalItems ?: number ;
7069 hasNextPage : boolean ;
7170 hasPreviousPage : boolean ;
@@ -96,32 +95,6 @@ const formatNumber = (num: number | undefined | null, locale?: string): string =
9695 return num . toLocaleString ( resolvedLocale ) ;
9796} ;
9897
99- const interpolate = ( str : string , values : Record < string , string | number > ) : string =>
100- str . replace ( / \{ ( \w + ) \} / g, ( _ , key ) => String ( values [ key ] ?? '' ) ) ;
101-
102- const generatePageNumbers = (
103- currentPage : number ,
104- totalPages : number ,
105- maxVisible : number = 5 ,
106- ) : ( number | 'ellipsis' ) [ ] => {
107- if ( totalPages <= maxVisible ) return Array . from ( { length : totalPages } , ( _ , i ) => i + 1 ) ;
108-
109- const pages : ( number | 'ellipsis' ) [ ] = [ 1 ] ;
110- const range = Math . floor ( ( maxVisible - 3 ) / 2 ) ;
111- let start = Math . max ( 2 , currentPage - range ) ;
112- let end = Math . min ( totalPages - 1 , currentPage + range ) ;
113-
114- if ( currentPage <= range + 2 ) end = maxVisible - 2 ;
115- if ( currentPage >= totalPages - range - 1 ) start = totalPages - ( maxVisible - 2 ) ;
116-
117- if ( start > 2 ) pages . push ( 'ellipsis' ) ;
118- for ( let i = start ; i <= end ; i ++ ) pages . push ( i ) ;
119- if ( end < totalPages - 1 ) pages . push ( 'ellipsis' ) ;
120- pages . push ( totalPages ) ;
121-
122- return pages ;
123- } ;
124-
12598/**
12699 *
127100 * @param props - Component props.
@@ -170,18 +143,6 @@ export function DataPagination({
170143 return Array . from ( uniqueOptions ) . sort ( ( a , b ) => a - b ) ;
171144 } , [ shouldShowPageSizeSelector , pageSizeOptions , currentPageSize ] ) ;
172145
173- const pageNumbers = useMemo (
174- ( ) =>
175- isRegular && regularState
176- ? generatePageNumbers (
177- regularState . currentPage ,
178- regularState . totalPages ,
179- regularState . maxVisiblePages ,
180- )
181- : [ ] ,
182- [ isRegular , regularState ] ,
183- ) ;
184-
185146 useEffect ( ( ) => {
186147 if ( ariaLiveRegionRef . current ) {
187148 if ( isRegular && regularState ) {
@@ -196,7 +157,6 @@ export function DataPagination({
196157 return null ;
197158 }
198159
199- const shouldShowPageNumbers = isRegular ;
200160 const safeCurrentPageSize = currentPageSize as number ;
201161
202162 return (
@@ -223,9 +183,7 @@ export function DataPagination({
223183 : ( regularState . currentPage - 1 ) * regularState . pageSize + 1 ,
224184 locale ,
225185 ) }
226- </ span > { ' ' }
227- { labels . to } { ' ' }
228- < span className = "font-medium text-foreground" >
186+ -
229187 { formatNumber (
230188 Math . min (
231189 regularState . currentPage * regularState . pageSize ,
@@ -237,8 +195,34 @@ export function DataPagination({
237195 { labels . of } { ' ' }
238196 < span className = "font-medium text-foreground" >
239197 { formatNumber ( regularState . totalItems , locale ) }
198+ </ span >
199+ { labels . results && < > { labels . results } </ > }
200+ </ >
201+ ) : checkpointState ?. totalItems !== undefined &&
202+ checkpointState ?. currentPage !== undefined ? (
203+ < >
204+ { labels . showing } { ' ' }
205+ < span className = "font-medium text-foreground" >
206+ { formatNumber (
207+ checkpointState . totalItems === 0
208+ ? 0
209+ : ( checkpointState . currentPage - 1 ) * checkpointState . pageSize + 1 ,
210+ locale ,
211+ ) }
212+ -
213+ { formatNumber (
214+ Math . min (
215+ checkpointState . currentPage * checkpointState . pageSize ,
216+ checkpointState . totalItems ,
217+ ) ,
218+ locale ,
219+ ) }
240220 </ span > { ' ' }
241- { labels . results }
221+ { labels . of } { ' ' }
222+ < span className = "font-medium text-foreground" >
223+ { formatNumber ( checkpointState . totalItems , locale ) }
224+ </ span >
225+ { labels . results && < > { labels . results } </ > }
242226 </ >
243227 ) : checkpointState ?. totalItems !== undefined ? (
244228 < >
@@ -254,7 +238,7 @@ export function DataPagination({
254238 < div className = "flex flex-col gap-4 sm:flex-row sm:items-center" >
255239 { shouldShowPageSizeSelector && allPageSizeOptions . length > 0 && (
256240 < div className = "flex items-center justify-center gap-2 whitespace-nowrap sm:justify-start" >
257- < span className = "text-sm text-foreground" > { labels . show } </ span >
241+ { labels . show && < span className = "text-sm text-foreground" > { labels . show } </ span > }
258242 < Select
259243 value = { safeCurrentPageSize . toString ( ) }
260244 onValueChange = { ( value ) => onPageSizeChange ?.( Number ( value ) ) }
@@ -291,28 +275,6 @@ export function DataPagination({
291275 />
292276 </ PaginationItem >
293277
294- { shouldShowPageNumbers &&
295- pageNumbers . map ( ( page , idx ) => (
296- < PaginationItem key = { `page-${ idx } ` } >
297- { page === 'ellipsis' ? (
298- < PaginationEllipsis >
299- < span className = "sr-only" > { labels . morePages } </ span >
300- </ PaginationEllipsis >
301- ) : (
302- < PaginationLink
303- onClick = { ( ) => onPageChange ?.( page ) }
304- isActive = { regularState . currentPage === page }
305- aria-label = { interpolate ( labels . goToPage , {
306- page : formatNumber ( page , locale ) ,
307- } ) }
308- aria-current = { regularState . currentPage === page ? 'page' : undefined }
309- >
310- { formatNumber ( page , locale ) }
311- </ PaginationLink >
312- ) }
313- </ PaginationItem >
314- ) ) }
315-
316278 < PaginationItem >
317279 < PaginationNext
318280 label = { labels . next }
0 commit comments