TablePaginationActions.js
8.29 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
'use client';
import * as React from 'react';
import PropTypes from 'prop-types';
import { useRtl } from '@mui/system/RtlProvider';
import composeClasses from '@mui/utils/composeClasses';
import clsx from 'clsx';
import { styled } from "../zero-styled/index.js";
import { useDefaultProps } from "../DefaultPropsProvider/index.js";
import KeyboardArrowLeft from "../internal/svg-icons/KeyboardArrowLeft.js";
import KeyboardArrowRight from "../internal/svg-icons/KeyboardArrowRight.js";
import IconButton from "../IconButton/index.js";
import LastPageIconDefault from "../internal/svg-icons/LastPage.js";
import FirstPageIconDefault from "../internal/svg-icons/FirstPage.js";
import { getTablePaginationActionsUtilityClass } from "./tablePaginationActionsClasses.js";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
const useUtilityClasses = ownerState => {
const {
classes
} = ownerState;
const slots = {
root: ['root']
};
return composeClasses(slots, getTablePaginationActionsUtilityClass, classes);
};
const TablePaginationActionsRoot = styled('div', {
name: 'MuiTablePaginationActions',
slot: 'Root'
})({});
const TablePaginationActions = /*#__PURE__*/React.forwardRef(function TablePaginationActions(inProps, ref) {
const props = useDefaultProps({
props: inProps,
name: 'MuiTablePaginationActions'
});
const {
backIconButtonProps,
className,
count,
disabled = false,
getItemAriaLabel,
nextIconButtonProps,
onPageChange,
page,
rowsPerPage,
showFirstButton,
showLastButton,
slots = {},
slotProps = {},
...other
} = props;
const isRtl = useRtl();
const ownerState = props;
const classes = useUtilityClasses(ownerState);
const handleFirstPageButtonClick = event => {
onPageChange(event, 0);
};
const handleBackButtonClick = event => {
onPageChange(event, page - 1);
};
const handleNextButtonClick = event => {
onPageChange(event, page + 1);
};
const handleLastPageButtonClick = event => {
onPageChange(event, Math.max(0, Math.ceil(count / rowsPerPage) - 1));
};
const FirstButton = slots.firstButton ?? IconButton;
const LastButton = slots.lastButton ?? IconButton;
const NextButton = slots.nextButton ?? IconButton;
const PreviousButton = slots.previousButton ?? IconButton;
const FirstButtonIcon = slots.firstButtonIcon ?? FirstPageIconDefault;
const LastButtonIcon = slots.lastButtonIcon ?? LastPageIconDefault;
const NextButtonIcon = slots.nextButtonIcon ?? KeyboardArrowRight;
const PreviousButtonIcon = slots.previousButtonIcon ?? KeyboardArrowLeft;
const FirstButtonSlot = isRtl ? LastButton : FirstButton;
const PreviousButtonSlot = isRtl ? NextButton : PreviousButton;
const NextButtonSlot = isRtl ? PreviousButton : NextButton;
const LastButtonSlot = isRtl ? FirstButton : LastButton;
const firstButtonSlotProps = isRtl ? slotProps.lastButton : slotProps.firstButton;
const previousButtonSlotProps = isRtl ? slotProps.nextButton : slotProps.previousButton;
const nextButtonSlotProps = isRtl ? slotProps.previousButton : slotProps.nextButton;
const lastButtonSlotProps = isRtl ? slotProps.firstButton : slotProps.lastButton;
return /*#__PURE__*/_jsxs(TablePaginationActionsRoot, {
ref: ref,
className: clsx(classes.root, className),
...other,
children: [showFirstButton && /*#__PURE__*/_jsx(FirstButtonSlot, {
onClick: handleFirstPageButtonClick,
disabled: disabled || page === 0,
"aria-label": getItemAriaLabel('first', page),
title: getItemAriaLabel('first', page),
...firstButtonSlotProps,
children: isRtl ? /*#__PURE__*/_jsx(LastButtonIcon, {
...slotProps.lastButtonIcon
}) : /*#__PURE__*/_jsx(FirstButtonIcon, {
...slotProps.firstButtonIcon
})
}), /*#__PURE__*/_jsx(PreviousButtonSlot, {
onClick: handleBackButtonClick,
disabled: disabled || page === 0,
color: "inherit",
"aria-label": getItemAriaLabel('previous', page),
title: getItemAriaLabel('previous', page),
...(previousButtonSlotProps ?? backIconButtonProps),
children: isRtl ? /*#__PURE__*/_jsx(NextButtonIcon, {
...slotProps.nextButtonIcon
}) : /*#__PURE__*/_jsx(PreviousButtonIcon, {
...slotProps.previousButtonIcon
})
}), /*#__PURE__*/_jsx(NextButtonSlot, {
onClick: handleNextButtonClick,
disabled: disabled || (count !== -1 ? page >= Math.ceil(count / rowsPerPage) - 1 : false),
color: "inherit",
"aria-label": getItemAriaLabel('next', page),
title: getItemAriaLabel('next', page),
...(nextButtonSlotProps ?? nextIconButtonProps),
children: isRtl ? /*#__PURE__*/_jsx(PreviousButtonIcon, {
...slotProps.previousButtonIcon
}) : /*#__PURE__*/_jsx(NextButtonIcon, {
...slotProps.nextButtonIcon
})
}), showLastButton && /*#__PURE__*/_jsx(LastButtonSlot, {
onClick: handleLastPageButtonClick,
disabled: disabled || page >= Math.ceil(count / rowsPerPage) - 1,
"aria-label": getItemAriaLabel('last', page),
title: getItemAriaLabel('last', page),
...lastButtonSlotProps,
children: isRtl ? /*#__PURE__*/_jsx(FirstButtonIcon, {
...slotProps.firstButtonIcon
}) : /*#__PURE__*/_jsx(LastButtonIcon, {
...slotProps.lastButtonIcon
})
})]
});
});
process.env.NODE_ENV !== "production" ? TablePaginationActions.propTypes /* remove-proptypes */ = {
// ┌────────────────────────────── Warning ──────────────────────────────┐
// │ These PropTypes are generated from the TypeScript type definitions. │
// │ To update them, edit the d.ts file and run `pnpm proptypes`. │
// └─────────────────────────────────────────────────────────────────────┘
/**
* This prop is an alias for `slotProps.previousButton` and will be overridden by it if both are used.
* @deprecated Use `slotProps.previousButton` instead.
*/
backIconButtonProps: PropTypes.object,
/**
* @ignore
*/
children: PropTypes.node,
/**
* Override or extend the styles applied to the component.
*/
classes: PropTypes.object,
/**
* @ignore
*/
className: PropTypes.string,
/**
* @ignore
*/
count: PropTypes.number.isRequired,
/**
* If `true`, the component is disabled.
* @default false
*/
disabled: PropTypes.bool,
/**
* Accepts a function which returns a string value that provides a user-friendly name for the current page.
* This is important for screen reader users.
*
* For localization purposes, you can use the provided [translations](https://mui.com/material-ui/guides/localization/).
* @param {string} type The link or button type to format ('first' | 'last' | 'next' | 'previous').
* @returns {string}
*/
getItemAriaLabel: PropTypes.func.isRequired,
/**
* This prop is an alias for `slotProps.nextButton` and will be overridden by it if both are used.
* @deprecated Use `slotProps.nextButton` instead.
*/
nextIconButtonProps: PropTypes.object,
/**
* @ignore
*/
onPageChange: PropTypes.func.isRequired,
/**
* @ignore
*/
page: PropTypes.number.isRequired,
/**
* @ignore
*/
rowsPerPage: PropTypes.number.isRequired,
/**
* @ignore
*/
showFirstButton: PropTypes.bool.isRequired,
/**
* @ignore
*/
showLastButton: PropTypes.bool.isRequired,
/**
* @ignore
*/
slotProps: PropTypes.shape({
firstButton: PropTypes.object,
firstButtonIcon: PropTypes.object,
lastButton: PropTypes.object,
lastButtonIcon: PropTypes.object,
nextButton: PropTypes.object,
nextButtonIcon: PropTypes.object,
previousButton: PropTypes.object,
previousButtonIcon: PropTypes.object
}),
/**
* @ignore
*/
slots: PropTypes.shape({
firstButton: PropTypes.elementType,
firstButtonIcon: PropTypes.elementType,
lastButton: PropTypes.elementType,
lastButtonIcon: PropTypes.elementType,
nextButton: PropTypes.elementType,
nextButtonIcon: PropTypes.elementType,
previousButton: PropTypes.elementType,
previousButtonIcon: PropTypes.elementType
})
} : void 0;
export default TablePaginationActions;