1 | 'use client';
|
2 |
|
3 | import * as React from 'react';
|
4 | import PropTypes from 'prop-types';
|
5 | import { useRtl } from '@mui/system/RtlProvider';
|
6 | import KeyboardArrowLeft from "../internal/svg-icons/KeyboardArrowLeft.js";
|
7 | import KeyboardArrowRight from "../internal/svg-icons/KeyboardArrowRight.js";
|
8 | import IconButton from "../IconButton/index.js";
|
9 | import LastPageIconDefault from "../internal/svg-icons/LastPage.js";
|
10 | import FirstPageIconDefault from "../internal/svg-icons/FirstPage.js";
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
16 | const TablePaginationActions = React.forwardRef(function TablePaginationActions(props, ref) {
|
17 | const {
|
18 | backIconButtonProps,
|
19 | count,
|
20 | disabled = false,
|
21 | getItemAriaLabel,
|
22 | nextIconButtonProps,
|
23 | onPageChange,
|
24 | page,
|
25 | rowsPerPage,
|
26 | showFirstButton,
|
27 | showLastButton,
|
28 | slots = {},
|
29 | slotProps = {},
|
30 | ...other
|
31 | } = props;
|
32 | const isRtl = useRtl();
|
33 | const handleFirstPageButtonClick = event => {
|
34 | onPageChange(event, 0);
|
35 | };
|
36 | const handleBackButtonClick = event => {
|
37 | onPageChange(event, page - 1);
|
38 | };
|
39 | const handleNextButtonClick = event => {
|
40 | onPageChange(event, page + 1);
|
41 | };
|
42 | const handleLastPageButtonClick = event => {
|
43 | onPageChange(event, Math.max(0, Math.ceil(count / rowsPerPage) - 1));
|
44 | };
|
45 | const FirstButton = slots.firstButton ?? IconButton;
|
46 | const LastButton = slots.lastButton ?? IconButton;
|
47 | const NextButton = slots.nextButton ?? IconButton;
|
48 | const PreviousButton = slots.previousButton ?? IconButton;
|
49 | const FirstButtonIcon = slots.firstButtonIcon ?? FirstPageIconDefault;
|
50 | const LastButtonIcon = slots.lastButtonIcon ?? LastPageIconDefault;
|
51 | const NextButtonIcon = slots.nextButtonIcon ?? KeyboardArrowRight;
|
52 | const PreviousButtonIcon = slots.previousButtonIcon ?? KeyboardArrowLeft;
|
53 | const FirstButtonSlot = isRtl ? LastButton : FirstButton;
|
54 | const PreviousButtonSlot = isRtl ? NextButton : PreviousButton;
|
55 | const NextButtonSlot = isRtl ? PreviousButton : NextButton;
|
56 | const LastButtonSlot = isRtl ? FirstButton : LastButton;
|
57 | const firstButtonSlotProps = isRtl ? slotProps.lastButton : slotProps.firstButton;
|
58 | const previousButtonSlotProps = isRtl ? slotProps.nextButton : slotProps.previousButton;
|
59 | const nextButtonSlotProps = isRtl ? slotProps.previousButton : slotProps.nextButton;
|
60 | const lastButtonSlotProps = isRtl ? slotProps.firstButton : slotProps.lastButton;
|
61 | return _jsxs("div", {
|
62 | ref: ref,
|
63 | ...other,
|
64 | children: [showFirstButton && _jsx(FirstButtonSlot, {
|
65 | onClick: handleFirstPageButtonClick,
|
66 | disabled: disabled || page === 0,
|
67 | "aria-label": getItemAriaLabel('first', page),
|
68 | title: getItemAriaLabel('first', page),
|
69 | ...firstButtonSlotProps,
|
70 | children: isRtl ? _jsx(LastButtonIcon, {
|
71 | ...slotProps.lastButtonIcon
|
72 | }) : _jsx(FirstButtonIcon, {
|
73 | ...slotProps.firstButtonIcon
|
74 | })
|
75 | }), _jsx(PreviousButtonSlot, {
|
76 | onClick: handleBackButtonClick,
|
77 | disabled: disabled || page === 0,
|
78 | color: "inherit",
|
79 | "aria-label": getItemAriaLabel('previous', page),
|
80 | title: getItemAriaLabel('previous', page),
|
81 | ...(previousButtonSlotProps ?? backIconButtonProps),
|
82 | children: isRtl ? _jsx(NextButtonIcon, {
|
83 | ...slotProps.nextButtonIcon
|
84 | }) : _jsx(PreviousButtonIcon, {
|
85 | ...slotProps.previousButtonIcon
|
86 | })
|
87 | }), _jsx(NextButtonSlot, {
|
88 | onClick: handleNextButtonClick,
|
89 | disabled: disabled || (count !== -1 ? page >= Math.ceil(count / rowsPerPage) - 1 : false),
|
90 | color: "inherit",
|
91 | "aria-label": getItemAriaLabel('next', page),
|
92 | title: getItemAriaLabel('next', page),
|
93 | ...(nextButtonSlotProps ?? nextIconButtonProps),
|
94 | children: isRtl ? _jsx(PreviousButtonIcon, {
|
95 | ...slotProps.previousButtonIcon
|
96 | }) : _jsx(NextButtonIcon, {
|
97 | ...slotProps.nextButtonIcon
|
98 | })
|
99 | }), showLastButton && _jsx(LastButtonSlot, {
|
100 | onClick: handleLastPageButtonClick,
|
101 | disabled: disabled || page >= Math.ceil(count / rowsPerPage) - 1,
|
102 | "aria-label": getItemAriaLabel('last', page),
|
103 | title: getItemAriaLabel('last', page),
|
104 | ...lastButtonSlotProps,
|
105 | children: isRtl ? _jsx(FirstButtonIcon, {
|
106 | ...slotProps.firstButtonIcon
|
107 | }) : _jsx(LastButtonIcon, {
|
108 | ...slotProps.lastButtonIcon
|
109 | })
|
110 | })]
|
111 | });
|
112 | });
|
113 | process.env.NODE_ENV !== "production" ? TablePaginationActions.propTypes = {
|
114 | |
115 |
|
116 |
|
117 | backIconButtonProps: PropTypes.object,
|
118 | |
119 |
|
120 |
|
121 | count: PropTypes.number.isRequired,
|
122 | |
123 |
|
124 |
|
125 |
|
126 | disabled: PropTypes.bool,
|
127 | |
128 |
|
129 |
|
130 |
|
131 |
|
132 |
|
133 |
|
134 |
|
135 |
|
136 | getItemAriaLabel: PropTypes.func.isRequired,
|
137 | |
138 |
|
139 |
|
140 | nextIconButtonProps: PropTypes.object,
|
141 | |
142 |
|
143 |
|
144 |
|
145 |
|
146 |
|
147 | onPageChange: PropTypes.func.isRequired,
|
148 | |
149 |
|
150 |
|
151 | page: PropTypes.number.isRequired,
|
152 | |
153 |
|
154 |
|
155 | rowsPerPage: PropTypes.number.isRequired,
|
156 | |
157 |
|
158 |
|
159 | showFirstButton: PropTypes.bool.isRequired,
|
160 | |
161 |
|
162 |
|
163 | showLastButton: PropTypes.bool.isRequired,
|
164 | |
165 |
|
166 |
|
167 |
|
168 | slotProps: PropTypes.shape({
|
169 | firstButton: PropTypes.object,
|
170 | firstButtonIcon: PropTypes.object,
|
171 | lastButton: PropTypes.object,
|
172 | lastButtonIcon: PropTypes.object,
|
173 | nextButton: PropTypes.object,
|
174 | nextButtonIcon: PropTypes.object,
|
175 | previousButton: PropTypes.object,
|
176 | previousButtonIcon: PropTypes.object
|
177 | }),
|
178 | |
179 |
|
180 |
|
181 |
|
182 |
|
183 | slots: PropTypes.shape({
|
184 | firstButton: PropTypes.elementType,
|
185 | firstButtonIcon: PropTypes.elementType,
|
186 | lastButton: PropTypes.elementType,
|
187 | lastButtonIcon: PropTypes.elementType,
|
188 | nextButton: PropTypes.elementType,
|
189 | nextButtonIcon: PropTypes.elementType,
|
190 | previousButton: PropTypes.elementType,
|
191 | previousButtonIcon: PropTypes.elementType
|
192 | })
|
193 | } : void 0;
|
194 | export default TablePaginationActions; |
\ | No newline at end of file |