UNPKG

5.69 kBJavaScriptView Raw
1import _extends from "@babel/runtime/helpers/esm/extends";
2import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
3
4var _LastPageIcon, _FirstPageIcon, _KeyboardArrowRight, _KeyboardArrowLeft, _KeyboardArrowLeft2, _KeyboardArrowRight2, _FirstPageIcon2, _LastPageIcon2;
5
6import * as React from 'react';
7import PropTypes from 'prop-types';
8import KeyboardArrowLeft from '../internal/svg-icons/KeyboardArrowLeft';
9import KeyboardArrowRight from '../internal/svg-icons/KeyboardArrowRight';
10import useTheme from '../styles/useTheme';
11import IconButton from '../IconButton';
12import LastPageIcon from '../internal/svg-icons/LastPage';
13import FirstPageIcon from '../internal/svg-icons/FirstPage';
14/**
15 * @ignore - internal component.
16 */
17
18import { jsx as _jsx } from "react/jsx-runtime";
19import { jsxs as _jsxs } from "react/jsx-runtime";
20var TablePaginationActions = /*#__PURE__*/React.forwardRef(function TablePaginationActions(props, ref) {
21 var backIconButtonProps = props.backIconButtonProps,
22 count = props.count,
23 getItemAriaLabel = props.getItemAriaLabel,
24 nextIconButtonProps = props.nextIconButtonProps,
25 onPageChange = props.onPageChange,
26 page = props.page,
27 rowsPerPage = props.rowsPerPage,
28 showFirstButton = props.showFirstButton,
29 showLastButton = props.showLastButton,
30 other = _objectWithoutProperties(props, ["backIconButtonProps", "count", "getItemAriaLabel", "nextIconButtonProps", "onPageChange", "page", "rowsPerPage", "showFirstButton", "showLastButton"]);
31
32 var theme = useTheme();
33
34 var handleFirstPageButtonClick = function handleFirstPageButtonClick(event) {
35 onPageChange(event, 0);
36 };
37
38 var handleBackButtonClick = function handleBackButtonClick(event) {
39 onPageChange(event, page - 1);
40 };
41
42 var handleNextButtonClick = function handleNextButtonClick(event) {
43 onPageChange(event, page + 1);
44 };
45
46 var handleLastPageButtonClick = function handleLastPageButtonClick(event) {
47 onPageChange(event, Math.max(0, Math.ceil(count / rowsPerPage) - 1));
48 };
49
50 return /*#__PURE__*/_jsxs("div", _extends({
51 ref: ref
52 }, other, {
53 children: [showFirstButton && /*#__PURE__*/_jsx(IconButton, {
54 onClick: handleFirstPageButtonClick,
55 disabled: page === 0,
56 "aria-label": getItemAriaLabel('first', page),
57 title: getItemAriaLabel('first', page),
58 children: theme.direction === 'rtl' ? _LastPageIcon || (_LastPageIcon = /*#__PURE__*/_jsx(LastPageIcon, {})) : _FirstPageIcon || (_FirstPageIcon = /*#__PURE__*/_jsx(FirstPageIcon, {}))
59 }), /*#__PURE__*/_jsx(IconButton, _extends({
60 onClick: handleBackButtonClick,
61 disabled: page === 0,
62 color: "inherit",
63 "aria-label": getItemAriaLabel('previous', page),
64 title: getItemAriaLabel('previous', page)
65 }, backIconButtonProps, {
66 children: theme.direction === 'rtl' ? _KeyboardArrowRight || (_KeyboardArrowRight = /*#__PURE__*/_jsx(KeyboardArrowRight, {})) : _KeyboardArrowLeft || (_KeyboardArrowLeft = /*#__PURE__*/_jsx(KeyboardArrowLeft, {}))
67 })), /*#__PURE__*/_jsx(IconButton, _extends({
68 onClick: handleNextButtonClick,
69 disabled: count !== -1 ? page >= Math.ceil(count / rowsPerPage) - 1 : false,
70 color: "inherit",
71 "aria-label": getItemAriaLabel('next', page),
72 title: getItemAriaLabel('next', page)
73 }, nextIconButtonProps, {
74 children: theme.direction === 'rtl' ? _KeyboardArrowLeft2 || (_KeyboardArrowLeft2 = /*#__PURE__*/_jsx(KeyboardArrowLeft, {})) : _KeyboardArrowRight2 || (_KeyboardArrowRight2 = /*#__PURE__*/_jsx(KeyboardArrowRight, {}))
75 })), showLastButton && /*#__PURE__*/_jsx(IconButton, {
76 onClick: handleLastPageButtonClick,
77 disabled: page >= Math.ceil(count / rowsPerPage) - 1,
78 "aria-label": getItemAriaLabel('last', page),
79 title: getItemAriaLabel('last', page),
80 children: theme.direction === 'rtl' ? _FirstPageIcon2 || (_FirstPageIcon2 = /*#__PURE__*/_jsx(FirstPageIcon, {})) : _LastPageIcon2 || (_LastPageIcon2 = /*#__PURE__*/_jsx(LastPageIcon, {}))
81 })]
82 }));
83});
84process.env.NODE_ENV !== "production" ? TablePaginationActions.propTypes = {
85 /**
86 * Props applied to the back arrow [`IconButton`](/material-ui/api/icon-button/) element.
87 */
88 backIconButtonProps: PropTypes.object,
89
90 /**
91 * The total number of rows.
92 */
93 count: PropTypes.number.isRequired,
94
95 /**
96 * Accepts a function which returns a string value that provides a user-friendly name for the current page.
97 *
98 * For localization purposes, you can use the provided [translations](/material-ui/guides/localization/).
99 *
100 * @param {string} type The link or button type to format ('page' | 'first' | 'last' | 'next' | 'previous'). Defaults to 'page'.
101 * @param {number} page The page number to format.
102 * @returns {string}
103 */
104 getItemAriaLabel: PropTypes.func.isRequired,
105
106 /**
107 * Props applied to the next arrow [`IconButton`](/material-ui/api/icon-button/) element.
108 */
109 nextIconButtonProps: PropTypes.object,
110
111 /**
112 * Callback fired when the page is changed.
113 *
114 * @param {object} event The event source of the callback.
115 * @param {number} page The page selected.
116 */
117 onPageChange: PropTypes.func.isRequired,
118
119 /**
120 * The zero-based index of the current page.
121 */
122 page: PropTypes.number.isRequired,
123
124 /**
125 * The number of rows per page.
126 */
127 rowsPerPage: PropTypes.number.isRequired,
128
129 /**
130 * If `true`, show the first-page button.
131 */
132 showFirstButton: PropTypes.bool.isRequired,
133
134 /**
135 * If `true`, show the last-page button.
136 */
137 showLastButton: PropTypes.bool.isRequired
138} : void 0;
139export default TablePaginationActions;
\No newline at end of file