1 | import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
2 | import _extends from "@babel/runtime/helpers/esm/extends";
|
3 | import * as React from 'react';
|
4 | import PropTypes from 'prop-types';
|
5 | import clsx from 'clsx';
|
6 | import { alpha, useTheme, withStyles } from '@material-ui/core/styles';
|
7 | import ButtonBase from '@material-ui/core/ButtonBase';
|
8 | import FirstPageIcon from '../internal/svg-icons/FirstPage';
|
9 | import LastPageIcon from '../internal/svg-icons/LastPage';
|
10 | import NavigateBeforeIcon from '../internal/svg-icons/NavigateBefore';
|
11 | import NavigateNextIcon from '../internal/svg-icons/NavigateNext';
|
12 | import { capitalize } from '@material-ui/core/utils';
|
13 | export const styles = theme => ({
|
14 |
|
15 | root: _extends({}, theme.typography.body2, {
|
16 | borderRadius: 32 / 2,
|
17 | textAlign: 'center',
|
18 | boxSizing: 'border-box',
|
19 | minWidth: 32,
|
20 | height: 32,
|
21 | padding: '0 6px',
|
22 | margin: '0 3px',
|
23 | color: theme.palette.text.primary
|
24 | }),
|
25 |
|
26 |
|
27 | page: {
|
28 | transition: theme.transitions.create(['color', 'background-color'], {
|
29 | duration: theme.transitions.duration.short
|
30 | }),
|
31 | '&:hover': {
|
32 | backgroundColor: theme.palette.action.hover,
|
33 |
|
34 | '@media (hover: none)': {
|
35 | backgroundColor: 'transparent'
|
36 | }
|
37 | },
|
38 | '&$focusVisible': {
|
39 | backgroundColor: theme.palette.action.focus
|
40 | },
|
41 | '&$selected': {
|
42 | backgroundColor: theme.palette.action.selected,
|
43 | '&:hover, &$focusVisible': {
|
44 | backgroundColor: alpha(theme.palette.action.selected, theme.palette.action.selectedOpacity + theme.palette.action.hoverOpacity),
|
45 |
|
46 | '@media (hover: none)': {
|
47 | backgroundColor: theme.palette.action.selected
|
48 | }
|
49 | },
|
50 | '&$disabled': {
|
51 | opacity: 1,
|
52 | color: theme.palette.action.disabled,
|
53 | backgroundColor: theme.palette.action.selected
|
54 | }
|
55 | },
|
56 | '&$disabled': {
|
57 | opacity: theme.palette.action.disabledOpacity
|
58 | }
|
59 | },
|
60 |
|
61 |
|
62 | sizeSmall: {
|
63 | minWidth: 26,
|
64 | height: 26,
|
65 | borderRadius: 26 / 2,
|
66 | margin: '0 1px',
|
67 | padding: '0 4px',
|
68 | '& $icon': {
|
69 | fontSize: theme.typography.pxToRem(18)
|
70 | }
|
71 | },
|
72 |
|
73 |
|
74 | sizeLarge: {
|
75 | minWidth: 40,
|
76 | height: 40,
|
77 | borderRadius: 40 / 2,
|
78 | padding: '0 10px',
|
79 | fontSize: theme.typography.pxToRem(15),
|
80 | '& $icon': {
|
81 | fontSize: theme.typography.pxToRem(22)
|
82 | }
|
83 | },
|
84 |
|
85 |
|
86 | textPrimary: {
|
87 | '&$selected': {
|
88 | color: theme.palette.primary.contrastText,
|
89 | backgroundColor: theme.palette.primary.main,
|
90 | '&:hover, &$focusVisible': {
|
91 | backgroundColor: theme.palette.primary.dark,
|
92 |
|
93 | '@media (hover: none)': {
|
94 | backgroundColor: theme.palette.primary.main
|
95 | }
|
96 | },
|
97 | '&$disabled': {
|
98 | color: theme.palette.action.disabled
|
99 | }
|
100 | }
|
101 | },
|
102 |
|
103 |
|
104 | textSecondary: {
|
105 | '&$selected': {
|
106 | color: theme.palette.secondary.contrastText,
|
107 | backgroundColor: theme.palette.secondary.main,
|
108 | '&:hover, &$focusVisible': {
|
109 | backgroundColor: theme.palette.secondary.dark,
|
110 |
|
111 | '@media (hover: none)': {
|
112 | backgroundColor: theme.palette.secondary.main
|
113 | }
|
114 | },
|
115 | '&$disabled': {
|
116 | color: theme.palette.action.disabled
|
117 | }
|
118 | }
|
119 | },
|
120 |
|
121 |
|
122 | outlined: {
|
123 | border: `1px solid ${theme.palette.type === 'light' ? 'rgba(0, 0, 0, 0.23)' : 'rgba(255, 255, 255, 0.23)'}`,
|
124 | '&$selected': {
|
125 | '&$disabled': {
|
126 | border: `1px solid ${theme.palette.action.disabledBackground}`
|
127 | }
|
128 | }
|
129 | },
|
130 |
|
131 |
|
132 | outlinedPrimary: {
|
133 | '&$selected': {
|
134 | color: theme.palette.primary.main,
|
135 | border: `1px solid ${alpha(theme.palette.primary.main, 0.5)}`,
|
136 | backgroundColor: alpha(theme.palette.primary.main, theme.palette.action.activatedOpacity),
|
137 | '&:hover, &$focusVisible': {
|
138 | backgroundColor: alpha(theme.palette.primary.main, theme.palette.action.activatedOpacity + theme.palette.action.hoverOpacity),
|
139 |
|
140 | '@media (hover: none)': {
|
141 | backgroundColor: 'transparent'
|
142 | }
|
143 | },
|
144 | '&$disabled': {
|
145 | color: theme.palette.action.disabled
|
146 | }
|
147 | }
|
148 | },
|
149 |
|
150 |
|
151 | outlinedSecondary: {
|
152 | '&$selected': {
|
153 | color: theme.palette.secondary.main,
|
154 | border: `1px solid ${alpha(theme.palette.secondary.main, 0.5)}`,
|
155 | backgroundColor: alpha(theme.palette.secondary.main, theme.palette.action.activatedOpacity),
|
156 | '&:hover, &$focusVisible': {
|
157 | backgroundColor: alpha(theme.palette.secondary.main, theme.palette.action.activatedOpacity + theme.palette.action.hoverOpacity),
|
158 |
|
159 | '@media (hover: none)': {
|
160 | backgroundColor: 'transparent'
|
161 | }
|
162 | },
|
163 | '&$disabled': {
|
164 | color: theme.palette.action.disabled
|
165 | }
|
166 | }
|
167 | },
|
168 |
|
169 |
|
170 | rounded: {
|
171 | borderRadius: theme.shape.borderRadius
|
172 | },
|
173 |
|
174 |
|
175 | ellipsis: {
|
176 | height: 'auto',
|
177 | '&$disabled': {
|
178 | opacity: theme.palette.action.disabledOpacity
|
179 | }
|
180 | },
|
181 |
|
182 |
|
183 | focusVisible: {},
|
184 |
|
185 |
|
186 | disabled: {},
|
187 |
|
188 |
|
189 | selected: {},
|
190 |
|
191 |
|
192 | icon: {
|
193 | fontSize: theme.typography.pxToRem(20),
|
194 | margin: '0 -8px'
|
195 | }
|
196 | });
|
197 | const PaginationItem = React.forwardRef(function PaginationItem(props, ref) {
|
198 | const {
|
199 | classes,
|
200 | className,
|
201 | color = 'standard',
|
202 | component,
|
203 | disabled = false,
|
204 | page,
|
205 | selected = false,
|
206 | shape = 'round',
|
207 | size = 'medium',
|
208 | type = 'page',
|
209 | variant = 'text'
|
210 | } = props,
|
211 | other = _objectWithoutPropertiesLoose(props, ["classes", "className", "color", "component", "disabled", "page", "selected", "shape", "size", "type", "variant"]);
|
212 |
|
213 | const theme = useTheme();
|
214 | const normalizedIcons = theme.direction === 'rtl' ? {
|
215 | previous: NavigateNextIcon,
|
216 | next: NavigateBeforeIcon,
|
217 | last: FirstPageIcon,
|
218 | first: LastPageIcon
|
219 | } : {
|
220 | previous: NavigateBeforeIcon,
|
221 | next: NavigateNextIcon,
|
222 | first: FirstPageIcon,
|
223 | last: LastPageIcon
|
224 | };
|
225 | const Icon = normalizedIcons[type];
|
226 | return type === 'start-ellipsis' || type === 'end-ellipsis' ? React.createElement("div", {
|
227 | ref: ref,
|
228 | className: clsx(classes.root, classes.ellipsis, disabled && classes.disabled, size !== 'medium' && classes[`size${capitalize(size)}`])
|
229 | }, "\u2026") : React.createElement(ButtonBase, _extends({
|
230 | ref: ref,
|
231 | component: component,
|
232 | disabled: disabled,
|
233 | focusVisibleClassName: classes.focusVisible,
|
234 | className: clsx(classes.root, classes.page, classes[variant], classes[shape], className, color !== 'standard' && classes[`${variant}${capitalize(color)}`], disabled && classes.disabled, selected && classes.selected, size !== 'medium' && classes[`size${capitalize(size)}`])
|
235 | }, other), type === 'page' && page, Icon ? React.createElement(Icon, {
|
236 | className: classes.icon
|
237 | }) : null);
|
238 | });
|
239 | process.env.NODE_ENV !== "production" ? PaginationItem.propTypes = {
|
240 | |
241 |
|
242 |
|
243 | classes: PropTypes.object.isRequired,
|
244 |
|
245 | |
246 |
|
247 |
|
248 | className: PropTypes.string,
|
249 |
|
250 | |
251 |
|
252 |
|
253 | color: PropTypes.oneOf(['standard', 'primary', 'secondary']),
|
254 |
|
255 | |
256 |
|
257 |
|
258 |
|
259 | component: PropTypes
|
260 |
|
261 | .elementType,
|
262 |
|
263 | |
264 |
|
265 |
|
266 | disabled: PropTypes.bool,
|
267 |
|
268 | |
269 |
|
270 |
|
271 | page: PropTypes.number,
|
272 |
|
273 | |
274 |
|
275 |
|
276 | selected: PropTypes.bool,
|
277 |
|
278 | |
279 |
|
280 |
|
281 | shape: PropTypes.oneOf(['round', 'rounded']),
|
282 |
|
283 | |
284 |
|
285 |
|
286 | size: PropTypes.oneOf(['small', 'medium', 'large']),
|
287 |
|
288 | |
289 |
|
290 |
|
291 | type: PropTypes.oneOf(['page', 'first', 'last', 'next', 'previous', 'start-ellipsis', 'end-ellipsis']),
|
292 |
|
293 | |
294 |
|
295 |
|
296 | variant: PropTypes.oneOf(['text', 'outlined'])
|
297 | } : void 0;
|
298 | export default withStyles(styles, {
|
299 | name: 'MuiPaginationItem'
|
300 | })(PaginationItem); |
\ | No newline at end of file |