PaginationBoot.js 1.45 KB
Newer Older
Kim, Subin's avatar
Kim, Subin committed
1
2
3
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
49
50
51
52
import { Link } from "react-router-dom";

const PaginationBoot = ({ children }) => {
  return (
    <nav aria-label="page navigation">
      <ul className="pagination justify-content-center py-3">{children}</ul>
    </nav>
  );
};

const PageItem = ({
  active = false,
  disabled = false,
  className = "",
  style,
  activeLabel = "(current)",
  children,
  ...props
}) => {
  return (
    <li
      style={style}
      className={`${className}` + " page-item " + (active ? "active " : "") + (disabled ? "disabled " : "")}
    >
      <Link to="#" className={"page-link border-0 shadow-none " + (active ? "rounded-circle text-white" : "text-dark")} {...props}>
        {children}
      </Link>
    </li>
  );
};

const createButton = (name, defaultValue, label = name) => {
  function Button({ children, ...props }) {
    return (
      <PageItem {...props}>
        <span aria-hidden="true">{children || defaultValue}</span>
        <span className="visually-hidden">{label}</span>
      </PageItem>
    );
  }

  Button.displayName = name;
  return Button;
};

PaginationBoot.First = createButton("First", <i className="bi bi-chevron-double-left"></i>);
PaginationBoot.Prev = createButton("Prev", <i className="bi bi-chevron-left"></i>);
PaginationBoot.Item = PageItem;
PaginationBoot.Next = createButton("Next", <i className="bi bi-chevron-right"></i>);
PaginationBoot.Last = createButton("Last", <i className="bi bi-chevron-double-right"></i>);

export default PaginationBoot