best-react-pagination 0.1.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.
Files changed (47) hide show
  1. package/.idea/best-react-pagination.iml +9 -0
  2. package/.idea/codeStyles/Project.xml +58 -0
  3. package/.idea/codeStyles/codeStyleConfig.xml +5 -0
  4. package/.idea/discord.xml +7 -0
  5. package/.idea/git_toolbox_prj.xml +15 -0
  6. package/.idea/inspectionProfiles/Project_Default.xml +6 -0
  7. package/.idea/misc.xml +6 -0
  8. package/.idea/modules.xml +8 -0
  9. package/.idea/prettier.xml +6 -0
  10. package/.idea/vcs.xml +6 -0
  11. package/package.json +1 -1
  12. package/demo/.babelrc +0 -14
  13. package/demo/public/index.html +0 -17
  14. package/demo/src/App.tsx +0 -24
  15. package/demo/src/Pagination/components/Item/Item.tsx +0 -19
  16. package/demo/src/Pagination/components/Item/index.ts +0 -1
  17. package/demo/src/Pagination/components/ItemList/ItemList.tsx +0 -17
  18. package/demo/src/Pagination/components/ItemList/index.ts +0 -1
  19. package/demo/src/Pagination/components/Wrapper/Wrapper.tsx +0 -17
  20. package/demo/src/Pagination/components/Wrapper/index.ts +0 -1
  21. package/demo/src/Pagination/components/constants.ts +0 -49
  22. package/demo/src/Pagination/components/index.ts +0 -3
  23. package/demo/src/Pagination/components/utils.ts +0 -3
  24. package/demo/src/Pagination/index.tsx +0 -356
  25. package/demo/src/index.html +0 -11
  26. package/demo/src/index.tsx +0 -7
  27. package/demo/tsconfig.json +0 -18
  28. package/demo/webpack.config.js +0 -50
  29. package/dist/components/Item/Item.d.ts +0 -10
  30. package/dist/components/Item/index.d.ts +0 -1
  31. package/dist/components/ItemList/ItemList.d.ts +0 -7
  32. package/dist/components/ItemList/index.d.ts +0 -1
  33. package/dist/components/Wrapper/Wrapper.d.ts +0 -7
  34. package/dist/components/Wrapper/index.d.ts +0 -1
  35. package/dist/components/constants.d.ts +0 -9
  36. package/dist/components/index.d.ts +0 -3
  37. package/dist/components/utils.d.ts +0 -1
  38. package/lib/components/Item/Item.tsx +0 -19
  39. package/lib/components/Item/index.ts +0 -1
  40. package/lib/components/ItemList/ItemList.tsx +0 -17
  41. package/lib/components/ItemList/index.ts +0 -1
  42. package/lib/components/Wrapper/Wrapper.tsx +0 -17
  43. package/lib/components/Wrapper/index.ts +0 -1
  44. package/lib/components/constants.ts +0 -49
  45. package/lib/components/index.ts +0 -3
  46. package/lib/components/utils.ts +0 -3
  47. package/lib/index.tsx +0 -356
@@ -1,356 +0,0 @@
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;
@@ -1,11 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>Empty project</title>
5
- <meta charset="utf-8">
6
- </head>
7
- <body>
8
- <div id="app"></div>
9
- <script src="bundle.js"></script>
10
- </body>
11
- </html>
@@ -1,7 +0,0 @@
1
- import React from "react";
2
- import ReactDOM from "react-dom";
3
-
4
- import App from "./App";
5
-
6
- const mountNode = document.getElementById("app");
7
- ReactDOM.render(<App />, mountNode);
@@ -1,18 +0,0 @@
1
- {
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
- }
@@ -1,50 +0,0 @@
1
- const path = require("path");
2
- const CopyPlugin = require("copy-webpack-plugin");
3
- const { CleanWebpackPlugin } = require("clean-webpack-plugin");
4
-
5
- const stcPath = path.resolve(__dirname, "src");
6
-
7
- const config = {
8
- entry: [
9
- // "react-hot-loader/patch",
10
- stcPath + "/index.tsx"
11
- ],
12
- output: {
13
- path: path.resolve(__dirname, "dist"),
14
- filename: "bundle.js"
15
- },
16
- module: {
17
- rules: [
18
- {
19
- test: /\.(js|jsx)$/,
20
- use: "babel-loader",
21
- exclude: /node_modules/
22
- },
23
- {
24
- test: /\.ts(x)?$/,
25
- loader: "ts-loader",
26
- exclude: /node_modules/
27
- }
28
- ]
29
- },
30
- resolve: {
31
- extensions: [
32
- ".tsx",
33
- ".ts",
34
- ".js"
35
- ],
36
- },
37
- devServer: {
38
- "static": {
39
- directory: "./dist"
40
- }
41
- },
42
- plugins: [
43
- new CopyPlugin({
44
- patterns: [{ from: stcPath + "/index.html" }],
45
- }),
46
- new CleanWebpackPlugin()
47
- ]
48
- };
49
-
50
- module.exports = config;
@@ -1,10 +0,0 @@
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;
@@ -1 +0,0 @@
1
- export { default } from "./Item";
@@ -1,7 +0,0 @@
1
- import { FC } from "react";
2
- interface ItemListProps {
3
- isDefaultStyles: boolean | undefined;
4
- itemListClass: string;
5
- }
6
- declare const ItemList: FC<ItemListProps>;
7
- export default ItemList;
@@ -1 +0,0 @@
1
- export { default } from "./ItemList";
@@ -1,7 +0,0 @@
1
- import { FC } from "react";
2
- interface WrapperProps {
3
- isDefaultStyles: boolean | undefined;
4
- wrapperClass: string;
5
- }
6
- declare const Wrapper: FC<WrapperProps>;
7
- export default Wrapper;
@@ -1 +0,0 @@
1
- export { default } from "./Wrapper";
@@ -1,9 +0,0 @@
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>;
@@ -1,3 +0,0 @@
1
- export { default as Wrapper } from "./Wrapper";
2
- export { default as ItemList } from "./ItemList";
3
- export { default as Item } from "./Item";
@@ -1 +0,0 @@
1
- export declare const range: (count: number) => Array<number>;
@@ -1,19 +0,0 @@
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;
@@ -1 +0,0 @@
1
- export { default } from "./Item";
@@ -1,17 +0,0 @@
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;
@@ -1 +0,0 @@
1
- export { default } from "./ItemList";
@@ -1,17 +0,0 @@
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;
@@ -1 +0,0 @@
1
- export { default } from "./Wrapper";
@@ -1,49 +0,0 @@
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
- };
@@ -1,3 +0,0 @@
1
- export { default as Wrapper } from "./Wrapper";
2
- export { default as ItemList } from "./ItemList";
3
- export { default as Item } from "./Item";
@@ -1,3 +0,0 @@
1
- export const range = (count: number): Array<number> => {
2
- return [...Array(count).keys()].map((i) => i);
3
- };