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

#373 add page size event to pagination component #374

Merged
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
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
peterugah marked this conversation as resolved.
Show resolved Hide resolved

- 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