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.
Files changed (48) hide show
  1. package/.editorconfig +9 -0
  2. package/.eslintignore +1 -1
  3. package/.eslintrc.js +3 -1
  4. package/.husky/commit-msg +4 -0
  5. package/.husky/pre-commit +7 -0
  6. package/.lintstagedrc.json +3 -0
  7. package/LICENCE +12 -12
  8. package/README.md +50 -48
  9. package/commitlint.config.js +1 -0
  10. package/demo/public/index.html +17 -17
  11. package/demo/src/App.tsx +19 -10
  12. package/demo/src/Pagination/components/Item/Item.tsx +19 -0
  13. package/demo/src/Pagination/components/Item/index.ts +1 -0
  14. package/demo/src/Pagination/components/ItemList/ItemList.tsx +17 -0
  15. package/demo/src/Pagination/components/ItemList/index.ts +1 -0
  16. package/demo/src/Pagination/components/Wrapper/Wrapper.tsx +17 -0
  17. package/demo/src/Pagination/components/Wrapper/index.ts +1 -0
  18. package/demo/src/Pagination/components/constants.ts +49 -0
  19. package/demo/src/Pagination/components/index.ts +3 -0
  20. package/demo/src/Pagination/components/utils.ts +3 -0
  21. package/demo/src/Pagination/index.tsx +356 -0
  22. package/demo/tsconfig.json +17 -17
  23. package/dist/components/Item/Item.d.ts +10 -0
  24. package/dist/components/Item/index.d.ts +1 -0
  25. package/dist/components/ItemList/ItemList.d.ts +7 -0
  26. package/dist/components/ItemList/index.d.ts +1 -0
  27. package/dist/components/Wrapper/Wrapper.d.ts +7 -0
  28. package/dist/components/Wrapper/index.d.ts +1 -0
  29. package/dist/components/constants.d.ts +9 -0
  30. package/dist/components/index.d.ts +3 -0
  31. package/dist/components/utils.d.ts +1 -0
  32. package/dist/index.d.ts +2 -2
  33. package/dist/index.js +1 -1
  34. package/husky.config.js +4 -4
  35. package/lib/components/Item/Item.tsx +19 -0
  36. package/lib/components/Item/index.ts +1 -0
  37. package/lib/components/ItemList/ItemList.tsx +17 -0
  38. package/lib/components/ItemList/index.ts +1 -0
  39. package/lib/components/Wrapper/Wrapper.tsx +17 -0
  40. package/lib/components/Wrapper/index.ts +1 -0
  41. package/lib/components/constants.ts +49 -0
  42. package/lib/components/index.ts +3 -0
  43. package/lib/components/utils.ts +3 -0
  44. package/lib/index.tsx +356 -368
  45. package/package.json +17 -6
  46. package/tsconfig.json +24 -23
  47. package/webpack.config.ts +53 -45
  48. package/demo/src/pagination/index.tsx +0 -369
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "best-react-pagination",
3
- "version": "0.0.1-alpha.1",
3
+ "version": "0.1.1",
4
4
  "description": "Pagination for work with React",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -13,7 +13,11 @@
13
13
  "scripts": {
14
14
  "build": "webpack --mode production",
15
15
  "dev": "webpack serve --config demo/webpack.config.js --hot --mode development",
16
- "start": "npm run dev"
16
+ "start": "npm run dev",
17
+ "prettier": "prettier --write --no-error-on-unmatched-pattern demo/src/**/*.{ts,tsx}",
18
+ "lint": "eslint --debug demo/src/",
19
+ "lint:write": "eslint --debug demo/src/ --fix",
20
+ "prepare": "npx husky install"
17
21
  },
18
22
  "author": "Dmitry Tsybizov",
19
23
  "license": "ISC",
@@ -21,15 +25,16 @@
21
25
  "url": "https://github.com/97Dmitry/best-react-pagination/issues"
22
26
  },
