UNPKG

18 kBJavaScriptView Raw
1'use client';
2
3import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
4import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
5import _extends from "@babel/runtime/helpers/esm/extends";
6var _InputBase;
7import * as React from 'react';
8import PropTypes from 'prop-types';
9import clsx from 'clsx';
10import integerPropType from '@mui/utils/integerPropType';
11import chainPropTypes from '@mui/utils/chainPropTypes';
12import { isHostComponent } from '@mui/base/utils';
13import composeClasses from '@mui/utils/composeClasses';
14import styled from '../styles/styled';
15import { useDefaultProps } from '../DefaultPropsProvider';
16import InputBase from '../InputBase';
17import MenuItem from '../MenuItem';
18import Select from '../Select';
19import TableCell from '../TableCell';
20import Toolbar from '../Toolbar';
21import TablePaginationActions from './TablePaginationActions';
22import useId from '../utils/useId';
23import tablePaginationClasses, { getTablePaginationUtilityClass } from './tablePaginationClasses';
24import { jsx as _jsx } from "react/jsx-runtime";
25import { createElement as _createElement } from "react";
26import { jsxs as _jsxs } from "react/jsx-runtime";
27var TablePaginationRoot = styled(TableCell, {
28 name: 'MuiTablePagination',
29 slot: 'Root',
30 overridesResolver: function overridesResolver(props, styles) {
31 return styles.root;
32 }
33})(function (_ref) {
34 var theme = _ref.theme;
35 return {
36 overflow: 'auto',
37 color: (theme.vars || theme).palette.text.primary,
38 fontSize: theme.typography.pxToRem(14),
39 // Increase the specificity to override TableCell.
40 '&:last-child': {
41 padding: 0
42 }
43 };
44});
45var TablePaginationToolbar = styled(Toolbar, {
46 name: 'MuiTablePagination',
47 slot: 'Toolbar',
48 overridesResolver: function overridesResolver(props, styles) {
49 return _extends(_defineProperty({}, "& .".concat(tablePaginationClasses.actions), styles.actions), styles.toolbar);
50 }
51})(function (_ref2) {
52 var theme = _ref2.theme;
53 return _defineProperty(_defineProperty(_defineProperty({
54 minHeight: 52,
55 paddingRight: 2
56 }, "".concat(theme.breakpoints.up('xs'), " and (orientation: landscape)"), {
57 minHeight: 52
58 }), theme.breakpoints.up('sm'), {
59 minHeight: 52,
60 paddingRight: 2
61 }), "& .".concat(tablePaginationClasses.actions), {
62 flexShrink: 0,
63 marginLeft: 20
64 });
65});
66var TablePaginationSpacer = styled('div', {
67 name: 'MuiTablePagination',
68 slot: 'Spacer',
69 overridesResolver: function overridesResolver(props, styles) {
70 return styles.spacer;
71 }
72})({
73 flex: '1 1 100%'
74});
75var TablePaginationSelectLabel = styled('p', {
76 name: 'MuiTablePagination',
77 slot: 'SelectLabel',
78 overridesResolver: function overridesResolver(props, styles) {
79 return styles.selectLabel;
80 }
81})(function (_ref4) {
82 var theme = _ref4.theme;
83 return _extends({}, theme.typography.body2, {
84 flexShrink: 0
85 });
86});
87var TablePaginationSelect = styled(Select, {
88 name: 'MuiTablePagination',
89 slot: 'Select',
90 overridesResolver: function overridesResolver(props, styles) {
91 return _extends(_defineProperty(_defineProperty({}, "& .".concat(tablePaginationClasses.selectIcon), styles.selectIcon), "& .".concat(tablePaginationClasses.select), styles.select), styles.input, styles.selectRoot);
92 }
93})(_defineProperty({
94 color: 'inherit',
95 fontSize: 'inherit',
96 flexShrink: 0,
97 marginRight: 32,
98 marginLeft: 8
99}, "& .".concat(tablePaginationClasses.select), {
100 paddingLeft: 8,
101 paddingRight: 24,
102 textAlign: 'right',
103 textAlignLast: 'right' // Align <select> on Chrome.
104}));
105var TablePaginationMenuItem = styled(MenuItem, {
106 name: 'MuiTablePagination',
107 slot: 'MenuItem',
108 overridesResolver: function overridesResolver(props, styles) {
109 return styles.menuItem;
110 }
111})({});
112var TablePaginationDisplayedRows = styled('p', {
113 name: 'MuiTablePagination',
114 slot: 'DisplayedRows',
115 overridesResolver: function overridesResolver(props, styles) {
116 return styles.displayedRows;
117 }
118})(function (_ref5) {
119 var theme = _ref5.theme;
120 return _extends({}, theme.typography.body2, {
121 flexShrink: 0
122 });
123});
124function defaultLabelDisplayedRows(_ref6) {
125 var from = _ref6.from,
126 to = _ref6.to,
127 count = _ref6.count;
128 return "".concat(from, "\u2013").concat(to, " of ").concat(count !== -1 ? count : "more than ".concat(to));
129}
130function defaultGetAriaLabel(type) {
131 return "Go to ".concat(type, " page");
132}
133var useUtilityClasses = function useUtilityClasses(ownerState) {
134 var classes = ownerState.classes;
135 var slots = {
136 root: ['root'],
137 toolbar: ['toolbar'],
138 spacer: ['spacer'],
139 selectLabel: ['selectLabel'],
140 select: ['select'],
141 input: ['input'],
142 selectIcon: ['selectIcon'],
143 menuItem: ['menuItem'],
144 displayedRows: ['displayedRows'],
145 actions: ['actions']
146 };
147 return composeClasses(slots, getTablePaginationUtilityClass, classes);
148};
149
150/**
151 * A `TableCell` based component for placing inside `TableFooter` for pagination.
152 */
153var TablePagination = /*#__PURE__*/React.forwardRef(function TablePagination(inProps, ref) {
154 var _slotProps$select;
155 var props = useDefaultProps({
156 props: inProps,
157 name: 'MuiTablePagination'
158 });
159 var _props$ActionsCompone = props.ActionsComponent,
160 ActionsComponent = _props$ActionsCompone === void 0 ? TablePaginationActions : _props$ActionsCompone,
161 backIconButtonProps = props.backIconButtonProps,
162 className = props.className,
163 colSpanProp = props.colSpan,
164 _props$component = props.component,
165 component = _props$component === void 0 ? TableCell : _props$component,
166 count = props.count,
167 _props$disabled = props.disabled,
168 disabled = _props$disabled === void 0 ? false : _props$disabled,
169 _props$getItemAriaLab = props.getItemAriaLabel,
170 getItemAriaLabel = _props$getItemAriaLab === void 0 ? defaultGetAriaLabel : _props$getItemAriaLab,
171 _props$labelDisplayed = props.labelDisplayedRows,
172 labelDisplayedRows = _props$labelDisplayed === void 0 ? defaultLabelDisplayedRows : _props$labelDisplayed,
173 _props$labelRowsPerPa = props.labelRowsPerPage,
174 labelRowsPerPage = _props$labelRowsPerPa === void 0 ? 'Rows per page:' : _props$labelRowsPerPa,
175 nextIconButtonProps = props.nextIconButtonProps,
176 onPageChange = props.onPageChange,
177 onRowsPerPageChange = props.onRowsPerPageChange,
178 page = props.page,
179 rowsPerPage = props.rowsPerPage,
180 _props$rowsPerPageOpt = props.rowsPerPageOptions,
181 rowsPerPageOptions = _props$rowsPerPageOpt === void 0 ? [10, 25, 50, 100] : _props$rowsPerPageOpt,
182 _props$SelectProps = props.SelectProps,
183 SelectProps = _props$SelectProps === void 0 ? {} : _props$SelectProps,
184 _props$showFirstButto = props.showFirstButton,
185 showFirstButton = _props$showFirstButto === void 0 ? false : _props$showFirstButto,
186 _props$showLastButton = props.showLastButton,
187 showLastButton = _props$showLastButton === void 0 ? false : _props$showLastButton,
188 _props$slotProps = props.slotProps,
189 slotProps = _props$slotProps === void 0 ? {} : _props$slotProps,
190 _props$slots = props.slots,
191 slots = _props$slots === void 0 ? {} : _props$slots,
192 other = _objectWithoutProperties(props, ["ActionsComponent", "backIconButtonProps", "className", "colSpan", "component", "count", "disabled", "getItemAriaLabel", "labelDisplayedRows", "labelRowsPerPage", "nextIconButtonProps", "onPageChange", "onRowsPerPageChange", "page", "rowsPerPage", "rowsPerPageOptions", "SelectProps", "showFirstButton", "showLastButton", "slotProps", "slots"]);
193 var ownerState = props;
194 var classes = useUtilityClasses(ownerState);
195 var selectProps = (_slotProps$select = slotProps == null ? void 0 : slotProps.select) != null ? _slotProps$select : SelectProps;
196 var MenuItemComponent = selectProps.native ? 'option' : TablePaginationMenuItem;
197 var colSpan;
198 if (component === TableCell || component === 'td') {
199 colSpan = colSpanProp || 1000; // col-span over everything
200 }
201 var selectId = useId(selectProps.id);
202 var labelId = useId(selectProps.labelId);
203 var getLabelDisplayedRowsTo = function getLabelDisplayedRowsTo() {
204 if (count === -1) {
205 return (page + 1) * rowsPerPage;
206 }
207 return rowsPerPage === -1 ? count : Math.min(count, (page + 1) * rowsPerPage);
208 };
209 return /*#__PURE__*/_jsx(TablePaginationRoot, _extends({
210 colSpan: colSpan,
211 ref: ref,
212 as: component,
213 ownerState: ownerState,
214 className: clsx(classes.root, className)
215 }, other, {
216 children: /*#__PURE__*/_jsxs(TablePaginationToolbar, {
217 className: classes.toolbar,
218 children: [/*#__PURE__*/_jsx(TablePaginationSpacer, {
219 className: classes.spacer
220 }), rowsPerPageOptions.length > 1 && /*#__PURE__*/_jsx(TablePaginationSelectLabel, {
221 className: classes.selectLabel,
222 id: labelId,
223 children: labelRowsPerPage
224 }), rowsPerPageOptions.length > 1 && /*#__PURE__*/_jsx(TablePaginationSelect, _extends({
225 variant: "standard"
226 }, !selectProps.variant && {
227 input: _InputBase || (_InputBase = /*#__PURE__*/_jsx(InputBase, {}))
228 }, {
229 value: rowsPerPage,
230 onChange: onRowsPerPageChange,
231 id: selectId,
232 labelId: labelId
233 }, selectProps, {
234 classes: _extends({}, selectProps.classes, {
235 // TODO v5 remove `classes.input`
236 root: clsx(classes.input, classes.selectRoot, (selectProps.classes || {}).root),
237 select: clsx(classes.select, (selectProps.classes || {}).select),
238 // TODO v5 remove `selectIcon`
239 icon: clsx(classes.selectIcon, (selectProps.classes || {}).icon)
240 }),
241 disabled: disabled,
242 children: rowsPerPageOptions.map(function (rowsPerPageOption) {
243 return /*#__PURE__*/_createElement(MenuItemComponent, _extends({}, !isHostComponent(MenuItemComponent) && {
244 ownerState: ownerState
245 }, {
246 className: classes.menuItem,
247 key: rowsPerPageOption.label ? rowsPerPageOption.label : rowsPerPageOption,
248 value: rowsPerPageOption.value ? rowsPerPageOption.value : rowsPerPageOption
249 }), rowsPerPageOption.label ? rowsPerPageOption.label : rowsPerPageOption);
250 })
251 })), /*#__PURE__*/_jsx(TablePaginationDisplayedRows, {
252 className: classes.displayedRows,
253 children: labelDisplayedRows({
254 from: count === 0 ? 0 : page * rowsPerPage + 1,
255 to: getLabelDisplayedRowsTo(),
256 count: count === -1 ? -1 : count,
257 page: page
258 })
259 }), /*#__PURE__*/_jsx(ActionsComponent, {
260 className: classes.actions,
261 backIconButtonProps: backIconButtonProps,
262 count: count,
263 nextIconButtonProps: nextIconButtonProps,
264 onPageChange: onPageChange,
265 page: page,
266 rowsPerPage: rowsPerPage,
267 showFirstButton: showFirstButton,
268 showLastButton: showLastButton,
269 slotProps: slotProps.actions,
270 slots: slots.actions,
271 getItemAriaLabel: getItemAriaLabel,
272 disabled: disabled
273 })]
274 })
275 }));
276});
277process.env.NODE_ENV !== "production" ? TablePagination.propTypes /* remove-proptypes */ = {
278 // ┌────────────────────────────── Warning ──────────────────────────────┐
279 // │ These PropTypes are generated from the TypeScript type definitions. │
280 // │ To update them, edit the d.ts file and run `pnpm proptypes`. │
281 // └─────────────────────────────────────────────────────────────────────┘
282 /**
283 * The component used for displaying the actions.
284 * Either a string to use a HTML element or a component.
285 * @default TablePaginationActions
286 */
287 ActionsComponent: PropTypes.elementType,
288 /**
289 * Props applied to the back arrow [`IconButton`](/material-ui/api/icon-button/) component.
290 *
291 * This prop is an alias for `slotProps.actions.previousButton` and will be overriden by it if both are used.
292 * @deprecated Use `slotProps.actions.previousButton` instead.
293 */
294 backIconButtonProps: PropTypes.object,
295 /**
296 * Override or extend the styles applied to the component.
297 */
298 classes: PropTypes.object,
299 /**
300 * @ignore
301 */
302 className: PropTypes.string,
303 /**
304 * @ignore
305 */
306 colSpan: PropTypes.number,
307 /**
308 * The component used for the root node.
309 * Either a string to use a HTML element or a component.
310 */
311 component: PropTypes.elementType,
312 /**
313 * The total number of rows.
314 *
315 * To enable server side pagination for an unknown number of items, provide -1.
316 */
317 count: integerPropType.isRequired,
318 /**
319 * If `true`, the component is disabled.
320 * @default false
321 */
322 disabled: PropTypes.bool,
323 /**
324 * Accepts a function which returns a string value that provides a user-friendly name for the current page.
325 * This is important for screen reader users.
326 *
327 * For localization purposes, you can use the provided [translations](/material-ui/guides/localization/).
328 * @param {string} type The link or button type to format ('first' | 'last' | 'next' | 'previous').
329 * @returns {string}
330 * @default function defaultGetAriaLabel(type) {
331 * return `Go to ${type} page`;
332 * }
333 */
334 getItemAriaLabel: PropTypes.func,
335 /**
336 * Customize the displayed rows label. Invoked with a `{ from, to, count, page }`
337 * object.
338 *
339 * For localization purposes, you can use the provided [translations](/material-ui/guides/localization/).
340 * @default function defaultLabelDisplayedRows({ from, to, count }) {
341 * return `${from}–${to} of ${count !== -1 ? count : `more than ${to}`}`;
342 * }
343 */
344 labelDisplayedRows: PropTypes.func,
345 /**
346 * Customize the rows per page label.
347 *
348 * For localization purposes, you can use the provided [translations](/material-ui/guides/localization/).
349 * @default 'Rows per page:'
350 */
351 labelRowsPerPage: PropTypes.node,
352 /**
353 * Props applied to the next arrow [`IconButton`](/material-ui/api/icon-button/) element.
354 *
355 * This prop is an alias for `slotProps.actions.nextButton` and will be overriden by it if both are used.
356 * @deprecated Use `slotProps.actions.nextButton` instead.
357 */
358 nextIconButtonProps: PropTypes.object,
359 /**
360 * Callback fired when the page is changed.
361 *
362 * @param {React.MouseEvent<HTMLButtonElement> | null} event The event source of the callback.
363 * @param {number} page The page selected.
364 */
365 onPageChange: PropTypes.func.isRequired,
366 /**
367 * Callback fired when the number of rows per page is changed.
368 *
369 * @param {React.ChangeEvent<HTMLTextAreaElement | HTMLInputElement>} event The event source of the callback.
370 */
371 onRowsPerPageChange: PropTypes.func,
372 /**
373 * The zero-based index of the current page.
374 */
375 page: chainPropTypes(integerPropType.isRequired, function (props) {
376 var count = props.count,
377 page = props.page,
378 rowsPerPage = props.rowsPerPage;
379 if (count === -1) {
380 return null;
381 }
382 var newLastPage = Math.max(0, Math.ceil(count / rowsPerPage) - 1);
383 if (page < 0 || page > newLastPage) {
384 return new Error('MUI: The page prop of a TablePagination is out of range ' + "(0 to ".concat(newLastPage, ", but page is ").concat(page, ")."));
385 }
386 return null;
387 }),
388 /**
389 * The number of rows per page.
390 *
391 * Set -1 to display all the rows.
392 */
393 rowsPerPage: integerPropType.isRequired,
394 /**
395 * Customizes the options of the rows per page select field. If less than two options are
396 * available, no select field will be displayed.
397 * Use -1 for the value with a custom label to show all the rows.
398 * @default [10, 25, 50, 100]
399 */
400 rowsPerPageOptions: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.number, PropTypes.shape({
401 label: PropTypes.string.isRequired,
402 value: PropTypes.number.isRequired
403 })]).isRequired),
404 /**
405 * Props applied to the rows per page [`Select`](/material-ui/api/select/) element.
406 *
407 * This prop is an alias for `slotProps.select` and will be overriden by it if both are used.
408 * @deprecated Use `slotProps.select` instead.
409 *
410 * @default {}
411 */
412 SelectProps: PropTypes.object,
413 /**
414 * If `true`, show the first-page button.
415 * @default false
416 */
417 showFirstButton: PropTypes.bool,
418 /**
419 * If `true`, show the last-page button.
420 * @default false
421 */
422 showLastButton: PropTypes.bool,
423 /**
424 * The props used for each slot inside the TablePagination.
425 * @default {}
426 */
427 slotProps: PropTypes.shape({
428 actions: PropTypes.shape({
429 firstButton: PropTypes.object,
430 firstButtonIcon: PropTypes.object,
431 lastButton: PropTypes.object,
432 lastButtonIcon: PropTypes.object,
433 nextButton: PropTypes.object,
434 nextButtonIcon: PropTypes.object,
435 previousButton: PropTypes.object,
436 previousButtonIcon: PropTypes.object
437 }),
438 select: PropTypes.object
439 }),
440 /**
441 * The components used for each slot inside the TablePagination.
442 * Either a string to use a HTML element or a component.
443 * @default {}
444 */
445 slots: PropTypes.shape({
446 actions: PropTypes.shape({
447 firstButton: PropTypes.elementType,
448 firstButtonIcon: PropTypes.elementType,
449 lastButton: PropTypes.elementType,
450 lastButtonIcon: PropTypes.elementType,
451 nextButton: PropTypes.elementType,
452 nextButtonIcon: PropTypes.elementType,
453 previousButton: PropTypes.elementType,
454 previousButtonIcon: PropTypes.elementType
455 })
456 }),
457 /**
458 * The system prop that allows defining system overrides as well as additional CSS styles.
459 */
460 sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
461} : void 0;
462export default TablePagination;
\No newline at end of file