Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve compressed EuiPagination #2779

Merged
merged 8 commits into from
Jan 24, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Converted `EuiFilterSelectItem` to TypeScript ([#2761](https://github.com/elastic/eui/pull/2761))
- Converted `EuiFieldSearch` to TypeScript ([#2775](https://github.com/elastic/eui/pull/2775))
- Added `data-test-subj` to the `EuiContextMenuItem` in `EuiTablePagination` ([#2778](https://github.com/elastic/eui/pull/2778))
- Improved compressed `EuiPagination` by including active and last page numbers ([#2779](https://github.com/elastic/eui/pull/2779))

**Bug fixes**

Expand Down
37 changes: 37 additions & 0 deletions src/components/pagination/pagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { CommonProps } from '../common';
import { EuiPaginationButton } from './pagination_button';
import { EuiButtonIcon } from '../button';
import { EuiI18n } from '../i18n';
import { EuiText } from '../text';

const MAX_VISIBLE_PAGES = 5;
const NUMBER_SURROUNDING_PAGES = Math.floor(MAX_VISIBLE_PAGES * 0.5);
Expand Down Expand Up @@ -175,9 +176,45 @@ export const EuiPagination: FunctionComponent<Props> = ({

const selectablePages = pages;
if (compressed) {
const firstPageButtonCompressed = (
<EuiI18n
token="euiPagination.pageOfTotal"
default="Page {page} of {total}"
values={{ page: activePage + 1, total: pageCount }}>
{(pageOfTotal: string) => (
<EuiPaginationButton
onClick={onPageClick.bind(null, 0)}
hideOnMobile
isActive={true}
aria-label={pageOfTotal}>
{activePage + 1}
</EuiPaginationButton>
)}
</EuiI18n>
);
const lastPageButtonCompressed = (
<EuiI18n
token="euiPagination.jumpToLastPage"
default="Jump to the last page, number {pageCount}"
values={{ pageCount }}>
{(jumpToLastPage: string) => (
<EuiPaginationButton
onClick={onPageClick.bind(null, pageCount - 1)}
hideOnMobile
aria-label={jumpToLastPage}>
{pageCount}
</EuiPaginationButton>
)}
</EuiI18n>
);
andreadelrio marked this conversation as resolved.
Show resolved Hide resolved
return (
<div className={classes} {...rest}>
{previousButton}
{firstPageButtonCompressed}
<EuiText size="s">
<EuiI18n token="euiPagination.of" default="of" />
</EuiText>
{lastPageButtonCompressed}
{nextButton}
</div>
);
Expand Down