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

[BD-46] refactor Pagination component #1911

Closed
Show file tree
Hide file tree
Changes from all 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
12 changes: 12 additions & 0 deletions src/Button/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,12 @@ fieldset:disabled a.btn {
$btn-tertiary-color,
$btn-tertiary-color
);

&.disabled,
&:disabled {
color: $yiq-text-dark;
}

@include button-focus(theme-color("primary", "focus"));
}

Expand All @@ -380,6 +386,12 @@ fieldset:disabled a.btn {
$btn-inverse-tertiary-color,
$btn-inverse-tertiary-color
);

&.disabled,
&:disabled {
color: $yiq-text-light;
}

@include button-focus($white);
}

Expand Down
9 changes: 7 additions & 2 deletions src/DataTable/TablePagination.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,15 @@ function TablePagination() {
const pageIndex = state?.pageIndex;

return (
<Pagination.Reduced
<Pagination
variant="reduced"
currentPage={pageIndex + 1}
handlePageSelect={(pageNum) => gotoPage(pageNum - 1)}
onPageSelect={(pageNum) => gotoPage(pageNum - 1)}
pageCount={pageCount}
icons={{
leftIcon: null,
rightIcon: null,
}}
/>
);
}
Expand Down
5 changes: 5 additions & 0 deletions src/DataTable/TablePaginationMinimal.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useContext } from 'react';
import DataTableContext from './DataTableContext';
import Pagination from '../Pagination';
import { ArrowBackIos, ArrowForwardIos } from '../../icons';

function TablePaginationMinimal() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add propTypes for this component?

Copy link
Contributor Author

@viktorrusakov viktorrusakov Oct 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This component does not receive any props, so I don't think propTypes are needed here

const {
Expand All @@ -21,6 +22,10 @@ function TablePaginationMinimal() {
pageCount={pageCount}
paginationLabel="table pagination"
onPageSelect={(pageNum) => gotoPage(pageNum - 1)}
icons={{
leftIcon: ArrowBackIos,
rightIcon: ArrowForwardIos,
}}
/>
);
}
Expand Down
12 changes: 6 additions & 6 deletions src/DataTable/tests/TablePagination.test.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { render, act } from '@testing-library/react';
import { render, act, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';

import TablePagination from '../TablePagination';
Expand Down Expand Up @@ -29,21 +29,21 @@ describe('<TablePagination />', () => {
it(
'Shows dropdown button with the page count as label and performs actions when dropdown items are clicked',
async () => {
const { getAllByTestId, getByRole } = render(<PaginationWrapper value={instance} />);
const dropdownButton = getByRole('button', { name: /2 of 3/i });
render(<PaginationWrapper value={instance} />);
const dropdownButton = screen.getByRole('button', { name: /2 of 3/i });
expect(dropdownButton).toBeInTheDocument();
await act(async () => {
await userEvent.click(dropdownButton);
});

const dropdownChoices = getAllByTestId('pagination-dropdown-item');
const dropdownChoices = screen.getAllByTestId('pagination-dropdown-item');
expect(dropdownChoices.length).toEqual(instance.pageCount);
await act(async () => {
await userEvent.click(dropdownChoices[1], undefined, { skipPointerEventsCheck: true });
await userEvent.click(dropdownChoices[2], undefined, { skipPointerEventsCheck: true });
});

expect(instance.gotoPage).toHaveBeenCalledTimes(1);
expect(instance.gotoPage).toHaveBeenCalledWith(1);
expect(instance.gotoPage).toHaveBeenCalledWith(2);
},
);
});
43 changes: 43 additions & 0 deletions src/Pagination/DefaultPagination.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import React, { useContext } from 'react';
import { useMediaQuery } from 'react-responsive';
import PaginationContext from './PaginationContext';
import { ELLIPSIS } from './constants';
import {
PreviousPageButton,
NextPageButton,
PageOfCountButton,
PageButton,
Ellipsis,
} from './subcomponents';
import breakpoints from '../utils/breakpoints';
import newId from '../utils/newId';

function PaginationPages() {
const { displayPages } = useContext(PaginationContext);
const isMobile = useMediaQuery({ maxWidth: breakpoints.extraSmall.maxWidth });

if (isMobile) {
return <PageOfCountButton />;
}

return (
<>
{displayPages.map((pageIndex) => {
if (pageIndex === ELLIPSIS) {
return <Ellipsis key={newId('pagination-ellipsis-')} />;
}
return <PageButton key={pageIndex} pageNum={pageIndex + 1} />;
})}
</>
);
}

export default function DefaultPagination() {
return (
<ul className="pagination">
<PreviousPageButton />
<PaginationPages />
<NextPageButton />
</ul>
);
}
11 changes: 11 additions & 0 deletions src/Pagination/MinimalPagination.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from 'react';
import { PreviousPageButton, NextPageButton } from './subcomponents';

export default function MinimalPagination() {
return (
<ul className="pagination">
<PreviousPageButton />
<NextPageButton />
</ul>
);
}
Loading
Loading