UNPKG

11.4 kBJavaScriptView Raw
1"use strict";
2
3var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
4
5var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
6
7Object.defineProperty(exports, "__esModule", {
8 value: true
9});
10exports.default = exports.styles = void 0;
11
12var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
13
14var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
15
16var React = _interopRequireWildcard(require("react"));
17
18var _propTypes = _interopRequireDefault(require("prop-types"));
19
20var _clsx = _interopRequireDefault(require("clsx"));
21
22var _styles = require("@material-ui/core/styles");
23
24var _ButtonBase = _interopRequireDefault(require("@material-ui/core/ButtonBase"));
25
26var _FirstPage = _interopRequireDefault(require("../internal/svg-icons/FirstPage"));
27
28var _LastPage = _interopRequireDefault(require("../internal/svg-icons/LastPage"));
29
30var _NavigateBefore = _interopRequireDefault(require("../internal/svg-icons/NavigateBefore"));
31
32var _NavigateNext = _interopRequireDefault(require("../internal/svg-icons/NavigateNext"));
33
34var _utils = require("@material-ui/core/utils");
35
36var styles = function styles(theme) {
37 return {
38 /* Styles applied to the root element. */
39 root: (0, _extends2.default)({}, theme.typography.body2, {
40 borderRadius: 32 / 2,
41 textAlign: 'center',
42 boxSizing: 'border-box',
43 minWidth: 32,
44 height: 32,
45 padding: '0 6px',
46 margin: '0 3px',
47 color: theme.palette.text.primary
48 }),
49
50 /* Styles applied to the root element if `type="page"`. */
51 page: {
52 transition: theme.transitions.create(['color', 'background-color'], {
53 duration: theme.transitions.duration.short
54 }),
55 '&:hover': {
56 backgroundColor: theme.palette.action.hover,
57 // Reset on touch devices, it doesn't add specificity
58 '@media (hover: none)': {
59 backgroundColor: 'transparent'
60 }
61 },
62 '&$focusVisible': {
63 backgroundColor: theme.palette.action.focus
64 },
65 '&$selected': {
66 backgroundColor: theme.palette.action.selected,
67 '&:hover, &$focusVisible': {
68 backgroundColor: (0, _styles.alpha)(theme.palette.action.selected, theme.palette.action.selectedOpacity + theme.palette.action.hoverOpacity),
69 // Reset on touch devices, it doesn't add specificity
70 '@media (hover: none)': {
71 backgroundColor: theme.palette.action.selected
72 }
73 },
74 '&$disabled': {
75 opacity: 1,
76 color: theme.palette.action.disabled,
77 backgroundColor: theme.palette.action.selected
78 }
79 },
80 '&$disabled': {
81 opacity: theme.palette.action.disabledOpacity
82 }
83 },
84
85 /* Styles applied applied to the root element if `size="small"`. */
86 sizeSmall: {
87 minWidth: 26,
88 height: 26,
89 borderRadius: 26 / 2,
90 margin: '0 1px',
91 padding: '0 4px',
92 '& $icon': {
93 fontSize: theme.typography.pxToRem(18)
94 }
95 },
96
97 /* Styles applied applied to the root element if `size="large"`. */
98 sizeLarge: {
99 minWidth: 40,
100 height: 40,
101 borderRadius: 40 / 2,
102 padding: '0 10px',
103 fontSize: theme.typography.pxToRem(15),
104 '& $icon': {
105 fontSize: theme.typography.pxToRem(22)
106 }
107 },
108
109 /* Styles applied to the root element if `variant="text"` and `color="primary"`. */
110 textPrimary: {
111 '&$selected': {
112 color: theme.palette.primary.contrastText,
113 backgroundColor: theme.palette.primary.main,
114 '&:hover, &$focusVisible': {
115 backgroundColor: theme.palette.primary.dark,
116 // Reset on touch devices, it doesn't add specificity
117 '@media (hover: none)': {
118 backgroundColor: theme.palette.primary.main
119 }
120 },
121 '&$disabled': {
122 color: theme.palette.action.disabled
123 }
124 }
125 },
126
127 /* Styles applied to the root element if `variant="text"` and `color="secondary"`. */
128 textSecondary: {
129 '&$selected': {
130 color: theme.palette.secondary.contrastText,
131 backgroundColor: theme.palette.secondary.main,
132 '&:hover, &$focusVisible': {
133 backgroundColor: theme.palette.secondary.dark,
134 // Reset on touch devices, it doesn't add specificity
135 '@media (hover: none)': {
136 backgroundColor: theme.palette.secondary.main
137 }
138 },
139 '&$disabled': {
140 color: theme.palette.action.disabled
141 }
142 }
143 },
144
145 /* Styles applied to the root element if `outlined="true"`. */
146 outlined: {
147 border: "1px solid ".concat(theme.palette.type === 'light' ? 'rgba(0, 0, 0, 0.23)' : 'rgba(255, 255, 255, 0.23)'),
148 '&$selected': {
149 '&$disabled': {
150 border: "1px solid ".concat(theme.palette.action.disabledBackground)
151 }
152 }
153 },
154
155 /* Styles applied to the root element if `variant="outlined"` and `color="primary"`. */
156 outlinedPrimary: {
157 '&$selected': {
158 color: theme.palette.primary.main,
159 border: "1px solid ".concat((0, _styles.alpha)(theme.palette.primary.main, 0.5)),
160 backgroundColor: (0, _styles.alpha)(theme.palette.primary.main, theme.palette.action.activatedOpacity),
161 '&:hover, &$focusVisible': {
162 backgroundColor: (0, _styles.alpha)(theme.palette.primary.main, theme.palette.action.activatedOpacity + theme.palette.action.hoverOpacity),
163 // Reset on touch devices, it doesn't add specificity
164 '@media (hover: none)': {
165 backgroundColor: 'transparent'
166 }
167 },
168 '&$disabled': {
169 color: theme.palette.action.disabled
170 }
171 }
172 },
173
174 /* Styles applied to the root element if `variant="outlined"` and `color="secondary"`. */
175 outlinedSecondary: {
176 '&$selected': {
177 color: theme.palette.secondary.main,
178 border: "1px solid ".concat((0, _styles.alpha)(theme.palette.secondary.main, 0.5)),
179 backgroundColor: (0, _styles.alpha)(theme.palette.secondary.main, theme.palette.action.activatedOpacity),
180 '&:hover, &$focusVisible': {
181 backgroundColor: (0, _styles.alpha)(theme.palette.secondary.main, theme.palette.action.activatedOpacity + theme.palette.action.hoverOpacity),
182 // Reset on touch devices, it doesn't add specificity
183 '@media (hover: none)': {
184 backgroundColor: 'transparent'
185 }
186 },
187 '&$disabled': {
188 color: theme.palette.action.disabled
189 }
190 }
191 },
192
193 /* Styles applied to the root element if `rounded="true"`. */
194 rounded: {
195 borderRadius: theme.shape.borderRadius
196 },
197
198 /* Styles applied to the root element if `type="start-ellipsis"` or `type="end-ellipsis"`. */
199 ellipsis: {
200 height: 'auto',
201 '&$disabled': {
202 opacity: theme.palette.action.disabledOpacity
203 }
204 },
205
206 /* Pseudo-class applied to the root element if keyboard focused. */
207 focusVisible: {},
208
209 /* Pseudo-class applied to the root element if `disabled={true}`. */
210 disabled: {},
211
212 /* Pseudo-class applied to the root element if `selected={true}`. */
213 selected: {},
214
215 /* Styles applied to the icon element. */
216 icon: {
217 fontSize: theme.typography.pxToRem(20),
218 margin: '0 -8px'
219 }
220 };
221};
222
223exports.styles = styles;
224var PaginationItem = /*#__PURE__*/React.forwardRef(function PaginationItem(props, ref) {
225 var classes = props.classes,
226 className = props.className,
227 _props$color = props.color,
228 color = _props$color === void 0 ? 'standard' : _props$color,
229 component = props.component,
230 _props$disabled = props.disabled,
231 disabled = _props$disabled === void 0 ? false : _props$disabled,
232 page = props.page,
233 _props$selected = props.selected,
234 selected = _props$selected === void 0 ? false : _props$selected,
235 _props$shape = props.shape,
236 shape = _props$shape === void 0 ? 'round' : _props$shape,
237 _props$size = props.size,
238 size = _props$size === void 0 ? 'medium' : _props$size,
239 _props$type = props.type,
240 type = _props$type === void 0 ? 'page' : _props$type,
241 _props$variant = props.variant,
242 variant = _props$variant === void 0 ? 'text' : _props$variant,
243 other = (0, _objectWithoutProperties2.default)(props, ["classes", "className", "color", "component", "disabled", "page", "selected", "shape", "size", "type", "variant"]);
244 var theme = (0, _styles.useTheme)();
245 var normalizedIcons = theme.direction === 'rtl' ? {
246 previous: _NavigateNext.default,
247 next: _NavigateBefore.default,
248 last: _FirstPage.default,
249 first: _LastPage.default
250 } : {
251 previous: _NavigateBefore.default,
252 next: _NavigateNext.default,
253 first: _FirstPage.default,
254 last: _LastPage.default
255 };
256 var Icon = normalizedIcons[type];
257 return type === 'start-ellipsis' || type === 'end-ellipsis' ? /*#__PURE__*/React.createElement("div", {
258 ref: ref,
259 className: (0, _clsx.default)(classes.root, classes.ellipsis, disabled && classes.disabled, size !== 'medium' && classes["size".concat((0, _utils.capitalize)(size))])
260 }, "\u2026") : /*#__PURE__*/React.createElement(_ButtonBase.default, (0, _extends2.default)({
261 ref: ref,
262 component: component,
263 disabled: disabled,
264 focusVisibleClassName: classes.focusVisible,
265 className: (0, _clsx.default)(classes.root, classes.page, classes[variant], classes[shape], className, color !== 'standard' && classes["".concat(variant).concat((0, _utils.capitalize)(color))], disabled && classes.disabled, selected && classes.selected, size !== 'medium' && classes["size".concat((0, _utils.capitalize)(size))])
266 }, other), type === 'page' && page, Icon ? /*#__PURE__*/React.createElement(Icon, {
267 className: classes.icon
268 }) : null);
269});
270process.env.NODE_ENV !== "production" ? PaginationItem.propTypes = {
271 /**
272 * @ignore
273 */
274 classes: _propTypes.default.object.isRequired,
275
276 /**
277 * @ignore
278 */
279 className: _propTypes.default.string,
280
281 /**
282 * The active color.
283 */
284 color: _propTypes.default.oneOf(['standard', 'primary', 'secondary']),
285
286 /**
287 * The component used for the root node.
288 * Either a string to use a HTML element or a component.
289 */
290 component: _propTypes.default
291 /* @typescript-to-proptypes-ignore */
292 .elementType,
293
294 /**
295 * If `true`, the item will be disabled.
296 */
297 disabled: _propTypes.default.bool,
298
299 /**
300 * The current page number.
301 */
302 page: _propTypes.default.number,
303
304 /**
305 * If `true` the pagination item is selected.
306 */
307 selected: _propTypes.default.bool,
308
309 /**
310 * The shape of the pagination item.
311 */
312 shape: _propTypes.default.oneOf(['round', 'rounded']),
313
314 /**
315 * The size of the pagination item.
316 */
317 size: _propTypes.default.oneOf(['small', 'medium', 'large']),
318
319 /**
320 * The type of pagination item.
321 */
322 type: _propTypes.default.oneOf(['page', 'first', 'last', 'next', 'previous', 'start-ellipsis', 'end-ellipsis']),
323
324 /**
325 * The pagination item variant.
326 */
327 variant: _propTypes.default.oneOf(['text', 'outlined'])
328} : void 0;
329
330var _default = (0, _styles.withStyles)(styles, {
331 name: 'MuiPaginationItem'
332})(PaginationItem);
333
334exports.default = _default;
\No newline at end of file