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/.editorconfig ADDED
@@ -0,0 +1,9 @@
1
+ root = true
2
+
3
+ [*]
4
+ indent_style = space
5
+ indent_size = 2
6
+ end_of_line = lf
7
+ charset = utf-8
8
+ insert_final_newline = true
9
+ max_line_length = 120
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: {
@@ -0,0 +1,4 @@
1
+ #!/bin/sh
2
+ . "$(dirname "$0")/_/husky.sh"
3
+
4
+ npx --no-install commitlint --edit "$1"
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env sh
2
+ . "$(dirname "$0")/_/husky.sh"
3
+
4
+ npm run build
5
+ git add dist
6
+ git add lib
7
+ npx lint-staged
@@ -0,0 +1,3 @@
1
+ {
2
+ "demo/src/**/*.(ts|tsx)": ["npm run lint:write", "npm run prettier"]
3
+ }
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
- [![NPM](https://nodei.co/npm/best-react-pagination.png?downloads=true)](https://nodei.co/npm/best-react-pagination/)
4
-
5
- **React component to render a pagination.**
6
-
7
- # WARNING
8
- Now correct works only with ```paginationStart={1} ```
9
-
10
- ## Installation
11
-
12
- ```
13
- npm install best-react-pagination --save
14
- ```
15
-
16
- ```javascript
17
- import Index from "best-react-pagination";
18
-
19
- const YourComponent: FC = () => {
20
- const [index, setIndex] = useState(0);
21
-
22
- return (
23
- // Your code
24
- <Index
25
- paginationStart={0}
26
- currentIndex={index}
27
- setIndex={setIndex}
28
- totalPages={10}
29
- />
30
- );
31
- };
32
- ```
33
-
34
- ## Props
35
-
36
- | Name | Type | Description |
37
- | ------------------- | ---------------------------------------------- | ---------------------------------------------------------------------- |
38
- | `paginationStart` | `Number` | **Required.** The number of start pages on your logic (0 or 1). |
39
- | `currentIndex` | `Number` | **Required.** The current index from hook useState of pages displayed. |
40
- | `totalPages` | `Number` | **Required.** The range of pages displayed. |
41
- | `setIndex` | `React.Dispatch<React.SetStateAction<number>>` | **Required.** The dispatch from hook useState |
42
- | `isDefaultStyles` | `Boolean` | **Default true** |
43
- | `wrapperClass` | `String` | Css class |
44
- | `itemListClass` | `String` | Css class |
45
- | `itemClass` | `String` | Css class |
46
- | `selectedItemClass` | `String` | Css class |
47
- | `disableItemClass` | `String` | Css class |
48
- | `className` | `String` | **Field for styled-component** |
1
+ # best-react-pagination
2
+
3
+ [![NPM](https://nodei.co/npm/best-react-pagination.png?downloads=true)](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']}
@@ -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 "./pagination";
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
- return (
9
- <>
10
- <Pagination paginationStart={1} currentIndex={index} setIndex={setIndex} totalPages={10} isDefaultStyles={true}/>
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
+ };
@@ -0,0 +1,3 @@
1
+ export { default as Wrapper } from "./Wrapper";
2
+ export { default as ItemList } from "./ItemList";
3
+ export { default as Item } from "./Item";
@@ -0,0 +1,3 @@
1
+ export const range = (count: number): Array<number> => {
2
+ return [...Array(count).keys()].map((i) => i);
3
+ };