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
package/.editorconfig
ADDED
package/.eslintignore
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/dist
|
|
1
|
+
/dist
|
|
2
2
|
webpack.config.ts
|
package/.eslintrc.js
CHANGED
|
@@ -23,8 +23,10 @@ module.exports = {
|
|
|
23
23
|
ecmaVersion: 2021,
|
|
24
24
|
sourceType: "module",
|
|
25
25
|
},
|
|
26
|
+
ignorePatterns: [".eslintrc.js"],
|
|
26
27
|
rules: {
|
|
27
|
-
"@typescript-eslint/no-var-requires": "off"
|
|
28
|
+
"@typescript-eslint/no-var-requires": "off",
|
|
29
|
+
"@typescript-eslint/no-unused-vars": ["error", { "vars": "all", "args": "after-used", "ignoreRestSiblings": false }]
|
|
28
30
|
},
|
|
29
31
|
settings: {
|
|
30
32
|
react: {
|
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
|
@@ -1,48 +1,50 @@
|
|
|
1
|
-
# best-react-pagination
|
|
2
|
-
|
|
3
|
-
[](https://nodei.co/npm/best-react-pagination/)
|
|
4
|
-
|
|
5
|
-
**
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
|
37
|
-
|
|
|
38
|
-
| `
|
|
39
|
-
| `
|
|
40
|
-
| `
|
|
41
|
-
| `
|
|
42
|
-
| `
|
|
43
|
-
| `
|
|
44
|
-
| `
|
|
45
|
-
| `
|
|
46
|
-
| `
|
|
47
|
-
| `
|
|
48
|
-
|
|
1
|
+
# best-react-pagination
|
|
2
|
+
|
|
3
|
+
[](https://nodei.co/npm/best-react-pagination/)
|
|
4
|
+
|
|
5
|
+
**Simple and stylized react component to render a pagination.**
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
npm install best-react-pagination --save
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
```javascript
|
|
14
|
+
import Pagination from "best-react-pagination";
|
|
15
|
+
|
|
16
|
+
const YourComponent: FC = () => {
|
|
17
|
+
const [index, setIndex] = useState(0);
|
|
18
|
+
|
|
19
|
+
return (
|
|
20
|
+
// Your code
|
|
21
|
+
<Pagination
|
|
22
|
+
paginationStart={0}
|
|
23
|
+
currentIndex={index}
|
|
24
|
+
setIndex={setIndex}
|
|
25
|
+
totalPages={10}
|
|
26
|
+
/>
|
|
27
|
+
);
|
|
28
|
+
};
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
#### Example https://codesandbox.io/s/lingering-breeze-gh2dk
|
|
32
|
+
|
|
33
|
+
## Props
|
|
34
|
+
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = {extends: ['@commitlint/config-conventional']}
|
package/demo/public/index.html
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
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>
|
|
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
CHANGED
|
@@ -1,15 +1,24 @@
|
|
|
1
|
-
import React, {FC, useState} from "react";
|
|
1
|
+
import React, { FC, useState } from "react";
|
|
2
2
|
import { hot } from "react-hot-loader/root";
|
|
3
|
-
import Pagination from "./
|
|
3
|
+
import Pagination from "./Pagination";
|
|
4
4
|
|
|
5
|
-
const App: FC = () =>
|
|
6
|
-
const [index, setIndex] = useState(1)
|
|
5
|
+
const App: FC = () => {
|
|
6
|
+
const [index, setIndex] = useState(1);
|
|
7
|
+
const totalPages = 10;
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
9
|
+
console.log(`Current: ${index}. Total: ${totalPages}`);
|
|
10
|
+
|
|
11
|
+
return (
|
|
12
|
+
<>
|
|
13
|
+
<Pagination
|
|
14
|
+
paginationStart={1}
|
|
15
|
+
currentIndex={index}
|
|
16
|
+
setIndex={setIndex}
|
|
17
|
+
totalPages={totalPages}
|
|
18
|
+
isDefaultStyles={true}
|
|
19
|
+
/>
|
|
20
|
+
</>
|
|
21
|
+
);
|
|
22
|
+
};
|
|
14
23
|
|
|
15
24
|
export default hot(App);
|
|
@@ -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
|
+
};
|