Skip to content

Commit 07bd0f6

Browse files
authored
fix: fix for #18
1 parent 81d8f92 commit 07bd0f6

File tree

8 files changed

+29855
-75
lines changed

8 files changed

+29855
-75
lines changed

example/package-lock.json

+19,247-56
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/src/App.tsx

+12-1
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,22 @@ function App() {
7373
setCounter(counter + 1);
7474
};
7575

76+
const removeItem = () => {
77+
setState({
78+
...state,
79+
users: [
80+
...state.users.slice(0, state.users.length - 1),
81+
],
82+
});
83+
if (counter > 1) setCounter(counter - 1);
84+
};
85+
7686
return (
7787
<div className="App">
7888
<div className="container">
7989
<h1>React Paginated List</h1>
80-
<Button onClick={addItem}>Add item</Button>
90+
<Button onClick={addItem}>Add Item</Button>
91+
<Button onClick={removeItem}>Remove Item</Button>
8192
<PaginatedList<User>
8293
list={state.users}
8394
itemsPerPage={5}

example/src/react-paginated-list/index.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable */
2-
import { useState, createElement, Fragment } from 'react';
2+
import { useState, useEffect, createElement, Fragment } from 'react';
33
import styled from 'styled-components';
44

55
/*! *****************************************************************************
@@ -86,6 +86,15 @@ var generatePageArray = function (items, currentPage, leftMargin, rightMargin, d
8686
var PaginatedList = function (_a) {
8787
var list = _a.list, _b = _a.itemsPerPage, itemsPerPage = _b === void 0 ? 10 : _b, onPageChange = _a.onPageChange, renderList = _a.renderList, _c = _a.isLoading, isLoading = _c === void 0 ? false : _c, _d = _a.ControlItem, ControlItem = _d === void 0 ? DefaultControlItem : _d, _e = _a.ControlContainer, ControlContainer = _e === void 0 ? DefaultControlContainer : _e, _f = _a.PaginatedListContainer, PaginatedListContainer = _f === void 0 ? DefaultPaginationContainer : _f, _g = _a.loadingItem, loadingItem = _g === void 0 ? function () { return createElement("p", null, "Loading..."); } : _g, _h = _a.breakText, breakText = _h === void 0 ? '...' : _h, _j = _a.breakClass, breakClass = _j === void 0 ? 'pagination-break' : _j, _k = _a.displayRange, displayRange = _k === void 0 ? 3 : _k, _l = _a.leftMargin, leftMargin = _l === void 0 ? 1 : _l, _m = _a.rightMargin, rightMargin = _m === void 0 ? 1 : _m, _o = _a.currentPage, currentPage = _o === void 0 ? 1 : _o, _p = _a.displayNumbers, displayNumbers = _p === void 0 ? true : _p, _q = _a.loopAround, loopAround = _q === void 0 ? false : _q, _r = _a.nextClass, nextClass = _r === void 0 ? 'next' : _r, _s = _a.prevClass, prevClass = _s === void 0 ? 'prev' : _s, _t = _a.controlClass, controlClass = _t === void 0 ? 'pagination' : _t, _u = _a.activeControlClass, activeControlClass = _u === void 0 ? 'active' : _u, _v = _a.nextText, nextText = _v === void 0 ? '〉' : _v, _w = _a.prevText, prevText = _w === void 0 ? '〈' : _w, _x = _a.controlItemClass, controlItemClass = _x === void 0 ? 'pagination-item' : _x, _y = _a.showPrev, showPrev = _y === void 0 ? true : _y, _z = _a.showNext, showNext = _z === void 0 ? true : _z, _0 = _a.useMinimalControls, useMinimalControls = _0 === void 0 ? false : _0, paginatedListContainerClass = _a.paginatedListContainerClass;
8888
var _1 = useState(currentPage - 1), currentPageState = _1[0], setcurrentPageState = _1[1];
89+
useEffect(function () {
90+
var maxPage = Math.floor((list.length - 1) / itemsPerPage);
91+
if (maxPage < currentPageState) {
92+
setcurrentPageState(maxPage);
93+
}
94+
if (maxPage < 0) {
95+
setcurrentPageState(0);
96+
}
97+
}, [list.length]);
8998
var onPageNumberChange = function (page, amount) {
9099
if (amount === void 0) { amount = 0; }
91100
var result = page + (amount % Math.ceil(list.length / itemsPerPage));

0 commit comments

Comments
 (0)