@star-insure/sdk 2.0.8 → 2.0.9
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.
- package/dist/components/common/Pagination.d.ts +2 -1
- package/dist/components/common/SimplePagination.d.ts +3 -2
- package/dist/sdk.cjs.development.js +8 -4
- package/dist/sdk.cjs.development.js.map +1 -1
- package/dist/sdk.cjs.production.min.js +1 -1
- package/dist/sdk.cjs.production.min.js.map +1 -1
- package/dist/sdk.esm.js +8 -4
- package/dist/sdk.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/common/Pagination.tsx +6 -2
- package/src/components/common/SimplePagination.tsx +101 -60
|
@@ -1,78 +1,119 @@
|
|
|
1
|
-
import React from
|
|
2
|
-
import { Link } from
|
|
3
|
-
import { Meta } from
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Link } from '@inertiajs/react';
|
|
3
|
+
import { Meta } from '../../types';
|
|
4
4
|
|
|
5
5
|
interface Props {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
className?: string;
|
|
7
|
+
meta: Meta;
|
|
8
|
+
showPerPageSelector?: boolean;
|
|
9
|
+
defaultValue?: number;
|
|
9
10
|
}
|
|
10
11
|
|
|
11
|
-
export default function SimplePagination({
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
export default function SimplePagination({
|
|
13
|
+
meta,
|
|
14
|
+
className,
|
|
15
|
+
showPerPageSelector = false,
|
|
16
|
+
defaultValue,
|
|
17
|
+
}: Props) {
|
|
18
|
+
const { current_page, per_page, to, from } = meta;
|
|
15
19
|
|
|
16
|
-
|
|
17
|
-
if (typeof window !== 'undefined') {
|
|
18
|
-
const search = new URLSearchParams(window.location.search);
|
|
19
|
-
search.set('page', String(current_page + 1));
|
|
20
|
+
const perPageValue = defaultValue ?? per_page;
|
|
20
21
|
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
const results_on_page = to - from + 1;
|
|
23
|
+
const has_more_pages = results_on_page === per_page;
|
|
23
24
|
|
|
24
|
-
|
|
25
|
+
function getNextPageLink() {
|
|
26
|
+
if (typeof window !== 'undefined') {
|
|
27
|
+
const search = new URLSearchParams(window.location.search);
|
|
28
|
+
search.set('page', String(current_page + 1));
|
|
29
|
+
|
|
30
|
+
return `?${search.toString()}`;
|
|
25
31
|
}
|
|
26
32
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const search = new URLSearchParams(window.location.search);
|
|
30
|
-
search.set('page', String(current_page - 1));
|
|
33
|
+
return '';
|
|
34
|
+
}
|
|
31
35
|
|
|
32
|
-
|
|
33
|
-
|
|
36
|
+
function getPrevPageLink() {
|
|
37
|
+
if (typeof window !== 'undefined') {
|
|
38
|
+
const search = new URLSearchParams(window.location.search);
|
|
39
|
+
search.set('page', String(current_page - 1));
|
|
34
40
|
|
|
35
|
-
|
|
41
|
+
return `?${search.toString()}`;
|
|
36
42
|
}
|
|
37
43
|
|
|
38
|
-
|
|
39
|
-
|
|
44
|
+
return '';
|
|
45
|
+
}
|
|
40
46
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
search.set('limit', e.currentTarget.value);
|
|
44
|
-
search.set('page', '1');
|
|
47
|
+
const nextPageLink = getNextPageLink();
|
|
48
|
+
const prevPageLink = getPrevPageLink();
|
|
45
49
|
|
|
46
|
-
|
|
47
|
-
|
|
50
|
+
function handlePerPageChange(e: React.SyntheticEvent<HTMLSelectElement>) {
|
|
51
|
+
const search = new URLSearchParams(window?.location.search);
|
|
52
|
+
search.set('limit', e.currentTarget.value);
|
|
53
|
+
search.set('page', '1');
|
|
54
|
+
|
|
55
|
+
window.location.href = `?${search.toString()}`;
|
|
56
|
+
}
|
|
48
57
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
58
|
+
return (
|
|
59
|
+
<div className={`${className ?? ''}`}>
|
|
60
|
+
<nav className="font-bold flex justify-between items-center gap-6">
|
|
61
|
+
<Link
|
|
62
|
+
href={prevPageLink}
|
|
63
|
+
className="flex items-center gap-2"
|
|
64
|
+
disabled={current_page === 1}
|
|
65
|
+
>
|
|
66
|
+
<svg
|
|
67
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
68
|
+
className="h-4 w-4"
|
|
69
|
+
fill="none"
|
|
70
|
+
viewBox="0 0 24 24"
|
|
71
|
+
stroke="currentColor"
|
|
72
|
+
strokeWidth="2"
|
|
73
|
+
>
|
|
74
|
+
<path
|
|
75
|
+
strokeLinecap="round"
|
|
76
|
+
strokeLinejoin="round"
|
|
77
|
+
d="M10 19l-7-7m0 0l7-7m-7 7h18"
|
|
78
|
+
/>
|
|
79
|
+
</svg>
|
|
80
|
+
Prev
|
|
81
|
+
</Link>
|
|
82
|
+
<div className="flex gap-6 items-center">
|
|
83
|
+
<p>Page {current_page}</p>
|
|
84
|
+
{showPerPageSelector ? (
|
|
85
|
+
<select value={perPageValue} onChange={handlePerPageChange}>
|
|
86
|
+
<option value="10">10 per page</option>
|
|
87
|
+
<option value="25">25 per page</option>
|
|
88
|
+
<option value="50">50 per page</option>
|
|
89
|
+
<option value="100">100 per page</option>
|
|
90
|
+
</select>
|
|
91
|
+
) : (
|
|
92
|
+
''
|
|
93
|
+
)}
|
|
76
94
|
</div>
|
|
77
|
-
|
|
95
|
+
<Link
|
|
96
|
+
href={nextPageLink}
|
|
97
|
+
className="flex items-center gap-2"
|
|
98
|
+
disabled={!has_more_pages}
|
|
99
|
+
>
|
|
100
|
+
Next
|
|
101
|
+
<svg
|
|
102
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
103
|
+
className="h-4 w-4"
|
|
104
|
+
fill="none"
|
|
105
|
+
viewBox="0 0 24 24"
|
|
106
|
+
stroke="currentColor"
|
|
107
|
+
strokeWidth="2"
|
|
108
|
+
>
|
|
109
|
+
<path
|
|
110
|
+
strokeLinecap="round"
|
|
111
|
+
strokeLinejoin="round"
|
|
112
|
+
d="M14 5l7 7m0 0l-7 7m7-7H3"
|
|
113
|
+
/>
|
|
114
|
+
</svg>
|
|
115
|
+
</Link>
|
|
116
|
+
</nav>
|
|
117
|
+
</div>
|
|
118
|
+
);
|
|
78
119
|
}
|