UNPKG

7.16 kBJavaScriptView Raw
1"use strict";
2
3var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
4
5var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
6
7Object.defineProperty(exports, "__esModule", {
8 value: true
9});
10exports.default = exports.styles = void 0;
11
12var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
13
14var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
15
16var React = _interopRequireWildcard(require("react"));
17
18var _propTypes = _interopRequireDefault(require("prop-types"));
19
20var _clsx = _interopRequireDefault(require("clsx"));
21
22var _styles = require("@material-ui/core/styles");
23
24var _usePagination2 = _interopRequireDefault(require("./usePagination"));
25
26var _PaginationItem = _interopRequireDefault(require("../PaginationItem"));
27
28var styles = {
29 /* Styles applied to the root element. */
30 root: {},
31
32 /* Styles applied to the ul element. */
33 ul: {
34 display: 'flex',
35 flexWrap: 'wrap',
36 alignItems: 'center',
37 padding: 0,
38 margin: 0,
39 listStyle: 'none'
40 }
41};
42exports.styles = styles;
43
44function defaultGetAriaLabel(type, page, selected) {
45 if (type === 'page') {
46 return "".concat(selected ? '' : 'Go to ', "page ").concat(page);
47 }
48
49 return "Go to ".concat(type, " page");
50}
51
52var Pagination = /*#__PURE__*/React.forwardRef(function Pagination(props, ref) {
53 var boundaryCount = props.boundaryCount,
54 classes = props.classes,
55 className = props.className,
56 _props$color = props.color,
57 color = _props$color === void 0 ? 'standard' : _props$color,
58 count = props.count,
59 defaultPage = props.defaultPage,
60 disabled = props.disabled,
61 _props$getItemAriaLab = props.getItemAriaLabel,
62 getItemAriaLabel = _props$getItemAriaLab === void 0 ? defaultGetAriaLabel : _props$getItemAriaLab,
63 hideNextButton = props.hideNextButton,
64 hidePrevButton = props.hidePrevButton,
65 onChange = props.onChange,
66 page = props.page,
67 _props$renderItem = props.renderItem,
68 renderItem = _props$renderItem === void 0 ? function (item) {
69 return /*#__PURE__*/React.createElement(_PaginationItem.default, item);
70 } : _props$renderItem,
71 _props$shape = props.shape,
72 shape = _props$shape === void 0 ? 'round' : _props$shape,
73 showFirstButton = props.showFirstButton,
74 showLastButton = props.showLastButton,
75 siblingCount = props.siblingCount,
76 _props$size = props.size,
77 size = _props$size === void 0 ? 'medium' : _props$size,
78 _props$variant = props.variant,
79 variant = _props$variant === void 0 ? 'text' : _props$variant,
80 other = (0, _objectWithoutProperties2.default)(props, ["boundaryCount", "classes", "className", "color", "count", "defaultPage", "disabled", "getItemAriaLabel", "hideNextButton", "hidePrevButton", "onChange", "page", "renderItem", "shape", "showFirstButton", "showLastButton", "siblingCount", "size", "variant"]);
81
82 var _usePagination = (0, _usePagination2.default)((0, _extends2.default)({}, props, {
83 componentName: 'Pagination'
84 })),
85 items = _usePagination.items;
86
87 return /*#__PURE__*/React.createElement("nav", (0, _extends2.default)({
88 "aria-label": "pagination navigation",
89 className: (0, _clsx.default)(classes.root, className),
90 ref: ref
91 }, other), /*#__PURE__*/React.createElement("ul", {
92 className: classes.ul
93 }, items.map(function (item, index) {
94 return /*#__PURE__*/React.createElement("li", {
95 key: index
96 }, renderItem((0, _extends2.default)({}, item, {
97 color: color,
98 'aria-label': getItemAriaLabel(item.type, item.page, item.selected),
99 shape: shape,
100 size: size,
101 variant: variant
102 })));
103 })));
104}); // @default tags synced with default values from usePagination
105
106process.env.NODE_ENV !== "production" ? Pagination.propTypes = {
107 // ----------------------------- Warning --------------------------------
108 // | These PropTypes are generated from the TypeScript type definitions |
109 // | To update them edit the d.ts file and run "yarn proptypes" |
110 // ----------------------------------------------------------------------
111
112 /**
113 * Number of always visible pages at the beginning and end.
114 * @default 1
115 */
116 boundaryCount: _propTypes.default.number,
117
118 /**
119 * Override or extend the styles applied to the component.
120 * See [CSS API](#css) below for more details.
121 */
122 classes: _propTypes.default.object,
123
124 /**
125 * @ignore
126 */
127 className: _propTypes.default.string,
128
129 /**
130 * The active color.
131 */
132 color: _propTypes.default.oneOf(['primary', 'secondary', 'standard']),
133
134 /**
135 * The total number of pages.
136 * @default 1
137 */
138 count: _propTypes.default.number,
139
140 /**
141 * The page selected by default when the component is uncontrolled.
142 * @default 1
143 */
144 defaultPage: _propTypes.default.number,
145
146 /**
147 * If `true`, the pagination component will be disabled.
148 * @default false
149 */
150 disabled: _propTypes.default.bool,
151
152 /**
153 * Accepts a function which returns a string value that provides a user-friendly name for the current page.
154 *
155 * For localization purposes, you can use the provided [translations](/guides/localization/).
156 *
157 * @param {string} type The link or button type to format ('page' | 'first' | 'last' | 'next' | 'previous'). Defaults to 'page'.
158 * @param {number} page The page number to format.
159 * @param {bool} selected If true, the current page is selected.
160 * @returns {string}
161 */
162 getItemAriaLabel: _propTypes.default.func,
163
164 /**
165 * If `true`, hide the next-page button.
166 * @default false
167 */
168 hideNextButton: _propTypes.default.bool,
169
170 /**
171 * If `true`, hide the previous-page button.
172 * @default false
173 */
174 hidePrevButton: _propTypes.default.bool,
175
176 /**
177 * Callback fired when the page is changed.
178 *
179 * @param {object} event The event source of the callback.
180 * @param {number} page The page selected.
181 */
182 onChange: _propTypes.default.func,
183
184 /**
185 * The current page.
186 */
187 page: _propTypes.default.number,
188
189 /**
190 * Render the item.
191 *
192 * @param {PaginationRenderItemParams} params The props to spread on a PaginationItem.
193 * @returns {ReactNode}
194 */
195 renderItem: _propTypes.default.func,
196
197 /**
198 * The shape of the pagination items.
199 */
200 shape: _propTypes.default.oneOf(['round', 'rounded']),
201
202 /**
203 * If `true`, show the first-page button.
204 * @default false
205 */
206 showFirstButton: _propTypes.default.bool,
207
208 /**
209 * If `true`, show the last-page button.
210 * @default false
211 */
212 showLastButton: _propTypes.default.bool,
213
214 /**
215 * Number of always visible pages before and after the current page.
216 * @default 1
217 */
218 siblingCount: _propTypes.default.number,
219
220 /**
221 * The size of the pagination component.
222 */
223 size: _propTypes.default.oneOf(['large', 'medium', 'small']),
224
225 /**
226 * The variant to use.
227 */
228 variant: _propTypes.default.oneOf(['outlined', 'text'])
229} : void 0;
230
231var _default = (0, _styles.withStyles)(styles, {
232 name: 'MuiPagination'
233})(Pagination);
234
235exports.default = _default;
\No newline at end of file