UNPKG

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