@rowsncolumns/grid 9.0.0 → 9.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -29,8 +29,8 @@ const react_1 = __importStar(require("react"));
|
|
|
29
29
|
* @param props
|
|
30
30
|
*/
|
|
31
31
|
const usePagination = (props) => {
|
|
32
|
-
const {
|
|
33
|
-
const [currentPage, setCurrentPage] = (0, react_1.useState)(
|
|
32
|
+
const { initialPage = 1, pageSize = 10, total = 0, onChange, component = PaginationComponent, } = props !== null && props !== void 0 ? props : {};
|
|
33
|
+
const [currentPage, setCurrentPage] = (0, react_1.useState)(initialPage);
|
|
34
34
|
const totalPages = Math.ceil(total / pageSize);
|
|
35
35
|
const nextPage = () => setCurrentPage((prev) => Math.min(prev + 1, totalPages));
|
|
36
36
|
const prevPage = () => setCurrentPage((prev) => Math.max(prev - 1, 1));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePagination.js","sourceRoot":"","sources":["../../src/hooks/usePagination.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAmD;AAuEnD;;;GAGG;AACH,MAAM,aAAa,GAAG,CAAC,KAAsB,EAAqB,EAAE;IAClE,MAAM,EACJ,
|
|
1
|
+
{"version":3,"file":"usePagination.js","sourceRoot":"","sources":["../../src/hooks/usePagination.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAmD;AAuEnD;;;GAGG;AACH,MAAM,aAAa,GAAG,CAAC,KAAsB,EAAqB,EAAE;IAClE,MAAM,EACJ,WAAW,GAAG,CAAC,EACf,QAAQ,GAAG,EAAE,EACb,KAAK,GAAG,CAAC,EACT,QAAQ,EACR,SAAS,GAAG,mBAAmB,GAChC,GAAG,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,EAAE,CAAC;IAChB,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,IAAA,gBAAQ,E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CAAC;IACjB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,UAAU,EAAE,CAAC,EAAE,EAAE;QACpC,MAAM,QAAQ,GAAG,WAAW,KAAK,CAAC,CAAC;QACnC,KAAK,CAAC,IAAI,CACR,0CAAQ,OAAO,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,IAC/B,QAAQ,CAAC,CAAC,CAAC,8CAAS,CAAC,CAAU,CAAC,CAAC,CAAC,CAAC,CAC7B,CACV,CAAC;KACH;IACD,OAAO,CACL;QACE,0CAAQ,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,WAAW,KAAK,CAAC,iBAE9C;QACT,0CAAQ,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,KAAK,CAAC,gBAE7C;QACR,KAAK;QACN,0CAAQ,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,KAAK,UAAU,gBAEtD;QACT,0CAAQ,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,KAAK,UAAU,gBAEtD,CACL,CACP,CAAC;AACJ,CAAC,CAAC;AAEF,kBAAe,aAAa,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rowsncolumns/grid",
|
|
3
3
|
"description": "Declarative React Canvas Grid primitive for Data table, Pivot table, Excel Worksheets",
|
|
4
|
-
"version": "9.0.
|
|
4
|
+
"version": "9.0.2",
|
|
5
5
|
"main": "dist/index.tsx",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"files": [
|
|
@@ -43,5 +43,5 @@
|
|
|
43
43
|
"react": "^18.2.0",
|
|
44
44
|
"react-dom": "^18.2.0"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "cdf9ed1a4d96bc0f412efc3496f2a1e2b04e66a7"
|
|
47
47
|
}
|
|
@@ -6,9 +6,9 @@ export interface PaginationProps {
|
|
|
6
6
|
*/
|
|
7
7
|
pageSize: number;
|
|
8
8
|
/**
|
|
9
|
-
* Initial
|
|
9
|
+
* Initial page index. Start from 1
|
|
10
10
|
*/
|
|
11
|
-
|
|
11
|
+
initialPage?: number;
|
|
12
12
|
/**
|
|
13
13
|
* Total number of rows
|
|
14
14
|
*/
|
|
@@ -75,13 +75,13 @@ export interface PaginationResults {
|
|
|
75
75
|
*/
|
|
76
76
|
const usePagination = (props: PaginationProps): PaginationResults => {
|
|
77
77
|
const {
|
|
78
|
-
|
|
78
|
+
initialPage = 1,
|
|
79
79
|
pageSize = 10,
|
|
80
80
|
total = 0,
|
|
81
81
|
onChange,
|
|
82
82
|
component = PaginationComponent,
|
|
83
|
-
} = props;
|
|
84
|
-
const [currentPage, setCurrentPage] = useState<number>(
|
|
83
|
+
} = props ?? {};
|
|
84
|
+
const [currentPage, setCurrentPage] = useState<number>(initialPage);
|
|
85
85
|
const totalPages = Math.ceil(total / pageSize);
|
|
86
86
|
const nextPage = () =>
|
|
87
87
|
setCurrentPage((prev) => Math.min(prev + 1, totalPages));
|
|
@@ -8,14 +8,7 @@ describe("usePagination", () => {
|
|
|
8
8
|
expect(typeof usePagination).toBe("function");
|
|
9
9
|
});
|
|
10
10
|
|
|
11
|
-
it("
|
|
12
|
-
const { result } = renderHook(() => usePagination());
|
|
13
|
-
expect(result.error.message).toBe(
|
|
14
|
-
"Cannot read properties of undefined (reading 'initialCurrentPage')"
|
|
15
|
-
);
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it("sets initialCurrentpage to 1", () => {
|
|
11
|
+
it("sets initialPage to 1", () => {
|
|
19
12
|
const { result } = renderHook(() => usePagination(options));
|
|
20
13
|
expect(result.current.currentPage).toBe(1);
|
|
21
14
|
expect(result.current.totalPages).toBe(10);
|