9.42 kBJavaScriptView Raw
1import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
2import _extends from "@babel/runtime/helpers/esm/extends";
3import * as React from 'react';
4import PropTypes from 'prop-types';
5import clsx from 'clsx';
6import { alpha, useTheme, withStyles } from '@material-ui/core/styles';
7import ButtonBase from '@material-ui/core/ButtonBase';
8import FirstPageIcon from '../internal/svg-icons/FirstPage';
9import LastPageIcon from '../internal/svg-icons/LastPage';
10import NavigateBeforeIcon from '../internal/svg-icons/NavigateBefore';
11import NavigateNextIcon from '../internal/svg-icons/NavigateNext';
12import { capitalize } from '@material-ui/core/utils';
13export const styles = theme => ({
14 /* Styles applied to the root element. */
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 /* Styles applied to the root element if `type="page"`. */
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 // Reset on touch devices, it doesn't add specificity
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 // Reset on touch devices, it doesn't add specificity
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 /* Styles applied applied to the root element if `size="small"`. */
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 /* Styles applied applied to the root element if `size="large"`. */
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 /* Styles applied to the root element if `variant="text"` and `color="primary"`. */
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 // Reset on touch devices, it doesn't add specificity
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 /* Styles applied to the root element if `variant="text"` and `color="secondary"`. */
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 // Reset on touch devices, it doesn't add specificity
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 /* Styles applied to the root element if `outlined="true"`. */
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 /* Styles applied to the root element if `variant="outlined"` and `color="primary"`. */
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 // Reset on touch devices, it doesn't add specificity
140 '@media (hover: none)': {
141 backgroundColor: 'transparent'
142 }
143 },
144 '&$disabled': {
145 color: theme.palette.action.disabled
146 }
147 }
148 },
149
150 /* Styles applied to the root element if `variant="outlined"` and `color="secondary"`. */
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 // Reset on touch devices, it doesn't add specificity
159 '@media (hover: none)': {
160 backgroundColor: 'transparent'
161 }
162 },
163 '&$disabled': {
164 color: theme.palette.action.disabled
165 }
166 }
167 },
168
169 /* Styles applied to the root element if `rounded="true"`. */
170 rounded: {
171 borderRadius: theme.shape.borderRadius
172 },
173
174 /* Styles applied to the root element if `type="start-ellipsis"` or `type="end-ellipsis"`. */
175 ellipsis: {
176 height: 'auto',
177 '&$disabled': {
178 opacity: theme.palette.action.disabledOpacity
179 }
180 },
181
182 /* Pseudo-class applied to the root element if keyboard focused. */
183 focusVisible: {},
184
185 /* Pseudo-class applied to the root element if `disabled={true}`. */
186 disabled: {},
187
188 /* Pseudo-class applied to the root element if `selected={true}`. */
189 selected: {},
190
191 /* Styles applied to the icon element. */
192 icon: {
193 fontSize: theme.typography.pxToRem(20),
194 margin: '0 -8px'
195 }
196});
197const PaginationItem = /*#__PURE__*/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' ? /*#__PURE__*/React.createElement("div", {
227 ref: ref,
228 className: clsx(classes.root, classes.ellipsis, disabled && classes.disabled, size !== 'medium' && classes[`size${capitalize(size)}`])
229 }, "\u2026") : /*#__PURE__*/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 ? /*#__PURE__*/React.createElement(Icon, {
236 className: classes.icon
237 }) : null);
238});
239process.env.NODE_ENV !== "production" ? PaginationItem.propTypes = {
240 /**
241 * @ignore
242 */
243 classes: PropTypes.object.isRequired,
244
245 /**
246 * @ignore
247 */
248 className: PropTypes.string,
249
250 /**
251 * The active color.
252 */
253 color: PropTypes.oneOf(['standard', 'primary', 'secondary']),
254
255 /**
256 * The component used for the root node.
257 * Either a string to use a HTML element or a component.
258 */
259 component: PropTypes
260 /* @typescript-to-proptypes-ignore */
261 .elementType,
262
263 /**
264 * If `true`, the item will be disabled.
265 */
266 disabled: PropTypes.bool,
267
268 /**
269 * The current page number.
270 */
271 page: PropTypes.number,
272
273 /**
274 * If `true` the pagination item is selected.
275 */
276 selected: PropTypes.bool,
277
278 /**
279 * The shape of the pagination item.
280 */
281 shape: PropTypes.oneOf(['round', 'rounded']),
282
283 /**
284 * The size of the pagination item.
285 */
286 size: PropTypes.oneOf(['small', 'medium', 'large']),
287
288 /**
289 * The type of pagination item.
290 */
291 type: PropTypes.oneOf(['page', 'first', 'last', 'next', 'previous', 'start-ellipsis', 'end-ellipsis']),
292
293 /**
294 * The pagination item variant.
295 */
296 variant: PropTypes.oneOf(['text', 'outlined'])
297} : void 0;
298export default withStyles(styles, {
299 name: 'MuiPaginationItem'
300})(PaginationItem);
\No newline at end of file