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