-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Expand file tree
/
Copy pathindex.js
More file actions
99 lines (97 loc) · 2.66 KB
/
index.js
File metadata and controls
99 lines (97 loc) · 2.66 KB
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
98
99
/**
* External dependencies
*/
import clsx from 'clsx';
/**
* WordPress dependencies
*/
import {
__experimentalHStack as HStack,
__experimentalText as Text,
Button,
} from '@wordpress/components';
import { __, _x, _n, sprintf } from '@wordpress/i18n';
export default function Pagination( {
currentPage,
numPages,
changePage,
totalItems,
className,
disabled = false,
buttonVariant = 'tertiary',
label = __( 'Pagination Navigation' ),
} ) {
return (
<HStack
expanded={ false }
as="nav"
aria-label={ label }
spacing={ 3 }
justify="flex-start"
className={ clsx( 'edit-site-pagination', className ) }
>
<Text variant="muted" className="edit-site-pagination__total">
{
// translators: %s: Total number of patterns.
sprintf(
// translators: %s: Total number of patterns.
_n( '%s item', '%s items', totalItems ),
totalItems
)
}
</Text>
<HStack expanded={ false } spacing={ 1 }>
<Button
variant={ buttonVariant }
onClick={ () => changePage( 1 ) }
// Disable reason: Would not cause confusion, and allows quicker access to a relevant nav button.
// eslint-disable-next-line no-restricted-syntax
disabled={ disabled || currentPage === 1 }
aria-label={ __( 'First page' ) }
>
«
</Button>
<Button
variant={ buttonVariant }
onClick={ () => changePage( currentPage - 1 ) }
// Disable reason: Would not cause confusion, and allows quicker access to a relevant nav button.
// eslint-disable-next-line no-restricted-syntax
disabled={ disabled || currentPage === 1 }
aria-label={ __( 'Previous page' ) }
>
‹
</Button>
</HStack>
<Text variant="muted">
{ sprintf(
// translators: %1$s: Current page number, %2$s: Total number of pages.
_x( '%1$s of %2$s', 'paging' ),
currentPage,
numPages
) }
</Text>
<HStack expanded={ false } spacing={ 1 }>
<Button
variant={ buttonVariant }
onClick={ () => changePage( currentPage + 1 ) }
// Disable reason: Would not cause confusion, and allows quicker access to a relevant nav button.
// eslint-disable-next-line no-restricted-syntax
disabled={ disabled || currentPage === numPages }
aria-label={ __( 'Next page' ) }
>
›
</Button>
<Button
variant={ buttonVariant }
onClick={ () => changePage( numPages ) }
// Disable reason: Would not cause confusion, and allows quicker access to a relevant nav button.
// eslint-disable-next-line no-restricted-syntax
disabled={ disabled || currentPage === numPages }
aria-label={ __( 'Last page' ) }
>
»
</Button>
</HStack>
</HStack>
);
}