best-react-pagination 0.0.1 → 0.1.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.
- package/.eslintignore +1 -1
- package/.husky/pre-commit +5 -2
- package/.idea/best-react-pagination.iml +9 -0
- package/.idea/codeStyles/Project.xml +58 -0
- package/.idea/codeStyles/codeStyleConfig.xml +5 -0
- package/.idea/discord.xml +7 -0
- package/.idea/git_toolbox_prj.xml +15 -0
- package/.idea/inspectionProfiles/Project_Default.xml +6 -0
- package/.idea/misc.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/prettier.xml +6 -0
- package/.idea/vcs.xml +6 -0
- package/.lintstagedrc.json +1 -1
- package/LICENCE +12 -12
- package/README.md +18 -13
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/husky.config.js +4 -4
- package/package.json +5 -3
- package/tsconfig.json +24 -23
- package/webpack.config.ts +53 -45
- package/demo/.babelrc +0 -14
- package/demo/public/index.html +0 -17
- package/demo/src/App.tsx +0 -15
- package/demo/src/Pagination/index.tsx +0 -331
- package/demo/src/index.html +0 -11
- package/demo/src/index.tsx +0 -7
- package/demo/tsconfig.json +0 -18
- package/demo/webpack.config.js +0 -50
- package/lib/index.tsx +0 -331
package/lib/index.tsx
DELETED
|
@@ -1,331 +0,0 @@
|
|
|
1
|
-
import React, { FC } from "react";
|
|
2
|
-
|
|
3
|
-
interface IPagination {
|
|
4
|
-
paginationStart: 0 | 1;
|
|
5
|
-
currentIndex: number;
|
|
6
|
-
totalPages: number;
|
|
7
|
-
setIndex: React.Dispatch<React.SetStateAction<number>>;
|
|
8
|
-
isDefaultStyles?: boolean;
|
|
9
|
-
|
|
10
|
-
wrapperClass?: string;
|
|
11
|
-
itemListClass?: string;
|
|
12
|
-
itemClass?: string;
|
|
13
|
-
selectedItemClass?: string;
|
|
14
|
-
disableItemClass?: string;
|
|
15
|
-
|
|
16
|
-
className?: string;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const Pagination: FC<IPagination> = ({
|
|
20
|
-
paginationStart,
|
|
21
|
-
currentIndex,
|
|
22
|
-
totalPages,
|
|
23
|
-
setIndex,
|
|
24
|
-
isDefaultStyles,
|
|
25
|
-
|
|
26
|
-
wrapperClass = "",
|
|
27
|
-
itemListClass = "",
|
|
28
|
-
itemClass = "",
|
|
29
|
-
selectedItemClass = "",
|
|
30
|
-
disableItemClass = "",
|
|
31
|
-
className,
|
|
32
|
-
}) => {
|
|
33
|
-
console.log(totalPages, currentIndex);
|
|
34
|
-
const countItems = [1, 2, 3, 4];
|
|
35
|
-
|
|
36
|
-
enum defaultStylesEnum {
|
|
37
|
-
wrapperClass = "wrapperClass",
|
|
38
|
-
itemListClass = "itemListClass",
|
|
39
|
-
itemClass = "itemClass",
|
|
40
|
-
selectedItemClass = "selectedItemClass",
|
|
41
|
-
disableItemClass = "disableItemClass",
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const defaultStyles: Record<defaultStylesEnum, React.CSSProperties> = {
|
|
45
|
-
wrapperClass: {
|
|
46
|
-
position: "sticky",
|
|
47
|
-
display: "flex",
|
|
48
|
-
justifyContent: "center",
|
|
49
|
-
alignItems: "center",
|
|
50
|
-
width: "100%",
|
|
51
|
-
bottom: 0,
|
|
52
|
-
},
|
|
53
|
-
itemListClass: {
|
|
54
|
-
padding: "10px 0",
|
|
55
|
-
},
|
|
56
|
-
itemClass: {
|
|
57
|
-
display: "inline",
|
|
58
|
-
cursor: "pointer",
|
|
59
|
-
padding: "6px 12px",
|
|
60
|
-
borderRadius: "4px",
|
|
61
|
-
margin: "0 2px",
|
|
62
|
-
backgroundColor: "#45c954",
|
|
63
|
-
},
|
|
64
|
-
selectedItemClass: {
|
|
65
|
-
display: "inline",
|
|
66
|
-
cursor: "pointer",
|
|
67
|
-
padding: "6px 12px",
|
|
68
|
-
borderRadius: "4px",
|
|
69
|
-
margin: "0 2px",
|
|
70
|
-
backgroundColor: "#48bbff",
|
|
71
|
-
},
|
|
72
|
-
disableItemClass: {
|
|
73
|
-
display: "inline",
|
|
74
|
-
cursor: "not-allowed",
|
|
75
|
-
padding: "6px 12px",
|
|
76
|
-
borderRadius: "4px",
|
|
77
|
-
margin: "0 2px",
|
|
78
|
-
},
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
if (totalPages <= 1) {
|
|
82
|
-
return (
|
|
83
|
-
<div className={wrapperClass} style={isDefaultStyles ? defaultStyles.wrapperClass : undefined}>
|
|
84
|
-
<ul className={itemListClass} style={isDefaultStyles ? defaultStyles.itemListClass : undefined}>
|
|
85
|
-
<li className={disableItemClass} style={isDefaultStyles ? defaultStyles.itemClass : undefined}>{`<<`}</li>
|
|
86
|
-
<li className={disableItemClass} style={isDefaultStyles ? defaultStyles.itemClass : undefined}>{`>>`}</li>
|
|
87
|
-
</ul>
|
|
88
|
-
</div>
|
|
89
|
-
);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
if (totalPages > 1 && totalPages < 4) {
|
|
93
|
-
return (
|
|
94
|
-
<div className={wrapperClass} style={isDefaultStyles ? defaultStyles.wrapperClass : undefined}>
|
|
95
|
-
<ul className={itemListClass} style={isDefaultStyles ? defaultStyles.itemListClass : undefined}>
|
|
96
|
-
{[1, 2, 3].map((el) => {
|
|
97
|
-
const index = paginationStart === 0 ? el - 1 : el;
|
|
98
|
-
if (currentIndex === index) {
|
|
99
|
-
return (
|
|
100
|
-
<li
|
|
101
|
-
className={selectedItemClass}
|
|
102
|
-
style={isDefaultStyles ? defaultStyles.selectedItemClass : undefined}
|
|
103
|
-
key={el}
|
|
104
|
-
>
|
|
105
|
-
{el}
|
|
106
|
-
</li>
|
|
107
|
-
);
|
|
108
|
-
}
|
|
109
|
-
return (
|
|
110
|
-
<li
|
|
111
|
-
className={selectedItemClass}
|
|
112
|
-
style={isDefaultStyles ? defaultStyles.itemClass : undefined}
|
|
113
|
-
key={el}
|
|
114
|
-
onClick={() => setIndex(index)}
|
|
115
|
-
>
|
|
116
|
-
{el}
|
|
117
|
-
</li>
|
|
118
|
-
);
|
|
119
|
-
})}
|
|
120
|
-
</ul>
|
|
121
|
-
</div>
|
|
122
|
-
);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
if (totalPages === 4) {
|
|
126
|
-
return (
|
|
127
|
-
<div className={wrapperClass} style={isDefaultStyles ? defaultStyles.wrapperClass : undefined}>
|
|
128
|
-
<ul className={itemListClass} style={isDefaultStyles ? defaultStyles.itemListClass : undefined}>
|
|
129
|
-
{currentIndex > (paginationStart === 0 ? 0 : 1) ? (
|
|
130
|
-
<li
|
|
131
|
-
className={itemClass}
|
|
132
|
-
style={isDefaultStyles ? defaultStyles.itemClass : undefined}
|
|
133
|
-
onClick={() => setIndex(currentIndex - 1)}
|
|
134
|
-
>{`<<`}</li>
|
|
135
|
-
) : (
|
|
136
|
-
<li
|
|
137
|
-
className={disableItemClass}
|
|
138
|
-
style={isDefaultStyles ? defaultStyles.disableItemClass : undefined}
|
|
139
|
-
>{`<<`}</li>
|
|
140
|
-
)}
|
|
141
|
-
{countItems.map((el) => {
|
|
142
|
-
const index = paginationStart === 0 ? el - 1 : el;
|
|
143
|
-
if (currentIndex === index) {
|
|
144
|
-
return (
|
|
145
|
-
<li
|
|
146
|
-
className={selectedItemClass}
|
|
147
|
-
style={isDefaultStyles ? defaultStyles.selectedItemClass : undefined}
|
|
148
|
-
key={el}
|
|
149
|
-
>
|
|
150
|
-
{el}
|
|
151
|
-
</li>
|
|
152
|
-
);
|
|
153
|
-
}
|
|
154
|
-
return (
|
|
155
|
-
<li
|
|
156
|
-
className={selectedItemClass}
|
|
157
|
-
style={isDefaultStyles ? defaultStyles.itemClass : undefined}
|
|
158
|
-
key={el}
|
|
159
|
-
onClick={() => setIndex(index)}
|
|
160
|
-
>
|
|
161
|
-
{el}
|
|
162
|
-
</li>
|
|
163
|
-
);
|
|
164
|
-
})}
|
|
165
|
-
{currentIndex < (paginationStart === 0 ? 3 : 4) ? (
|
|
166
|
-
<li
|
|
167
|
-
className={itemClass}
|
|
168
|
-
style={isDefaultStyles ? defaultStyles.itemClass : undefined}
|
|
169
|
-
onClick={() => setIndex(currentIndex + 1)}
|
|
170
|
-
>{`>>`}</li>
|
|
171
|
-
) : (
|
|
172
|
-
<li
|
|
173
|
-
className={disableItemClass}
|
|
174
|
-
style={isDefaultStyles ? defaultStyles.disableItemClass : undefined}
|
|
175
|
-
>{`>>`}</li>
|
|
176
|
-
)}
|
|
177
|
-
</ul>
|
|
178
|
-
</div>
|
|
179
|
-
);
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
return (
|
|
183
|
-
<>
|
|
184
|
-
<div className={wrapperClass && className} style={isDefaultStyles ? defaultStyles.wrapperClass : undefined}>
|
|
185
|
-
<ul className={itemListClass} style={isDefaultStyles ? defaultStyles.itemListClass : undefined}>
|
|
186
|
-
{/*Previous button*/}
|
|
187
|
-
{currentIndex > (paginationStart === 0 ? 0 : 1) ? (
|
|
188
|
-
<li
|
|
189
|
-
style={isDefaultStyles ? defaultStyles.itemClass : undefined}
|
|
190
|
-
onClick={() => setIndex(currentIndex - 1)}
|
|
191
|
-
>{`<<`}</li>
|
|
192
|
-
) : (
|
|
193
|
-
<li
|
|
194
|
-
className={disableItemClass}
|
|
195
|
-
style={isDefaultStyles ? defaultStyles.disableItemClass : undefined}
|
|
196
|
-
>{`<<`}</li>
|
|
197
|
-
)}
|
|
198
|
-
{/*First page button*/}
|
|
199
|
-
{currentIndex > (paginationStart == 0 ? 2 : 3) ? (
|
|
200
|
-
<li
|
|
201
|
-
className={itemClass}
|
|
202
|
-
style={isDefaultStyles ? defaultStyles.itemClass : undefined}
|
|
203
|
-
onClick={() => setIndex(paginationStart === 0 ? 0 : 1)}
|
|
204
|
-
>{`1`}</li>
|
|
205
|
-
) : null}
|
|
206
|
-
|
|
207
|
-
{currentIndex < (paginationStart === 0 ? 3 : 4)
|
|
208
|
-
? countItems.map((el) => {
|
|
209
|
-
if (paginationStart === 0 ? currentIndex + 1 === el : currentIndex === el) {
|
|
210
|
-
return (
|
|
211
|
-
<li
|
|
212
|
-
className={selectedItemClass}
|
|
213
|
-
style={isDefaultStyles ? defaultStyles.selectedItemClass : undefined}
|
|
214
|
-
key={el}
|
|
215
|
-
>
|
|
216
|
-
{el}
|
|
217
|
-
</li>
|
|
218
|
-
);
|
|
219
|
-
}
|
|
220
|
-
return (
|
|
221
|
-
<li
|
|
222
|
-
className={itemClass}
|
|
223
|
-
style={isDefaultStyles ? defaultStyles.itemClass : undefined}
|
|
224
|
-
onClick={() => setIndex(paginationStart === 0 ? el - 1 : el)}
|
|
225
|
-
key={el}
|
|
226
|
-
>
|
|
227
|
-
{el}
|
|
228
|
-
</li>
|
|
229
|
-
);
|
|
230
|
-
})
|
|
231
|
-
: null}
|
|
232
|
-
|
|
233
|
-
{currentIndex > (paginationStart === 0 ? 2 : 3) ? (
|
|
234
|
-
<li
|
|
235
|
-
className={disableItemClass}
|
|
236
|
-
style={isDefaultStyles ? defaultStyles.disableItemClass : undefined}
|
|
237
|
-
>{`...`}</li>
|
|
238
|
-
) : null}
|
|
239
|
-
|
|
240
|
-
{currentIndex > (paginationStart === 0 ? 2 : 3) &&
|
|
241
|
-
(paginationStart === 0 ? currentIndex : currentIndex - 1) < totalPages ? (
|
|
242
|
-
<>
|
|
243
|
-
{currentIndex === (paginationStart === 0 ? totalPages - 2 : totalPages - 1) && (
|
|
244
|
-
<li
|
|
245
|
-
className={itemClass}
|
|
246
|
-
style={isDefaultStyles ? defaultStyles.itemClass : undefined}
|
|
247
|
-
onClick={() => setIndex(paginationStart === 0 ? totalPages - 4 : totalPages - 3)}
|
|
248
|
-
>
|
|
249
|
-
{totalPages - 3}
|
|
250
|
-
</li>
|
|
251
|
-
)}
|
|
252
|
-
|
|
253
|
-
{currentIndex === (paginationStart === 0 ? totalPages - 1 : totalPages) && (
|
|
254
|
-
<>
|
|
255
|
-
<li
|
|
256
|
-
className={itemClass}
|
|
257
|
-
style={isDefaultStyles ? defaultStyles.itemClass : undefined}
|
|
258
|
-
onClick={() => setIndex(paginationStart === 0 ? totalPages - 4 : totalPages - 3)}
|
|
259
|
-
>
|
|
260
|
-
{totalPages - 3}
|
|
261
|
-
</li>
|
|
262
|
-
<li
|
|
263
|
-
className={itemClass}
|
|
264
|
-
style={isDefaultStyles ? defaultStyles.itemClass : undefined}
|
|
265
|
-
onClick={() => setIndex(paginationStart === 0 ? totalPages - 3 : totalPages - 2)}
|
|
266
|
-
>
|
|
267
|
-
{totalPages - 2}
|
|
268
|
-
</li>
|
|
269
|
-
</>
|
|
270
|
-
)}
|
|
271
|
-
|
|
272
|
-
<li
|
|
273
|
-
className={itemClass}
|
|
274
|
-
style={isDefaultStyles ? defaultStyles.itemClass : undefined}
|
|
275
|
-
onClick={() => setIndex(currentIndex - 1)}
|
|
276
|
-
>
|
|
277
|
-
{paginationStart === 0 ? currentIndex : currentIndex - 1}
|
|
278
|
-
</li>
|
|
279
|
-
|
|
280
|
-
<li className={selectedItemClass} style={isDefaultStyles ? defaultStyles.selectedItemClass : undefined}>
|
|
281
|
-
{paginationStart === 0 ? currentIndex + 1 : currentIndex}
|
|
282
|
-
</li>
|
|
283
|
-
|
|
284
|
-
{currentIndex < (paginationStart === 0 ? totalPages - 1 : totalPages) ? (
|
|
285
|
-
<li
|
|
286
|
-
className={itemClass}
|
|
287
|
-
style={isDefaultStyles ? defaultStyles.itemClass : undefined}
|
|
288
|
-
onClick={() => setIndex(currentIndex + 1)}
|
|
289
|
-
>
|
|
290
|
-
{paginationStart === 0 ? currentIndex + 2 : currentIndex + 1}
|
|
291
|
-
</li>
|
|
292
|
-
) : null}
|
|
293
|
-
</>
|
|
294
|
-
) : null}
|
|
295
|
-
|
|
296
|
-
{currentIndex < (paginationStart === 0 ? totalPages - 3 : totalPages - 2) ? (
|
|
297
|
-
<li
|
|
298
|
-
className={disableItemClass}
|
|
299
|
-
style={isDefaultStyles ? defaultStyles.disableItemClass : undefined}
|
|
300
|
-
>{`...`}</li>
|
|
301
|
-
) : null}
|
|
302
|
-
|
|
303
|
-
{currentIndex < (paginationStart === 0 ? totalPages - 2 : totalPages - 1) ? (
|
|
304
|
-
<li
|
|
305
|
-
className={itemClass}
|
|
306
|
-
style={isDefaultStyles ? defaultStyles.itemClass : undefined}
|
|
307
|
-
onClick={() => setIndex(paginationStart === 0 ? totalPages - 1 : totalPages)}
|
|
308
|
-
>
|
|
309
|
-
{totalPages}
|
|
310
|
-
</li>
|
|
311
|
-
) : null}
|
|
312
|
-
|
|
313
|
-
{(paginationStart === 0 ? currentIndex + 1 : currentIndex) < totalPages ? (
|
|
314
|
-
<li
|
|
315
|
-
className={itemClass}
|
|
316
|
-
style={isDefaultStyles ? defaultStyles.itemClass : undefined}
|
|
317
|
-
onClick={() => setIndex(currentIndex + 1)}
|
|
318
|
-
>{`>>`}</li>
|
|
319
|
-
) : (
|
|
320
|
-
<li
|
|
321
|
-
className={disableItemClass}
|
|
322
|
-
style={isDefaultStyles ? defaultStyles.disableItemClass : undefined}
|
|
323
|
-
>{`>>`}</li>
|
|
324
|
-
)}
|
|
325
|
-
</ul>
|
|
326
|
-
</div>
|
|
327
|
-
</>
|
|
328
|
-
);
|
|
329
|
-
};
|
|
330
|
-
|
|
331
|
-
export default Pagination;
|