-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
pagination.js
97 lines (95 loc) · 2.24 KB
/
pagination.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/**
* WordPress dependencies
*/
import {
Button,
__experimentalHStack as HStack,
SelectControl,
} from '@wordpress/components';
import { createInterpolateElement, memo } from '@wordpress/element';
import { sprintf, __, _x } from '@wordpress/i18n';
import { chevronRight, chevronLeft } from '@wordpress/icons';
const Pagination = memo( function Pagination( {
view,
onChangeView,
paginationInfo: { totalItems = 0, totalPages },
} ) {
if ( ! totalItems || ! totalPages ) {
return null;
}
return (
!! totalItems &&
totalPages !== 1 && (
<HStack
expanded={ false }
spacing={ 6 }
justify="end"
className="dataviews-pagination"
>
<HStack
justify="flex-start"
expanded={ false }
spacing={ 2 }
className="dataviews-pagination__page-selection"
>
{ createInterpolateElement(
sprintf(
// translators: %s: Total number of pages.
_x( 'Page <CurrentPageControl /> of %s', 'paging' ),
totalPages
),
{
CurrentPageControl: (
<SelectControl
aria-label={ __( 'Current page' ) }
value={ view.page }
options={ Array.from(
Array( totalPages )
).map( ( _, i ) => {
const page = i + 1;
return { value: page, label: page };
} ) }
onChange={ ( newValue ) => {
onChangeView( {
...view,
page: +newValue,
} );
} }
size={ 'compact' }
__nextHasNoMarginBottom
/>
),
}
) }
</HStack>
<HStack expanded={ false } spacing={ 1 }>
<Button
onClick={ () =>
onChangeView( { ...view, page: view.page - 1 } )
}
disabled={ view.page === 1 }
__experimentalIsFocusable
label={ __( 'Previous page' ) }
icon={ chevronLeft }
showTooltip
size="compact"
tooltipPosition="top"
/>
<Button
onClick={ () =>
onChangeView( { ...view, page: view.page + 1 } )
}
disabled={ view.page >= totalPages }
__experimentalIsFocusable
label={ __( 'Next page' ) }
icon={ chevronRight }
showTooltip
size="compact"
tooltipPosition="top"
/>
</HStack>
</HStack>
)
);
} );
export default Pagination;