-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPagination.tsx
More file actions
executable file
·68 lines (62 loc) · 1.99 KB
/
Pagination.tsx
File metadata and controls
executable file
·68 lines (62 loc) · 1.99 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
import React from "react";
import { PaginationProps } from "./Pagination.types";
import { NavigationButton } from "./NavigationButton";
import { DOTS } from "./UsePagination";
const Pagination: React.FC<PaginationProps> = ({
previous,
next,
items,
className,
}) => {
if (!previous && !next && (!items || items.length === 0)) return null;
// Block layout is used when there are no numbered page items — govuk renders
// the nav with an extra class and the link title with --decorated modifier.
const isBlockLayout = !items || items.length === 0;
return (
<nav
className={`govuk-pagination${isBlockLayout ? " govuk-pagination--block" : ""}${className ? ` ${className}` : ""}`}
role="navigation"
aria-label="Pagination"
>
{previous && (
<div className="govuk-pagination__prev">
<NavigationButton type="previous" {...previous} />
</div>
)}
{items && items.length > 0 && (
<ul className="govuk-pagination__list">
{items.map((item, index) =>
item.ellipsis ? (
<li
key={index}
className="govuk-pagination__item govuk-pagination__item--ellipses"
>
{DOTS}
</li>
) : (
<li
key={index}
className={`govuk-pagination__item${item.current ? " govuk-pagination__item--current" : ""}`}
>
<a
className="govuk-link govuk-pagination__link"
href={item.href ?? "#"}
aria-label={`Page ${item.number}`}
{...(item.current ? { "aria-current": "page" } : {})}
>
{item.number}
</a>
</li>
),
)}
</ul>
)}
{next && (
<div className="govuk-pagination__next">
<NavigationButton type="next" {...next} />
</div>
)}
</nav>
);
};
export default Pagination;