23
27
  "homepage": "https://github.com/97Dmitry/best-react-pagination#readme",
24
- "dependencies": {
25
- "react": "^17.0.2",
26
- "react-dom": "^17.0.2"
28
+ "peerDependencies": {
29
+ "react": ">=16.8"
27
30
  },
28
31
  "devDependencies": {
29
32
  "@babel/core": "^7.15.8",
30
33
  "@babel/preset-env": "^7.15.8",
31
34
  "@babel/preset-react": "^7.14.5",
32
35
  "@babel/preset-typescript": "^7.15.0",
36
+ "@commitlint/cli": "^15.0.0",
37
+ "@commitlint/config-conventional": "^15.0.0",
33
38
  "@types/jest": "^27.0.2",
34
39
  "@types/node": "^16.11.0",
35
40
  "@types/react": "^17.0.30",
@@ -44,8 +49,14 @@
44
49
  "eslint": "^7.32.0",
45
50
  "eslint-plugin-react": "^7.26.1",
46
51
  "eslint-plugin-react-hooks": "^4.2.0",
47
- "husky": "^7.0.2",
52
+ "fs-extra": "^10.0.0",
53
+ "husky": "^7.0.4",
48
54
  "jest": "^27.2.5",
55
+ "lint-staged": "^12.1.2",
56
+ "ncp": "^2.0.0",
57
+ "prettier": "^2.5.1",
58
+ "react": "17.0.2",
59
+ "react-dom": "^17.0.2",
49
60
  "react-hot-loader": "^4.13.0",
50
61
  "ts-loader": "^9.2.6",
51
62
  "ts-node": "^10.3.0",
package/tsconfig.json CHANGED
@@ -1,23 +1,24 @@
1
- {
2
- "compilerOptions": {
3
- "outDir": "./dist/",
4
- "baseUrl": "lib",
5
- "noImplicitAny": true,
6
- "esModuleInterop": true,
7
- "module": "CommonJS",
8
- "sourceMap": true,
9
- "target": "ESNext",
10
- "lib": ["ESNext", "dom"],
11
- "declaration": true,
12
- "jsx": "react",
13
- "strict": true,
14
- "allowJs": true,
15
- "moduleResolution": "node"
16
- },
17
- "include": ["./lib/**/*"],
18
- "exclude": [
19
- "node_modules",
20
- "dist",
21
- "test"
22
- ]
23
- }
1
+ {
2
+ "compilerOptions": {
3
+ "outDir": "./dist/",
4
+ "noImplicitAny": true,
5
+ "esModuleInterop": true,
6
+ "module": "CommonJS",
7
+ "sourceMap": true,
8
+ "target": "ESNext",
9
+ "lib": ["ESNext", "dom"],
10
+ "declaration": true,
11
+ "declarationDir": "dist",
12
+ "jsx": "react",
13
+ "strict": true,
14
+ "allowJs": true,
15
+ "moduleResolution": "node",
16
+ "downlevelIteration": true
17
+ },
18
+ "include": ["./lib/index.tsx"],
19
+ "exclude": [
20
+ "node_modules",
21
+ "dist",
22
+ "test"
23
+ ]
24
+ }
package/webpack.config.ts CHANGED
@@ -1,45 +1,53 @@
1
- const path = require("path");
2
- import { Configuration } from "webpack";
3
- const nodeExternals = require("webpack-node-externals");
4
- const fs = require("fs");
5
-
6
- const libPath = path.resolve(__dirname, "lib");
7
- const distPath = path.resolve(__dirname, "dist");
8
- const demoPath = path.resolve(__dirname, "demo");
9
-
10
- const config: Configuration = {
11
- entry: path.resolve(libPath, "index.tsx"),
12
- output: {
13
- path: distPath,
14
- filename: "index.js",
15
- library: "best-react-pagination",
16
- libraryTarget: "umd",
17
- },
18
- resolve: {
19
- extensions: [".tsx", ".ts", ".js"],
20
- },
21
- externals: [nodeExternals()],
22
- plugins: [
23
- {
24
- apply: (compiler) => {
25
- compiler.hooks.compile.tap("Copy file", () => {
26
- fs.copyFile(demoPath + "/src/pagination/index.tsx", libPath + "/index.tsx", (err: any) => {
27
- if (err) throw err;
28
- console.log("Pagination was copied to ", libPath);
29
- });
30
- });
31
- },
32
- },
33
- ],
34
- module: {
35
- rules: [
36
- {
37
- test: /\.tsx?$/,
38
- exclude: /(node_modules|bower_components)/,
39
- use: ["babel-loader", "ts-loader"],
40
- },
41
- ],
42
- },
43
- };
44
-
45
- export default config;
1
+ const path = require("path");
2
+ import { Configuration } from "webpack";
3
+ const nodeExternals = require("webpack-node-externals");
4
+ const ncp = require("ncp").ncp;
5
+ const fs = require("fs-extra");
6
+
7
+ const libPath = path.resolve(__dirname, "lib");
8
+ const distPath = path.resolve(__dirname, "dist");
9
+ const demoPath = path.resolve(__dirname, "demo");
10
+
11
+ const config: Configuration = {
12
+ entry: path.resolve(libPath, "index.tsx"),
13
+ output: {
14
+ path: distPath,
15
+ filename: "index.js",
16
+ library: "best-react-pagination",
17
+ libraryTarget: "umd",
18
+ clean: true,
19
+ },
20
+ resolve: {
21
+ extensions: [".tsx", ".ts", ".js"],
22
+ },
23
+ externals: [nodeExternals()],
24
+ plugins: [
25
+ {
26
+ apply: (compiler) => {
27
+ compiler.hooks.beforeCompile.tapPromise("Copy file", () => {
28
+ return new Promise<void>((resolve, reject) => {
29
+ fs.emptyDirSync(libPath);
30
+ ncp(demoPath + "/src/Pagination/", libPath, (err: any) => {
31
+ if (err) {
32
+ reject(err);
33
+ }
34
+ console.log("Pagination was copied to ", libPath);
35
+ resolve();
36
+ });
37
+ });
38
+ });
39
+ },
40
+ },
41
+ ],
42
+ module: {
43
+ rules: [
44
+ {
45
+ test: /\.tsx?$/,
46
+ exclude: /(node_modules|bower_components)/,
47
+ use: ["babel-loader", "ts-loader"],
48
+ },
49
+ ],
50
+ },
51
+ };
52
+
53
+ export default config;
@@ -1,369 +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
84
- className={wrapperClass}
85
- style={isDefaultStyles ? defaultStyles.wrapperClass : undefined}
86
- >
87
- <ul
88
- className={itemListClass}
89
- style={isDefaultStyles ? defaultStyles.itemListClass : undefined}
90
- >
91
- <li
92
- className={disableItemClass}
93
- style={isDefaultStyles ? defaultStyles.itemClass : undefined}
94
- >{`<<`}</li>
95
- <li
96
- className={disableItemClass}
97
- style={isDefaultStyles ? defaultStyles.itemClass : undefined}
98
- >{`>>`}</li>
99
- </ul>
100
- </div>
101
- );
102
- }
103
-
104
- if (totalPages > 1 && totalPages < 4) {
105
- return (
106
- <div
107
- className={wrapperClass}
108
- style={isDefaultStyles ? defaultStyles.wrapperClass : undefined}
109
- >
110
- <ul
111
- className={itemListClass}
112
- style={isDefaultStyles ? defaultStyles.itemListClass : undefined}
113
- >
114
- {[1, 2, 3].map((el) => {
115
- const index = paginationStart === 0 ? el - 1 : el;
116
- if (currentIndex === index) {
117
- return (
118
- <li
119
- className={selectedItemClass}
120
- style={
121
- isDefaultStyles
122
- ? defaultStyles.selectedItemClass
123
- : undefined
124
- }
125
- key={el}
126
- >
127
- {el}
128
- </li>
129
- );
130
- }
131
- return (
132
- <li
133
- className={selectedItemClass}
134
- style={isDefaultStyles ? defaultStyles.itemClass : undefined}
135
- key={el}
136
- onClick={() => setIndex(index)}
137
- >
138
- {el}
139
- </li>
140
- );
141
- })}
142
- </ul>
143
- </div>
144
- );
145
- }
146
-
147
- if (totalPages === 4) {
148
- return (
149
- <div
150
- className={wrapperClass}
151
- style={isDefaultStyles ? defaultStyles.wrapperClass : undefined}
152
- >
153
- <ul
154
- className={itemListClass}
155
- style={isDefaultStyles ? defaultStyles.itemListClass : undefined}
156
- >
157
- {currentIndex > (paginationStart === 0 ? 0 : 1) ? (
158
- <li
159
- className={itemClass}
160
- style={isDefaultStyles ? defaultStyles.itemClass : undefined}
161
- onClick={() => setIndex(currentIndex - 1)}
162
- >{`<<`}</li>
163
- ) : (
164
- <li
165
- className={disableItemClass}
166
- style={
167
- isDefaultStyles ? defaultStyles.disableItemClass : undefined
168
- }
169
- >{`<<`}</li>
170
- )}
171
- {countItems.map((el) => {
172
- const index = paginationStart === 0 ? el - 1 : el;
173
- if (currentIndex === index) {
174
- return (
175
- <li
176
- className={selectedItemClass}
177
- style={
178
- isDefaultStyles
179
- ? defaultStyles.selectedItemClass
180
- : undefined
181
- }
182
- key={el}
183
- >
184
- {el}
185
- </li>
186
- );
187
- }
188
- return (
189
- <li
190
- className={selectedItemClass}
191
- style={isDefaultStyles ? defaultStyles.itemClass : undefined}
192
- key={el}
193
- onClick={() => setIndex(index)}
194
- >
195
- {el}
196
- </li>
197
- );
198
- })}
199
- {currentIndex < (paginationStart === 0 ? 3 : 4) ? (
200
- <li
201
- className={itemClass}
202
- style={isDefaultStyles ? defaultStyles.itemClass : undefined}
203
- >{`>>`}</li>
204
- ) : (
205
- <li
206
- className={disableItemClass}
207
- style={
208
- isDefaultStyles ? defaultStyles.disableItemClass : undefined
209
- }
210
- >{`>>`}</li>
211
- )}
212
- </ul>
213
- </div>
214
- );
215
- }
216
-
217
- return (
218
- <>
219
- <div
220
- className={wrapperClass && className}
221
- style={isDefaultStyles ? defaultStyles.wrapperClass : undefined}
222
- >
223
- <ul
224
- className={itemListClass}
225
- style={isDefaultStyles ? defaultStyles.itemListClass : undefined}
226
- >
227
- {/*Previous button*/}
228
- {currentIndex > (paginationStart === 0 ? 0 : 1) ? (
229
- <li
230
- style={isDefaultStyles ? defaultStyles.itemClass : undefined}
231
- onClick={() => setIndex(currentIndex - 1)}
232
- >{`<<`}</li>
233
- ) : (
234
- <li
235
- className={disableItemClass}
236
- style={
237
- isDefaultStyles ? defaultStyles.disableItemClass : undefined
238
- }
239
- >{`<<`}</li>
240
- )}
241
- {/*First page button*/}
242
- {currentIndex > (paginationStart == 0 ? 2 : 3) ? (
243
- <li
244
- className={itemClass}
245
- style={isDefaultStyles ? defaultStyles.itemClass : undefined}
246
- onClick={() => setIndex(paginationStart === 0 ? 0 : 1)}
247
- >{`1`}</li>
248
- ) : null}
249
-
250
- {currentIndex < (paginationStart === 0 ? 3 : 4)
251
- ? countItems.map((el) => {
252
- if (
253
- paginationStart === 0 ? currentIndex + 1 : currentIndex === el
254
- ) {
255
- return (
256
- <li
257
- className={selectedItemClass}
258
- style={
259
- isDefaultStyles
260
- ? defaultStyles.selectedItemClass
261
- : undefined
262
- }
263
- key={el}
264
- >
265
- {el}
266
- </li>
267
- );
268
- }
269
- return (
270
- <li
271
- className={itemClass}
272
- style={
273
- isDefaultStyles ? defaultStyles.itemClass : undefined
274
- }
275
- onClick={() =>
276
- setIndex(paginationStart === 0 ? el - 1 : el)
277
- }
278
- key={el}
279
- >
280
- {el}
281
- </li>
282
- );
283
- })
284
- : null}
285
-
286
- {currentIndex > (paginationStart === 0 ? 2 : 3) ? (
287
- <li
288
- className={disableItemClass}
289
- style={
290
- isDefaultStyles ? defaultStyles.disableItemClass : undefined
291
- }
292
- >{`...`}</li>
293
- ) : null}
294
-
295
- {currentIndex > (paginationStart === 0 ? 2 : 3) &&
296
- (paginationStart === 0 ? currentIndex : currentIndex - 1) <
297
- totalPages ? (
298
- <>
299
- <li
300
- className={itemClass}
301
- style={isDefaultStyles ? defaultStyles.itemClass : undefined}
302
- onClick={() => setIndex(currentIndex - 1)}
303
- >
304
- {paginationStart === 0 ? currentIndex : currentIndex - 1}
305
- </li>
306
- <li
307
- className={selectedItemClass}
308
- style={
309
- isDefaultStyles ? defaultStyles.selectedItemClass : undefined
310
- }
311
- >
312
- {paginationStart === 0 ? currentIndex + 1 : currentIndex}
313
- </li>
314
- {currentIndex <
315
- (paginationStart === 0 ? totalPages - 1 : totalPages) ? (
316
- <li
317
- className={itemClass}
318
- style={isDefaultStyles ? defaultStyles.itemClass : undefined}
319
- onClick={() => setIndex(currentIndex + 1)}
320
- >
321
- {paginationStart === 0 ? currentIndex + 2 : currentIndex + 1}
322
- </li>
323
- ) : null}
324
- </>
325
- ) : null}
326
-
327
- {currentIndex <
328
- (paginationStart === 0 ? totalPages - 3 : totalPages - 2) ? (
329
- <li
330
- className={disableItemClass}
331
- style={
332
- isDefaultStyles ? defaultStyles.disableItemClass : undefined
333
- }
334
- >{`...`}</li>
335
- ) : null}
336
-
337
- {currentIndex <
338
- (paginationStart === 0 ? totalPages - 2 : totalPages - 1) ? (
339
- <li
340
- className={itemClass}
341
- style={isDefaultStyles ? defaultStyles.itemClass : undefined}
342
- onClick={() => setIndex(paginationStart === 0 ? totalPages - 1 : totalPages)}
343
- >
344
- {totalPages}
345
- </li>
346
- ) : null}
347
-
348
- {(paginationStart === 0 ? currentIndex + 1 : currentIndex) <
349
- totalPages ? (
350
- <li
351
- className={itemClass}
352
- style={isDefaultStyles ? defaultStyles.itemClass : undefined}
353
- onClick={() => setIndex(currentIndex + 1)}
354
- >{`>>`}</li>
355
- ) : (
356
- <li
357
- className={disableItemClass}
358
- style={
359
- isDefaultStyles ? defaultStyles.disableItemClass : undefined
360
- }
361
- >{`>>`}</li>
362
- )}
363
- </ul>
364
- </div>
365
- </>
366
- );
367
- };
368
-
369
- export default Pagination;