1 | 'use client';
|
2 |
|
3 | var _InputBase;
|
4 | import * as React from 'react';
|
5 | import PropTypes from 'prop-types';
|
6 | import clsx from 'clsx';
|
7 | import integerPropType from '@mui/utils/integerPropType';
|
8 | import chainPropTypes from '@mui/utils/chainPropTypes';
|
9 | import composeClasses from '@mui/utils/composeClasses';
|
10 | import isHostComponent from "../utils/isHostComponent.js";
|
11 | import { styled } from "../zero-styled/index.js";
|
12 | import memoTheme from "../utils/memoTheme.js";
|
13 | import { useDefaultProps } from "../DefaultPropsProvider/index.js";
|
14 | import InputBase from "../InputBase/index.js";
|
15 | import MenuItem from "../MenuItem/index.js";
|
16 | import Select from "../Select/index.js";
|
17 | import TableCell from "../TableCell/index.js";
|
18 | import Toolbar from "../Toolbar/index.js";
|
19 | import TablePaginationActions from "./TablePaginationActions.js";
|
20 | import useId from "../utils/useId.js";
|
21 | import tablePaginationClasses, { getTablePaginationUtilityClass } from "./tablePaginationClasses.js";
|
22 | import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
23 | import { createElement as _createElement } from "react";
|
24 | const TablePaginationRoot = styled(TableCell, {
|
25 | name: 'MuiTablePagination',
|
26 | slot: 'Root',
|
27 | overridesResolver: (props, styles) => styles.root
|
28 | })(memoTheme(({
|
29 | theme
|
30 | }) => ({
|
31 | overflow: 'auto',
|
32 | color: (theme.vars || theme).palette.text.primary,
|
33 | fontSize: theme.typography.pxToRem(14),
|
34 |
|
35 | '&:last-child': {
|
36 | padding: 0
|
37 | }
|
38 | })));
|
39 | const TablePaginationToolbar = styled(Toolbar, {
|
40 | name: 'MuiTablePagination',
|
41 | slot: 'Toolbar',
|
42 | overridesResolver: (props, styles) => ({
|
43 | [`& .${tablePaginationClasses.actions}`]: styles.actions,
|
44 | ...styles.toolbar
|
45 | })
|
46 | })(memoTheme(({
|
47 | theme
|
48 | }) => ({
|
49 | minHeight: 52,
|
50 | paddingRight: 2,
|
51 | [`${theme.breakpoints.up('xs')} and (orientation: landscape)`]: {
|
52 | minHeight: 52
|
53 | },
|
54 | [theme.breakpoints.up('sm')]: {
|
55 | minHeight: 52,
|
56 | paddingRight: 2
|
57 | },
|
58 | [`& .${tablePaginationClasses.actions}`]: {
|
59 | flexShrink: 0,
|
60 | marginLeft: 20
|
61 | }
|
62 | })));
|
63 | const TablePaginationSpacer = styled('div', {
|
64 | name: 'MuiTablePagination',
|
65 | slot: 'Spacer',
|
66 | overridesResolver: (props, styles) => styles.spacer
|
67 | })({
|
68 | flex: '1 1 100%'
|
69 | });
|
70 | const TablePaginationSelectLabel = styled('p', {
|
71 | name: 'MuiTablePagination',
|
72 | slot: 'SelectLabel',
|
73 | overridesResolver: (props, styles) => styles.selectLabel
|
74 | })(memoTheme(({
|
75 | theme
|
76 | }) => ({
|
77 | ...theme.typography.body2,
|
78 | flexShrink: 0
|
79 | })));
|
80 | const TablePaginationSelect = styled(Select, {
|
81 | name: 'MuiTablePagination',
|
82 | slot: 'Select',
|
83 | overridesResolver: (props, styles) => ({
|
84 | [`& .${tablePaginationClasses.selectIcon}`]: styles.selectIcon,
|
85 | [`& .${tablePaginationClasses.select}`]: styles.select,
|
86 | ...styles.input,
|
87 | ...styles.selectRoot
|
88 | })
|
89 | })({
|
90 | color: 'inherit',
|
91 | fontSize: 'inherit',
|
92 | flexShrink: 0,
|
93 | marginRight: 32,
|
94 | marginLeft: 8,
|
95 | [`& .${tablePaginationClasses.select}`]: {
|
96 | paddingLeft: 8,
|
97 | paddingRight: 24,
|
98 | textAlign: 'right',
|
99 | textAlignLast: 'right'
|
100 | }
|
101 | });
|
102 | const TablePaginationMenuItem = styled(MenuItem, {
|
103 | name: 'MuiTablePagination',
|
104 | slot: 'MenuItem',
|
105 | overridesResolver: (props, styles) => styles.menuItem
|
106 | })({});
|
107 | const TablePaginationDisplayedRows = styled('p', {
|
108 | name: 'MuiTablePagination',
|
109 | slot: 'DisplayedRows',
|
110 | overridesResolver: (props, styles) => styles.displayedRows
|
111 | })(memoTheme(({
|
112 | theme
|
113 | }) => ({
|
114 | ...theme.typography.body2,
|
115 | flexShrink: 0
|
116 | })));
|
117 | function defaultLabelDisplayedRows({
|
118 | from,
|
119 | to,
|
120 | count
|
121 | }) {
|
122 | return `${from}–${to} of ${count !== -1 ? count : `more than ${to}`}`;
|
123 | }
|
124 | function defaultGetAriaLabel(type) {
|
125 | return `Go to ${type} page`;
|
126 | }
|
127 | const useUtilityClasses = ownerState => {
|
128 | const {
|
129 | classes
|
130 | } = ownerState;
|
131 | const slots = {
|
132 | root: ['root'],
|
133 | toolbar: ['toolbar'],
|
134 | spacer: ['spacer'],
|
135 | selectLabel: ['selectLabel'],
|
136 | select: ['select'],
|
137 | input: ['input'],
|
138 | selectIcon: ['selectIcon'],
|
139 | menuItem: ['menuItem'],
|
140 | displayedRows: ['displayedRows'],
|
141 | actions: ['actions']
|
142 | };
|
143 | return composeClasses(slots, getTablePaginationUtilityClass, classes);
|
144 | };
|
145 |
|
146 |
|
147 |
|
148 |
|
149 | const TablePagination = React.forwardRef(function TablePagination(inProps, ref) {
|
150 | const props = useDefaultProps({
|
151 | props: inProps,
|
152 | name: 'MuiTablePagination'
|
153 | });
|
154 | const {
|
155 | ActionsComponent = TablePaginationActions,
|
156 | backIconButtonProps,
|
157 | className,
|
158 | colSpan: colSpanProp,
|
159 | component = TableCell,
|
160 | count,
|
161 | disabled = false,
|
162 | getItemAriaLabel = defaultGetAriaLabel,
|
163 | labelDisplayedRows = defaultLabelDisplayedRows,
|
164 | labelRowsPerPage = 'Rows per page:',
|
165 | nextIconButtonProps,
|
166 | onPageChange,
|
167 | onRowsPerPageChange,
|
168 | page,
|
169 | rowsPerPage,
|
170 | rowsPerPageOptions = [10, 25, 50, 100],
|
171 | SelectProps = {},
|
172 | showFirstButton = false,
|
173 | showLastButton = false,
|
174 | slotProps = {},
|
175 | slots = {},
|
176 | ...other
|
177 | } = props;
|
178 | const ownerState = props;
|
179 | const classes = useUtilityClasses(ownerState);
|
180 | const selectProps = slotProps?.select ?? SelectProps;
|
181 | const MenuItemComponent = selectProps.native ? 'option' : TablePaginationMenuItem;
|
182 | let colSpan;
|
183 | if (component === TableCell || component === 'td') {
|
184 | colSpan = colSpanProp || 1000;
|
185 | }
|
186 | const selectId = useId(selectProps.id);
|
187 | const labelId = useId(selectProps.labelId);
|
188 | const getLabelDisplayedRowsTo = () => {
|
189 | if (count === -1) {
|
190 | return (page + 1) * rowsPerPage;
|
191 | }
|
192 | return rowsPerPage === -1 ? count : Math.min(count, (page + 1) * rowsPerPage);
|
193 | };
|
194 | return _jsx(TablePaginationRoot, {
|
195 | colSpan: colSpan,
|
196 | ref: ref,
|
197 | as: component,
|
198 | ownerState: ownerState,
|
199 | className: clsx(classes.root, className),
|
200 | ...other,
|
201 | children: _jsxs(TablePaginationToolbar, {
|
202 | className: classes.toolbar,
|
203 | children: [_jsx(TablePaginationSpacer, {
|
204 | className: classes.spacer
|
205 | }), rowsPerPageOptions.length > 1 && _jsx(TablePaginationSelectLabel, {
|
206 | className: classes.selectLabel,
|
207 | id: labelId,
|
208 | children: labelRowsPerPage
|
209 | }), rowsPerPageOptions.length > 1 && _jsx(TablePaginationSelect, {
|
210 | variant: "standard",
|
211 | ...(!selectProps.variant && {
|
212 | input: _InputBase || (_InputBase = _jsx(InputBase, {}))
|
213 | }),
|
214 | value: rowsPerPage,
|
215 | onChange: onRowsPerPageChange,
|
216 | id: selectId,
|
217 | labelId: labelId,
|
218 | ...selectProps,
|
219 | classes: {
|
220 | ...selectProps.classes,
|
221 |
|
222 | root: clsx(classes.input, classes.selectRoot, (selectProps.classes || {}).root),
|
223 | select: clsx(classes.select, (selectProps.classes || {}).select),
|
224 |
|
225 | icon: clsx(classes.selectIcon, (selectProps.classes || {}).icon)
|
226 | },
|
227 | disabled: disabled,
|
228 | children: rowsPerPageOptions.map(rowsPerPageOption => _createElement(MenuItemComponent, {
|
229 | ...(!isHostComponent(MenuItemComponent) && {
|
230 | ownerState
|
231 | }),
|
232 | className: classes.menuItem,
|
233 | key: rowsPerPageOption.label ? rowsPerPageOption.label : rowsPerPageOption,
|
234 | value: rowsPerPageOption.value ? rowsPerPageOption.value : rowsPerPageOption
|
235 | }, rowsPerPageOption.label ? rowsPerPageOption.label : rowsPerPageOption))
|
236 | }), _jsx(TablePaginationDisplayedRows, {
|
237 | className: classes.displayedRows,
|
238 | children: labelDisplayedRows({
|
239 | from: count === 0 ? 0 : page * rowsPerPage + 1,
|
240 | to: getLabelDisplayedRowsTo(),
|
241 | count: count === -1 ? -1 : count,
|
242 | page
|
243 | })
|
244 | }), _jsx(ActionsComponent, {
|
245 | className: classes.actions,
|
246 | backIconButtonProps: backIconButtonProps,
|
247 | count: count,
|
248 | nextIconButtonProps: nextIconButtonProps,
|
249 | onPageChange: onPageChange,
|
250 | page: page,
|
251 | rowsPerPage: rowsPerPage,
|
252 | showFirstButton: showFirstButton,
|
253 | showLastButton: showLastButton,
|
254 | slotProps: slotProps.actions,
|
255 | slots: slots.actions,
|
256 | getItemAriaLabel: getItemAriaLabel,
|
257 | disabled: disabled
|
258 | })]
|
259 | })
|
260 | });
|
261 | });
|
262 | process.env.NODE_ENV !== "production" ? TablePagination.propTypes = {
|
263 |
|
264 |
|
265 |
|
266 |
|
267 | |
268 |
|
269 |
|
270 |
|
271 |
|
272 | ActionsComponent: PropTypes.elementType,
|
273 | |
274 |
|
275 |
|
276 |
|
277 |
|
278 |
|
279 | backIconButtonProps: PropTypes.object,
|
280 | |
281 |
|
282 |
|
283 | classes: PropTypes.object,
|
284 | |
285 |
|
286 |
|
287 | className: PropTypes.string,
|
288 | |
289 |
|
290 |
|
291 | colSpan: PropTypes.number,
|
292 | |
293 |
|
294 |
|
295 |
|
296 | component: PropTypes.elementType,
|
297 | |
298 |
|
299 |
|
300 |
|
301 |
|
302 | count: integerPropType.isRequired,
|
303 | |
304 |
|
305 |
|
306 |
|
307 | disabled: PropTypes.bool,
|
308 | |
309 |
|
310 |
|
311 |
|
312 |
|
313 |
|
314 |
|
315 |
|
316 |
|
317 |
|
318 |
|
319 | getItemAriaLabel: PropTypes.func,
|
320 | |
321 |
|
322 |
|
323 |
|
324 |
|
325 |
|
326 |
|
327 |
|
328 |
|
329 | labelDisplayedRows: PropTypes.func,
|
330 | |
331 |
|
332 |
|
333 |
|
334 |
|
335 |
|
336 | labelRowsPerPage: PropTypes.node,
|
337 | |
338 |
|
339 |
|
340 |
|
341 |
|
342 |
|
343 | nextIconButtonProps: PropTypes.object,
|
344 | |
345 |
|
346 |
|
347 |
|
348 |
|
349 |
|
350 | onPageChange: PropTypes.func.isRequired,
|
351 | |
352 |
|
353 |
|
354 |
|
355 |
|
356 | onRowsPerPageChange: PropTypes.func,
|
357 | |
358 |
|
359 |
|
360 | page: chainPropTypes(integerPropType.isRequired, props => {
|
361 | const {
|
362 | count,
|
363 | page,
|
364 | rowsPerPage
|
365 | } = props;
|
366 | if (count === -1) {
|
367 | return null;
|
368 | }
|
369 | const newLastPage = Math.max(0, Math.ceil(count / rowsPerPage) - 1);
|
370 | if (page < 0 || page > newLastPage) {
|
371 | return new Error('MUI: The page prop of a TablePagination is out of range ' + `(0 to ${newLastPage}, but page is ${page}).`);
|
372 | }
|
373 | return null;
|
374 | }),
|
375 | |
376 |
|
377 |
|
378 |
|
379 |
|
380 | rowsPerPage: integerPropType.isRequired,
|
381 | |
382 |
|
383 |
|
384 |
|
385 |
|
386 |
|
387 | rowsPerPageOptions: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.number, PropTypes.shape({
|
388 | label: PropTypes.string.isRequired,
|
389 | value: PropTypes.number.isRequired
|
390 | })]).isRequired),
|
391 | |
392 |
|
393 |
|
394 |
|
395 |
|
396 |
|
397 |
|
398 |
|
399 | SelectProps: PropTypes.object,
|
400 | |
401 |
|
402 |
|
403 |
|
404 | showFirstButton: PropTypes.bool,
|
405 | |
406 |
|
407 |
|
408 |
|
409 | showLastButton: PropTypes.bool,
|
410 | |
411 |
|
412 |
|
413 |
|
414 | slotProps: PropTypes.shape({
|
415 | actions: PropTypes.shape({
|
416 | firstButton: PropTypes.object,
|
417 | firstButtonIcon: PropTypes.object,
|
418 | lastButton: PropTypes.object,
|
419 | lastButtonIcon: PropTypes.object,
|
420 | nextButton: PropTypes.object,
|
421 | nextButtonIcon: PropTypes.object,
|
422 | previousButton: PropTypes.object,
|
423 | previousButtonIcon: PropTypes.object
|
424 | }),
|
425 | select: PropTypes.object
|
426 | }),
|
427 | |
428 |
|
429 |
|
430 |
|
431 |
|
432 | slots: PropTypes.shape({
|
433 | actions: PropTypes.shape({
|
434 | firstButton: PropTypes.elementType,
|
435 | firstButtonIcon: PropTypes.elementType,
|
436 | lastButton: PropTypes.elementType,
|
437 | lastButtonIcon: PropTypes.elementType,
|
438 | nextButton: PropTypes.elementType,
|
439 | nextButtonIcon: PropTypes.elementType,
|
440 | previousButton: PropTypes.elementType,
|
441 | previousButtonIcon: PropTypes.elementType
|
442 | })
|
443 | }),
|
444 | |
445 |
|
446 |
|
447 | sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
|
448 | } : void 0;
|
449 | export default TablePagination; |
\ | No newline at end of file |