diff --git a/README.md b/README.md index be8a8c6b6..30901a161 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ > Here is the [working version](https://mate-academy.github.io/react_pagination/) -You a given a list of items and markup for the `Pagination`. Implement the +You a given a list of items and markup for the `Pagination`. Implement the `Pagination` as a stateless component to show only the items for a current page. 1. The `Pagination` should be used with the next props: @@ -24,7 +24,7 @@ You a given a list of items and markup for the `Pagination`. Implement the 1. Show the pagination info inside `data-cy="info"` in the next format `Page 1 (items 1 - 5 of 42)`; 1. Implement the ` + className="form-control" + value={perPage} + onChange={handleSelectChange} + > @@ -32,78 +56,19 @@ export const App: React.FC = () => { - {/* Move this markup to Pagination */} - + + ); diff --git a/src/components/Pagination/Pagination.tsx b/src/components/Pagination/Pagination.tsx index e417a09fc..02567e7e3 100644 --- a/src/components/Pagination/Pagination.tsx +++ b/src/components/Pagination/Pagination.tsx @@ -1 +1,86 @@ -export const Pagination = () => {}; +import React from 'react'; +import classNames from 'classnames'; +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 pagesCount = Math.ceil(total / perPage); + const pages = getNumbers(1, pagesCount); + + return ( + + ); +}; diff --git a/src/index.tsx b/src/index.tsx index 226f3f4bd..202bc516f 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -1,5 +1,10 @@ import { createRoot } from 'react-dom/client'; +import { BrowserRouter } from 'react-router-dom'; import { App } from './App'; -createRoot(document.getElementById('root') as HTMLElement).render(); +createRoot(document.getElementById('root') as HTMLElement).render( + + + , +);