1 | "use strict";
|
2 |
|
3 | var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
|
4 |
|
5 | var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
6 |
|
7 | Object.defineProperty(exports, "__esModule", {
|
8 | value: true
|
9 | });
|
10 | exports.default = exports.styles = void 0;
|
11 |
|
12 | var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
13 |
|
14 | var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
15 |
|
16 | var _extends8 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
17 |
|
18 | var React = _interopRequireWildcard(require("react"));
|
19 |
|
20 | var _propTypes = _interopRequireDefault(require("prop-types"));
|
21 |
|
22 | var _clsx = _interopRequireDefault(require("clsx"));
|
23 |
|
24 | var _withStyles = _interopRequireDefault(require("../styles/withStyles"));
|
25 |
|
26 | var _transitions = require("../styles/transitions");
|
27 |
|
28 | var _ClickAwayListener = _interopRequireDefault(require("../ClickAwayListener"));
|
29 |
|
30 | var _useEventCallback = _interopRequireDefault(require("../utils/useEventCallback"));
|
31 |
|
32 | var _capitalize = _interopRequireDefault(require("../utils/capitalize"));
|
33 |
|
34 | var _createChainedFunction = _interopRequireDefault(require("../utils/createChainedFunction"));
|
35 |
|
36 | var _Grow = _interopRequireDefault(require("../Grow"));
|
37 |
|
38 | var _SnackbarContent = _interopRequireDefault(require("../SnackbarContent"));
|
39 |
|
40 | var styles = function styles(theme) {
|
41 | var top1 = {
|
42 | top: 8
|
43 | };
|
44 | var bottom1 = {
|
45 | bottom: 8
|
46 | };
|
47 | var right = {
|
48 | justifyContent: 'flex-end'
|
49 | };
|
50 | var left = {
|
51 | justifyContent: 'flex-start'
|
52 | };
|
53 | var top3 = {
|
54 | top: 24
|
55 | };
|
56 | var bottom3 = {
|
57 | bottom: 24
|
58 | };
|
59 | var right3 = {
|
60 | right: 24
|
61 | };
|
62 | var left3 = {
|
63 | left: 24
|
64 | };
|
65 | var center = {
|
66 | left: '50%',
|
67 | right: 'auto',
|
68 | transform: 'translateX(-50%)'
|
69 | };
|
70 | return {
|
71 |
|
72 | root: {
|
73 | zIndex: theme.zIndex.snackbar,
|
74 | position: 'fixed',
|
75 | display: 'flex',
|
76 | left: 8,
|
77 | right: 8,
|
78 | justifyContent: 'center',
|
79 | alignItems: 'center'
|
80 | },
|
81 |
|
82 |
|
83 | anchorOriginTopCenter: (0, _extends8.default)({}, top1, (0, _defineProperty2.default)({}, theme.breakpoints.up('sm'), (0, _extends8.default)({}, top3, center))),
|
84 |
|
85 |
|
86 | anchorOriginBottomCenter: (0, _extends8.default)({}, bottom1, (0, _defineProperty2.default)({}, theme.breakpoints.up('sm'), (0, _extends8.default)({}, bottom3, center))),
|
87 |
|
88 |
|
89 | anchorOriginTopRight: (0, _extends8.default)({}, top1, right, (0, _defineProperty2.default)({}, theme.breakpoints.up('sm'), (0, _extends8.default)({
|
90 | left: 'auto'
|
91 | }, top3, right3))),
|
92 |
|
93 |
|
94 | anchorOriginBottomRight: (0, _extends8.default)({}, bottom1, right, (0, _defineProperty2.default)({}, theme.breakpoints.up('sm'), (0, _extends8.default)({
|
95 | left: 'auto'
|
96 | }, bottom3, right3))),
|
97 |
|
98 |
|
99 | anchorOriginTopLeft: (0, _extends8.default)({}, top1, left, (0, _defineProperty2.default)({}, theme.breakpoints.up('sm'), (0, _extends8.default)({
|
100 | right: 'auto'
|
101 | }, top3, left3))),
|
102 |
|
103 |
|
104 | anchorOriginBottomLeft: (0, _extends8.default)({}, bottom1, left, (0, _defineProperty2.default)({}, theme.breakpoints.up('sm'), (0, _extends8.default)({
|
105 | right: 'auto'
|
106 | }, bottom3, left3)))
|
107 | };
|
108 | };
|
109 |
|
110 | exports.styles = styles;
|
111 | var Snackbar = React.forwardRef(function Snackbar(props, ref) {
|
112 | var action = props.action,
|
113 | _props$anchorOrigin = props.anchorOrigin;
|
114 | _props$anchorOrigin = _props$anchorOrigin === void 0 ? {
|
115 | vertical: 'bottom',
|
116 | horizontal: 'center'
|
117 | } : _props$anchorOrigin;
|
118 | var vertical = _props$anchorOrigin.vertical,
|
119 | horizontal = _props$anchorOrigin.horizontal,
|
120 | _props$autoHideDurati = props.autoHideDuration,
|
121 | autoHideDuration = _props$autoHideDurati === void 0 ? null : _props$autoHideDurati,
|
122 | children = props.children,
|
123 | classes = props.classes,
|
124 | className = props.className,
|
125 | ClickAwayListenerProps = props.ClickAwayListenerProps,
|
126 | ContentProps = props.ContentProps,
|
127 | _props$disableWindowB = props.disableWindowBlurListener,
|
128 | disableWindowBlurListener = _props$disableWindowB === void 0 ? false : _props$disableWindowB,
|
129 | message = props.message,
|
130 | onClose = props.onClose,
|
131 | onEnter = props.onEnter,
|
132 | onEntered = props.onEntered,
|
133 | onEntering = props.onEntering,
|
134 | onExit = props.onExit,
|
135 | onExited = props.onExited,
|
136 | onExiting = props.onExiting,
|
137 | onMouseEnter = props.onMouseEnter,
|
138 | onMouseLeave = props.onMouseLeave,
|
139 | open = props.open,
|
140 | resumeHideDuration = props.resumeHideDuration,
|
141 | _props$TransitionComp = props.TransitionComponent,
|
142 | TransitionComponent = _props$TransitionComp === void 0 ? _Grow.default : _props$TransitionComp,
|
143 | _props$transitionDura = props.transitionDuration,
|
144 | transitionDuration = _props$transitionDura === void 0 ? {
|
145 | enter: _transitions.duration.enteringScreen,
|
146 | exit: _transitions.duration.leavingScreen
|
147 | } : _props$transitionDura,
|
148 | TransitionProps = props.TransitionProps,
|
149 | other = (0, _objectWithoutProperties2.default)(props, ["action", "anchorOrigin", "autoHideDuration", "children", "classes", "className", "ClickAwayListenerProps", "ContentProps", "disableWindowBlurListener", "message", "onClose", "onEnter", "onEntered", "onEntering", "onExit", "onExited", "onExiting", "onMouseEnter", "onMouseLeave", "open", "resumeHideDuration", "TransitionComponent", "transitionDuration", "TransitionProps"]);
|
150 | var timerAutoHide = React.useRef();
|
151 |
|
152 | var _React$useState = React.useState(true),
|
153 | exited = _React$useState[0],
|
154 | setExited = _React$useState[1];
|
155 |
|
156 | var handleClose = (0, _useEventCallback.default)(function () {
|
157 | if (onClose) {
|
158 | onClose.apply(void 0, arguments);
|
159 | }
|
160 | });
|
161 | var setAutoHideTimer = (0, _useEventCallback.default)(function (autoHideDurationParam) {
|
162 | if (!onClose || autoHideDurationParam == null) {
|
163 | return;
|
164 | }
|
165 |
|
166 | clearTimeout(timerAutoHide.current);
|
167 | timerAutoHide.current = setTimeout(function () {
|
168 | handleClose(null, 'timeout');
|
169 | }, autoHideDurationParam);
|
170 | });
|
171 | React.useEffect(function () {
|
172 | if (open) {
|
173 | setAutoHideTimer(autoHideDuration);
|
174 | }
|
175 |
|
176 | return function () {
|
177 | clearTimeout(timerAutoHide.current);
|
178 | };
|
179 | }, [open, autoHideDuration, setAutoHideTimer]);
|
180 |
|
181 |
|
182 | var handlePause = function handlePause() {
|
183 | clearTimeout(timerAutoHide.current);
|
184 | };
|
185 |
|
186 |
|
187 |
|
188 | var handleResume = React.useCallback(function () {
|
189 | if (autoHideDuration != null) {
|
190 | setAutoHideTimer(resumeHideDuration != null ? resumeHideDuration : autoHideDuration * 0.5);
|
191 | }
|
192 | }, [autoHideDuration, resumeHideDuration, setAutoHideTimer]);
|
193 |
|
194 | var handleMouseEnter = function handleMouseEnter(event) {
|
195 | if (onMouseEnter) {
|
196 | onMouseEnter(event);
|
197 | }
|
198 |
|
199 | handlePause();
|
200 | };
|
201 |
|
202 | var handleMouseLeave = function handleMouseLeave(event) {
|
203 | if (onMouseLeave) {
|
204 | onMouseLeave(event);
|
205 | }
|
206 |
|
207 | handleResume();
|
208 | };
|
209 |
|
210 | var handleClickAway = function handleClickAway(event) {
|
211 | if (onClose) {
|
212 | onClose(event, 'clickaway');
|
213 | }
|
214 | };
|
215 |
|
216 | var handleExited = function handleExited() {
|
217 | setExited(true);
|
218 | };
|
219 |
|
220 | var handleEnter = function handleEnter() {
|
221 | setExited(false);
|
222 | };
|
223 |
|
224 | React.useEffect(function () {
|
225 | if (!disableWindowBlurListener && open) {
|
226 | window.addEventListener('focus', handleResume);
|
227 | window.addEventListener('blur', handlePause);
|
228 | return function () {
|
229 | window.removeEventListener('focus', handleResume);
|
230 | window.removeEventListener('blur', handlePause);
|
231 | };
|
232 | }
|
233 |
|
234 | return undefined;
|
235 | }, [disableWindowBlurListener, handleResume, open]);
|
236 |
|
237 | if (!open && exited) {
|
238 | return null;
|
239 | }
|
240 |
|
241 | return React.createElement(_ClickAwayListener.default, (0, _extends8.default)({
|
242 | onClickAway: handleClickAway
|
243 | }, ClickAwayListenerProps), React.createElement("div", (0, _extends8.default)({
|
244 | className: (0, _clsx.default)(classes.root, classes["anchorOrigin".concat((0, _capitalize.default)(vertical)).concat((0, _capitalize.default)(horizontal))], className),
|
245 | onMouseEnter: handleMouseEnter,
|
246 | onMouseLeave: handleMouseLeave,
|
247 | ref: ref
|
248 | }, other), React.createElement(TransitionComponent, (0, _extends8.default)({
|
249 | appear: true,
|
250 | in: open,
|
251 | onEnter: (0, _createChainedFunction.default)(handleEnter, onEnter),
|
252 | onEntered: onEntered,
|
253 | onEntering: onEntering,
|
254 | onExit: onExit,
|
255 | onExited: (0, _createChainedFunction.default)(handleExited, onExited),
|
256 | onExiting: onExiting,
|
257 | timeout: transitionDuration,
|
258 | direction: vertical === 'top' ? 'down' : 'up'
|
259 | }, TransitionProps), children || React.createElement(_SnackbarContent.default, (0, _extends8.default)({
|
260 | message: message,
|
261 | action: action
|
262 | }, ContentProps)))));
|
263 | });
|
264 | process.env.NODE_ENV !== "production" ? Snackbar.propTypes = {
|
265 |
|
266 |
|
267 |
|
268 |
|
269 |
|
270 | |
271 |
|
272 |
|
273 | action: _propTypes.default.node,
|
274 |
|
275 | |
276 |
|
277 |
|
278 | anchorOrigin: _propTypes.default.shape({
|
279 | horizontal: _propTypes.default.oneOf(['center', 'left', 'right']).isRequired,
|
280 | vertical: _propTypes.default.oneOf(['bottom', 'top']).isRequired
|
281 | }),
|
282 |
|
283 | |
284 |
|
285 |
|
286 |
|
287 |
|
288 |
|
289 | autoHideDuration: _propTypes.default.number,
|
290 |
|
291 | |
292 |
|
293 |
|
294 | children: _propTypes.default.element,
|
295 |
|
296 | |
297 |
|
298 |
|
299 |
|
300 | classes: _propTypes.default.object,
|
301 |
|
302 | |
303 |
|
304 |
|
305 | className: _propTypes.default.string,
|
306 |
|
307 | |
308 |
|
309 |
|
310 | ClickAwayListenerProps: _propTypes.default.object,
|
311 |
|
312 | |
313 |
|
314 |
|
315 | ContentProps: _propTypes.default.object,
|
316 |
|
317 | |
318 |
|
319 |
|
320 | disableWindowBlurListener: _propTypes.default.bool,
|
321 |
|
322 | |
323 |
|
324 |
|
325 |
|
326 |
|
327 |
|
328 | key: _propTypes.default.any,
|
329 |
|
330 | |
331 |
|
332 |
|
333 | message: _propTypes.default.node,
|
334 |
|
335 | |
336 |
|
337 |
|
338 |
|
339 |
|
340 |
|
341 |
|
342 |
|
343 |
|
344 |
|
345 | onClose: _propTypes.default.func,
|
346 |
|
347 | |
348 |
|
349 |
|
350 | onEnter: _propTypes.default.func,
|
351 |
|
352 | |
353 |
|
354 |
|
355 | onEntered: _propTypes.default.func,
|
356 |
|
357 | |
358 |
|
359 |
|
360 | onEntering: _propTypes.default.func,
|
361 |
|
362 | |
363 |
|
364 |
|
365 | onExit: _propTypes.default.func,
|
366 |
|
367 | |
368 |
|
369 |
|
370 | onExited: _propTypes.default.func,
|
371 |
|
372 | |
373 |
|
374 |
|
375 | onExiting: _propTypes.default.func,
|
376 |
|
377 | |
378 |
|
379 |
|
380 | onMouseEnter: _propTypes.default.func,
|
381 |
|
382 | |
383 |
|
384 |
|
385 | onMouseLeave: _propTypes.default.func,
|
386 |
|
387 | |
388 |
|
389 |
|
390 | open: _propTypes.default.bool,
|
391 |
|
392 | |
393 |
|
394 |
|
395 |
|
396 |
|
397 |
|
398 | resumeHideDuration: _propTypes.default.number,
|
399 |
|
400 | |
401 |
|
402 |
|
403 |
|
404 | TransitionComponent: _propTypes.default.elementType,
|
405 |
|
406 | |
407 |
|
408 |
|
409 |
|
410 | transitionDuration: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.shape({
|
411 | appear: _propTypes.default.number,
|
412 | enter: _propTypes.default.number,
|
413 | exit: _propTypes.default.number
|
414 | })]),
|
415 |
|
416 | |
417 |
|
418 |
|
419 | TransitionProps: _propTypes.default.object
|
420 | } : void 0;
|
421 |
|
422 | var _default = (0, _withStyles.default)(styles, {
|
423 | flip: false,
|
424 | name: 'MuiSnackbar'
|
425 | })(Snackbar);
|
426 |
|
427 | exports.default = _default; |
\ | No newline at end of file |