best-react-pagination 0.0.3 → 0.1.3
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/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/.babelrc +0 -7
- package/.editorconfig +0 -9
- package/.eslintignore +0 -2
- package/.eslintrc.js +0 -37
- package/.lintstagedrc.json +0 -3
- package/commitlint.config.js +0 -1
- 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 -334
- 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/index.js +0 -1
- package/lib/index.tsx +0 -334
- package/tsconfig.json +0 -23
- package/webpack.config.ts +0 -45
package/LICENCE
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
Copyright (c) 2021, Dmitriy Tsybizov <dts97@yandex.ru>
|
|
2
|
-
|
|
3
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
4
|
-
purpose with or without fee is hereby granted, provided that the above
|
|
5
|
-
copyright notice and this permission notice appear in all copies.
|
|
6
|
-
|
|
7
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
8
|
-
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
9
|
-
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
10
|
-
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
11
|
-
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
12
|
-
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
1
|
+
Copyright (c) 2021, Dmitriy Tsybizov <dts97@yandex.ru>
|
|
2
|
+
|
|
3
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
4
|
+
purpose with or without fee is hereby granted, provided that the above
|
|
5
|
+
copyright notice and this permission notice appear in all copies.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
8
|
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
9
|
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
10
|
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
11
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
12
|
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
13
13
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
package/README.md
CHANGED
|
@@ -28,18 +28,23 @@ const YourComponent: FC = () => {
|
|
|
28
28
|
};
|
|
29
29
|
```
|
|
30
30
|
|
|
31
|
+
#### Example https://codesandbox.io/s/lingering-breeze-gh2dk
|
|
32
|
+
|
|
31
33
|
## Props
|
|
32
34
|
|
|
33
|
-
| Name | Type
|
|
34
|
-
| -------------------
|
|
35
|
-
| `paginationStart` | `Number`
|
|
36
|
-
| `currentIndex` | `Number`
|
|
37
|
-
| `totalPages` | `Number`
|
|
38
|
-
| `setIndex` | `React.
|
|
39
|
-
| `isDefaultStyles` | `Boolean`
|
|
40
|
-
| `wrapperClass` | `String`
|
|
41
|
-
| `itemListClass` | `String`
|
|
42
|
-
| `itemClass` | `String`
|
|
43
|
-
| `selectedItemClass` | `String`
|
|
44
|
-
| `disableItemClass` | `String`
|
|
45
|
-
| `className` | `String`
|
|
35
|
+
| Name | Type | Description |
|
|
36
|
+
| ------------------- |----------------------------------| ---------------------------------------------------------------------- |
|
|
37
|
+
| `paginationStart` | `Number` | **Required.** The number of start pages on your logic (0 or 1). |
|
|
38
|
+
| `currentIndex` | `Number` | **Required.** The current index from hook useState of pages displayed. |
|
|
39
|
+
| `totalPages` | `Number` | **Required.** The range of pages displayed. |
|
|
40
|
+
| `setIndex` | `React.SetStateAction<number>` | **Required.** The dispatch from hook useState |
|
|
41
|
+
| `isDefaultStyles` | `Boolean` | **Default true** |
|
|
42
|
+
| `wrapperClass` | `String` | Css class |
|
|
43
|
+
| `itemListClass` | `String` | Css class |
|
|
44
|
+
| `itemClass` | `String` | Css class |
|
|
45
|
+
| `selectedItemClass` | `String` | Css class |
|
|
46
|
+
| `disableItemClass` | `String` | Css class |
|
|
47
|
+
| `className` | `String` | **Field for styled-component** |
|
|
48
|
+
|
|
49
|
+
### Remark
|
|
50
|
+
For rewrite default styles - use !important in your css
|
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
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "best-react-pagination",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Pagination for work with React",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -33,6 +33,8 @@
|
|
|
33
33
|
"@babel/preset-env": "^7.15.8",
|
|
34
34
|
"@babel/preset-react": "^7.14.5",
|
|
35
35
|
"@babel/preset-typescript": "^7.15.0",
|
|
36
|
+
"@commitlint/cli": "^15.0.0",
|
|
37
|
+
"@commitlint/config-conventional": "^15.0.0",
|
|
36
38
|
"@types/jest": "^27.0.2",
|
|
37
39
|
"@types/node": "^16.11.0",
|
|
38
40
|
"@types/react": "^17.0.30",
|
|
@@ -45,13 +47,13 @@
|
|
|
45
47
|
"clean-webpack-plugin": "^4.0.0",
|
|
46
48
|
"copy-webpack-plugin": "^9.0.1",
|
|
47
49
|
"eslint": "^7.32.0",
|
|
48
|
-
"@commitlint/cli": "^15.0.0",
|
|
49
|
-
"@commitlint/config-conventional": "^15.0.0",
|
|
50
50
|
"eslint-plugin-react": "^7.26.1",
|
|
51
51
|
"eslint-plugin-react-hooks": "^4.2.0",
|
|
52
|
+
"fs-extra": "^10.0.0",
|
|
52
53
|
"husky": "^7.0.4",
|
|
53
54
|
"jest": "^27.2.5",
|
|
54
55
|
"lint-staged": "^12.1.2",
|
|
56
|
+
"ncp": "^2.0.0",
|
|
55
57
|
"prettier": "^2.5.1",
|
|
56
58
|
"react": "17.0.2",
|
|
57
59
|
"react-dom": "^17.0.2",
|
package/.babelrc
DELETED
package/.editorconfig
DELETED
package/.eslintignore
DELETED
package/.eslintrc.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
root: true,
|
|
3
|
-
env: {
|
|
4
|
-
node: true,
|
|
5
|
-
browser: true,
|
|
6
|
-
es2021: true,
|
|
7
|
-
},
|
|
8
|
-
plugins: ["@typescript-eslint", "react"],
|
|
9
|
-
extends: [
|
|
10
|
-
"eslint:recommended",
|
|
11
|
-
"plugin:@typescript-eslint/eslint-recommended",
|
|
12
|
-
"plugin:@typescript-eslint/recommended",
|
|
13
|
-
"plugin:react/recommended",
|
|
14
|
-
"plugin:react-hooks/recommended",
|
|
15
|
-
],
|
|
16
|
-
parser: "@typescript-eslint/parser",
|
|
17
|
-
parserOptions: {
|
|
18
|
-
ecmaFeatures: {
|
|
19
|
-
tsconfigRootDir: __dirname,
|
|
20
|
-
project: ["./tsconfig.json"],
|
|
21
|
-
jsx: true,
|
|
22
|
-
},
|
|
23
|
-
ecmaVersion: 2021,
|
|
24
|
-
sourceType: "module",
|
|
25
|
-
},
|
|
26
|
-
ignorePatterns: [".eslintrc.js"],
|
|
27
|
-
rules: {
|
|
28
|
-
"@typescript-eslint/no-var-requires": "off",
|
|
29
|
-
"@typescript-eslint/no-unused-vars": ["error", { "vars": "all", "args": "after-used", "ignoreRestSiblings": false }]
|
|
30
|
-
},
|
|
31
|
-
settings: {
|
|
32
|
-
react: {
|
|
33
|
-
pragma: "React",
|
|
34
|
-
version: "detect",
|
|
35
|
-
},
|
|
36
|
-
},
|
|
37
|
-
};
|
package/.lintstagedrc.json
DELETED
package/commitlint.config.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = {extends: ['@commitlint/config-conventional']}
|
package/demo/.babelrc
DELETED
package/demo/public/index.html
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="utf-8" />
|
|
5
|
-
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
6
|
-
<meta name="theme-color" content="#000000" />
|
|
7
|
-
<meta
|
|
8
|
-
name="description"
|
|
9
|
-
content="Web site created using create-react-app"
|
|
10
|
-
/>
|
|
11
|
-
<title>React App</title>
|
|
12
|
-
</head>
|
|
13
|
-
<body>
|
|
14
|
-
<noscript>You need to enable JavaScript to run this app.</noscript>
|
|
15
|
-
<div id="root"></div>
|
|
16
|
-
</body>
|
|
17
|
-
</html>
|
package/demo/src/App.tsx
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import React, { FC, useState } from "react";
|
|
2
|
-
import { hot } from "react-hot-loader/root";
|
|
3
|
-
import Pagination from "./Pagination";
|
|
4
|
-
|
|
5
|
-
const App: FC = () => {
|
|
6
|
-
const [index, setIndex] = useState(1);
|
|
7
|
-
|
|
8
|
-
return (
|
|
9
|
-
<>
|
|
10
|
-
<Pagination paginationStart={1} currentIndex={index} setIndex={setIndex} totalPages={10} isDefaultStyles={true} />
|
|
11
|
-
</>
|
|
12
|
-
);
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export default hot(App);
|
|
@@ -1,334 +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
|
-
userSelect: "none",
|
|
64
|
-
},
|
|
65
|
-
selectedItemClass: {
|
|
66
|
-
display: "inline",
|
|
67
|
-
cursor: "pointer",
|
|
68
|
-
padding: "6px 12px",
|
|
69
|
-
borderRadius: "4px",
|
|
70
|
-
margin: "0 2px",
|
|
71
|
-
backgroundColor: "#48bbff",
|
|
72
|
-
userSelect: "none",
|
|
73
|
-
},
|
|
74
|
-
disableItemClass: {
|
|
75
|
-
display: "inline",
|
|
76
|
-
cursor: "not-allowed",
|
|
77
|
-
padding: "6px 12px",
|
|
78
|
-
borderRadius: "4px",
|
|
79
|
-
margin: "0 2px",
|
|
80
|
-
userSelect: "none",
|
|
81
|
-
},
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
if (totalPages <= 1) {
|
|
85
|
-
return (
|
|
86
|
-
<div className={wrapperClass} style={isDefaultStyles ? defaultStyles.wrapperClass : undefined}>
|
|
87
|
-
<ul className={itemListClass} style={isDefaultStyles ? defaultStyles.itemListClass : undefined}>
|
|
88
|
-
<li className={disableItemClass} style={isDefaultStyles ? defaultStyles.itemClass : undefined}>{`<<`}</li>
|
|
89
|
-
<li className={disableItemClass} style={isDefaultStyles ? defaultStyles.itemClass : undefined}>{`>>`}</li>
|
|
90
|
-
</ul>
|
|
91
|
-
</div>
|
|
92
|
-
);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
if (totalPages > 1 && totalPages < 4) {
|
|
96
|
-
return (
|
|
97
|
-
<div className={wrapperClass} style={isDefaultStyles ? defaultStyles.wrapperClass : undefined}>
|
|
98
|
-
<ul className={itemListClass} style={isDefaultStyles ? defaultStyles.itemListClass : undefined}>
|
|
99
|
-
{[1, 2, 3].map((el) => {
|
|
100
|
-
const index = paginationStart === 0 ? el - 1 : el;
|
|
101
|
-
if (currentIndex === index) {
|
|
102
|
-
return (
|
|
103
|
-
<li
|
|
104
|
-
className={selectedItemClass}
|
|
105
|
-
style={isDefaultStyles ? defaultStyles.selectedItemClass : undefined}
|
|
106
|
-
key={el}
|
|
107
|
-
>
|
|
108
|
-
{el}
|
|
109
|
-
</li>
|
|
110
|
-
);
|
|
111
|
-
}
|
|
112
|
-
return (
|
|
113
|
-
<li
|
|
114
|
-
className={selectedItemClass}
|
|
115
|
-
style={isDefaultStyles ? defaultStyles.itemClass : undefined}
|
|
116
|
-
key={el}
|
|
117
|
-
onClick={() => setIndex(index)}
|
|
118
|
-
>
|
|
119
|
-
{el}
|
|
120
|
-
</li>
|
|
121
|
-
);
|
|
122
|
-
})}
|
|
123
|
-
</ul>
|
|
124
|
-
</div>
|
|
125
|
-
);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
if (totalPages === 4) {
|
|
129
|
-
return (
|
|
130
|
-
<div className={wrapperClass} style={isDefaultStyles ? defaultStyles.wrapperClass : undefined}>
|
|
131
|
-
<ul className={itemListClass} style={isDefaultStyles ? defaultStyles.itemListClass : undefined}>
|
|
132
|
-
{currentIndex > (paginationStart === 0 ? 0 : 1) ? (
|
|
133
|
-
<li
|
|
134
|
-
className={itemClass}
|
|
135
|
-
style={isDefaultStyles ? defaultStyles.itemClass : undefined}
|
|
136
|
-
onClick={() => setIndex(currentIndex - 1)}
|
|
137
|
-
>{`<<`}</li>
|
|
138
|
-
) : (
|
|
139
|
-
<li
|
|
140
|
-
className={disableItemClass}
|
|
141
|
-
style={isDefaultStyles ? defaultStyles.disableItemClass : undefined}
|
|
142
|
-
>{`<<`}</li>
|
|
143
|
-
)}
|
|
144
|
-
{countItems.map((el) => {
|
|
145
|
-
const index = paginationStart === 0 ? el - 1 : el;
|
|
146
|
-
if (currentIndex === index) {
|
|
147
|
-
return (
|
|
148
|
-
<li
|
|
149
|
-
className={selectedItemClass}
|
|
150
|
-
style={isDefaultStyles ? defaultStyles.selectedItemClass : undefined}
|
|
151
|
-
key={el}
|
|
152
|
-
>
|
|
153
|
-
{el}
|
|
154
|
-
</li>
|
|
155
|
-
);
|
|
156
|
-
}
|
|
157
|
-
return (
|
|
158
|
-
<li
|
|
159
|
-
className={selectedItemClass}
|
|
160
|
-
style={isDefaultStyles ? defaultStyles.itemClass : undefined}
|
|
161
|
-
key={el}
|
|
162
|
-
onClick={() => setIndex(index)}
|
|
163
|
-
>
|
|
164
|
-
{el}
|
|
165
|
-
</li>
|
|
166
|
-
);
|
|
167
|
-
})}
|
|
168
|
-
{currentIndex < (paginationStart === 0 ? 3 : 4) ? (
|
|
169
|
-
<li
|
|
170
|
-
className={itemClass}
|
|
171
|
-
style={isDefaultStyles ? defaultStyles.itemClass : undefined}
|
|
172
|
-
onClick={() => setIndex(currentIndex + 1)}
|
|
173
|
-
>{`>>`}</li>
|
|
174
|
-
) : (
|
|
175
|
-
<li
|
|
176
|
-
className={disableItemClass}
|
|
177
|
-
style={isDefaultStyles ? defaultStyles.disableItemClass : undefined}
|
|
178
|
-
>{`>>`}</li>
|
|
179
|
-
)}
|
|
180
|
-
</ul>
|
|
181
|
-
</div>
|
|
182
|
-
);
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
return (
|
|
186
|
-
<>
|
|
187
|
-
<div className={wrapperClass && className} style={isDefaultStyles ? defaultStyles.wrapperClass : undefined}>
|
|
188
|
-
<ul className={itemListClass} style={isDefaultStyles ? defaultStyles.itemListClass : undefined}>
|
|
189
|
-
{/*Previous button*/}
|
|
190
|
-
{currentIndex > (paginationStart === 0 ? 0 : 1) ? (
|
|
191
|
-
<li
|
|
192
|
-
style={isDefaultStyles ? defaultStyles.itemClass : undefined}
|
|
193
|
-
onClick={() => setIndex(currentIndex - 1)}
|
|
194
|
-
>{`<<`}</li>
|
|
195
|
-
) : (
|
|
196
|
-
<li
|
|
197
|
-
className={disableItemClass}
|
|
198
|
-
style={isDefaultStyles ? defaultStyles.disableItemClass : undefined}
|
|
199
|
-
>{`<<`}</li>
|
|
200
|
-
)}
|
|
201
|
-
{/*First page button*/}
|
|
202
|
-
{currentIndex > (paginationStart == 0 ? 2 : 3) ? (
|
|
203
|
-
<li
|
|
204
|
-
className={itemClass}
|
|
205
|
-
style={isDefaultStyles ? defaultStyles.itemClass : undefined}
|
|
206
|
-
onClick={() => setIndex(paginationStart === 0 ? 0 : 1)}
|
|
207
|
-
>{`1`}</li>
|
|
208
|
-
) : null}
|
|
209
|
-
|
|
210
|
-
{currentIndex < (paginationStart === 0 ? 3 : 4)
|
|
211
|
-
? countItems.map((el) => {
|
|
212
|
-
if (paginationStart === 0 ? currentIndex + 1 === el : currentIndex === el) {
|
|
213
|
-
return (
|
|
214
|
-
<li
|
|
215
|
-
className={selectedItemClass}
|
|
216
|
-
style={isDefaultStyles ? defaultStyles.selectedItemClass : undefined}
|
|
217
|
-
key={el}
|
|
218
|
-
>
|
|
219
|
-
{el}
|
|
220
|
-
</li>
|
|
221
|
-
);
|
|
222
|
-
}
|
|
223
|
-
return (
|
|
224
|
-
<li
|
|
225
|
-
className={itemClass}
|
|
226
|
-
style={isDefaultStyles ? defaultStyles.itemClass : undefined}
|
|
227
|
-
onClick={() => setIndex(paginationStart === 0 ? el - 1 : el)}
|
|
228
|
-
key={el}
|
|
229
|
-
>
|
|
230
|
-
{el}
|
|
231
|
-
</li>
|
|
232
|
-
);
|
|
233
|
-
})
|
|
234
|
-
: null}
|
|
235
|
-
|
|
236
|
-
{currentIndex > (paginationStart === 0 ? 2 : 3) ? (
|
|
237
|
-
<li
|
|
238
|
-
className={disableItemClass}
|
|
239
|
-
style={isDefaultStyles ? defaultStyles.disableItemClass : undefined}
|
|
240
|
-
>{`...`}</li>
|
|
241
|
-
) : null}
|
|
242
|
-
|
|
243
|
-
{currentIndex > (paginationStart === 0 ? 2 : 3) &&
|
|
244
|
-
(paginationStart === 0 ? currentIndex : currentIndex - 1) < totalPages ? (
|
|
245
|
-
<>
|
|
246
|
-
{currentIndex === (paginationStart === 0 ? totalPages - 2 : totalPages - 1) && (
|
|
247
|
-
<li
|
|
248
|
-
className={itemClass}
|
|
249
|
-
style={isDefaultStyles ? defaultStyles.itemClass : undefined}
|
|
250
|
-
onClick={() => setIndex(paginationStart === 0 ? totalPages - 4 : totalPages - 3)}
|
|
251
|
-
>
|
|
252
|
-
{totalPages - 3}
|
|
253
|
-
</li>
|
|
254
|
-
)}
|
|
255
|
-
|
|
256
|
-
{currentIndex === (paginationStart === 0 ? totalPages - 1 : totalPages) && (
|
|
257
|
-
<>
|
|
258
|
-
<li
|
|
259
|
-
className={itemClass}
|
|
260
|
-
style={isDefaultStyles ? defaultStyles.itemClass : undefined}
|
|
261
|
-
onClick={() => setIndex(paginationStart === 0 ? totalPages - 4 : totalPages - 3)}
|
|
262
|
-
>
|
|
263
|
-
{totalPages - 3}
|
|
264
|
-
</li>
|
|
265
|
-
<li
|
|
266
|
-
className={itemClass}
|
|
267
|
-
style={isDefaultStyles ? defaultStyles.itemClass : undefined}
|
|
268
|
-
onClick={() => setIndex(paginationStart === 0 ? totalPages - 3 : totalPages - 2)}
|
|
269
|
-
>
|
|
270
|
-
{totalPages - 2}
|
|
271
|
-
</li>
|
|
272
|
-
</>
|
|
273
|
-
)}
|
|
274
|
-
|
|
275
|
-
<li
|
|
276
|
-
className={itemClass}
|
|
277
|
-
style={isDefaultStyles ? defaultStyles.itemClass : undefined}
|
|
278
|
-
onClick={() => setIndex(currentIndex - 1)}
|
|
279
|
-
>
|
|
280
|
-
{paginationStart === 0 ? currentIndex : currentIndex - 1}
|
|
281
|
-
</li>
|
|
282
|
-
|
|
283
|
-
<li className={selectedItemClass} style={isDefaultStyles ? defaultStyles.selectedItemClass : undefined}>
|
|
284
|
-
{paginationStart === 0 ? currentIndex + 1 : currentIndex}
|
|
285
|
-
</li>
|
|
286
|
-
|
|
287
|
-
{currentIndex < (paginationStart === 0 ? totalPages - 1 : totalPages) ? (
|
|
288
|
-
<li
|
|
289
|
-
className={itemClass}
|
|
290
|
-
style={isDefaultStyles ? defaultStyles.itemClass : undefined}
|
|
291
|
-
onClick={() => setIndex(currentIndex + 1)}
|
|
292
|
-
>
|
|
293
|
-
{paginationStart === 0 ? currentIndex + 2 : currentIndex + 1}
|
|
294
|
-
</li>
|
|
295
|
-
) : null}
|
|
296
|
-
</>
|
|
297
|
-
) : null}
|
|
298
|
-
|
|
299
|
-
{currentIndex < (paginationStart === 0 ? totalPages - 3 : totalPages - 2) ? (
|
|
300
|
-
<li
|
|
301
|
-
className={disableItemClass}
|
|
302
|
-
style={isDefaultStyles ? defaultStyles.disableItemClass : undefined}
|
|
303
|
-
>{`...`}</li>
|
|
304
|
-
) : null}
|
|
305
|
-
|
|
306
|
-
{currentIndex < (paginationStart === 0 ? totalPages - 2 : totalPages - 1) ? (
|
|
307
|
-
<li
|
|
308
|
-
className={itemClass}
|
|
309
|
-
style={isDefaultStyles ? defaultStyles.itemClass : undefined}
|
|
310
|
-
onClick={() => setIndex(paginationStart === 0 ? totalPages - 1 : totalPages)}
|
|
311
|
-
>
|
|
312
|
-
{totalPages}
|
|
313
|
-
</li>
|
|
314
|
-
) : null}
|
|
315
|
-
|
|
316
|
-
{(paginationStart === 0 ? currentIndex + 1 : currentIndex) < totalPages ? (
|
|
317
|
-
<li
|
|
318
|
-
className={itemClass}
|
|
319
|
-
style={isDefaultStyles ? defaultStyles.itemClass : undefined}
|
|
320
|
-
onClick={() => setIndex(currentIndex + 1)}
|
|
321
|
-
>{`>>`}</li>
|
|
322
|
-
) : (
|
|
323
|
-
<li
|
|
324
|
-
className={disableItemClass}
|
|
325
|
-
style={isDefaultStyles ? defaultStyles.disableItemClass : undefined}
|
|
326
|
-
>{`>>`}</li>
|
|
327
|
-
)}
|
|
328
|
-
</ul>
|
|
329
|
-
</div>
|
|
330
|
-
</>
|
|
331
|
-
);
|
|
332
|
-
};
|
|
333
|
-
|
|
334
|
-
export default Pagination;
|
package/demo/src/index.html
DELETED
package/demo/src/index.tsx
DELETED
package/demo/tsconfig.json
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"outDir": "./dist/",
|
|
4
|
-
"sourceMap": true,
|
|
5
|
-
"strict": true,
|
|
6
|
-
"noImplicitReturns": true,
|
|
7
|
-
"noImplicitAny": true,
|
|
8
|
-
"module": "es6",
|
|
9
|
-
"moduleResolution": "node",
|
|
10
|
-
"target": "es5",
|
|
11
|
-
"allowJs": true,
|
|
12
|
-
"jsx": "react",
|
|
13
|
-
"allowSyntheticDefaultImports": true
|
|
14
|
-
},
|
|
15
|
-
"include": [
|
|
16
|
-
"./src/**/*"
|
|
17
|
-
]
|
|
18
|
-
}
|
package/demo/webpack.config.js
DELETED
|
@@ -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;
|
package/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
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={708:function(e,t,l){var s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});var a=s(l(689));t.default=function(e){var t,l=e.paginationStart,s=e.currentIndex,i=e.totalPages,n=e.setIndex,r=e.isDefaultStyles,d=e.wrapperClass,c=void 0===d?"":d,m=e.itemListClass,o=void 0===m?"":m,u=e.itemClass,f=void 0===u?"":u,C=e.selectedItemClass,p=void 0===C?"":C,v=e.disableItemClass,y=void 0===v?"":v,E=e.className,N=[1,2,3,4];!function(e){e.wrapperClass="wrapperClass",e.itemListClass="itemListClass",e.itemClass="itemClass",e.selectedItemClass="selectedItemClass",e.disableItemClass="disableItemClass"}(t||(t={}));var x={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"},selectedItemClass:{display:"inline",cursor:"pointer",padding:"6px 12px",borderRadius:"4px",margin:"0 2px",backgroundColor:"#48bbff"},disableItemClass:{display:"inline",cursor:"not-allowed",padding:"6px 12px",borderRadius:"4px",margin:"0 2px"}};return i<=1?a.default.createElement("div",{className:c,style:r?x.wrapperClass:void 0},a.default.createElement("ul",{className:o,style:r?x.itemListClass:void 0},a.default.createElement("li",{className:y,style:r?x.itemClass:void 0},"<<"),a.default.createElement("li",{className:y,style:r?x.itemClass:void 0},">>"))):i>1&&i<4?a.default.createElement("div",{className:c,style:r?x.wrapperClass:void 0},a.default.createElement("ul",{className:o,style:r?x.itemListClass:void 0},[1,2,3].map((function(e){var t=0===l?e-1:e;return s===t?a.default.createElement("li",{className:p,style:r?x.selectedItemClass:void 0,key:e},e):a.default.createElement("li",{className:p,style:r?x.itemClass:void 0,key:e,onClick:function(){return n(t)}},e)})))):4===i?a.default.createElement("div",{className:c,style:r?x.wrapperClass:void 0},a.default.createElement("ul",{className:o,style:r?x.itemListClass:void 0},s>(0===l?0:1)?a.default.createElement("li",{className:f,style:r?x.itemClass:void 0,onClick:function(){return n(s-1)}},"<<"):a.default.createElement("li",{className:y,style:r?x.disableItemClass:void 0},"<<"),N.map((function(e){var t=0===l?e-1:e;return s===t?a.default.createElement("li",{className:p,style:r?x.selectedItemClass:void 0,key:e},e):a.default.createElement("li",{className:p,style:r?x.itemClass:void 0,key:e,onClick:function(){return n(t)}},e)})),s<(0===l?3:4)?a.default.createElement("li",{className:f,style:r?x.itemClass:void 0},">>"):a.default.createElement("li",{className:y,style:r?x.disableItemClass:void 0},">>"))):a.default.createElement(a.default.Fragment,null,a.default.createElement("div",{className:c&&E,style:r?x.wrapperClass:void 0},a.default.createElement("ul",{className:o,style:r?x.itemListClass:void 0},s>(0===l?0:1)?a.default.createElement("li",{style:r?x.itemClass:void 0,onClick:function(){return n(s-1)}},"<<"):a.default.createElement("li",{className:y,style:r?x.disableItemClass:void 0},"<<"),s>(0==l?2:3)?a.default.createElement("li",{className:f,style:r?x.itemClass:void 0,onClick:function(){return n(0===l?0:1)}},"1"):null,s<(0===l?3:4)?N.map((function(e){return(0===l?s+1:s===e)?a.default.createElement("li",{className:p,style:r?x.selectedItemClass:void 0,key:e},e):a.default.createElement("li",{className:f,style:r?x.itemClass:void 0,onClick:function(){return n(0===l?e-1:e)},key:e},e)})):null,s>(0===l?2:3)?a.default.createElement("li",{className:y,style:r?x.disableItemClass:void 0},"..."):null,s>(0===l?2:3)&&(0===l?s:s-1)<i?a.default.createElement(a.default.Fragment,null,a.default.createElement("li",{className:f,style:r?x.itemClass:void 0,onClick:function(){return n(s-1)}},0===l?s:s-1),a.default.createElement("li",{className:p,style:r?x.selectedItemClass:void 0},0===l?s+1:s),s<(0===l?i-1:i)?a.default.createElement("li",{className:f,style:r?x.itemClass:void 0,onClick:function(){return n(s+1)}},0===l?s+2:s+1):null):null,s<(0===l?i-3:i-2)?a.default.createElement("li",{className:y,style:r?x.disableItemClass:void 0},"..."):null,s<(0===l?i-3:i-2)?a.default.createElement("li",{className:f,style:r?x.itemClass:void 0,onClick:function(){return n(i-1)}},i):null,(0===l?s+1:s)<i?a.default.createElement("li",{className:f,style:r?x.itemClass:void 0,onClick:function(){return n(s+1)}},">>"):a.default.createElement("li",{className:y,style:r?x.disableItemClass:void 0},">>"))))}},689:e=>{e.exports=require("react")}},t={};return function l(s){var a=t[s];if(void 0!==a)return a.exports;var i=t[s]={exports:{}};return e[s].call(i.exports,i,i.exports,l),i.exports}(708)})()}));
|
package/lib/index.tsx
DELETED
|
@@ -1,334 +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
|
-
userSelect: "none",
|
|
64
|
-
},
|
|
65
|
-
selectedItemClass: {
|
|
66
|
-
display: "inline",
|
|
67
|
-
cursor: "pointer",
|
|
68
|
-
padding: "6px 12px",
|
|
69
|
-
borderRadius: "4px",
|
|
70
|
-
margin: "0 2px",
|
|
71
|
-
backgroundColor: "#48bbff",
|
|
72
|
-
userSelect: "none",
|
|
73
|
-
},
|
|
74
|
-
disableItemClass: {
|
|
75
|
-
display: "inline",
|
|
76
|
-
cursor: "not-allowed",
|
|
77
|
-
padding: "6px 12px",
|
|
78
|
-
borderRadius: "4px",
|
|
79
|
-
margin: "0 2px",
|
|
80
|
-
userSelect: "none",
|
|
81
|
-
},
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
if (totalPages <= 1) {
|
|
85
|
-
return (
|
|
86
|
-
<div className={wrapperClass} style={isDefaultStyles ? defaultStyles.wrapperClass : undefined}>
|
|
87
|
-
<ul className={itemListClass} style={isDefaultStyles ? defaultStyles.itemListClass : undefined}>
|
|
88
|
-
<li className={disableItemClass} style={isDefaultStyles ? defaultStyles.itemClass : undefined}>{`<<`}</li>
|
|
89
|
-
<li className={disableItemClass} style={isDefaultStyles ? defaultStyles.itemClass : undefined}>{`>>`}</li>
|
|
90
|
-
</ul>
|
|
91
|
-
</div>
|
|
92
|
-
);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
if (totalPages > 1 && totalPages < 4) {
|
|
96
|
-
return (
|
|
97
|
-
<div className={wrapperClass} style={isDefaultStyles ? defaultStyles.wrapperClass : undefined}>
|
|
98
|
-
<ul className={itemListClass} style={isDefaultStyles ? defaultStyles.itemListClass : undefined}>
|
|
99
|
-
{[1, 2, 3].map((el) => {
|
|
100
|
-
const index = paginationStart === 0 ? el - 1 : el;
|
|
101
|
-
if (currentIndex === index) {
|
|
102
|
-
return (
|
|
103
|
-
<li
|
|
104
|
-
className={selectedItemClass}
|
|
105
|
-
style={isDefaultStyles ? defaultStyles.selectedItemClass : undefined}
|
|
106
|
-
key={el}
|
|
107
|
-
>
|
|
108
|
-
{el}
|
|
109
|
-
</li>
|
|
110
|
-
);
|
|
111
|
-
}
|
|
112
|
-
return (
|
|
113
|
-
<li
|
|
114
|
-
className={selectedItemClass}
|
|
115
|
-
style={isDefaultStyles ? defaultStyles.itemClass : undefined}
|
|
116
|
-
key={el}
|
|
117
|
-
onClick={() => setIndex(index)}
|
|
118
|
-
>
|
|
119
|
-
{el}
|
|
120
|
-
</li>
|
|
121
|
-
);
|
|
122
|
-
})}
|
|
123
|
-
</ul>
|
|
124
|
-
</div>
|
|
125
|
-
);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
if (totalPages === 4) {
|
|
129
|
-
return (
|
|
130
|
-
<div className={wrapperClass} style={isDefaultStyles ? defaultStyles.wrapperClass : undefined}>
|
|
131
|
-
<ul className={itemListClass} style={isDefaultStyles ? defaultStyles.itemListClass : undefined}>
|
|
132
|
-
{currentIndex > (paginationStart === 0 ? 0 : 1) ? (
|
|
133
|
-
<li
|
|
134
|
-
className={itemClass}
|
|
135
|
-
style={isDefaultStyles ? defaultStyles.itemClass : undefined}
|
|
136
|
-
onClick={() => setIndex(currentIndex - 1)}
|
|
137
|
-
>{`<<`}</li>
|
|
138
|
-
) : (
|
|
139
|
-
<li
|
|
140
|
-
className={disableItemClass}
|
|
141
|
-
style={isDefaultStyles ? defaultStyles.disableItemClass : undefined}
|
|
142
|
-
>{`<<`}</li>
|
|
143
|
-
)}
|
|
144
|
-
{countItems.map((el) => {
|
|
145
|
-
const index = paginationStart === 0 ? el - 1 : el;
|
|
146
|
-
if (currentIndex === index) {
|
|
147
|
-
return (
|
|
148
|
-
<li
|
|
149
|
-
className={selectedItemClass}
|
|
150
|
-
style={isDefaultStyles ? defaultStyles.selectedItemClass : undefined}
|
|
151
|
-
key={el}
|
|
152
|
-
>
|
|
153
|
-
{el}
|
|
154
|
-
</li>
|
|
155
|
-
);
|
|
156
|
-
}
|
|
157
|
-
return (
|
|
158
|
-
<li
|
|
159
|
-
className={selectedItemClass}
|
|
160
|
-
style={isDefaultStyles ? defaultStyles.itemClass : undefined}
|
|
161
|
-
key={el}
|
|
162
|
-
onClick={() => setIndex(index)}
|
|
163
|
-
>
|
|
164
|
-
{el}
|
|
165
|
-
</li>
|
|
166
|
-
);
|
|
167
|
-
})}
|
|
168
|
-
{currentIndex < (paginationStart === 0 ? 3 : 4) ? (
|
|
169
|
-
<li
|
|
170
|
-
className={itemClass}
|
|
171
|
-
style={isDefaultStyles ? defaultStyles.itemClass : undefined}
|
|
172
|
-
onClick={() => setIndex(currentIndex + 1)}
|
|
173
|
-
>{`>>`}</li>
|
|
174
|
-
) : (
|
|
175
|
-
<li
|
|
176
|
-
className={disableItemClass}
|
|
177
|
-
style={isDefaultStyles ? defaultStyles.disableItemClass : undefined}
|
|
178
|
-
>{`>>`}</li>
|
|
179
|
-
)}
|
|
180
|
-
</ul>
|
|
181
|
-
</div>
|
|
182
|
-
);
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
return (
|
|
186
|
-
<>
|
|
187
|
-
<div className={wrapperClass && className} style={isDefaultStyles ? defaultStyles.wrapperClass : undefined}>
|
|
188
|
-
<ul className={itemListClass} style={isDefaultStyles ? defaultStyles.itemListClass : undefined}>
|
|
189
|
-
{/*Previous button*/}
|
|
190
|
-
{currentIndex > (paginationStart === 0 ? 0 : 1) ? (
|
|
191
|
-
<li
|
|
192
|
-
style={isDefaultStyles ? defaultStyles.itemClass : undefined}
|
|
193
|
-
onClick={() => setIndex(currentIndex - 1)}
|
|
194
|
-
>{`<<`}</li>
|
|
195
|
-
) : (
|
|
196
|
-
<li
|
|
197
|
-
className={disableItemClass}
|
|
198
|
-
style={isDefaultStyles ? defaultStyles.disableItemClass : undefined}
|
|
199
|
-
>{`<<`}</li>
|
|
200
|
-
)}
|
|
201
|
-
{/*First page button*/}
|
|
202
|
-
{currentIndex > (paginationStart == 0 ? 2 : 3) ? (
|
|
203
|
-
<li
|
|
204
|
-
className={itemClass}
|
|
205
|
-
style={isDefaultStyles ? defaultStyles.itemClass : undefined}
|
|
206
|
-
onClick={() => setIndex(paginationStart === 0 ? 0 : 1)}
|
|
207
|
-
>{`1`}</li>
|
|
208
|
-
) : null}
|
|
209
|
-
|
|
210
|
-
{currentIndex < (paginationStart === 0 ? 3 : 4)
|
|
211
|
-
? countItems.map((el) => {
|
|
212
|
-
if (paginationStart === 0 ? currentIndex + 1 === el : currentIndex === el) {
|
|
213
|
-
return (
|
|
214
|
-
<li
|
|
215
|
-
className={selectedItemClass}
|
|
216
|
-
style={isDefaultStyles ? defaultStyles.selectedItemClass : undefined}
|
|
217
|
-
key={el}
|
|
218
|
-
>
|
|
219
|
-
{el}
|
|
220
|
-
</li>
|
|
221
|
-
);
|
|
222
|
-
}
|
|
223
|
-
return (
|
|
224
|
-
<li
|
|
225
|
-
className={itemClass}
|
|
226
|
-
style={isDefaultStyles ? defaultStyles.itemClass : undefined}
|
|
227
|
-
onClick={() => setIndex(paginationStart === 0 ? el - 1 : el)}
|
|
228
|
-
key={el}
|
|
229
|
-
>
|
|
230
|
-
{el}
|
|
231
|
-
</li>
|
|
232
|
-
);
|
|
233
|
-
})
|
|
234
|
-
: null}
|
|
235
|
-
|
|
236
|
-
{currentIndex > (paginationStart === 0 ? 2 : 3) ? (
|
|
237
|
-
<li
|
|
238
|
-
className={disableItemClass}
|
|
239
|
-
style={isDefaultStyles ? defaultStyles.disableItemClass : undefined}
|
|
240
|
-
>{`...`}</li>
|
|
241
|
-
) : null}
|
|
242
|
-
|
|
243
|
-
{currentIndex > (paginationStart === 0 ? 2 : 3) &&
|
|
244
|
-
(paginationStart === 0 ? currentIndex : currentIndex - 1) < totalPages ? (
|
|
245
|
-
<>
|
|
246
|
-
{currentIndex === (paginationStart === 0 ? totalPages - 2 : totalPages - 1) && (
|
|
247
|
-
<li
|
|
248
|
-
className={itemClass}
|
|
249
|
-
style={isDefaultStyles ? defaultStyles.itemClass : undefined}
|
|
250
|
-
onClick={() => setIndex(paginationStart === 0 ? totalPages - 4 : totalPages - 3)}
|
|
251
|
-
>
|
|
252
|
-
{totalPages - 3}
|
|
253
|
-
</li>
|
|
254
|
-
)}
|
|
255
|
-
|
|
256
|
-
{currentIndex === (paginationStart === 0 ? totalPages - 1 : totalPages) && (
|
|
257
|
-
<>
|
|
258
|
-
<li
|
|
259
|
-
className={itemClass}
|
|
260
|
-
style={isDefaultStyles ? defaultStyles.itemClass : undefined}
|
|
261
|
-
onClick={() => setIndex(paginationStart === 0 ? totalPages - 4 : totalPages - 3)}
|
|
262
|
-
>
|
|
263
|
-
{totalPages - 3}
|
|
264
|
-
</li>
|
|
265
|
-
<li
|
|
266
|
-
className={itemClass}
|
|
267
|
-
style={isDefaultStyles ? defaultStyles.itemClass : undefined}
|
|
268
|
-
onClick={() => setIndex(paginationStart === 0 ? totalPages - 3 : totalPages - 2)}
|
|
269
|
-
>
|
|
270
|
-
{totalPages - 2}
|
|
271
|
-
</li>
|
|
272
|
-
</>
|
|
273
|
-
)}
|
|
274
|
-
|
|
275
|
-
<li
|
|
276
|
-
className={itemClass}
|
|
277
|
-
style={isDefaultStyles ? defaultStyles.itemClass : undefined}
|
|
278
|
-
onClick={() => setIndex(currentIndex - 1)}
|
|
279
|
-
>
|
|
280
|
-
{paginationStart === 0 ? currentIndex : currentIndex - 1}
|
|
281
|
-
</li>
|
|
282
|
-
|
|
283
|
-
<li className={selectedItemClass} style={isDefaultStyles ? defaultStyles.selectedItemClass : undefined}>
|
|
284
|
-
{paginationStart === 0 ? currentIndex + 1 : currentIndex}
|
|
285
|
-
</li>
|
|
286
|
-
|
|
287
|
-
{currentIndex < (paginationStart === 0 ? totalPages - 1 : totalPages) ? (
|
|
288
|
-
<li
|
|
289
|
-
className={itemClass}
|
|
290
|
-
style={isDefaultStyles ? defaultStyles.itemClass : undefined}
|
|
291
|
-
onClick={() => setIndex(currentIndex + 1)}
|
|
292
|
-
>
|
|
293
|
-
{paginationStart === 0 ? currentIndex + 2 : currentIndex + 1}
|
|
294
|
-
</li>
|
|
295
|
-
) : null}
|
|
296
|
-
</>
|
|
297
|
-
) : null}
|
|
298
|
-
|
|
299
|
-
{currentIndex < (paginationStart === 0 ? totalPages - 3 : totalPages - 2) ? (
|
|
300
|
-
<li
|
|
301
|
-
className={disableItemClass}
|
|
302
|
-
style={isDefaultStyles ? defaultStyles.disableItemClass : undefined}
|
|
303
|
-
>{`...`}</li>
|
|
304
|
-
) : null}
|
|
305
|
-
|
|
306
|
-
{currentIndex < (paginationStart === 0 ? totalPages - 2 : totalPages - 1) ? (
|
|
307
|
-
<li
|
|
308
|
-
className={itemClass}
|
|
309
|
-
style={isDefaultStyles ? defaultStyles.itemClass : undefined}
|
|
310
|
-
onClick={() => setIndex(paginationStart === 0 ? totalPages - 1 : totalPages)}
|
|
311
|
-
>
|
|
312
|
-
{totalPages}
|
|
313
|
-
</li>
|
|
314
|
-
) : null}
|
|
315
|
-
|
|
316
|
-
{(paginationStart === 0 ? currentIndex + 1 : currentIndex) < totalPages ? (
|
|
317
|
-
<li
|
|
318
|
-
className={itemClass}
|
|
319
|
-
style={isDefaultStyles ? defaultStyles.itemClass : undefined}
|
|
320
|
-
onClick={() => setIndex(currentIndex + 1)}
|
|
321
|
-
>{`>>`}</li>
|
|
322
|
-
) : (
|
|
323
|
-
<li
|
|
324
|
-
className={disableItemClass}
|
|
325
|
-
style={isDefaultStyles ? defaultStyles.disableItemClass : undefined}
|
|
326
|
-
>{`>>`}</li>
|
|
327
|
-
)}
|
|
328
|
-
</ul>
|
|
329
|
-
</div>
|
|
330
|
-
</>
|
|
331
|
-
);
|
|
332
|
-
};
|
|
333
|
-
|
|
334
|
-
export default Pagination;
|
package/tsconfig.json
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
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
|
-
}
|
package/webpack.config.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
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;
|