1 | 'use client';
|
2 |
|
3 | import * as React from 'react';
|
4 | import PropTypes from 'prop-types';
|
5 | import clsx from 'clsx';
|
6 | import composeClasses from '@mui/utils/composeClasses';
|
7 | import integerPropType from '@mui/utils/integerPropType';
|
8 | import { getPaginationUtilityClass } from "./paginationClasses.js";
|
9 | import usePagination from "../usePagination/index.js";
|
10 | import PaginationItem from "../PaginationItem/index.js";
|
11 | import { styled } from "../zero-styled/index.js";
|
12 | import { useDefaultProps } from "../DefaultPropsProvider/index.js";
|
13 | import { jsx as _jsx } from "react/jsx-runtime";
|
14 | const 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 | };
|
25 | const 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 | })({});
|
35 | const 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 | });
|
47 | function defaultGetAriaLabel(type, page, selected) {
|
48 | if (type === 'page') {
|
49 | return `${selected ? '' : 'Go to '}page ${page}`;
|
50 | }
|
51 | return `Go to ${type} page`;
|
52 | }
|
53 | const Pagination = 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 => _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 _jsx(PaginationRoot, {
|
107 | "aria-label": "pagination navigation",
|
108 | className: clsx(classes.root, className),
|
109 | ownerState: ownerState,
|
110 | ref: ref,
|
111 | ...other,
|
112 | children: _jsx(PaginationUl, {
|
113 | className: classes.ul,
|
114 | ownerState: ownerState,
|
115 | children: items.map((item, index) => _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 |
|
130 |
|
131 | process.env.NODE_ENV !== "production" ? Pagination.propTypes = {
|
132 |
|
133 |
|
134 |
|
135 |
|
136 | |
137 |
|
138 |
|
139 |
|
140 | boundaryCount: integerPropType,
|
141 | |
142 |
|
143 |
|
144 | classes: PropTypes.object,
|
145 | |
146 |
|
147 |
|
148 | className: PropTypes.string,
|
149 | |
150 |
|
151 |
|
152 |
|
153 |
|
154 |
|
155 | color: PropTypes .oneOfType([PropTypes.oneOf(['primary', 'secondary', 'standard']), PropTypes.string]),
|
156 | |
157 |
|
158 |
|
159 |
|
160 | count: integerPropType,
|
161 | |
162 |
|
163 |
|
164 |
|
165 | defaultPage: integerPropType,
|
166 | |
167 |
|
168 |
|
169 |
|
170 | disabled: PropTypes.bool,
|
171 | |
172 |
|
173 |
|
174 |
|
175 |
|
176 |
|
177 |
|
178 |
|
179 |
|
180 |
|
181 | getItemAriaLabel: PropTypes.func,
|
182 | |
183 |
|
184 |
|
185 |
|
186 | hideNextButton: PropTypes.bool,
|
187 | |
188 |
|
189 |
|
190 |
|
191 | hidePrevButton: PropTypes.bool,
|
192 | |
193 |
|
194 |
|
195 |
|
196 |
|
197 |
|
198 | onChange: PropTypes.func,
|
199 | |
200 |
|
201 |
|
202 | page: integerPropType,
|
203 | |
204 |
|
205 |
|
206 |
|
207 |
|
208 |
|
209 | renderItem: PropTypes.func,
|
210 | |
211 |
|
212 |
|
213 |
|
214 | shape: PropTypes.oneOf(['circular', 'rounded']),
|
215 | |
216 |
|
217 |
|
218 |
|
219 | showFirstButton: PropTypes.bool,
|
220 | |
221 |
|
222 |
|
223 |
|
224 | showLastButton: PropTypes.bool,
|
225 | |
226 |
|
227 |
|
228 |
|
229 | siblingCount: integerPropType,
|
230 | |
231 |
|
232 |
|
233 |
|
234 | size: PropTypes .oneOfType([PropTypes.oneOf(['small', 'medium', 'large']), PropTypes.string]),
|
235 | |
236 |
|
237 |
|
238 | sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
|
239 | |
240 |
|
241 |
|
242 |
|
243 | variant: PropTypes .oneOfType([PropTypes.oneOf(['outlined', 'text']), PropTypes.string])
|
244 | } : void 0;
|
245 | export default Pagination; |
\ | No newline at end of file |