Skip to content

Commit

Permalink
Merge pull request #374 from peterugah/feature/373-add-pageSize-event…
Browse files Browse the repository at this point in the history
…-to-pagination-component

#373 add page size event to pagination component
  • Loading branch information
FlorianRappl authored Mar 24, 2022
2 parents a4c1afe + 4e049f0 commit 4cc3771
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Precise UI Changelog

## 2.1.11

- fixed issue 373, passed onSizeChanged event as a prop to the Pagination component

## 2.1.10

- Fix WCAG error: Empty table header
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "precise-ui",
"version": "2.1.10",
"version": "2.1.11",
"description": "Precise UI React component library powered by Styled Components.",
"keywords": [
"react",
Expand Down
18 changes: 17 additions & 1 deletion src/components/Pagination/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ export interface PaginationChangeEvent {
*/
value: number;
}
export interface PaginationSizeChangeEvent {
/**
* The current item size per page.
*/
value: number;
}

export interface PaginationState {
current: number;
Expand Down Expand Up @@ -68,6 +74,10 @@ export interface PaginationProps extends StandardProps {
* Event fired when the selected page changes.
*/
onChange?(e: PaginationChangeEvent): void;
/**
* Event fired when the size per page changes.
*/
onSizeChanged?(e: PaginationSizeChangeEvent): void;
/**
* The optional footer info label override, e.g., for localization.
*/
Expand Down Expand Up @@ -137,14 +147,20 @@ export class Pagination extends React.Component<PaginationProps, PaginationState
};

private handleSizeChange = ({ size }: PaginationBarSizeChangedEvent) => {
const { children } = this.props;
const { children, onSizeChanged } = this.props;
const { current } = this.state;
const total = React.Children.count(children);
const maxPageCount = Math.max(Math.ceil(total / size) - 1, 0);
this.setState({
size,
current: Math.min(current, maxPageCount),
});

if (typeof onSizeChanged === 'function') {
onSizeChanged({
value: size,
});
}
};

private getDim(count: number) {
Expand Down

0 comments on commit 4cc3771

Please sign in to comment.