-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Expand file tree
/
Copy pathindex.tsx
More file actions
77 lines (68 loc) · 1.86 KB
/
index.tsx
File metadata and controls
77 lines (68 loc) · 1.86 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
import { ArrowRightIcon, ArrowLeftIcon } from '@heroicons/react/20/solid';
import type { FC } from 'react';
import Button from '#ui/Common/BaseButton';
import { useGetPageElements } from '#ui/Common/BasePagination/useGetPageElements';
import type { LinkLike } from '#ui/types';
import styles from './index.module.css';
type Page = { url: string };
export type PaginationProps = {
// One-based number of the current page
currentPage: number;
pages: Array<Page>;
// The number of page buttons on each side of the current page button
// @default 1
currentPageSiblingsCount?: number;
as?: LinkLike;
getPageLabel: (pageNumber: number) => string;
labels: {
aria: string;
prevAria: string;
prev: string;
nextAria: string;
next: string;
};
};
const BasePagination: FC<PaginationProps> = ({
currentPage,
pages,
as = 'a',
currentPageSiblingsCount = 1,
labels,
getPageLabel,
}) => {
const parsedPages = useGetPageElements(
currentPage,
pages,
currentPageSiblingsCount,
as,
getPageLabel
);
return (
<nav aria-label={labels.aria} className={styles.pagination}>
<Button
as={as}
aria-label={labels.prevAria}
disabled={currentPage === 1}
kind="secondary"
className={styles.previousButton}
href={pages[currentPage - 2]?.url}
>
<ArrowLeftIcon className={styles.arrowIcon} />
<span>{labels.prev}</span>
</Button>
<ol className={styles.list}>{parsedPages}</ol>
<Button
as={as}
aria-label={labels.nextAria}
disabled={currentPage === pages.length}
kind="secondary"
className={styles.nextButton}
href={pages[currentPage]?.url}
>
<span>{labels.next}</span>
<ArrowRightIcon className={styles.arrowIcon} />
</Button>
</nav>
);
};
export default BasePagination;