@unitedstatespowersquadrons/components 1.2.29 → 1.2.31
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/Pagination.tsx +80 -0
- package/index.tsx +1 -0
- package/package.json +1 -1
package/Pagination.tsx
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { createUseStyles } from "react-jss";
|
|
3
|
+
import IconButton from "./IconButton";
|
|
4
|
+
|
|
5
|
+
const useStyles = createUseStyles({
|
|
6
|
+
currentPage: {
|
|
7
|
+
fontWeight: "bold",
|
|
8
|
+
},
|
|
9
|
+
label: {
|
|
10
|
+
fontWeight: "bold",
|
|
11
|
+
marginRight: "0.25em",
|
|
12
|
+
},
|
|
13
|
+
pagination: {
|
|
14
|
+
alignItems: "center",
|
|
15
|
+
display: "flex",
|
|
16
|
+
flexDirection: "row",
|
|
17
|
+
gap: "0.5em",
|
|
18
|
+
justifyContent: "center",
|
|
19
|
+
margin: "1em auto",
|
|
20
|
+
},
|
|
21
|
+
spacer: {
|
|
22
|
+
display: "inline-block",
|
|
23
|
+
width: "2em",
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
interface Props {
|
|
28
|
+
label?: string;
|
|
29
|
+
maxPage: number;
|
|
30
|
+
pageNumber: number;
|
|
31
|
+
path: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const Pagination = (props: Props) => {
|
|
35
|
+
const { label, maxPage, pageNumber, path } = props;
|
|
36
|
+
const classes = useStyles();
|
|
37
|
+
|
|
38
|
+
const button = (number: number, icon: string, title: string) => {
|
|
39
|
+
return <IconButton href={`${path}?page=${number}`} icon={icon} title={title} />;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const spacer = <span className={classes.spacer} />;
|
|
43
|
+
|
|
44
|
+
const firstButton = () => {
|
|
45
|
+
return pageNumber > 2 ? button(1, "backward-fast", "First Page") : spacer;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const previousButton = () => {
|
|
49
|
+
return pageNumber > 1 ? button(pageNumber - 1, "backward", "Previous Page") : spacer;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const currentPage = () => {
|
|
53
|
+
return(
|
|
54
|
+
<>
|
|
55
|
+
{label && <span className={classes.label}>{label}</span>}
|
|
56
|
+
<span className={classes.currentPage}>{pageNumber}</span>
|
|
57
|
+
</>
|
|
58
|
+
);
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const nextButton = () => {
|
|
62
|
+
return pageNumber < maxPage ? button(pageNumber + 1, "forward", "Next Page") : spacer;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const lastButton = () => {
|
|
66
|
+
return pageNumber < maxPage -1 ? button(maxPage, "fast-forward", "Last Page") : spacer;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
return(
|
|
70
|
+
<div className={classes.pagination}>
|
|
71
|
+
{firstButton()}
|
|
72
|
+
{previousButton()}
|
|
73
|
+
{currentPage()}
|
|
74
|
+
{nextButton()}
|
|
75
|
+
{lastButton()}
|
|
76
|
+
</div>
|
|
77
|
+
);
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
export default Pagination;
|
package/index.tsx
CHANGED
|
@@ -16,6 +16,7 @@ export { default as ActionButton } from "./ActionButton";
|
|
|
16
16
|
export { default as IconButton } from "./IconButton";
|
|
17
17
|
export { default as SelectionIconButton } from "./SelectionIconButton";
|
|
18
18
|
export { default as RailsForm } from "./RailsForm";
|
|
19
|
+
export * from "./Pagination";
|
|
19
20
|
export * from "./Toasts";
|
|
20
21
|
export { default as Colors } from "./Colors";
|
|
21
22
|
export { default as Styles } from "./Styles";
|