1 | "use strict";
|
2 |
|
3 | var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
|
4 |
|
5 | var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
6 |
|
7 | Object.defineProperty(exports, "__esModule", {
|
8 | value: true
|
9 | });
|
10 | exports.default = exports.styles = void 0;
|
11 |
|
12 | var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
13 |
|
14 | var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
15 |
|
16 | var React = _interopRequireWildcard(require("react"));
|
17 |
|
18 | var _propTypes = _interopRequireDefault(require("prop-types"));
|
19 |
|
20 | var _utils = require("@material-ui/utils");
|
21 |
|
22 | var _clsx = _interopRequireDefault(require("clsx"));
|
23 |
|
24 | var _deprecatedPropType = _interopRequireDefault(require("../utils/deprecatedPropType"));
|
25 |
|
26 | var _withStyles = _interopRequireDefault(require("../styles/withStyles"));
|
27 |
|
28 | var _InputBase = _interopRequireDefault(require("../InputBase"));
|
29 |
|
30 | var _MenuItem = _interopRequireDefault(require("../MenuItem"));
|
31 |
|
32 | var _Select = _interopRequireDefault(require("../Select"));
|
33 |
|
34 | var _TableCell = _interopRequireDefault(require("../TableCell"));
|
35 |
|
36 | var _Toolbar = _interopRequireDefault(require("../Toolbar"));
|
37 |
|
38 | var _Typography = _interopRequireDefault(require("../Typography"));
|
39 |
|
40 | var _TablePaginationActions = _interopRequireDefault(require("./TablePaginationActions"));
|
41 |
|
42 | var _unstable_useId = _interopRequireDefault(require("../utils/unstable_useId"));
|
43 |
|
44 | var styles = function styles(theme) {
|
45 | return {
|
46 |
|
47 | root: {
|
48 | color: theme.palette.text.primary,
|
49 | fontSize: theme.typography.pxToRem(14),
|
50 | overflow: 'auto',
|
51 |
|
52 | '&:last-child': {
|
53 | padding: 0
|
54 | }
|
55 | },
|
56 |
|
57 |
|
58 | toolbar: {
|
59 | minHeight: 52,
|
60 | paddingRight: 2
|
61 | },
|
62 |
|
63 |
|
64 | spacer: {
|
65 | flex: '1 1 100%'
|
66 | },
|
67 |
|
68 |
|
69 | caption: {
|
70 | flexShrink: 0
|
71 | },
|
72 |
|
73 |
|
74 |
|
75 | selectRoot: {
|
76 | marginRight: 32,
|
77 | marginLeft: 8
|
78 | },
|
79 |
|
80 |
|
81 | select: {
|
82 | paddingLeft: 8,
|
83 | paddingRight: 24,
|
84 | textAlign: 'right',
|
85 | textAlignLast: 'right'
|
86 |
|
87 | },
|
88 |
|
89 |
|
90 |
|
91 | selectIcon: {},
|
92 |
|
93 |
|
94 | input: {
|
95 | color: 'inherit',
|
96 | fontSize: 'inherit',
|
97 | flexShrink: 0
|
98 | },
|
99 |
|
100 |
|
101 | menuItem: {},
|
102 |
|
103 |
|
104 | actions: {
|
105 | flexShrink: 0,
|
106 | marginLeft: 20
|
107 | }
|
108 | };
|
109 | };
|
110 |
|
111 | exports.styles = styles;
|
112 |
|
113 | var defaultLabelDisplayedRows = function defaultLabelDisplayedRows(_ref) {
|
114 | var from = _ref.from,
|
115 | to = _ref.to,
|
116 | count = _ref.count;
|
117 | return "".concat(from, "-").concat(to, " of ").concat(count !== -1 ? count : "more than ".concat(to));
|
118 | };
|
119 |
|
120 | var defaultRowsPerPageOptions = [10, 25, 50, 100];
|
121 |
|
122 |
|
123 |
|
124 |
|
125 | var TablePagination = React.forwardRef(function TablePagination(props, ref) {
|
126 | var _props$ActionsCompone = props.ActionsComponent,
|
127 | ActionsComponent = _props$ActionsCompone === void 0 ? _TablePaginationActions.default : _props$ActionsCompone,
|
128 | backIconButtonProps = props.backIconButtonProps,
|
129 | _props$backIconButton = props.backIconButtonText,
|
130 | backIconButtonText = _props$backIconButton === void 0 ? 'Previous page' : _props$backIconButton,
|
131 | classes = props.classes,
|
132 | className = props.className,
|
133 | colSpanProp = props.colSpan,
|
134 | _props$component = props.component,
|
135 | Component = _props$component === void 0 ? _TableCell.default : _props$component,
|
136 | count = props.count,
|
137 | _props$labelDisplayed = props.labelDisplayedRows,
|
138 | labelDisplayedRows = _props$labelDisplayed === void 0 ? defaultLabelDisplayedRows : _props$labelDisplayed,
|
139 | _props$labelRowsPerPa = props.labelRowsPerPage,
|
140 | labelRowsPerPage = _props$labelRowsPerPa === void 0 ? 'Rows per page:' : _props$labelRowsPerPa,
|
141 | nextIconButtonProps = props.nextIconButtonProps,
|
142 | _props$nextIconButton = props.nextIconButtonText,
|
143 | nextIconButtonText = _props$nextIconButton === void 0 ? 'Next page' : _props$nextIconButton,
|
144 | onChangePage = props.onChangePage,
|
145 | onPageChange = props.onPageChange,
|
146 | onChangeRowsPerPageProp = props.onChangeRowsPerPage,
|
147 | onRowsPerPageChangeProp = props.onRowsPerPageChange,
|
148 | page = props.page,
|
149 | rowsPerPage = props.rowsPerPage,
|
150 | _props$rowsPerPageOpt = props.rowsPerPageOptions,
|
151 | rowsPerPageOptions = _props$rowsPerPageOpt === void 0 ? defaultRowsPerPageOptions : _props$rowsPerPageOpt,
|
152 | _props$SelectProps = props.SelectProps,
|
153 | SelectProps = _props$SelectProps === void 0 ? {} : _props$SelectProps,
|
154 | other = (0, _objectWithoutProperties2.default)(props, ["ActionsComponent", "backIconButtonProps", "backIconButtonText", "classes", "className", "colSpan", "component", "count", "labelDisplayedRows", "labelRowsPerPage", "nextIconButtonProps", "nextIconButtonText", "onChangePage", "onPageChange", "onChangeRowsPerPage", "onRowsPerPageChange", "page", "rowsPerPage", "rowsPerPageOptions", "SelectProps"]);
|
155 | var onChangeRowsPerPage = onChangeRowsPerPageProp || onRowsPerPageChangeProp;
|
156 | var colSpan;
|
157 |
|
158 | if (Component === _TableCell.default || Component === 'td') {
|
159 | colSpan = colSpanProp || 1000;
|
160 | }
|
161 |
|
162 | var selectId = (0, _unstable_useId.default)();
|
163 | var labelId = (0, _unstable_useId.default)();
|
164 | var MenuItemComponent = SelectProps.native ? 'option' : _MenuItem.default;
|
165 | return React.createElement(Component, (0, _extends2.default)({
|
166 | className: (0, _clsx.default)(classes.root, className),
|
167 | colSpan: colSpan,
|
168 | ref: ref
|
169 | }, other), React.createElement(_Toolbar.default, {
|
170 | className: classes.toolbar
|
171 | }, React.createElement("div", {
|
172 | className: classes.spacer
|
173 | }), rowsPerPageOptions.length > 1 && React.createElement(_Typography.default, {
|
174 | color: "inherit",
|
175 | variant: "body2",
|
176 | className: classes.caption,
|
177 | id: labelId
|
178 | }, labelRowsPerPage), rowsPerPageOptions.length > 1 && React.createElement(_Select.default, (0, _extends2.default)({
|
179 | classes: {
|
180 | select: classes.select,
|
181 | icon: classes.selectIcon
|
182 | },
|
183 | input: React.createElement(_InputBase.default, {
|
184 | className: (0, _clsx.default)(classes.input, classes.selectRoot)
|
185 | }),
|
186 | value: rowsPerPage,
|
187 | onChange: onChangeRowsPerPage,
|
188 | id: selectId,
|
189 | labelId: labelId
|
190 | }, SelectProps), rowsPerPageOptions.map(function (rowsPerPageOption) {
|
191 | return React.createElement(MenuItemComponent, {
|
192 | className: classes.menuItem,
|
193 | key: rowsPerPageOption.value ? rowsPerPageOption.value : rowsPerPageOption,
|
194 | value: rowsPerPageOption.value ? rowsPerPageOption.value : rowsPerPageOption
|
195 | }, rowsPerPageOption.label ? rowsPerPageOption.label : rowsPerPageOption);
|
196 | })), React.createElement(_Typography.default, {
|
197 | color: "inherit",
|
198 | variant: "body2",
|
199 | className: classes.caption
|
200 | }, labelDisplayedRows({
|
201 | from: count === 0 ? 0 : page * rowsPerPage + 1,
|
202 | to: count !== -1 ? Math.min(count, (page + 1) * rowsPerPage) : (page + 1) * rowsPerPage,
|
203 | count: count === -1 ? -1 : count,
|
204 | page: page
|
205 | })), React.createElement(ActionsComponent, {
|
206 | className: classes.actions,
|
207 | backIconButtonProps: (0, _extends2.default)({
|
208 | title: backIconButtonText,
|
209 | 'aria-label': backIconButtonText
|
210 | }, backIconButtonProps),
|
211 | count: count,
|
212 | nextIconButtonProps: (0, _extends2.default)({
|
213 | title: nextIconButtonText,
|
214 | 'aria-label': nextIconButtonText
|
215 | }, nextIconButtonProps),
|
216 | onChangePage: onChangePage,
|
217 | onPageChange: onPageChange,
|
218 | page: page,
|
219 | rowsPerPage: rowsPerPage
|
220 | })));
|
221 | });
|
222 | process.env.NODE_ENV !== "production" ? TablePagination.propTypes = {
|
223 | |
224 |
|
225 |
|
226 |
|
227 | ActionsComponent: _propTypes.default.elementType,
|
228 |
|
229 | |
230 |
|
231 |
|
232 | backIconButtonProps: _propTypes.default.object,
|
233 |
|
234 | |
235 |
|
236 |
|
237 |
|
238 |
|
239 | backIconButtonText: _propTypes.default.string,
|
240 |
|
241 | |
242 |
|
243 |
|
244 |
|
245 | classes: _propTypes.default.object.isRequired,
|
246 |
|
247 | |
248 |
|
249 |
|
250 | className: _propTypes.default.string,
|
251 |
|
252 | |
253 |
|
254 |
|
255 | colSpan: _propTypes.default.number,
|
256 |
|
257 | |
258 |
|
259 |
|
260 |
|
261 | component: _propTypes.default
|
262 |
|
263 | .elementType,
|
264 |
|
265 | |
266 |
|
267 |
|
268 |
|
269 |
|
270 | count: _propTypes.default.number.isRequired,
|
271 |
|
272 | |
273 |
|
274 |
|
275 |
|
276 |
|
277 |
|
278 | labelDisplayedRows: _propTypes.default.func,
|
279 |
|
280 | |
281 |
|
282 |
|
283 |
|
284 |
|
285 | labelRowsPerPage: _propTypes.default.node,
|
286 |
|
287 | |
288 |
|
289 |
|
290 | nextIconButtonProps: _propTypes.default.object,
|
291 |
|
292 | |
293 |
|
294 |
|
295 |
|
296 |
|
297 | nextIconButtonText: _propTypes.default.string,
|
298 |
|
299 | |
300 |
|
301 |
|
302 |
|
303 |
|
304 |
|
305 |
|
306 | onChangePage: (0, _deprecatedPropType.default)(_propTypes.default.func, 'Use the `onPageChange` prop instead.'),
|
307 |
|
308 | |
309 |
|
310 |
|
311 |
|
312 |
|
313 |
|
314 | onChangeRowsPerPage: (0, _deprecatedPropType.default)(_propTypes.default.func, 'Use the `onRowsPerPageChange` prop instead.'),
|
315 |
|
316 | |
317 |
|
318 |
|
319 |
|
320 |
|
321 |
|
322 | onPageChange: _propTypes.default.func.isRequired,
|
323 |
|
324 | |
325 |
|
326 |
|
327 |
|
328 |
|
329 | onRowsPerPageChange: _propTypes.default.func,
|
330 |
|
331 | |
332 |
|
333 |
|
334 | page: (0, _utils.chainPropTypes)(_propTypes.default.number.isRequired, function (props) {
|
335 | var count = props.count,
|
336 | page = props.page,
|
337 | rowsPerPage = props.rowsPerPage;
|
338 |
|
339 | if (count === -1) {
|
340 | return null;
|
341 | }
|
342 |
|
343 | var newLastPage = Math.max(0, Math.ceil(count / rowsPerPage) - 1);
|
344 |
|
345 | if (page < 0 || page > newLastPage) {
|
346 | return new Error('Material-UI: The page prop of a TablePagination is out of range ' + "(0 to ".concat(newLastPage, ", but page is ").concat(page, ")."));
|
347 | }
|
348 |
|
349 | return null;
|
350 | }),
|
351 |
|
352 | |
353 |
|
354 |
|
355 | rowsPerPage: _propTypes.default.number.isRequired,
|
356 |
|
357 | |
358 |
|
359 |
|
360 |
|
361 | rowsPerPageOptions: _propTypes.default.array,
|
362 |
|
363 | |
364 |
|
365 |
|
366 | SelectProps: _propTypes.default.object
|
367 | } : void 0;
|
368 |
|
369 | var _default = (0, _withStyles.default)(styles, {
|
370 | name: 'MuiTablePagination'
|
371 | })(TablePagination);
|
372 |
|
373 | exports.default = _default; |
\ | No newline at end of file |