Skip to content

Commit

Permalink
feat(paginator): navigation by clicking on page number
Browse files Browse the repository at this point in the history
  • Loading branch information
Ali Obaji committed Sep 18, 2019
1 parent 29b3c61 commit f0ad656
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const IndexPage: NextPage = (props: Props) => {
</div>
</div>
<div className="pagination">
<Paginator handlePaginationChange={(event) => updateSkip(event)} range={range}/>
<Paginator handlePaginationChange={(event) => updateSkip(event)} range={range} skip={2}/>
</div>
</div>
</Layout>
Expand Down
12 changes: 10 additions & 2 deletions shared/components/paginator/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, {FunctionComponent, Fragment, useState, useEffect} from 'react';
import './styles.css';
import {render} from "react-dom";

type Props = {
skip?: number;
Expand All @@ -12,6 +11,10 @@ const Paginator: FunctionComponent<Props> = ({skip, range, handlePaginationChang

const [page, setPageNumber] = useState(1);

// useEffect(() => {
// return setPageNumber(skip);
// }, [skip]);

const moveToNextPage = () => {
if (page > 1) {
handlePaginationChange(page - 1);
Expand All @@ -30,6 +33,11 @@ const Paginator: FunctionComponent<Props> = ({skip, range, handlePaginationChang
return null;
};

const moveToPage = (pageNumber: number) => {
handlePaginationChange(pageNumber);
return setPageNumber(pageNumber);
};

return (
<Fragment>
<div className="paginator">
Expand All @@ -41,7 +49,7 @@ const Paginator: FunctionComponent<Props> = ({skip, range, handlePaginationChang
{range.map((num, index) => {
return (<span
className={`paginator__page-number ${num === page ? 'paginator__page-number--selected' : ''}`}
key={index} onClick={() => setPageNumber(num)}>{num}</span>)
key={index} onClick={() => moveToPage(num)}>{num}</span>)
})}

{range.length > 1 ?
Expand Down
4 changes: 2 additions & 2 deletions shared/components/paginator/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

cursor: pointer;

transition: all .3s;
/*transition: all .2s;*/
}

.paginator__page-number:hover {
Expand All @@ -24,7 +24,7 @@
border: 1px solid #00AFDA;
background-color: rgba(39, 173, 213, .2);

transition: all .3s;
/*transition: all .2s;*/
}

.paginator__button {
Expand Down

0 comments on commit f0ad656

Please sign in to comment.