best-react-pagination 0.0.1-alpha.1 → 0.1.1
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/.editorconfig +9 -0
- package/.eslintignore +1 -1
- package/.eslintrc.js +3 -1
- package/.husky/commit-msg +4 -0
- package/.husky/pre-commit +7 -0
- package/.lintstagedrc.json +3 -0
- package/LICENCE +12 -12
- package/README.md +50 -48
- package/commitlint.config.js +1 -0
- package/demo/public/index.html +17 -17
- package/demo/src/App.tsx +19 -10
- package/demo/src/Pagination/components/Item/Item.tsx +19 -0
- package/demo/src/Pagination/components/Item/index.ts +1 -0
- package/demo/src/Pagination/components/ItemList/ItemList.tsx +17 -0
- package/demo/src/Pagination/components/ItemList/index.ts +1 -0
- package/demo/src/Pagination/components/Wrapper/Wrapper.tsx +17 -0
- package/demo/src/Pagination/components/Wrapper/index.ts +1 -0
- package/demo/src/Pagination/components/constants.ts +49 -0
- package/demo/src/Pagination/components/index.ts +3 -0
- package/demo/src/Pagination/components/utils.ts +3 -0
- package/demo/src/Pagination/index.tsx +356 -0
- package/demo/tsconfig.json +17 -17
- package/dist/components/Item/Item.d.ts +10 -0
- package/dist/components/Item/index.d.ts +1 -0
- package/dist/components/ItemList/ItemList.d.ts +7 -0
- package/dist/components/ItemList/index.d.ts +1 -0
- package/dist/components/Wrapper/Wrapper.d.ts +7 -0
- package/dist/components/Wrapper/index.d.ts +1 -0
- package/dist/components/constants.d.ts +9 -0
- package/dist/components/index.d.ts +3 -0
- package/dist/components/utils.d.ts +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/husky.config.js +4 -4
- package/lib/components/Item/Item.tsx +19 -0
- package/lib/components/Item/index.ts +1 -0
- package/lib/components/ItemList/ItemList.tsx +17 -0
- package/lib/components/ItemList/index.ts +1 -0
- package/lib/components/Wrapper/Wrapper.tsx +17 -0
- package/lib/components/Wrapper/index.ts +1 -0
- package/lib/components/constants.ts +49 -0
- package/lib/components/index.ts +3 -0
- package/lib/components/utils.ts +3 -0
- package/lib/index.tsx +356 -368
- package/package.json +17 -6
- package/tsconfig.json +24 -23
- package/webpack.config.ts +53 -45
- package/demo/src/pagination/index.tsx +0 -369
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
import React, { FC } from "react";
|
|
2
|
+
import { defaultStylesEnum } from "./components/constants";
|
|
3
|
+
import { Item, ItemList, Wrapper } from "./components";
|
|
4
|
+
import { range } from "./components/utils";
|
|
5
|
+
|
|
6
|
+
interface PaginationProps {
|
|
7
|
+
paginationStart: 0 | 1;
|
|
8
|
+
currentIndex: number;
|
|
9
|
+
totalPages: number;
|
|
10
|
+
setIndex: React.Dispatch<React.SetStateAction<number>>;
|
|
11
|
+
isDefaultStyles?: boolean;
|
|
12
|
+
|
|
13
|
+
wrapperClass?: string;
|
|
14
|
+
itemListClass?: string;
|
|
15
|
+
itemClass?: string;
|
|
16
|
+
selectedItemClass?: string;
|
|
17
|
+
disableItemClass?: string;
|
|
18
|
+
|
|
19
|
+
className?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const Pagination: FC<PaginationProps> = ({
|
|
23
|
+
paginationStart,
|
|
24
|
+
currentIndex,
|
|
25
|
+
totalPages,
|
|
26
|
+
setIndex,
|
|
27
|
+
isDefaultStyles,
|
|
28
|
+
|
|
29
|
+
wrapperClass = "",
|
|
30
|
+
itemListClass = "",
|
|
31
|
+
itemClass = "",
|
|
32
|
+
selectedItemClass = "",
|
|
33
|
+
disableItemClass = "",
|
|
34
|
+
className,
|
|
35
|
+
}) => {
|
|
36
|
+
if (totalPages <= 1) {
|
|
37
|
+
return (
|
|
38
|
+
<Wrapper wrapperClass={className ? className : wrapperClass} isDefaultStyles={isDefaultStyles}>
|
|
39
|
+
<ItemList itemListClass={itemListClass} isDefaultStyles={isDefaultStyles}>
|
|
40
|
+
<Item
|
|
41
|
+
itemClass={disableItemClass}
|
|
42
|
+
itemStyle={defaultStylesEnum.disableItemClass}
|
|
43
|
+
isDefaultStyles={isDefaultStyles}
|
|
44
|
+
>
|
|
45
|
+
{`<<`}
|
|
46
|
+
</Item>
|
|
47
|
+
|
|
48
|
+
<Item
|
|
49
|
+
itemClass={disableItemClass}
|
|
50
|
+
itemStyle={defaultStylesEnum.disableItemClass}
|
|
51
|
+
isDefaultStyles={isDefaultStyles}
|
|
52
|
+
>
|
|
53
|
+
1
|
|
54
|
+
</Item>
|
|
55
|
+
|
|
56
|
+
<Item
|
|
57
|
+
itemClass={disableItemClass}
|
|
58
|
+
itemStyle={defaultStylesEnum.disableItemClass}
|
|
59
|
+
isDefaultStyles={isDefaultStyles}
|
|
60
|
+
>
|
|
61
|
+
{`>>`}
|
|
62
|
+
</Item>
|
|
63
|
+
</ItemList>
|
|
64
|
+
</Wrapper>
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (totalPages > 1 && totalPages < 4) {
|
|
69
|
+
return (
|
|
70
|
+
<Wrapper wrapperClass={className ? className : wrapperClass} isDefaultStyles={isDefaultStyles}>
|
|
71
|
+
<ItemList itemListClass={itemListClass} isDefaultStyles={isDefaultStyles}>
|
|
72
|
+
{range(totalPages).map((el) => {
|
|
73
|
+
const index = paginationStart === 0 ? el : el + 1;
|
|
74
|
+
if (currentIndex === index) {
|
|
75
|
+
return (
|
|
76
|
+
<Item
|
|
77
|
+
itemClass={selectedItemClass}
|
|
78
|
+
itemStyle={defaultStylesEnum.selectedItemClass}
|
|
79
|
+
isDefaultStyles={isDefaultStyles}
|
|
80
|
+
key={el}
|
|
81
|
+
>
|
|
82
|
+
{el + 1}
|
|
83
|
+
</Item>
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
return (
|
|
87
|
+
<Item
|
|
88
|
+
itemClass={selectedItemClass}
|
|
89
|
+
itemStyle={defaultStylesEnum.itemClass}
|
|
90
|
+
isDefaultStyles={isDefaultStyles}
|
|
91
|
+
onClick={() => setIndex(index)}
|
|
92
|
+
key={el}
|
|
93
|
+
>
|
|
94
|
+
{el + 1}
|
|
95
|
+
</Item>
|
|
96
|
+
);
|
|
97
|
+
})}
|
|
98
|
+
</ItemList>
|
|
99
|
+
</Wrapper>
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (totalPages === 4) {
|
|
104
|
+
return (
|
|
105
|
+
<Wrapper wrapperClass={className ? className : wrapperClass} isDefaultStyles={isDefaultStyles}>
|
|
106
|
+
<ItemList itemListClass={itemListClass} isDefaultStyles={isDefaultStyles}>
|
|
107
|
+
{currentIndex > (paginationStart === 0 ? 0 : 1) ? (
|
|
108
|
+
<Item
|
|
109
|
+
itemClass={itemClass}
|
|
110
|
+
itemStyle={defaultStylesEnum.itemClass}
|
|
111
|
+
isDefaultStyles={isDefaultStyles}
|
|
112
|
+
onClick={() => setIndex(currentIndex - 1)}
|
|
113
|
+
>
|
|
114
|
+
{`<<`}
|
|
115
|
+
</Item>
|
|
116
|
+
) : (
|
|
117
|
+
<Item
|
|
118
|
+
itemClass={disableItemClass}
|
|
119
|
+
itemStyle={defaultStylesEnum.disableItemClass}
|
|
120
|
+
isDefaultStyles={isDefaultStyles}
|
|
121
|
+
>
|
|
122
|
+
{`<<`}
|
|
123
|
+
</Item>
|
|
124
|
+
)}
|
|
125
|
+
{range(totalPages).map((el) => {
|
|
126
|
+
const index = paginationStart === 0 ? el : el + 1;
|
|
127
|
+
if (currentIndex === index) {
|
|
128
|
+
return (
|
|
129
|
+
<Item
|
|
130
|
+
itemClass={selectedItemClass}
|
|
131
|
+
itemStyle={defaultStylesEnum.selectedItemClass}
|
|
132
|
+
isDefaultStyles={isDefaultStyles}
|
|
133
|
+
key={el}
|
|
134
|
+
>
|
|
135
|
+
{el + 1}
|
|
136
|
+
</Item>
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
return (
|
|
140
|
+
<Item
|
|
141
|
+
itemClass={selectedItemClass}
|
|
142
|
+
itemStyle={defaultStylesEnum.itemClass}
|
|
143
|
+
isDefaultStyles={isDefaultStyles}
|
|
144
|
+
key={el}
|
|
145
|
+
onClick={() => setIndex(index)}
|
|
146
|
+
>
|
|
147
|
+
{el + 1}
|
|
148
|
+
</Item>
|
|
149
|
+
);
|
|
150
|
+
})}
|
|
151
|
+
{currentIndex < (paginationStart === 0 ? 3 : 4) ? (
|
|
152
|
+
<Item
|
|
153
|
+
itemClass={itemClass}
|
|
154
|
+
itemStyle={defaultStylesEnum.itemClass}
|
|
155
|
+
isDefaultStyles={isDefaultStyles}
|
|
156
|
+
onClick={() => setIndex(currentIndex + 1)}
|
|
157
|
+
>
|
|
158
|
+
{`>>`}
|
|
159
|
+
</Item>
|
|
160
|
+
) : (
|
|
161
|
+
<Item
|
|
162
|
+
itemClass={disableItemClass}
|
|
163
|
+
itemStyle={defaultStylesEnum.disableItemClass}
|
|
164
|
+
isDefaultStyles={isDefaultStyles}
|
|
165
|
+
>
|
|
166
|
+
{`>>`}
|
|
167
|
+
</Item>
|
|
168
|
+
)}
|
|
169
|
+
</ItemList>
|
|
170
|
+
</Wrapper>
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return (
|
|
175
|
+
<Wrapper wrapperClass={className ? className : wrapperClass} isDefaultStyles={isDefaultStyles}>
|
|
176
|
+
<ItemList itemListClass={itemListClass} isDefaultStyles={isDefaultStyles}>
|
|
177
|
+
{/*Previous button*/}
|
|
178
|
+
{currentIndex > (paginationStart === 0 ? 0 : 1) ? (
|
|
179
|
+
<Item
|
|
180
|
+
itemClass={itemClass}
|
|
181
|
+
itemStyle={defaultStylesEnum.itemClass}
|
|
182
|
+
isDefaultStyles={isDefaultStyles}
|
|
183
|
+
onClick={() => setIndex(currentIndex - 1)}
|
|
184
|
+
>
|
|
185
|
+
{`<<`}
|
|
186
|
+
</Item>
|
|
187
|
+
) : (
|
|
188
|
+
<Item
|
|
189
|
+
itemClass={disableItemClass}
|
|
190
|
+
itemStyle={defaultStylesEnum.disableItemClass}
|
|
191
|
+
isDefaultStyles={isDefaultStyles}
|
|
192
|
+
>
|
|
193
|
+
{`<<`}
|
|
194
|
+
</Item>
|
|
195
|
+
)}
|
|
196
|
+
{/*First page button*/}
|
|
197
|
+
{currentIndex > (paginationStart == 0 ? 2 : 3) ? (
|
|
198
|
+
<Item
|
|
199
|
+
itemClass={itemClass}
|
|
200
|
+
itemStyle={defaultStylesEnum.itemClass}
|
|
201
|
+
isDefaultStyles={isDefaultStyles}
|
|
202
|
+
onClick={() => setIndex(paginationStart === 0 ? 0 : 1)}
|
|
203
|
+
>
|
|
204
|
+
{`1`}
|
|
205
|
+
</Item>
|
|
206
|
+
) : null}
|
|
207
|
+
|
|
208
|
+
{currentIndex < (paginationStart === 0 ? 3 : 4)
|
|
209
|
+
? range(4).map((el) => {
|
|
210
|
+
const index = paginationStart === 0 ? el : el + 1;
|
|
211
|
+
if (currentIndex === index) {
|
|
212
|
+
return (
|
|
213
|
+
<Item
|
|
214
|
+
itemClass={selectedItemClass}
|
|
215
|
+
itemStyle={defaultStylesEnum.selectedItemClass}
|
|
216
|
+
isDefaultStyles={isDefaultStyles}
|
|
217
|
+
key={el}
|
|
218
|
+
>
|
|
219
|
+
{el + 1}
|
|
220
|
+
</Item>
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
return (
|
|
224
|
+
<Item
|
|
225
|
+
itemClass={itemClass}
|
|
226
|
+
itemStyle={defaultStylesEnum.itemClass}
|
|
227
|
+
isDefaultStyles={isDefaultStyles}
|
|
228
|
+
onClick={() => setIndex(index)}
|
|
229
|
+
key={el}
|
|
230
|
+
>
|
|
231
|
+
{el + 1}
|
|
232
|
+
</Item>
|
|
233
|
+
);
|
|
234
|
+
})
|
|
235
|
+
: null}
|
|
236
|
+
|
|
237
|
+
{currentIndex > (paginationStart === 0 ? 2 : 3) ? (
|
|
238
|
+
<Item
|
|
239
|
+
itemClass={disableItemClass}
|
|
240
|
+
itemStyle={defaultStylesEnum.disableItemClass}
|
|
241
|
+
isDefaultStyles={isDefaultStyles}
|
|
242
|
+
>
|
|
243
|
+
{`...`}
|
|
244
|
+
</Item>
|
|
245
|
+
) : null}
|
|
246
|
+
|
|
247
|
+
{currentIndex > (paginationStart === 0 ? 2 : 3) &&
|
|
248
|
+
(paginationStart === 0 ? currentIndex : currentIndex - 1) < totalPages ? (
|
|
249
|
+
<>
|
|
250
|
+
{currentIndex === (paginationStart === 0 ? totalPages - 2 : totalPages - 1) && (
|
|
251
|
+
<Item
|
|
252
|
+
itemClass={itemClass}
|
|
253
|
+
itemStyle={defaultStylesEnum.itemClass}
|
|
254
|
+
isDefaultStyles={isDefaultStyles}
|
|
255
|
+
onClick={() => setIndex(paginationStart === 0 ? totalPages - 4 : totalPages - 3)}
|
|
256
|
+
>
|
|
257
|
+
{totalPages - 3}
|
|
258
|
+
</Item>
|
|
259
|
+
)}
|
|
260
|
+
|
|
261
|
+
{currentIndex === (paginationStart === 0 ? totalPages - 1 : totalPages) && (
|
|
262
|
+
<>
|
|
263
|
+
<Item
|
|
264
|
+
itemClass={itemClass}
|
|
265
|
+
itemStyle={defaultStylesEnum.itemClass}
|
|
266
|
+
isDefaultStyles={isDefaultStyles}
|
|
267
|
+
onClick={() => setIndex(paginationStart === 0 ? totalPages - 4 : totalPages - 3)}
|
|
268
|
+
>
|
|
269
|
+
{totalPages - 3}
|
|
270
|
+
</Item>
|
|
271
|
+
<Item
|
|
272
|
+
itemClass={itemClass}
|
|
273
|
+
itemStyle={defaultStylesEnum.itemClass}
|
|
274
|
+
isDefaultStyles={isDefaultStyles}
|
|
275
|
+
onClick={() => setIndex(paginationStart === 0 ? totalPages - 3 : totalPages - 2)}
|
|
276
|
+
>
|
|
277
|
+
{totalPages - 2}
|
|
278
|
+
</Item>
|
|
279
|
+
</>
|
|
280
|
+
)}
|
|
281
|
+
|
|
282
|
+
<Item
|
|
283
|
+
itemClass={itemClass}
|
|
284
|
+
itemStyle={defaultStylesEnum.itemClass}
|
|
285
|
+
isDefaultStyles={isDefaultStyles}
|
|
286
|
+
onClick={() => setIndex(currentIndex - 1)}
|
|
287
|
+
>
|
|
288
|
+
{paginationStart === 0 ? currentIndex : currentIndex - 1}
|
|
289
|
+
</Item>
|
|
290
|
+
|
|
291
|
+
<Item
|
|
292
|
+
itemClass={selectedItemClass}
|
|
293
|
+
itemStyle={defaultStylesEnum.selectedItemClass}
|
|
294
|
+
isDefaultStyles={isDefaultStyles}
|
|
295
|
+
>
|
|
296
|
+
{paginationStart === 0 ? currentIndex + 1 : currentIndex}
|
|
297
|
+
</Item>
|
|
298
|
+
|
|
299
|
+
{currentIndex < (paginationStart === 0 ? totalPages - 1 : totalPages) ? (
|
|
300
|
+
<Item
|
|
301
|
+
itemClass={itemClass}
|
|
302
|
+
itemStyle={defaultStylesEnum.itemClass}
|
|
303
|
+
isDefaultStyles={isDefaultStyles}
|
|
304
|
+
onClick={() => setIndex(currentIndex + 1)}
|
|
305
|
+
>
|
|
306
|
+
{paginationStart === 0 ? currentIndex + 2 : currentIndex + 1}
|
|
307
|
+
</Item>
|
|
308
|
+
) : null}
|
|
309
|
+
</>
|
|
310
|
+
) : null}
|
|
311
|
+
|
|
312
|
+
{currentIndex < (paginationStart === 0 ? totalPages - 3 : totalPages - 2) ? (
|
|
313
|
+
<Item
|
|
314
|
+
itemClass={disableItemClass}
|
|
315
|
+
itemStyle={defaultStylesEnum.disableItemClass}
|
|
316
|
+
isDefaultStyles={isDefaultStyles}
|
|
317
|
+
>
|
|
318
|
+
{`...`}
|
|
319
|
+
</Item>
|
|
320
|
+
) : null}
|
|
321
|
+
|
|
322
|
+
{currentIndex < (paginationStart === 0 ? totalPages - 2 : totalPages - 1) ? (
|
|
323
|
+
<Item
|
|
324
|
+
itemClass={itemClass}
|
|
325
|
+
itemStyle={defaultStylesEnum.itemClass}
|
|
326
|
+
isDefaultStyles={isDefaultStyles}
|
|
327
|
+
onClick={() => setIndex(paginationStart === 0 ? totalPages - 1 : totalPages)}
|
|
328
|
+
>
|
|
329
|
+
{totalPages}
|
|
330
|
+
</Item>
|
|
331
|
+
) : null}
|
|
332
|
+
|
|
333
|
+
{(paginationStart === 0 ? currentIndex + 1 : currentIndex) < totalPages ? (
|
|
334
|
+
<Item
|
|
335
|
+
itemClass={itemClass}
|
|
336
|
+
itemStyle={defaultStylesEnum.itemClass}
|
|
337
|
+
isDefaultStyles={isDefaultStyles}
|
|
338
|
+
onClick={() => setIndex(currentIndex + 1)}
|
|
339
|
+
>
|
|
340
|
+
{`>>`}
|
|
341
|
+
</Item>
|
|
342
|
+
) : (
|
|
343
|
+
<Item
|
|
344
|
+
itemClass={disableItemClass}
|
|
345
|
+
itemStyle={defaultStylesEnum.disableItemClass}
|
|
346
|
+
isDefaultStyles={isDefaultStyles}
|
|
347
|
+
>
|
|
348
|
+
{`>>`}
|
|
349
|
+
</Item>
|
|
350
|
+
)}
|
|
351
|
+
</ItemList>
|
|
352
|
+
</Wrapper>
|
|
353
|
+
);
|
|
354
|
+
};
|
|
355
|
+
|
|
356
|
+
export default Pagination;
|
package/demo/tsconfig.json
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"sourceMap": true,
|
|
4
|
+
"strict": true,
|
|
5
|
+
"noImplicitReturns": true,
|
|
6
|
+
"noImplicitAny": true,
|
|
7
|
+
"module": "es6",
|
|
8
|
+
"moduleResolution": "node",
|
|
9
|
+
"target": "es5",
|
|
10
|
+
"allowJs": true,
|
|
11
|
+
"jsx": "react",
|
|
12
|
+
"allowSyntheticDefaultImports": true,
|
|
13
|
+
"downlevelIteration": true
|
|
14
|
+
},
|
|
15
|
+
"include": [
|
|
16
|
+
"./src/**/*"
|
|
17
|
+
]
|
|
18
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { FC } from "react";
|
|
2
|
+
import { defaultStylesEnum } from "../constants";
|
|
3
|
+
interface ItemProps {
|
|
4
|
+
isDefaultStyles: boolean | undefined;
|
|
5
|
+
itemClass: string;
|
|
6
|
+
itemStyle: defaultStylesEnum;
|
|
7
|
+
onClick?: () => void;
|
|
8
|
+
}
|
|
9
|
+
declare const Item: FC<ItemProps>;
|
|
10
|
+
export default Item;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./Item";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./ItemList";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./Wrapper";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
export declare enum defaultStylesEnum {
|
|
3
|
+
wrapperClass = "wrapperClass",
|
|
4
|
+
itemListClass = "itemListClass",
|
|
5
|
+
itemClass = "itemClass",
|
|
6
|
+
selectedItemClass = "selectedItemClass",
|
|
7
|
+
disableItemClass = "disableItemClass"
|
|
8
|
+
}
|
|
9
|
+
export declare const defaultStyles: Record<defaultStylesEnum, React.CSSProperties>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const range: (count: number) => Array<number>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { FC } from "react";
|
|
2
|
-
interface
|
|
2
|
+
interface PaginationProps {
|
|
3
3
|
paginationStart: 0 | 1;
|
|
4
4
|
currentIndex: number;
|
|
5
5
|
totalPages: number;
|
|
@@ -12,5 +12,5 @@ interface IPagination {
|
|
|
12
12
|
disableItemClass?: string;
|
|
13
13
|
className?: string;
|
|
14
14
|
}
|
|
15
|
-
declare const Pagination: FC<
|
|
15
|
+
declare const Pagination: FC<PaginationProps>;
|
|
16
16
|
export default Pagination;
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["best-react-pagination"]=t():e["best-react-pagination"]=t()}(self,(function(){return(()=>{"use strict";var e={
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["best-react-pagination"]=t():e["best-react-pagination"]=t()}(self,(function(){return(()=>{"use strict";var e={743:function(e,t,l){var a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});var s=a(l(689)),n=l(40);t.default=function(e){var t=e.isDefaultStyles,l=e.itemListClass,a=e.children;return s.default.createElement("ul",{className:l,style:t?n.defaultStyles.itemListClass:void 0},a)}},175:function(e,t,l){var a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var s=l(743);Object.defineProperty(t,"default",{enumerable:!0,get:function(){return a(s).default}})},775:function(e,t,l){var a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});var s=a(l(689)),n=l(40);t.default=function(e){var t=e.isDefaultStyles,l=e.itemClass,a=e.itemStyle,u=e.onClick,i=e.children;return s.default.createElement("li",{className:l,style:t?n.defaultStyles[a]:void 0,onClick:u},i)}},541:function(e,t,l){var a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var s=l(775);Object.defineProperty(t,"default",{enumerable:!0,get:function(){return a(s).default}})},989:function(e,t,l){var a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});var s=a(l(689)),n=l(40);t.default=function(e){var t=e.isDefaultStyles,l=e.wrapperClass,a=e.children;return s.default.createElement("div",{className:l,style:t?n.defaultStyles.wrapperClass:void 0},a)}},704:function(e,t,l){var a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var s=l(989);Object.defineProperty(t,"default",{enumerable:!0,get:function(){return a(s).default}})},40:(e,t)=>{var l;Object.defineProperty(t,"__esModule",{value:!0}),t.defaultStyles=t.defaultStylesEnum=void 0,(l=t.defaultStylesEnum||(t.defaultStylesEnum={})).wrapperClass="wrapperClass",l.itemListClass="itemListClass",l.itemClass="itemClass",l.selectedItemClass="selectedItemClass",l.disableItemClass="disableItemClass",t.defaultStyles={wrapperClass:{position:"sticky",display:"flex",justifyContent:"center",alignItems:"center",width:"100%",bottom:0},itemListClass:{padding:"10px 0"},itemClass:{display:"inline",cursor:"pointer",padding:"6px 12px",borderRadius:"4px",margin:"0 2px",backgroundColor:"#45c954",userSelect:"none"},selectedItemClass:{display:"inline",cursor:"pointer",padding:"6px 12px",borderRadius:"4px",margin:"0 2px",backgroundColor:"#48bbff",userSelect:"none"},disableItemClass:{display:"inline",cursor:"not-allowed",padding:"6px 12px",borderRadius:"4px",margin:"0 2px",userSelect:"none"}}},741:function(e,t,l){var a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.Item=t.ItemList=t.Wrapper=void 0;var s=l(704);Object.defineProperty(t,"Wrapper",{enumerable:!0,get:function(){return a(s).default}});var n=l(175);Object.defineProperty(t,"ItemList",{enumerable:!0,get:function(){return a(n).default}});var u=l(541);Object.defineProperty(t,"Item",{enumerable:!0,get:function(){return a(u).default}})},876:(e,t)=>{function l(e,t){(null==t||t>e.length)&&(t=e.length);for(var l=0,a=new Array(t);l<t;l++)a[l]=e[l];return a}Object.defineProperty(t,"__esModule",{value:!0}),t.range=void 0,t.range=function(e){return(t=Array(e).keys(),function(e){if(Array.isArray(e))return l(e)}(t)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(t)||function(e,t){if(e){if("string"==typeof e)return l(e,t);var a=Object.prototype.toString.call(e).slice(8,-1);return"Object"===a&&e.constructor&&(a=e.constructor.name),"Map"===a||"Set"===a?Array.from(e):"Arguments"===a||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(a)?l(e,t):void 0}}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()).map((function(e){return e}));var t}},708:function(e,t,l){var a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});var s=a(l(689)),n=l(40),u=l(741),i=l(876);t.default=function(e){var t=e.paginationStart,l=e.currentIndex,a=e.totalPages,r=e.setIndex,m=e.isDefaultStyles,f=e.wrapperClass,d=void 0===f?"":f,o=e.itemListClass,c=void 0===o?"":o,y=e.itemClass,S=void 0===y?"":y,p=e.selectedItemClass,C=void 0===p?"":p,E=e.disableItemClass,I=void 0===E?"":E,v=e.className;return a<=1?s.default.createElement(u.Wrapper,{wrapperClass:v||d,isDefaultStyles:m},s.default.createElement(u.ItemList,{itemListClass:c,isDefaultStyles:m},s.default.createElement(u.Item,{itemClass:I,itemStyle:n.defaultStylesEnum.disableItemClass,isDefaultStyles:m},"<<"),s.default.createElement(u.Item,{itemClass:I,itemStyle:n.defaultStylesEnum.disableItemClass,isDefaultStyles:m},"1"),s.default.createElement(u.Item,{itemClass:I,itemStyle:n.defaultStylesEnum.disableItemClass,isDefaultStyles:m},">>"))):a>1&&a<4?s.default.createElement(u.Wrapper,{wrapperClass:v||d,isDefaultStyles:m},s.default.createElement(u.ItemList,{itemListClass:c,isDefaultStyles:m},(0,i.range)(a).map((function(e){var a=0===t?e:e+1;return l===a?s.default.createElement(u.Item,{itemClass:C,itemStyle:n.defaultStylesEnum.selectedItemClass,isDefaultStyles:m,key:e},e+1):s.default.createElement(u.Item,{itemClass:C,itemStyle:n.defaultStylesEnum.itemClass,isDefaultStyles:m,onClick:function(){return r(a)},key:e},e+1)})))):4===a?s.default.createElement(u.Wrapper,{wrapperClass:v||d,isDefaultStyles:m},s.default.createElement(u.ItemList,{itemListClass:c,isDefaultStyles:m},l>(0===t?0:1)?s.default.createElement(u.Item,{itemClass:S,itemStyle:n.defaultStylesEnum.itemClass,isDefaultStyles:m,onClick:function(){return r(l-1)}},"<<"):s.default.createElement(u.Item,{itemClass:I,itemStyle:n.defaultStylesEnum.disableItemClass,isDefaultStyles:m},"<<"),(0,i.range)(a).map((function(e){var a=0===t?e:e+1;return l===a?s.default.createElement(u.Item,{itemClass:C,itemStyle:n.defaultStylesEnum.selectedItemClass,isDefaultStyles:m,key:e},e+1):s.default.createElement(u.Item,{itemClass:C,itemStyle:n.defaultStylesEnum.itemClass,isDefaultStyles:m,key:e,onClick:function(){return r(a)}},e+1)})),l<(0===t?3:4)?s.default.createElement(u.Item,{itemClass:S,itemStyle:n.defaultStylesEnum.itemClass,isDefaultStyles:m,onClick:function(){return r(l+1)}},">>"):s.default.createElement(u.Item,{itemClass:I,itemStyle:n.defaultStylesEnum.disableItemClass,isDefaultStyles:m},">>"))):s.default.createElement(u.Wrapper,{wrapperClass:v||d,isDefaultStyles:m},s.default.createElement(u.ItemList,{itemListClass:c,isDefaultStyles:m},l>(0===t?0:1)?s.default.createElement(u.Item,{itemClass:S,itemStyle:n.defaultStylesEnum.itemClass,isDefaultStyles:m,onClick:function(){return r(l-1)}},"<<"):s.default.createElement(u.Item,{itemClass:I,itemStyle:n.defaultStylesEnum.disableItemClass,isDefaultStyles:m},"<<"),l>(0==t?2:3)?s.default.createElement(u.Item,{itemClass:S,itemStyle:n.defaultStylesEnum.itemClass,isDefaultStyles:m,onClick:function(){return r(0===t?0:1)}},"1"):null,l<(0===t?3:4)?(0,i.range)(4).map((function(e){var a=0===t?e:e+1;return l===a?s.default.createElement(u.Item,{itemClass:C,itemStyle:n.defaultStylesEnum.selectedItemClass,isDefaultStyles:m,key:e},e+1):s.default.createElement(u.Item,{itemClass:S,itemStyle:n.defaultStylesEnum.itemClass,isDefaultStyles:m,onClick:function(){return r(a)},key:e},e+1)})):null,l>(0===t?2:3)?s.default.createElement(u.Item,{itemClass:I,itemStyle:n.defaultStylesEnum.disableItemClass,isDefaultStyles:m},"..."):null,l>(0===t?2:3)&&(0===t?l:l-1)<a?s.default.createElement(s.default.Fragment,null,l===(0===t?a-2:a-1)&&s.default.createElement(u.Item,{itemClass:S,itemStyle:n.defaultStylesEnum.itemClass,isDefaultStyles:m,onClick:function(){return r(0===t?a-4:a-3)}},a-3),l===(0===t?a-1:a)&&s.default.createElement(s.default.Fragment,null,s.default.createElement(u.Item,{itemClass:S,itemStyle:n.defaultStylesEnum.itemClass,isDefaultStyles:m,onClick:function(){return r(0===t?a-4:a-3)}},a-3),s.default.createElement(u.Item,{itemClass:S,itemStyle:n.defaultStylesEnum.itemClass,isDefaultStyles:m,onClick:function(){return r(0===t?a-3:a-2)}},a-2)),s.default.createElement(u.Item,{itemClass:S,itemStyle:n.defaultStylesEnum.itemClass,isDefaultStyles:m,onClick:function(){return r(l-1)}},0===t?l:l-1),s.default.createElement(u.Item,{itemClass:C,itemStyle:n.defaultStylesEnum.selectedItemClass,isDefaultStyles:m},0===t?l+1:l),l<(0===t?a-1:a)?s.default.createElement(u.Item,{itemClass:S,itemStyle:n.defaultStylesEnum.itemClass,isDefaultStyles:m,onClick:function(){return r(l+1)}},0===t?l+2:l+1):null):null,l<(0===t?a-3:a-2)?s.default.createElement(u.Item,{itemClass:I,itemStyle:n.defaultStylesEnum.disableItemClass,isDefaultStyles:m},"..."):null,l<(0===t?a-2:a-1)?s.default.createElement(u.Item,{itemClass:S,itemStyle:n.defaultStylesEnum.itemClass,isDefaultStyles:m,onClick:function(){return r(0===t?a-1:a)}},a):null,(0===t?l+1:l)<a?s.default.createElement(u.Item,{itemClass:S,itemStyle:n.defaultStylesEnum.itemClass,isDefaultStyles:m,onClick:function(){return r(l+1)}},">>"):s.default.createElement(u.Item,{itemClass:I,itemStyle:n.defaultStylesEnum.disableItemClass,isDefaultStyles:m},">>")))}},689:e=>{e.exports=require("react")}},t={};return function l(a){var s=t[a];if(void 0!==s)return s.exports;var n=t[a]={exports:{}};return e[a].call(n.exports,n,n.exports,l),n.exports}(708)})()}));
|
package/husky.config.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
"hooks": {
|
|
3
|
-
"pre-commit": "npm run build && npm run test"
|
|
4
|
-
}
|
|
1
|
+
module.exports = {
|
|
2
|
+
"hooks": {
|
|
3
|
+
"pre-commit": "npm run build && npm run test"
|
|
4
|
+
}
|
|
5
5
|
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import React, { FC } from "react";
|
|
2
|
+
import { defaultStyles, defaultStylesEnum } from "../constants";
|
|
3
|
+
|
|
4
|
+
interface ItemProps {
|
|
5
|
+
isDefaultStyles: boolean | undefined;
|
|
6
|
+
itemClass: string;
|
|
7
|
+
itemStyle: defaultStylesEnum;
|
|
8
|
+
onClick?: () => void;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const Item: FC<ItemProps> = ({ isDefaultStyles, itemClass, itemStyle, onClick, children }) => {
|
|
12
|
+
return (
|
|
13
|
+
<li className={itemClass} style={isDefaultStyles ? defaultStyles[itemStyle] : undefined} onClick={onClick}>
|
|
14
|
+
{children}
|
|
15
|
+
</li>
|
|
16
|
+
);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export default Item;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./Item";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React, { FC } from "react";
|
|
2
|
+
import { defaultStyles } from "../constants";
|
|
3
|
+
|
|
4
|
+
interface ItemListProps {
|
|
5
|
+
isDefaultStyles: boolean | undefined;
|
|
6
|
+
itemListClass: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const ItemList: FC<ItemListProps> = ({ isDefaultStyles, itemListClass, children }) => {
|
|
10
|
+
return (
|
|
11
|
+
<ul className={itemListClass} style={isDefaultStyles ? defaultStyles.itemListClass : undefined}>
|
|
12
|
+
{children}
|
|
13
|
+
</ul>
|
|
14
|
+
);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export default ItemList;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./ItemList";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React, { FC } from "react";
|
|
2
|
+
import { defaultStyles } from "../constants";
|
|
3
|
+
|
|
4
|
+
interface WrapperProps {
|
|
5
|
+
isDefaultStyles: boolean | undefined;
|
|
6
|
+
wrapperClass: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const Wrapper: FC<WrapperProps> = ({ isDefaultStyles, wrapperClass, children }) => {
|
|
10
|
+
return (
|
|
11
|
+
<div className={wrapperClass} style={isDefaultStyles ? defaultStyles.wrapperClass : undefined}>
|
|
12
|
+
{children}
|
|
13
|
+
</div>
|
|
14
|
+
);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export default Wrapper;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./Wrapper";
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
|
|
3
|
+
export enum defaultStylesEnum {
|
|
4
|
+
wrapperClass = "wrapperClass",
|
|
5
|
+
itemListClass = "itemListClass",
|
|
6
|
+
itemClass = "itemClass",
|
|
7
|
+
selectedItemClass = "selectedItemClass",
|
|
8
|
+
disableItemClass = "disableItemClass",
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const defaultStyles: Record<defaultStylesEnum, React.CSSProperties> = {
|
|
12
|
+
wrapperClass: {
|
|
13
|
+
position: "sticky",
|
|
14
|
+
display: "flex",
|
|
15
|
+
justifyContent: "center",
|
|
16
|
+
alignItems: "center",
|
|
17
|
+
width: "100%",
|
|
18
|
+
bottom: 0,
|
|
19
|
+
},
|
|
20
|
+
itemListClass: {
|
|
21
|
+
padding: "10px 0",
|
|
22
|
+
},
|
|
23
|
+
itemClass: {
|
|
24
|
+
display: "inline",
|
|
25
|
+
cursor: "pointer",
|
|
26
|
+
padding: "6px 12px",
|
|
27
|
+
borderRadius: "4px",
|
|
28
|
+
margin: "0 2px",
|
|
29
|
+
backgroundColor: "#45c954",
|
|
30
|
+
userSelect: "none",
|
|
31
|
+
},
|
|
32
|
+
selectedItemClass: {
|
|
33
|
+
display: "inline",
|
|
34
|
+
cursor: "pointer",
|
|
35
|
+
padding: "6px 12px",
|
|
36
|
+
borderRadius: "4px",
|
|
37
|
+
margin: "0 2px",
|
|
38
|
+
backgroundColor: "#48bbff",
|
|
39
|
+
userSelect: "none",
|
|
40
|
+
},
|
|
41
|
+
disableItemClass: {
|
|
42
|
+
display: "inline",
|
|
43
|
+
cursor: "not-allowed",
|
|
44
|
+
padding: "6px 12px",
|
|
45
|
+
borderRadius: "4px",
|
|
46
|
+
margin: "0 2px",
|
|
47
|
+
userSelect: "none",
|
|
48
|
+
},
|
|
49
|
+
};
|