1 | 'use client';
|
2 |
|
3 | import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
4 | import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
5 | import _extends from "@babel/runtime/helpers/esm/extends";
|
6 | import * as React from 'react';
|
7 | import PropTypes from 'prop-types';
|
8 | import { useSlotProps } from '@mui/base/utils';
|
9 | import composeClasses from '@mui/utils/composeClasses';
|
10 | import { ClickAwayListener } from '@mui/base/ClickAwayListener';
|
11 | import { useSnackbar } from '@mui/base/useSnackbar';
|
12 | import styled from '../styles/styled';
|
13 | import useTheme from '../styles/useTheme';
|
14 | import { useDefaultProps } from '../DefaultPropsProvider';
|
15 | import capitalize from '../utils/capitalize';
|
16 | import Grow from '../Grow';
|
17 | import SnackbarContent from '../SnackbarContent';
|
18 | import { getSnackbarUtilityClass } from './snackbarClasses';
|
19 | import { jsx as _jsx } from "react/jsx-runtime";
|
20 | var useUtilityClasses = function useUtilityClasses(ownerState) {
|
21 | var classes = ownerState.classes,
|
22 | anchorOrigin = ownerState.anchorOrigin;
|
23 | var slots = {
|
24 | root: ['root', "anchorOrigin".concat(capitalize(anchorOrigin.vertical)).concat(capitalize(anchorOrigin.horizontal))]
|
25 | };
|
26 | return composeClasses(slots, getSnackbarUtilityClass, classes);
|
27 | };
|
28 | var SnackbarRoot = styled('div', {
|
29 | name: 'MuiSnackbar',
|
30 | slot: 'Root',
|
31 | overridesResolver: function overridesResolver(props, styles) {
|
32 | var ownerState = props.ownerState;
|
33 | return [styles.root, styles["anchorOrigin".concat(capitalize(ownerState.anchorOrigin.vertical)).concat(capitalize(ownerState.anchorOrigin.horizontal))]];
|
34 | }
|
35 | })(function (_ref) {
|
36 | var theme = _ref.theme,
|
37 | ownerState = _ref.ownerState;
|
38 | var center = {
|
39 | left: '50%',
|
40 | right: 'auto',
|
41 | transform: 'translateX(-50%)'
|
42 | };
|
43 | return _extends({
|
44 | zIndex: (theme.vars || theme).zIndex.snackbar,
|
45 | position: 'fixed',
|
46 | display: 'flex',
|
47 | left: 8,
|
48 | right: 8,
|
49 | justifyContent: 'center',
|
50 | alignItems: 'center'
|
51 | }, ownerState.anchorOrigin.vertical === 'top' ? {
|
52 | top: 8
|
53 | } : {
|
54 | bottom: 8
|
55 | }, ownerState.anchorOrigin.horizontal === 'left' && {
|
56 | justifyContent: 'flex-start'
|
57 | }, ownerState.anchorOrigin.horizontal === 'right' && {
|
58 | justifyContent: 'flex-end'
|
59 | }, _defineProperty({}, theme.breakpoints.up('sm'), _extends({}, ownerState.anchorOrigin.vertical === 'top' ? {
|
60 | top: 24
|
61 | } : {
|
62 | bottom: 24
|
63 | }, ownerState.anchorOrigin.horizontal === 'center' && center, ownerState.anchorOrigin.horizontal === 'left' && {
|
64 | left: 24,
|
65 | right: 'auto'
|
66 | }, ownerState.anchorOrigin.horizontal === 'right' && {
|
67 | right: 24,
|
68 | left: 'auto'
|
69 | })));
|
70 | });
|
71 | var Snackbar = React.forwardRef(function Snackbar(inProps, ref) {
|
72 | var props = useDefaultProps({
|
73 | props: inProps,
|
74 | name: 'MuiSnackbar'
|
75 | });
|
76 | var theme = useTheme();
|
77 | var defaultTransitionDuration = {
|
78 | enter: theme.transitions.duration.enteringScreen,
|
79 | exit: theme.transitions.duration.leavingScreen
|
80 | };
|
81 | var action = props.action,
|
82 | _props$anchorOrigin = props.anchorOrigin,
|
83 | _props$anchorOrigin2 = _props$anchorOrigin === void 0 ? {
|
84 | vertical: 'bottom',
|
85 | horizontal: 'left'
|
86 | } : _props$anchorOrigin,
|
87 | vertical = _props$anchorOrigin2.vertical,
|
88 | horizontal = _props$anchorOrigin2.horizontal,
|
89 | _props$autoHideDurati = props.autoHideDuration,
|
90 | autoHideDuration = _props$autoHideDurati === void 0 ? null : _props$autoHideDurati,
|
91 | children = props.children,
|
92 | className = props.className,
|
93 | ClickAwayListenerProps = props.ClickAwayListenerProps,
|
94 | ContentProps = props.ContentProps,
|
95 | _props$disableWindowB = props.disableWindowBlurListener,
|
96 | disableWindowBlurListener = _props$disableWindowB === void 0 ? false : _props$disableWindowB,
|
97 | message = props.message,
|
98 | onBlur = props.onBlur,
|
99 | onClose = props.onClose,
|
100 | onFocus = props.onFocus,
|
101 | onMouseEnter = props.onMouseEnter,
|
102 | onMouseLeave = props.onMouseLeave,
|
103 | open = props.open,
|
104 | resumeHideDuration = props.resumeHideDuration,
|
105 | _props$TransitionComp = props.TransitionComponent,
|
106 | TransitionComponent = _props$TransitionComp === void 0 ? Grow : _props$TransitionComp,
|
107 | _props$transitionDura = props.transitionDuration,
|
108 | transitionDuration = _props$transitionDura === void 0 ? defaultTransitionDuration : _props$transitionDura,
|
109 | _props$TransitionProp = props.TransitionProps,
|
110 | _props$TransitionProp2 = _props$TransitionProp === void 0 ? {} : _props$TransitionProp,
|
111 | onEnter = _props$TransitionProp2.onEnter,
|
112 | onExited = _props$TransitionProp2.onExited,
|
113 | TransitionProps = _objectWithoutProperties(_props$TransitionProp2, ["onEnter", "onExited"]),
|
114 | other = _objectWithoutProperties(props, ["action", "anchorOrigin", "autoHideDuration", "children", "className", "ClickAwayListenerProps", "ContentProps", "disableWindowBlurListener", "message", "onBlur", "onClose", "onFocus", "onMouseEnter", "onMouseLeave", "open", "resumeHideDuration", "TransitionComponent", "transitionDuration", "TransitionProps"]);
|
115 | var ownerState = _extends({}, props, {
|
116 | anchorOrigin: {
|
117 | vertical: vertical,
|
118 | horizontal: horizontal
|
119 | },
|
120 | autoHideDuration: autoHideDuration,
|
121 | disableWindowBlurListener: disableWindowBlurListener,
|
122 | TransitionComponent: TransitionComponent,
|
123 | transitionDuration: transitionDuration
|
124 | });
|
125 | var classes = useUtilityClasses(ownerState);
|
126 | var _useSnackbar = useSnackbar(_extends({}, ownerState)),
|
127 | getRootProps = _useSnackbar.getRootProps,
|
128 | onClickAway = _useSnackbar.onClickAway;
|
129 | var _React$useState = React.useState(true),
|
130 | exited = _React$useState[0],
|
131 | setExited = _React$useState[1];
|
132 | var rootProps = useSlotProps({
|
133 | elementType: SnackbarRoot,
|
134 | getSlotProps: getRootProps,
|
135 | externalForwardedProps: other,
|
136 | ownerState: ownerState,
|
137 | additionalProps: {
|
138 | ref: ref
|
139 | },
|
140 | className: [classes.root, className]
|
141 | });
|
142 | var handleExited = function handleExited(node) {
|
143 | setExited(true);
|
144 | if (onExited) {
|
145 | onExited(node);
|
146 | }
|
147 | };
|
148 | var handleEnter = function handleEnter(node, isAppearing) {
|
149 | setExited(false);
|
150 | if (onEnter) {
|
151 | onEnter(node, isAppearing);
|
152 | }
|
153 | };
|
154 |
|
155 |
|
156 | if (!open && exited) {
|
157 | return null;
|
158 | }
|
159 | return _jsx(ClickAwayListener, _extends({
|
160 | onClickAway: onClickAway
|
161 | }, ClickAwayListenerProps, {
|
162 | children: _jsx(SnackbarRoot, _extends({}, rootProps, {
|
163 | children: _jsx(TransitionComponent, _extends({
|
164 | appear: true,
|
165 | in: open,
|
166 | timeout: transitionDuration,
|
167 | direction: vertical === 'top' ? 'down' : 'up',
|
168 | onEnter: handleEnter,
|
169 | onExited: handleExited
|
170 | }, TransitionProps, {
|
171 | children: children || _jsx(SnackbarContent, _extends({
|
172 | message: message,
|
173 | action: action
|
174 | }, ContentProps))
|
175 | }))
|
176 | }))
|
177 | }));
|
178 | });
|
179 | process.env.NODE_ENV !== "production" ? Snackbar.propTypes = {
|
180 |
|
181 |
|
182 |
|
183 |
|
184 | |
185 |
|
186 |
|
187 | action: PropTypes.node,
|
188 | |
189 |
|
190 |
|
191 |
|
192 |
|
193 |
|
194 | anchorOrigin: PropTypes.shape({
|
195 | horizontal: PropTypes.oneOf(['center', 'left', 'right']).isRequired,
|
196 | vertical: PropTypes.oneOf(['bottom', 'top']).isRequired
|
197 | }),
|
198 | |
199 |
|
200 |
|
201 |
|
202 |
|
203 |
|
204 |
|
205 | autoHideDuration: PropTypes.number,
|
206 | |
207 |
|
208 |
|
209 | children: PropTypes.element,
|
210 | |
211 |
|
212 |
|
213 | classes: PropTypes.object,
|
214 | |
215 |
|
216 |
|
217 | className: PropTypes.string,
|
218 | |
219 |
|
220 |
|
221 | ClickAwayListenerProps: PropTypes.object,
|
222 | |
223 |
|
224 |
|
225 | ContentProps: PropTypes.object,
|
226 | |
227 |
|
228 |
|
229 |
|
230 | disableWindowBlurListener: PropTypes.bool,
|
231 | |
232 |
|
233 |
|
234 |
|
235 |
|
236 |
|
237 | key: function key() {
|
238 | return null;
|
239 | },
|
240 | |
241 |
|
242 |
|
243 | message: PropTypes.node,
|
244 | |
245 |
|
246 |
|
247 | onBlur: PropTypes.func,
|
248 | |
249 |
|
250 |
|
251 |
|
252 |
|
253 |
|
254 |
|
255 |
|
256 |
|
257 |
|
258 | onClose: PropTypes.func,
|
259 | |
260 |
|
261 |
|
262 | onFocus: PropTypes.func,
|
263 | |
264 |
|
265 |
|
266 | onMouseEnter: PropTypes.func,
|
267 | |
268 |
|
269 |
|
270 | onMouseLeave: PropTypes.func,
|
271 | |
272 |
|
273 |
|
274 | open: PropTypes.bool,
|
275 | |
276 |
|
277 |
|
278 |
|
279 |
|
280 |
|
281 | resumeHideDuration: PropTypes.number,
|
282 | |
283 |
|
284 |
|
285 | sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
|
286 | |
287 |
|
288 |
|
289 |
|
290 |
|
291 | TransitionComponent: PropTypes.elementType,
|
292 | |
293 |
|
294 |
|
295 |
|
296 |
|
297 |
|
298 |
|
299 |
|
300 | transitionDuration: PropTypes.oneOfType([PropTypes.number, PropTypes.shape({
|
301 | appear: PropTypes.number,
|
302 | enter: PropTypes.number,
|
303 | exit: PropTypes.number
|
304 | })]),
|
305 | |
306 |
|
307 |
|
308 |
|
309 |
|
310 | TransitionProps: PropTypes.object
|
311 | } : void 0;
|
312 | export default Snackbar; |
\ | No newline at end of file |