Skip to content

Commit

Permalink
Merge pull request #475 from Panenco/feat/table-pagination-rowsPerPag…
Browse files Browse the repository at this point in the history
…eSelectProps-and-pageSelectProps

feat: table pagination rows per page select and page select
  • Loading branch information
vlacher12 authored Jan 30, 2023
2 parents 32b831a + 02e0831 commit 9c7b4f9
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 111 deletions.
14 changes: 13 additions & 1 deletion src/components/pagination/table-pagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react';
import cx from 'classnames';

import { useTheme } from 'styled-components';
import { Text, SelectInput, Button } from 'components';
import { Text, SelectInput, SelectInputProps, Button } from 'components';
import { usePagination } from './usePagination';
import { StyledPagination } from './styles';
import { additionalStyles } from '../select/style';
Expand All @@ -25,8 +25,16 @@ export type TablePaginationProps = {
onChangePage: (page: number | PaginationOption) => void;
onChangeRowsPerPage: any;
page: number;
/**
* used to pass props to the page select input
*/
pageSelectProps?: SelectInputProps;
rowsPerPage: number;
rowsPerPageOptions?: any;
/**
* used to pass props to the rows per page select input
*/
rowsPerPageSelectProps?: SelectInputProps;
selectStyles?: {
[key: string]: (...args) => { [k: string]: any };
};
Expand Down Expand Up @@ -88,6 +96,8 @@ export const TablePagination = ({
`Displaying ${rangeStart}-${rangeEnd} of ${pCount} items`,
currentPage: (currentPage: number, pagesAmount: number) => `${currentPage} of ${pagesAmount} pages`,
},
rowsPerPageSelectProps = {},
pageSelectProps = {},
...otherProps
}: TablePaginationProps): JSX.Element => {
const [isFirst, isLast, pagesAmount] = usePagination({ page, count, rowsPerPage });
Expand All @@ -114,6 +124,7 @@ export const TablePagination = ({
{locales.itemsPerPage}
</Text>
<SelectInput
{...rowsPerPageSelectProps}
options={rowsPerPageOptions}
className='paginationSelect'
id='rowsPerPage'
Expand Down Expand Up @@ -142,6 +153,7 @@ export const TablePagination = ({
}}
/>
<SelectInput
{...pageSelectProps}
options={pagesOptions}
className='paginationSelect'
id='page'
Expand Down
46 changes: 46 additions & 0 deletions stories/pagination/TablePagination.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import * as React from 'react';
import { ComponentStory, ComponentMeta } from '@storybook/react';
import { TablePagination } from 'components/pagination/table-pagination';
import { BrowserRouter } from 'react-router-dom';
import { Col, Row } from 'components';

export default {
title: 'Example/Pagination/TablePagination',
component: TablePagination,
} as ComponentMeta<typeof TablePagination>;

const Template: ComponentStory<typeof TablePagination> = (args) => <TablePagination {...args} />;

export const Default = Template.bind({});

const DemoTemplate = () => {
const [page, setPage] = React.useState(0);
const [rowsPerPage, setRowsPerPage] = React.useState(12);

const handleChangePage = (val) => {
setPage(Number(val));
};

const handleChangeRowsPerPage = (val) => {
setRowsPerPage(Number(val));
setPage(0);
};

return (
<BrowserRouter>
<Row style={{ justifyContent: 'center' }}>
<Col>
<TablePagination
page={page}
onChangePage={handleChangePage}
onChangeRowsPerPage={handleChangeRowsPerPage}
count={201}
rowsPerPage={rowsPerPage}
/>
</Col>
</Row>
</BrowserRouter>
);
};

export const Demo = DemoTemplate.bind({});
110 changes: 0 additions & 110 deletions stories/pagination/index.jsx

This file was deleted.

0 comments on commit 9c7b4f9

Please sign in to comment.