Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

65 рядки
1.8 KiB

  1. import React from "react";
  2. // nodejs library to set properties for components
  3. import PropTypes from "prop-types";
  4. // nodejs library that concatenates classes
  5. import classNames from "classnames";
  6. // @material-ui/core components
  7. import { makeStyles } from "@material-ui/core/styles";
  8. import Button from "@material-ui/core/Button";
  9. import styles from "assets/jss/nextjs-material-kit/components/paginationStyle.js";
  10. const useStyles = makeStyles(styles);
  11. export default function Pagination(props) {
  12. const classes = useStyles();
  13. const { pages, color } = props;
  14. return (
  15. <ul className={classes.pagination}>
  16. {pages.map((prop, key) => {
  17. const paginationLink = classNames({
  18. [classes.paginationLink]: true,
  19. [classes[color]]: prop.active,
  20. [classes.disabled]: prop.disabled
  21. });
  22. return (
  23. <li className={classes.paginationItem} key={key}>
  24. {prop.onClick !== undefined ? (
  25. <Button onClick={prop.onClick} className={paginationLink}>
  26. {prop.text}
  27. </Button>
  28. ) : (
  29. <Button
  30. onClick={() => alert("you've clicked " + prop.text)}
  31. className={paginationLink}
  32. >
  33. {prop.text}
  34. </Button>
  35. )}
  36. </li>
  37. );
  38. })}
  39. </ul>
  40. );
  41. }
  42. Pagination.defaultProps = {
  43. color: "primary"
  44. };
  45. Pagination.propTypes = {
  46. pages: PropTypes.arrayOf(
  47. PropTypes.shape({
  48. active: PropTypes.bool,
  49. disabled: PropTypes.bool,
  50. text: PropTypes.oneOfType([
  51. PropTypes.number,
  52. PropTypes.oneOf(["PREV", "NEXT", "..."])
  53. ]).isRequired,
  54. onClick: PropTypes.func
  55. })
  56. ).isRequired,
  57. color: PropTypes.oneOf(["primary", "info", "success", "warning", "danger"])
  58. };