diff --git a/src/App.tsx b/src/App.tsx
index 189a990c8..4a103df3d 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -1,17 +1,27 @@
import React from 'react';
import './App.css';
import { getNumbers } from './utils';
+import { useState } from 'react';
+import { Pagination } from './components/Pagination';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const items = getNumbers(1, 42).map(n => `Item ${n}`);
export const App: React.FC = () => {
+ const [perPage, setPerPage] = useState(Number('5'));
+ const [currentPage, setCurrentPage] = useState(1);
+ const lastItems = perPage * currentPage;
+ const firstItem = lastItems - perPage;
+
+ const newItems = items.slice(firstItem, lastItems);
+
return (
Items with Pagination
- Page 1 (items 1 - 5 of 42)
+ Page {currentPage} (items {firstItem + 1} -{' '}
+ {lastItems > items.length ? items.length : lastItems} of {items.length})
@@ -19,7 +29,13 @@ export const App: React.FC = () => {
- {/* Move this markup to Pagination */}
-
+
- - Item 1
- - Item 2
- - Item 3
- - Item 4
- - Item 5
+ {newItems.map(item => (
+ -
+ {item}
+
+ ))}
);
diff --git a/src/components/Pagination/Pagination.tsx b/src/components/Pagination/Pagination.tsx
index e417a09fc..f1b6962e4 100644
--- a/src/components/Pagination/Pagination.tsx
+++ b/src/components/Pagination/Pagination.tsx
@@ -1 +1,72 @@
-export const Pagination = () => {};
+import cn from 'classnames';
+import React from 'react';
+import { getNumbers } from '../../utils';
+
+type Props = {
+ total: number;
+ perPage: number;
+ currentPage: number;
+ onPageChange: (page: number) => void;
+};
+export const Pagination: React.FC = ({
+ total,
+ perPage,
+ currentPage = 1,
+ onPageChange,
+}) => {
+ const pageCount = Math.ceil(total / perPage);
+ const listItems = getNumbers(1, pageCount).map(n => n);
+
+ const handlePageChange = (page: number) => {
+ if (page !== currentPage && page >= 1 && page <= pageCount) {
+ onPageChange(page);
+ }
+ };
+
+ return (
+
+ );
+};