Pagination.js 2.23 KB
Newer Older
kusang96's avatar
kusang96 committed
1
import { Pagination } from "react-bootstrap";
2
import React from 'react';
Kim, Subin's avatar
Kim, Subin committed
3

kusang96's avatar
kusang96 committed
4
function Paginations({ index, totalPages, handlePage }) {
Kim, Subin's avatar
Kim, Subin committed
5
6

    return (
kusang96's avatar
kusang96 committed
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
        <Pagination className="d-flex justify-content-center">
            <style type="text/css">
                {`
                .page-link, .page-link:hover {
                    color: #91877F;
                    margin: 0;
                    border: 0;
                }

                .page-link:focus {
                    box-shadow: 0 0 0 0;
                }

                .page-item.active .page-link {
                    background-color: #CDC5C2;
                    border-color: #CDC5C2;
                    color: #fff;
                }
                `}
            </style>
kusang96's avatar
kusang96 committed
27
            <Pagination.First onClick={() => handlePage(1)} />
kusang96's avatar
css    
kusang96 committed
28
            {index === 1 ? <Pagination.Prev disabled /> : <Pagination.Prev onClick={()=>handlePage(index - 1)} />}
kusang96's avatar
kusang96 committed
29
30
            {index === totalPages && index > 4 ? <Pagination.Item onClick={()=>handlePage(index - 4)}>{index - 4}</Pagination.Item> : ""}
            {index > 3 && index >= totalPages-1 ? <Pagination.Item onClick={()=>handlePage(index - 3)}>{index - 3}</Pagination.Item> : ""}
kusang96's avatar
kusang96 committed
31
32
            {index < 3 ? "" : <Pagination.Item onClick={()=>handlePage(index - 2)}>{index - 2}</Pagination.Item>}
            {index === 1 ? "" : <Pagination.Item onClick={()=>handlePage(index - 1)}>{index - 1}</Pagination.Item>}
kusang96's avatar
kusang96 committed
33

kusang96's avatar
kusang96 committed
34
            <Pagination.Item active>{index}</Pagination.Item>
kusang96's avatar
kusang96 committed
35

kusang96's avatar
kusang96 committed
36
37
            {index === totalPages ? "" : <Pagination.Item onClick={()=>handlePage(index + 1)}>{index + 1}</Pagination.Item>}
            {index > totalPages-2 ? "" : <Pagination.Item onClick={()=>handlePage(index + 2)}>{index + 2}</Pagination.Item>}
kusang96's avatar
css    
kusang96 committed
38
39
40
            {index <= totalPages-3 && index >= 1 ? <Pagination.Item onClick={()=>handlePage(index + 3)}>{index + 3}</Pagination.Item> : ""}
            {index <= totalPages-4 && index >= 1 ? <Pagination.Item onClick={()=>handlePage(index + 4)}>{index + 4}</Pagination.Item> : ""}
            {index === totalPages ? <Pagination.Next disabled /> : <Pagination.Next onClick={()=>handlePage(index + 1)} />}
kusang96's avatar
kusang96 committed
41

kusang96's avatar
kusang96 committed
42
            <Pagination.Last onClick={() =>handlePage(totalPages)} />
kusang96's avatar
kusang96 committed
43
        </Pagination>
Kim, Subin's avatar
Kim, Subin committed
44
    )
kusang96's avatar
kusang96 committed
45
}
kusang96's avatar
DSAD    
kusang96 committed
46

kusang96's avatar
kusang96 committed
47
export default Paginations