UNPKG

7.54 kBJavaScriptView Raw
1'use client';
2
3import * as React from 'react';
4import PropTypes from 'prop-types';
5import clsx from 'clsx';
6import composeClasses from '@mui/utils/composeClasses';
7import integerPropType from '@mui/utils/integerPropType';
8import { getPaginationUtilityClass } from "./paginationClasses.js";
9import usePagination from "../usePagination/index.js";
10import PaginationItem from "../PaginationItem/index.js";
11import { styled } from "../zero-styled/index.js";
12import { useDefaultProps } from "../DefaultPropsProvider/index.js";
13import { jsx as _jsx } from "react/jsx-runtime";
14const useUtilityClasses = ownerState => {
15 const {
16 classes,
17 variant
18 } = ownerState;
19 const slots = {
20 root: ['root', variant],
21 ul: ['ul']
22 };
23 return composeClasses(slots, getPaginationUtilityClass, classes);
24};
25const PaginationRoot = styled('nav', {
26 name: 'MuiPagination',
27 slot: 'Root',
28 overridesResolver: (props, styles) => {
29 const {
30 ownerState
31 } = props;
32 return [styles.root, styles[ownerState.variant]];
33 }
34})({});
35const PaginationUl = styled('ul', {
36 name: 'MuiPagination',
37 slot: 'Ul',
38 overridesResolver: (props, styles) => styles.ul
39})({
40 display: 'flex',
41 flexWrap: 'wrap',
42 alignItems: 'center',
43 padding: 0,
44 margin: 0,
45 listStyle: 'none'
46});
47function defaultGetAriaLabel(type, page, selected) {
48 if (type === 'page') {
49 return `${selected ? '' : 'Go to '}page ${page}`;
50 }
51 return `Go to ${type} page`;
52}
53const Pagination = /*#__PURE__*/React.forwardRef(function Pagination(inProps, ref) {
54 const props = useDefaultProps({
55 props: inProps,
56 name: 'MuiPagination'
57 });
58 const {
59 boundaryCount = 1,
60 className,
61 color = 'standard',
62 count = 1,
63 defaultPage = 1,
64 disabled = false,
65 getItemAriaLabel = defaultGetAriaLabel,
66 hideNextButton = false,
67 hidePrevButton = false,
68 onChange,
69 page,
70 renderItem = item => /*#__PURE__*/_jsx(PaginationItem, {
71 ...item
72 }),
73 shape = 'circular',
74 showFirstButton = false,
75 showLastButton = false,
76 siblingCount = 1,
77 size = 'medium',
78 variant = 'text',
79 ...other
80 } = props;
81 const {
82 items
83 } = usePagination({
84 ...props,
85 componentName: 'Pagination'
86 });
87 const ownerState = {
88 ...props,
89 boundaryCount,
90 color,
91 count,
92 defaultPage,
93 disabled,
94 getItemAriaLabel,
95 hideNextButton,
96 hidePrevButton,
97 renderItem,
98 shape,
99 showFirstButton,
100 showLastButton,
101 siblingCount,
102 size,
103 variant
104 };
105 const classes = useUtilityClasses(ownerState);
106 return /*#__PURE__*/_jsx(PaginationRoot, {
107 "aria-label": "pagination navigation",
108 className: clsx(classes.root, className),
109 ownerState: ownerState,
110 ref: ref,
111 ...other,
112 children: /*#__PURE__*/_jsx(PaginationUl, {
113 className: classes.ul,
114 ownerState: ownerState,
115 children: items.map((item, index) => /*#__PURE__*/_jsx("li", {
116 children: renderItem({
117 ...item,
118 color,
119 'aria-label': getItemAriaLabel(item.type, item.page, item.selected),
120 shape,
121 size,
122 variant
123 })
124 }, index))
125 })
126 });
127});
128
129// @default tags synced with default values from usePagination
130
131process.env.NODE_ENV !== "production" ? Pagination.propTypes /* remove-proptypes */ = {
132 // ┌────────────────────────────── Warning ──────────────────────────────┐
133 // │ These PropTypes are generated from the TypeScript type definitions. │
134 // │ To update them, edit the d.ts file and run `pnpm proptypes`. │
135 // └─────────────────────────────────────────────────────────────────────┘
136 /**
137 * Number of always visible pages at the beginning and end.
138 * @default 1
139 */
140 boundaryCount: integerPropType,
141 /**
142 * Override or extend the styles applied to the component.
143 */
144 classes: PropTypes.object,
145 /**
146 * @ignore
147 */
148 className: PropTypes.string,
149 /**
150 * The active color.
151 * It supports both default and custom theme colors, which can be added as shown in the
152 * [palette customization guide](https://mui.com/material-ui/customization/palette/#custom-colors).
153 * @default 'standard'
154 */
155 color: PropTypes /* @typescript-to-proptypes-ignore */.oneOfType([PropTypes.oneOf(['primary', 'secondary', 'standard']), PropTypes.string]),
156 /**
157 * The total number of pages.
158 * @default 1
159 */
160 count: integerPropType,
161 /**
162 * The page selected by default when the component is uncontrolled.
163 * @default 1
164 */
165 defaultPage: integerPropType,
166 /**
167 * If `true`, the component is disabled.
168 * @default false
169 */
170 disabled: PropTypes.bool,
171 /**
172 * Accepts a function which returns a string value that provides a user-friendly name for the current page.
173 * This is important for screen reader users.
174 *
175 * For localization purposes, you can use the provided [translations](https://mui.com/material-ui/guides/localization/).
176 * @param {string} type The link or button type to format ('page' | 'first' | 'last' | 'next' | 'previous' | 'start-ellipsis' | 'end-ellipsis'). Defaults to 'page'.
177 * @param {number | null} page The page number to format.
178 * @param {boolean} selected If true, the current page is selected.
179 * @returns {string}
180 */
181 getItemAriaLabel: PropTypes.func,
182 /**
183 * If `true`, hide the next-page button.
184 * @default false
185 */
186 hideNextButton: PropTypes.bool,
187 /**
188 * If `true`, hide the previous-page button.
189 * @default false
190 */
191 hidePrevButton: PropTypes.bool,
192 /**
193 * Callback fired when the page is changed.
194 *
195 * @param {React.ChangeEvent<unknown>} event The event source of the callback.
196 * @param {number} page The page selected.
197 */
198 onChange: PropTypes.func,
199 /**
200 * The current page. Unlike `TablePagination`, which starts numbering from `0`, this pagination starts from `1`.
201 */
202 page: integerPropType,
203 /**
204 * Render the item.
205 * @param {PaginationRenderItemParams} params The props to spread on a PaginationItem.
206 * @returns {ReactNode}
207 * @default (item) => <PaginationItem {...item} />
208 */
209 renderItem: PropTypes.func,
210 /**
211 * The shape of the pagination items.
212 * @default 'circular'
213 */
214 shape: PropTypes.oneOf(['circular', 'rounded']),
215 /**
216 * If `true`, show the first-page button.
217 * @default false
218 */
219 showFirstButton: PropTypes.bool,
220 /**
221 * If `true`, show the last-page button.
222 * @default false
223 */
224 showLastButton: PropTypes.bool,
225 /**
226 * Number of always visible pages before and after the current page.
227 * @default 1
228 */
229 siblingCount: integerPropType,
230 /**
231 * The size of the component.
232 * @default 'medium'
233 */
234 size: PropTypes /* @typescript-to-proptypes-ignore */.oneOfType([PropTypes.oneOf(['small', 'medium', 'large']), PropTypes.string]),
235 /**
236 * The system prop that allows defining system overrides as well as additional CSS styles.
237 */
238 sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
239 /**
240 * The variant to use.
241 * @default 'text'
242 */
243 variant: PropTypes /* @typescript-to-proptypes-ignore */.oneOfType([PropTypes.oneOf(['outlined', 'text']), PropTypes.string])
244} : void 0;
245export default Pagination;
\No newline at end of file