-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add new Pagination component using pagination custom hook * Change up data table pagination to only use the datastore functions and not react table * Use offset / limit instead of current page to keep caching of state
- Loading branch information
Showing
8 changed files
with
243 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import React, { useEffect } from 'react'; | ||
import { Button } from '@cmsgov/design-system'; | ||
import { usePagination, buildPageArray } from '@civicactions/data-catalog-services'; | ||
|
||
const Pagination = ({ | ||
currentPage, totalItems, itemsPerPage, gotoPage, | ||
}) => { | ||
const { | ||
pageIndex, | ||
pages, | ||
setPageIndex, | ||
canGoToPrevious, | ||
canGoToNext, | ||
goToNext, | ||
goToPrevious, | ||
} = usePagination(0, totalItems, itemsPerPage); | ||
const pageButtons = buildPageArray(pageIndex, 2, pages); | ||
|
||
useEffect(()=> { | ||
gotoPage((Number(pageIndex)) * itemsPerPage) | ||
}, [pageIndex]) | ||
return ( | ||
<div className="dc-pagination ds-u-display--flex ds-u-flex-direction--row ds-u-justify-content--between ds-u-align-items--center"> | ||
<Button | ||
disabled={!canGoToPrevious} | ||
className="dc-pagination--previous" | ||
size="small" | ||
variation="transparent" | ||
onClick={() => goToPrevious()} | ||
> | ||
Previous | ||
</Button> | ||
<ol className="ds-u-display--flex ds-u-flex-direction--row ds-u-padding-x--0"> | ||
{pageButtons.map((p) => { | ||
if (p === 'end') { | ||
return ( | ||
<li key={p}> | ||
<Button | ||
className={p === currentPage ? "dc-pagination-current" : ""} | ||
size="small" | ||
variation="transparent" | ||
onClick={() => setPageIndex(pages - 1)} | ||
> | ||
{pages} | ||
</Button> | ||
</li> | ||
) | ||
} else if (p === 'start') { | ||
return ( | ||
<li key={p}> | ||
<Button | ||
className={p === currentPage ? "dc-pagination-current" : ""} | ||
size="small" | ||
variation="transparent" | ||
onClick={() => setPageIndex(0)} | ||
> | ||
1 | ||
</Button> | ||
</li> | ||
) | ||
} else if (p === 'filler') { | ||
return ( | ||
<li key={p + (Math.random() * 10)}> | ||
<span>...</span> | ||
</li> | ||
) | ||
} else { | ||
return ( | ||
<li key={p}> | ||
<Button | ||
className={p === currentPage ? "dc-pagination-current" : ""} | ||
size="small" | ||
variation="transparent" | ||
onClick={() => setPageIndex(p)} | ||
> | ||
{p + 1} | ||
</Button> | ||
</li> | ||
) | ||
} | ||
})} | ||
</ol> | ||
<Button | ||
disabled={!canGoToNext} | ||
className="dc-pagination--next" | ||
size="small" | ||
variation="transparent" | ||
onClick={() => goToNext()} | ||
> | ||
Next | ||
</Button> | ||
</div> | ||
); | ||
} | ||
|
||
export default Pagination; |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
@import "./datatable.scss"; | ||
@import "./dataset-tags.scss"; | ||
@import "./dataset-downloads.scss"; | ||
@import "./dataset-downloads.scss"; | ||
@import "./pagination.scss"; |
Oops, something went wrong.