1 | import _extends from "@babel/runtime/helpers/esm/extends";
|
2 | import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
3 | import * as React from 'react';
|
4 | import PropTypes from 'prop-types';
|
5 | import { unstable_useId as useId, chainPropTypes, integerPropType } from '@mui/utils';
|
6 | import { useSlotProps } from '../utils';
|
7 | import composeClasses from '../composeClasses';
|
8 | import isHostComponent from '../utils/isHostComponent';
|
9 | import TablePaginationActions from './TablePaginationActions';
|
10 | import { getTablePaginationUtilityClass } from './tablePaginationClasses';
|
11 | import { useClassNamesOverride } from '../utils/ClassNameConfigurator';
|
12 | import { jsx as _jsx } from "react/jsx-runtime";
|
13 | import { createElement as _createElement } from "react";
|
14 | import { jsxs as _jsxs } from "react/jsx-runtime";
|
15 | function defaultLabelDisplayedRows(_ref) {
|
16 | var from = _ref.from,
|
17 | to = _ref.to,
|
18 | count = _ref.count;
|
19 | return "".concat(from, "\u2013").concat(to, " of ").concat(count !== -1 ? count : "more than ".concat(to));
|
20 | }
|
21 | function defaultGetAriaLabel(type) {
|
22 | return "Go to ".concat(type, " page");
|
23 | }
|
24 | var useUtilityClasses = function useUtilityClasses() {
|
25 | var slots = {
|
26 | root: ['root'],
|
27 | toolbar: ['toolbar'],
|
28 | spacer: ['spacer'],
|
29 | selectLabel: ['selectLabel'],
|
30 | select: ['select'],
|
31 | input: ['input'],
|
32 | selectIcon: ['selectIcon'],
|
33 | menuItem: ['menuItem'],
|
34 | displayedRows: ['displayedRows'],
|
35 | actions: ['actions']
|
36 | };
|
37 | return composeClasses(slots, useClassNamesOverride(getTablePaginationUtilityClass));
|
38 | };
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 | var TablePagination = React.forwardRef(function TablePagination(props, forwardedRef) {
|
52 | var _slots$root, _slots$select, _slots$actions, _slots$menuItem, _slots$selectLabel, _slots$displayedRows, _slots$toolbar, _slots$spacer;
|
53 | var colSpanProp = props.colSpan,
|
54 | count = props.count,
|
55 | _props$getItemAriaLab = props.getItemAriaLabel,
|
56 | getItemAriaLabel = _props$getItemAriaLab === void 0 ? defaultGetAriaLabel : _props$getItemAriaLab,
|
57 | _props$labelDisplayed = props.labelDisplayedRows,
|
58 | labelDisplayedRows = _props$labelDisplayed === void 0 ? defaultLabelDisplayedRows : _props$labelDisplayed,
|
59 | labelIdProp = props.labelId,
|
60 | _props$labelRowsPerPa = props.labelRowsPerPage,
|
61 | labelRowsPerPage = _props$labelRowsPerPa === void 0 ? 'Rows per page:' : _props$labelRowsPerPa,
|
62 | onPageChange = props.onPageChange,
|
63 | onRowsPerPageChange = props.onRowsPerPageChange,
|
64 | page = props.page,
|
65 | rowsPerPage = props.rowsPerPage,
|
66 | _props$rowsPerPageOpt = props.rowsPerPageOptions,
|
67 | rowsPerPageOptions = _props$rowsPerPageOpt === void 0 ? [10, 25, 50, 100] : _props$rowsPerPageOpt,
|
68 | selectIdProp = props.selectId,
|
69 | _props$slotProps = props.slotProps,
|
70 | slotProps = _props$slotProps === void 0 ? {} : _props$slotProps,
|
71 | _props$slots = props.slots,
|
72 | slots = _props$slots === void 0 ? {} : _props$slots,
|
73 | other = _objectWithoutProperties(props, ["colSpan", "count", "getItemAriaLabel", "labelDisplayedRows", "labelId", "labelRowsPerPage", "onPageChange", "onRowsPerPageChange", "page", "rowsPerPage", "rowsPerPageOptions", "selectId", "slotProps", "slots"]);
|
74 | var ownerState = props;
|
75 | var classes = useUtilityClasses();
|
76 | var colSpan;
|
77 | var Root = (_slots$root = slots.root) != null ? _slots$root : 'td';
|
78 | if (Root === 'td' || !isHostComponent(Root)) {
|
79 | colSpan = colSpanProp || 1000;
|
80 | }
|
81 |
|
82 | var getLabelDisplayedRowsTo = function getLabelDisplayedRowsTo() {
|
83 | if (count === -1) {
|
84 | return (page + 1) * rowsPerPage;
|
85 | }
|
86 | return rowsPerPage === -1 ? count : Math.min(count, (page + 1) * rowsPerPage);
|
87 | };
|
88 | var selectId = useId(selectIdProp);
|
89 | var labelId = useId(labelIdProp);
|
90 | var rootProps = useSlotProps({
|
91 | elementType: Root,
|
92 | externalSlotProps: slotProps.root,
|
93 | externalForwardedProps: other,
|
94 | additionalProps: {
|
95 | colSpan: colSpan,
|
96 | ref: forwardedRef
|
97 | },
|
98 | ownerState: ownerState,
|
99 | className: classes.root
|
100 | });
|
101 | var Select = (_slots$select = slots.select) != null ? _slots$select : 'select';
|
102 | var selectProps = useSlotProps({
|
103 | elementType: Select,
|
104 | externalSlotProps: slotProps.select,
|
105 | additionalProps: {
|
106 | value: rowsPerPage,
|
107 | id: selectId,
|
108 | onChange: function onChange(event) {
|
109 | return onRowsPerPageChange && onRowsPerPageChange(event);
|
110 | },
|
111 | 'aria-label': rowsPerPage.toString(),
|
112 | 'aria-labelledby': [labelId, selectId].filter(Boolean).join(' ') || undefined
|
113 | },
|
114 | ownerState: ownerState,
|
115 | className: classes.select
|
116 | });
|
117 | var Actions = (_slots$actions = slots.actions) != null ? _slots$actions : TablePaginationActions;
|
118 | var actionsProps = useSlotProps({
|
119 | elementType: Actions,
|
120 | externalSlotProps: slotProps.actions,
|
121 | additionalProps: {
|
122 | page: page,
|
123 | rowsPerPage: rowsPerPage,
|
124 | count: count,
|
125 | onPageChange: onPageChange,
|
126 | getItemAriaLabel: getItemAriaLabel
|
127 | },
|
128 | ownerState: ownerState,
|
129 | className: classes.actions
|
130 | });
|
131 | var MenuItem = (_slots$menuItem = slots.menuItem) != null ? _slots$menuItem : 'option';
|
132 | var menuItemProps = useSlotProps({
|
133 | elementType: MenuItem,
|
134 | externalSlotProps: slotProps.menuItem,
|
135 | additionalProps: {
|
136 | value: undefined
|
137 | },
|
138 | ownerState: ownerState,
|
139 | className: classes.menuItem
|
140 | });
|
141 | var SelectLabel = (_slots$selectLabel = slots.selectLabel) != null ? _slots$selectLabel : 'p';
|
142 | var selectLabelProps = useSlotProps({
|
143 | elementType: SelectLabel,
|
144 | externalSlotProps: slotProps.selectLabel,
|
145 | additionalProps: {
|
146 | id: labelId
|
147 | },
|
148 | ownerState: ownerState,
|
149 | className: classes.selectLabel
|
150 | });
|
151 | var DisplayedRows = (_slots$displayedRows = slots.displayedRows) != null ? _slots$displayedRows : 'p';
|
152 | var displayedRowsProps = useSlotProps({
|
153 | elementType: DisplayedRows,
|
154 | externalSlotProps: slotProps.displayedRows,
|
155 | ownerState: ownerState,
|
156 | className: classes.displayedRows
|
157 | });
|
158 | var Toolbar = (_slots$toolbar = slots.toolbar) != null ? _slots$toolbar : 'div';
|
159 | var toolbarProps = useSlotProps({
|
160 | elementType: Toolbar,
|
161 | externalSlotProps: slotProps.toolbar,
|
162 | ownerState: ownerState,
|
163 | className: classes.toolbar
|
164 | });
|
165 | var Spacer = (_slots$spacer = slots.spacer) != null ? _slots$spacer : 'div';
|
166 | var spacerProps = useSlotProps({
|
167 | elementType: Spacer,
|
168 | externalSlotProps: slotProps.spacer,
|
169 | ownerState: ownerState,
|
170 | className: classes.spacer
|
171 | });
|
172 | return _jsx(Root, _extends({}, rootProps, {
|
173 | children: _jsxs(Toolbar, _extends({}, toolbarProps, {
|
174 | children: [_jsx(Spacer, _extends({}, spacerProps)), rowsPerPageOptions.length > 1 && _jsx(SelectLabel, _extends({}, selectLabelProps, {
|
175 | children: labelRowsPerPage
|
176 | })), rowsPerPageOptions.length > 1 && _jsx(Select, _extends({}, selectProps, {
|
177 | children: rowsPerPageOptions.map(function (rowsPerPageOption) {
|
178 | return _createElement(MenuItem, _extends({}, menuItemProps, {
|
179 | key: typeof rowsPerPageOption !== 'number' && rowsPerPageOption.label ? rowsPerPageOption.label : rowsPerPageOption,
|
180 | value: typeof rowsPerPageOption !== 'number' && rowsPerPageOption.value ? rowsPerPageOption.value : rowsPerPageOption
|
181 | }), typeof rowsPerPageOption !== 'number' && rowsPerPageOption.label ? rowsPerPageOption.label : rowsPerPageOption);
|
182 | })
|
183 | })), _jsx(DisplayedRows, _extends({}, displayedRowsProps, {
|
184 | children: labelDisplayedRows({
|
185 | from: count === 0 ? 0 : page * rowsPerPage + 1,
|
186 | to: getLabelDisplayedRowsTo(),
|
187 | count: count === -1 ? -1 : count,
|
188 | page: page
|
189 | })
|
190 | })), _jsx(Actions, _extends({}, actionsProps))]
|
191 | }))
|
192 | }));
|
193 | });
|
194 | process.env.NODE_ENV !== "production" ? TablePagination.propTypes = {
|
195 |
|
196 |
|
197 |
|
198 |
|
199 | |
200 |
|
201 |
|
202 | colSpan: PropTypes.number,
|
203 | |
204 |
|
205 |
|
206 |
|
207 |
|
208 | count: PropTypes.number.isRequired,
|
209 | |
210 |
|
211 |
|
212 |
|
213 |
|
214 |
|
215 |
|
216 |
|
217 |
|
218 |
|
219 |
|
220 | getItemAriaLabel: PropTypes.func,
|
221 | |
222 |
|
223 |
|
224 |
|
225 |
|
226 |
|
227 |
|
228 |
|
229 |
|
230 | labelDisplayedRows: PropTypes.func,
|
231 | |
232 |
|
233 |
|
234 | labelId: PropTypes.string,
|
235 | |
236 |
|
237 |
|
238 |
|
239 |
|
240 |
|
241 | labelRowsPerPage: PropTypes.node,
|
242 | |
243 |
|
244 |
|
245 |
|
246 |
|
247 |
|
248 | onPageChange: PropTypes.func.isRequired,
|
249 | |
250 |
|
251 |
|
252 |
|
253 |
|
254 | onRowsPerPageChange: PropTypes.func,
|
255 | |
256 |
|
257 |
|
258 | page: chainPropTypes(integerPropType.isRequired, function (props) {
|
259 | var count = props.count,
|
260 | page = props.page,
|
261 | rowsPerPage = props.rowsPerPage;
|
262 | if (count === -1) {
|
263 | return null;
|
264 | }
|
265 | var newLastPage = Math.max(0, Math.ceil(count / rowsPerPage) - 1);
|
266 | if (page < 0 || page > newLastPage) {
|
267 | return new Error('MUI: The page prop of a TablePagination is out of range ' + "(0 to ".concat(newLastPage, ", but page is ").concat(page, ")."));
|
268 | }
|
269 | return null;
|
270 | }),
|
271 | |
272 |
|
273 |
|
274 |
|
275 |
|
276 | rowsPerPage: integerPropType.isRequired,
|
277 | |
278 |
|
279 |
|
280 |
|
281 |
|
282 |
|
283 | rowsPerPageOptions: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.number, PropTypes.shape({
|
284 | label: PropTypes.string.isRequired,
|
285 | value: PropTypes.number.isRequired
|
286 | })]).isRequired),
|
287 | |
288 |
|
289 |
|
290 | selectId: PropTypes.string,
|
291 | |
292 |
|
293 |
|
294 |
|
295 | slotProps: PropTypes .shape({
|
296 | actions: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
297 | displayedRows: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
298 | menuItem: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
299 | root: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
300 | select: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
301 | selectLabel: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
302 | spacer: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
303 | toolbar: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
|
304 | }),
|
305 | |
306 |
|
307 |
|
308 |
|
309 |
|
310 | slots: PropTypes.shape({
|
311 | actions: PropTypes.elementType,
|
312 | displayedRows: PropTypes.elementType,
|
313 | menuItem: PropTypes.elementType,
|
314 | root: PropTypes.elementType,
|
315 | select: PropTypes.elementType,
|
316 | selectLabel: PropTypes.elementType,
|
317 | spacer: PropTypes.elementType,
|
318 | toolbar: PropTypes.elementType
|
319 | })
|
320 | } : void 0;
|
321 | export default TablePagination; |
\ | No newline at end of file |