UNPKG

6.31 kBJavaScriptView Raw
1import _extends from "@babel/runtime/helpers/esm/extends";
2import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
3var _span, _span2, _span3, _span4;
4import * as React from 'react';
5import { useSlotProps } from '../utils';
6import { jsx as _jsx } from "react/jsx-runtime";
7import { jsxs as _jsxs } from "react/jsx-runtime";
8function LastPageIconDefault() {
9 return _span || (_span = /*#__PURE__*/_jsx("span", {
10 children: '⇾|'
11 }));
12}
13function FirstPageIconDefault() {
14 return _span2 || (_span2 = /*#__PURE__*/_jsx("span", {
15 children: '|⇽'
16 }));
17}
18function NextPageIconDefault() {
19 return _span3 || (_span3 = /*#__PURE__*/_jsx("span", {
20 children: '⇾'
21 }));
22}
23function BackPageIconDefault() {
24 return _span4 || (_span4 = /*#__PURE__*/_jsx("span", {
25 children: '⇽'
26 }));
27}
28function defaultGetAriaLabel(type) {
29 return "Go to ".concat(type, " page");
30}
31
32/**
33 * @ignore - internal component.
34 */
35var TablePaginationActions = /*#__PURE__*/React.forwardRef(function TablePaginationActions(props, forwardedRef) {
36 var _slots$root, _slots$firstButton, _slots$lastButton, _slots$nextButton, _slots$backButton, _slots$lastPageIcon, _slots$firstPageIcon, _slots$nextPageIcon, _slots$backPageIcon;
37 var count = props.count,
38 _props$getItemAriaLab = props.getItemAriaLabel,
39 getItemAriaLabel = _props$getItemAriaLab === void 0 ? defaultGetAriaLabel : _props$getItemAriaLab,
40 onPageChange = props.onPageChange,
41 page = props.page,
42 rowsPerPage = props.rowsPerPage,
43 _props$showFirstButto = props.showFirstButton,
44 showFirstButton = _props$showFirstButto === void 0 ? false : _props$showFirstButto,
45 _props$showLastButton = props.showLastButton,
46 showLastButton = _props$showLastButton === void 0 ? false : _props$showLastButton,
47 direction = props.direction,
48 ownerStateProp = props.ownerState,
49 _props$slotProps = props.slotProps,
50 slotProps = _props$slotProps === void 0 ? {} : _props$slotProps,
51 _props$slots = props.slots,
52 slots = _props$slots === void 0 ? {} : _props$slots,
53 other = _objectWithoutProperties(props, ["count", "getItemAriaLabel", "onPageChange", "page", "rowsPerPage", "showFirstButton", "showLastButton", "direction", "ownerState", "slotProps", "slots"]);
54 var ownerState = props;
55 var handleFirstPageButtonClick = function handleFirstPageButtonClick(event) {
56 onPageChange(event, 0);
57 };
58 var handleBackButtonClick = function handleBackButtonClick(event) {
59 onPageChange(event, page - 1);
60 };
61 var handleNextButtonClick = function handleNextButtonClick(event) {
62 onPageChange(event, page + 1);
63 };
64 var handleLastPageButtonClick = function handleLastPageButtonClick(event) {
65 onPageChange(event, Math.max(0, Math.ceil(count / rowsPerPage) - 1));
66 };
67 var Root = (_slots$root = slots.root) != null ? _slots$root : 'div';
68 var rootProps = useSlotProps({
69 elementType: Root,
70 externalSlotProps: slotProps.root,
71 externalForwardedProps: other,
72 additionalProps: {
73 ref: forwardedRef
74 },
75 ownerState: ownerState
76 });
77 var FirstButton = (_slots$firstButton = slots.firstButton) != null ? _slots$firstButton : 'button';
78 var firstButtonProps = useSlotProps({
79 elementType: FirstButton,
80 externalSlotProps: slotProps.firstButton,
81 additionalProps: {
82 onClick: handleFirstPageButtonClick,
83 disabled: page === 0,
84 'aria-label': getItemAriaLabel('first', page),
85 title: getItemAriaLabel('first', page)
86 },
87 ownerState: ownerState
88 });
89 var LastButton = (_slots$lastButton = slots.lastButton) != null ? _slots$lastButton : 'button';
90 var lastButtonProps = useSlotProps({
91 elementType: LastButton,
92 externalSlotProps: slotProps.lastButton,
93 additionalProps: {
94 onClick: handleLastPageButtonClick,
95 disabled: page >= Math.ceil(count / rowsPerPage) - 1,
96 'aria-label': getItemAriaLabel('last', page),
97 title: getItemAriaLabel('last', page)
98 },
99 ownerState: ownerState
100 });
101 var NextButton = (_slots$nextButton = slots.nextButton) != null ? _slots$nextButton : 'button';
102 var nextButtonProps = useSlotProps({
103 elementType: NextButton,
104 externalSlotProps: slotProps.nextButton,
105 additionalProps: {
106 onClick: handleNextButtonClick,
107 disabled: count !== -1 ? page >= Math.ceil(count / rowsPerPage) - 1 : false,
108 'aria-label': getItemAriaLabel('next', page),
109 title: getItemAriaLabel('next', page)
110 },
111 ownerState: ownerState
112 });
113 var BackButton = (_slots$backButton = slots.backButton) != null ? _slots$backButton : 'button';
114 var backButtonProps = useSlotProps({
115 elementType: BackButton,
116 externalSlotProps: slotProps.backButton,
117 additionalProps: {
118 onClick: handleBackButtonClick,
119 disabled: page === 0,
120 'aria-label': getItemAriaLabel('previous', page),
121 title: getItemAriaLabel('previous', page)
122 },
123 ownerState: ownerState
124 });
125 var LastPageIcon = (_slots$lastPageIcon = slots.lastPageIcon) != null ? _slots$lastPageIcon : LastPageIconDefault;
126 var FirstPageIcon = (_slots$firstPageIcon = slots.firstPageIcon) != null ? _slots$firstPageIcon : FirstPageIconDefault;
127 var NextPageIcon = (_slots$nextPageIcon = slots.nextPageIcon) != null ? _slots$nextPageIcon : NextPageIconDefault;
128 var BackPageIcon = (_slots$backPageIcon = slots.backPageIcon) != null ? _slots$backPageIcon : BackPageIconDefault;
129 return /*#__PURE__*/_jsxs(Root, _extends({}, rootProps, {
130 children: [showFirstButton && /*#__PURE__*/_jsx(FirstButton, _extends({}, firstButtonProps, {
131 children: direction === 'rtl' ? /*#__PURE__*/_jsx(LastPageIcon, {}) : /*#__PURE__*/_jsx(FirstPageIcon, {})
132 })), /*#__PURE__*/_jsx(BackButton, _extends({}, backButtonProps, {
133 children: direction === 'rtl' ? /*#__PURE__*/_jsx(NextPageIcon, {}) : /*#__PURE__*/_jsx(BackPageIcon, {})
134 })), /*#__PURE__*/_jsx(NextButton, _extends({}, nextButtonProps, {
135 children: direction === 'rtl' ? /*#__PURE__*/_jsx(BackPageIcon, {}) : /*#__PURE__*/_jsx(NextPageIcon, {})
136 })), showLastButton && /*#__PURE__*/_jsx(LastButton, _extends({}, lastButtonProps, {
137 children: direction === 'rtl' ? /*#__PURE__*/_jsx(FirstPageIcon, {}) : /*#__PURE__*/_jsx(LastPageIcon, {})
138 }))]
139 }));
140});
141export default TablePaginationActions;
\No newline at end of file