|
|
@@ -1,18 +1,21 @@
|
|
|
-import React, { useCallback, useMemo } from 'react';
|
|
|
-import PropTypes from 'prop-types';
|
|
|
+import React, {
|
|
|
+ FC, memo, useCallback, useMemo,
|
|
|
+} from 'react';
|
|
|
|
|
|
import { Pagination, PaginationItem, PaginationLink } from 'reactstrap';
|
|
|
|
|
|
-/**
|
|
|
- *
|
|
|
- * @author Mikitaka Itizawa <itizawa@weseek.co.jp>
|
|
|
- *
|
|
|
- * @export
|
|
|
- * @class PaginationWrapper
|
|
|
- * @extends {React.Component}
|
|
|
- */
|
|
|
|
|
|
-const PaginationWrapper = React.memo((props) => {
|
|
|
+type Props = {
|
|
|
+ activePage: number,
|
|
|
+ changePage?: (number) => void,
|
|
|
+ totalItemsCount: number,
|
|
|
+ pagingLimit?: number,
|
|
|
+ align?: string,
|
|
|
+ size?: string,
|
|
|
+};
|
|
|
+
|
|
|
+
|
|
|
+const PaginationWrapper: FC<Props> = memo((props: Props) => {
|
|
|
const {
|
|
|
activePage, changePage, totalItemsCount, pagingLimit, align,
|
|
|
} = props;
|
|
|
@@ -59,14 +62,14 @@ const PaginationWrapper = React.memo((props) => {
|
|
|
* this function set << & <
|
|
|
*/
|
|
|
const generateFirstPrev = useCallback(() => {
|
|
|
- const paginationItems = [];
|
|
|
+ const paginationItems: JSX.Element[] = [];
|
|
|
if (activePage !== 1) {
|
|
|
paginationItems.push(
|
|
|
<PaginationItem key="painationItemFirst">
|
|
|
- <PaginationLink first onClick={() => { return changePage(1) }} />
|
|
|
+ <PaginationLink first onClick={() => { return changePage != null && changePage(1) }} />
|
|
|
</PaginationItem>,
|
|
|
<PaginationItem key="painationItemPrevious">
|
|
|
- <PaginationLink previous onClick={() => { return changePage(activePage - 1) }} />
|
|
|
+ <PaginationLink previous onClick={() => { return changePage != null && changePage(activePage - 1) }} />
|
|
|
</PaginationItem>,
|
|
|
);
|
|
|
}
|
|
|
@@ -89,11 +92,11 @@ const PaginationWrapper = React.memo((props) => {
|
|
|
* this function set numbers
|
|
|
*/
|
|
|
const generatePaginations = useCallback(() => {
|
|
|
- const paginationItems = [];
|
|
|
+ const paginationItems: JSX.Element[] = [];
|
|
|
for (let number = paginationStart; number <= maxViewPageNum; number++) {
|
|
|
paginationItems.push(
|
|
|
<PaginationItem key={`paginationItem-${number}`} active={number === activePage}>
|
|
|
- <PaginationLink onClick={() => { return changePage(number) }}>
|
|
|
+ <PaginationLink onClick={() => { return changePage != null && changePage(number) }}>
|
|
|
{number}
|
|
|
</PaginationLink>
|
|
|
</PaginationItem>,
|
|
|
@@ -108,14 +111,14 @@ const PaginationWrapper = React.memo((props) => {
|
|
|
* this function set > & >>
|
|
|
*/
|
|
|
const generateNextLast = useCallback(() => {
|
|
|
- const paginationItems = [];
|
|
|
+ const paginationItems: JSX.Element[] = [];
|
|
|
if (totalPage !== activePage) {
|
|
|
paginationItems.push(
|
|
|
<PaginationItem key="painationItemNext">
|
|
|
- <PaginationLink next onClick={() => { return changePage(activePage + 1) }} />
|
|
|
+ <PaginationLink next onClick={() => { return changePage != null && changePage(activePage + 1) }} />
|
|
|
</PaginationItem>,
|
|
|
<PaginationItem key="painationItemLast">
|
|
|
- <PaginationLink last onClick={() => { return changePage(totalPage) }} />
|
|
|
+ <PaginationLink last onClick={() => { return changePage != null && changePage(totalPage) }} />
|
|
|
</PaginationItem>,
|
|
|
);
|
|
|
}
|
|
|
@@ -133,7 +136,7 @@ const PaginationWrapper = React.memo((props) => {
|
|
|
}, [activePage, changePage, totalPage]);
|
|
|
|
|
|
const getListClassName = useMemo(() => {
|
|
|
- const listClassNames = [];
|
|
|
+ const listClassNames: string[] = [];
|
|
|
|
|
|
if (align === 'center') {
|
|
|
listClassNames.push('justify-content-center');
|
|
|
@@ -157,15 +160,6 @@ const PaginationWrapper = React.memo((props) => {
|
|
|
|
|
|
});
|
|
|
|
|
|
-PaginationWrapper.propTypes = {
|
|
|
- activePage: PropTypes.number.isRequired,
|
|
|
- changePage: PropTypes.func.isRequired,
|
|
|
- totalItemsCount: PropTypes.number.isRequired,
|
|
|
- pagingLimit: PropTypes.number,
|
|
|
- align: PropTypes.string,
|
|
|
- size: PropTypes.string,
|
|
|
-};
|
|
|
-
|
|
|
PaginationWrapper.defaultProps = {
|
|
|
align: 'left',
|
|
|
size: 'md',
|