@arkyn/components 1.3.147 → 1.3.149

Sign up to get free protection for your applications and to get access to all the features.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/ImageUpload/index.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAQhD,OAAO,cAAc,CAAC;AAEtB,iBAAS,WAAW,CAAC,KAAK,EAAE,gBAAgB,2CA4F3C;AAED,OAAO,EAAE,WAAW,EAAE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/ImageUpload/index.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAQhD,OAAO,cAAc,CAAC;AAEtB,iBAAS,WAAW,CAAC,KAAK,EAAE,gBAAgB,2CA6F3C;AAED,OAAO,EAAE,WAAW,EAAE,CAAC"}
@@ -18,6 +18,7 @@ function ImageUpload(props) {
18
18
  async function handleUploadImage(file) {
19
19
  setIsLoading(true);
20
20
  setFile(file);
21
+ setError("");
21
22
  const formData = new FormData();
22
23
  formData.append(fileName, file);
23
24
  await fetch(action, { method: method, body: formData })
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/Pagination/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAO/C,OAAO,cAAc,CAAC;AAEtB,iBAAS,UAAU,CAAC,KAAK,EAAE,eAAe,2CAsGzC;AAED,OAAO,EAAE,UAAU,EAAE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/Pagination/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAM/C,OAAO,cAAc,CAAC;AAUtB,iBAAS,UAAU,CAAC,KAAK,EAAE,eAAe,2CAoHzC;AAED,OAAO,EAAE,UAAU,EAAE,CAAC"}
@@ -2,20 +2,32 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
2
2
  import { useNavigate } from "@remix-run/react";
3
3
  import { ChevronLeft, ChevronRight, Ellipsis } from "lucide-react";
4
4
  import { useScopedParams } from "../../hooks/useScopedParams";
5
- import { getNextPages, getPreviousPages } from "../../services";
6
5
  import "./styles.css";
6
+ function generatePagesArray(from, to) {
7
+ return [...new Array(to - from)]
8
+ .map((_, index) => {
9
+ return from + index + 1;
10
+ })
11
+ .filter((page) => page > 0);
12
+ }
7
13
  function Pagination(props) {
8
- const { scope, totalCountRegisters, perPageKey = "per_page", pageKey = "page", siblingsCount = 2, ...rest } = props;
14
+ const { scope, totalCountRegisters, perPageKey = "per_page", pageKey = "page", siblingsCount = 2, currentPage: baseCurrentPage = 1, registerPerPage: baseRegisterPerPage = 20, ...rest } = props;
9
15
  const navigate = useNavigate();
10
16
  const { getParam, getScopedSearch } = useScopedParams(scope);
11
- const currentPage = Number(getParam(pageKey)) || 1;
12
- const registerPerPage = Number(getParam(perPageKey)) || 20;
17
+ const currentPage = Number(getParam("page")) || baseCurrentPage;
18
+ const registerPerPage = Number(getParam("per_page")) || baseRegisterPerPage;
13
19
  const lastPage = Math.ceil(totalCountRegisters / registerPerPage);
14
- const previosPages = getPreviousPages(currentPage, siblingsCount);
15
- const nextPages = getNextPages(currentPage, siblingsCount, lastPage);
20
+ const previosPages = currentPage > 1
21
+ ? generatePagesArray(currentPage - 1 - siblingsCount, currentPage - 1)
22
+ : [];
23
+ const nextPages = currentPage < lastPage
24
+ ? generatePagesArray(currentPage, Math.min(currentPage + siblingsCount, lastPage))
25
+ : [];
16
26
  function handlePageChange(page) {
17
27
  navigate(getScopedSearch({ page }));
18
28
  }
19
- return (_jsxs("div", { className: "arkynPagination", ...rest, children: [_jsx("button", { className: "arkynPaginationIconButton", disabled: currentPage <= 1, onClick: () => handlePageChange(currentPage - 1), children: _jsx(ChevronLeft, {}) }), currentPage > 1 + siblingsCount && (_jsxs(_Fragment, { children: [_jsx("button", { className: "arkynPaginationPageButton", onClick: () => handlePageChange(1), children: "1" }), currentPage > 2 + siblingsCount && (_jsx("button", { disabled: true, className: "arkynPaginationSpread", children: _jsx(Ellipsis, {}) }))] })), previosPages.map((page, index) => (_jsx("button", { onClick: () => handlePageChange(page), className: "arkynPaginationPageButton", children: page }, index))), _jsx("button", { className: "arkynPaginationCurrent", disabled: true, children: currentPage }), nextPages.map((page, index) => (_jsx("button", { onClick: () => handlePageChange(page), className: "arkynPaginationPageButton", children: page }, index))), currentPage + siblingsCount < lastPage && (_jsxs(_Fragment, { children: [currentPage + 1 + siblingsCount < lastPage && (_jsx("button", { disabled: true, className: "arkynPaginationSpread", children: _jsx(Ellipsis, {}) })), _jsx("button", { className: "arkynPaginationPageButton", onClick: () => handlePageChange(lastPage), children: lastPage })] })), _jsx("button", { className: "arkynPaginationIconButton", disabled: currentPage >= lastPage, onClick: () => handlePageChange(currentPage + 1), children: _jsx(ChevronRight, {}) })] }));
29
+ return (_jsxs("div", { className: "arkynPagination", ...rest, children: [_jsx("button", { className: "arkynPaginationIconButton", disabled: currentPage <= 1, onClick: () => handlePageChange(currentPage - 1), children: _jsx(ChevronLeft, {}) }), currentPage > 1 + siblingsCount && (_jsxs(_Fragment, { children: [_jsx("button", { className: "arkynPaginationPageButton", onClick: () => handlePageChange(1), children: "1" }), currentPage > 2 + siblingsCount && (_jsx("button", { disabled: true, className: "arkynPaginationSpread", children: _jsx(Ellipsis, {}) }))] })), previosPages.length > 0 &&
30
+ previosPages.map((page, index) => (_jsx("button", { onClick: () => handlePageChange(page), className: "arkynPaginationPageButton", children: page }, index))), _jsx("button", { className: "arkynPaginationCurrent", disabled: true, children: currentPage }), nextPages.length > 0 &&
31
+ nextPages.map((page, index) => (_jsx("button", { onClick: () => handlePageChange(page), className: "arkynPaginationPageButton", children: page }, index))), currentPage + siblingsCount < lastPage && (_jsxs(_Fragment, { children: [currentPage + 1 + siblingsCount < lastPage && (_jsx("button", { disabled: true, className: "arkynPaginationSpread", children: _jsx(Ellipsis, {}) })), _jsx("button", { className: "arkynPaginationPageButton", onClick: () => handlePageChange(lastPage), children: lastPage })] })), _jsx("button", { className: "arkynPaginationIconButton", disabled: currentPage >= lastPage, onClick: () => handlePageChange(currentPage + 1), children: _jsx(ChevronRight, {}) })] }));
20
32
  }
21
33
  export { Pagination };
@@ -1,7 +1,5 @@
1
1
  import { GenerateIcon } from "./generateIcon";
2
2
  import { generatePagesArray } from "./generatePagerArray";
3
- import { getNextPages } from "./getNextPages";
4
- import { getPreviousPages } from "./getPreviousPages";
5
3
  import { morpheme } from "./morpheme";
6
- export { GenerateIcon, generatePagesArray, getNextPages, getPreviousPages, morpheme, };
4
+ export { GenerateIcon, generatePagesArray, morpheme };
7
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,OAAO,EACL,YAAY,EACZ,kBAAkB,EAClB,YAAY,EACZ,gBAAgB,EAChB,QAAQ,GACT,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,QAAQ,EAAE,CAAC"}
@@ -1,6 +1,4 @@
1
1
  import { GenerateIcon } from "./generateIcon";
2
2
  import { generatePagesArray } from "./generatePagerArray";
3
- import { getNextPages } from "./getNextPages";
4
- import { getPreviousPages } from "./getPreviousPages";
5
3
  import { morpheme } from "./morpheme";
6
- export { GenerateIcon, generatePagesArray, getNextPages, getPreviousPages, morpheme, };
4
+ export { GenerateIcon, generatePagesArray, morpheme };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arkyn/components",
3
- "version": "1.3.147",
3
+ "version": "1.3.149",
4
4
  "main": "./dist/bundle.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "author": "Lucas Gonçalves",
@@ -38,6 +38,7 @@ function ImageUpload(props: ImageUploadProps) {
38
38
  async function handleUploadImage(file: File) {
39
39
  setIsLoading(true);
40
40
  setFile(file);
41
+ setError("");
41
42
 
42
43
  const formData = new FormData();
43
44
  formData.append(fileName, file);
@@ -3,10 +3,17 @@ import { useNavigate } from "@remix-run/react";
3
3
  import { ChevronLeft, ChevronRight, Ellipsis } from "lucide-react";
4
4
 
5
5
  import { useScopedParams } from "../../hooks/useScopedParams";
6
- import { getNextPages, getPreviousPages } from "../../services";
7
6
 
8
7
  import "./styles.css";
9
8
 
9
+ function generatePagesArray(from: number, to: number) {
10
+ return [...new Array(to - from)]
11
+ .map((_, index) => {
12
+ return from + index + 1;
13
+ })
14
+ .filter((page) => page > 0);
15
+ }
16
+
10
17
  function Pagination(props: PaginationProps) {
11
18
  const {
12
19
  scope,
@@ -14,19 +21,31 @@ function Pagination(props: PaginationProps) {
14
21
  perPageKey = "per_page",
15
22
  pageKey = "page",
16
23
  siblingsCount = 2,
24
+ currentPage: baseCurrentPage = 1,
25
+ registerPerPage: baseRegisterPerPage = 20,
17
26
  ...rest
18
27
  } = props;
19
28
 
20
29
  const navigate = useNavigate();
21
30
  const { getParam, getScopedSearch } = useScopedParams(scope);
22
31
 
23
- const currentPage = Number(getParam(pageKey)) || 1;
24
- const registerPerPage = Number(getParam(perPageKey)) || 20;
32
+ const currentPage = Number(getParam("page")) || baseCurrentPage;
33
+ const registerPerPage = Number(getParam("per_page")) || baseRegisterPerPage;
25
34
 
26
35
  const lastPage = Math.ceil(totalCountRegisters / registerPerPage);
27
36
 
28
- const previosPages = getPreviousPages(currentPage, siblingsCount);
29
- const nextPages = getNextPages(currentPage, siblingsCount, lastPage);
37
+ const previosPages =
38
+ currentPage > 1
39
+ ? generatePagesArray(currentPage - 1 - siblingsCount, currentPage - 1)
40
+ : [];
41
+
42
+ const nextPages =
43
+ currentPage < lastPage
44
+ ? generatePagesArray(
45
+ currentPage,
46
+ Math.min(currentPage + siblingsCount, lastPage)
47
+ )
48
+ : [];
30
49
 
31
50
  function handlePageChange(page: number) {
32
51
  navigate(getScopedSearch({ page }));
@@ -59,29 +78,31 @@ function Pagination(props: PaginationProps) {
59
78
  </>
60
79
  )}
61
80
 
62
- {previosPages.map((page, index) => (
63
- <button
64
- key={index}
65
- onClick={() => handlePageChange(page)}
66
- className="arkynPaginationPageButton"
67
- >
68
- {page}
69
- </button>
70
- ))}
81
+ {previosPages.length > 0 &&
82
+ previosPages.map((page, index) => (
83
+ <button
84
+ key={index}
85
+ onClick={() => handlePageChange(page)}
86
+ className="arkynPaginationPageButton"
87
+ >
88
+ {page}
89
+ </button>
90
+ ))}
71
91
 
72
92
  <button className="arkynPaginationCurrent" disabled>
73
93
  {currentPage}
74
94
  </button>
75
95
 
76
- {nextPages.map((page, index) => (
77
- <button
78
- key={index}
79
- onClick={() => handlePageChange(page)}
80
- className="arkynPaginationPageButton"
81
- >
82
- {page}
83
- </button>
84
- ))}
96
+ {nextPages.length > 0 &&
97
+ nextPages.map((page, index) => (
98
+ <button
99
+ key={index}
100
+ onClick={() => handlePageChange(page)}
101
+ className="arkynPaginationPageButton"
102
+ >
103
+ {page}
104
+ </button>
105
+ ))}
85
106
 
86
107
  {currentPage + siblingsCount < lastPage && (
87
108
  <>
@@ -1,13 +1,5 @@
1
1
  import { GenerateIcon } from "./generateIcon";
2
2
  import { generatePagesArray } from "./generatePagerArray";
3
- import { getNextPages } from "./getNextPages";
4
- import { getPreviousPages } from "./getPreviousPages";
5
3
  import { morpheme } from "./morpheme";
6
4
 
7
- export {
8
- GenerateIcon,
9
- generatePagesArray,
10
- getNextPages,
11
- getPreviousPages,
12
- morpheme,
13
- };
5
+ export { GenerateIcon, generatePagesArray, morpheme };
@@ -1,3 +0,0 @@
1
- declare function getNextPages(currentPage: number, siblingsCount: number, lastPage: number): number[];
2
- export { getNextPages };
3
- //# sourceMappingURL=getNextPages.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getNextPages.d.ts","sourceRoot":"","sources":["../../src/services/getNextPages.ts"],"names":[],"mappings":"AAEA,iBAAS,YAAY,CACnB,WAAW,EAAE,MAAM,EACnB,aAAa,EAAE,MAAM,EACrB,QAAQ,EAAE,MAAM,YAIjB;AAED,OAAO,EAAE,YAAY,EAAE,CAAC"}
@@ -1,7 +0,0 @@
1
- import { generatePagesArray } from "./generatePagerArray";
2
- function getNextPages(currentPage, siblingsCount, lastPage) {
3
- if (currentPage >= lastPage)
4
- return [];
5
- return generatePagesArray(currentPage, currentPage + siblingsCount);
6
- }
7
- export { getNextPages };
@@ -1,3 +0,0 @@
1
- declare function getPreviousPages(currentPage: number, siblingsCount: number): number[];
2
- export { getPreviousPages };
3
- //# sourceMappingURL=getPreviousPages.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getPreviousPages.d.ts","sourceRoot":"","sources":["../../src/services/getPreviousPages.ts"],"names":[],"mappings":"AAEA,iBAAS,gBAAgB,CAAC,WAAW,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,YAGnE;AAED,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
@@ -1,7 +0,0 @@
1
- import { generatePagesArray } from "./generatePagerArray";
2
- function getPreviousPages(currentPage, siblingsCount) {
3
- if (currentPage <= 1)
4
- return [];
5
- return generatePagesArray(currentPage - 1 - siblingsCount, currentPage - 1);
6
- }
7
- export { getPreviousPages };
@@ -1,12 +0,0 @@
1
- import { generatePagesArray } from "./generatePagerArray";
2
-
3
- function getNextPages(
4
- currentPage: number,
5
- siblingsCount: number,
6
- lastPage: number
7
- ) {
8
- if (currentPage >= lastPage) return [];
9
- return generatePagesArray(currentPage, currentPage + siblingsCount);
10
- }
11
-
12
- export { getNextPages };
@@ -1,8 +0,0 @@
1
- import { generatePagesArray } from "./generatePagerArray";
2
-
3
- function getPreviousPages(currentPage: number, siblingsCount: number) {
4
- if (currentPage <= 1) return [];
5
- return generatePagesArray(currentPage - 1 - siblingsCount, currentPage - 1);
6
- }
7
-
8
- export { getPreviousPages };