Skip to content

Commit

Permalink
feat: refactor Pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
viktorrusakov committed Jan 13, 2023
1 parent 865ca93 commit e2cd9f2
Show file tree
Hide file tree
Showing 21 changed files with 806 additions and 696 deletions.
12 changes: 12 additions & 0 deletions src/Button/Button.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
7 changes: 6 additions & 1 deletion src/DataTable/TablePaginationMinimal.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useContext } from 'react';
import { Pagination } from '..';
import DataTableContext from './DataTableContext';
import { Pagination } from '..';
import { ArrowBackIos, ArrowForwardIos } from '../../icons';

function TablePaginationMinimal() {
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
41 changes: 41 additions & 0 deletions src/Pagination/DefaultPagination.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import React, { useContext } from 'react';
import { useMediaQuery } from 'react-responsive';
import PaginationContext from './PaginationContext';
import PreviousPageButton from './subcomponents/PreviousPageButton';
import NextPageButton from './subcomponents/NextPageButton';
import PageOfCountButton from './subcomponents/PageOfCountButton';
import breakpoints from '../utils/breakpoints';
import { ELLIPSIS } from './constants';
import Ellipsis from './subcomponents/Ellipsis';
import newId from '../utils/newId';
import PageButton from './subcomponents/PageButton';

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

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} />;
})}
</>
);
}
12 changes: 12 additions & 0 deletions src/Pagination/MinimalPagination.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from 'react';
import PreviousPageButton from './subcomponents/PreviousPageButton';
import NextPageButton from './subcomponents/NextPageButton';

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

0 comments on commit e2cd9f2

Please sign in to comment.