1 | import _extends from "@babel/runtime/helpers/esm/extends";
|
2 | import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
3 | const _excluded = ["autoHideDuration", "children", "disableWindowBlurListener", "exited", "onBlur", "onClose", "onFocus", "onMouseEnter", "onMouseLeave", "open", "resumeHideDuration", "slotProps", "slots"];
|
4 | import * as React from 'react';
|
5 | import PropTypes from 'prop-types';
|
6 | import ClickAwayListener from '../ClickAwayListener';
|
7 | import composeClasses from '../composeClasses';
|
8 | import { getSnackbarUtilityClass } from './snackbarClasses';
|
9 | import useSnackbar from '../useSnackbar';
|
10 | import { useSlotProps } from '../utils';
|
11 | import { useClassNamesOverride } from '../utils/ClassNameConfigurator';
|
12 | import { jsx as _jsx } from "react/jsx-runtime";
|
13 | const useUtilityClasses = () => {
|
14 | const slots = {
|
15 | root: ['root']
|
16 | };
|
17 | return composeClasses(slots, useClassNamesOverride(getSnackbarUtilityClass));
|
18 | };
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 | const Snackbar = React.forwardRef(function Snackbar(props, forwardedRef) {
|
31 | const {
|
32 | autoHideDuration = null,
|
33 | children,
|
34 | disableWindowBlurListener = false,
|
35 | exited = true,
|
36 | onClose,
|
37 | open,
|
38 | resumeHideDuration,
|
39 | slotProps = {},
|
40 | slots = {}
|
41 | } = props,
|
42 | other = _objectWithoutPropertiesLoose(props, _excluded);
|
43 | const classes = useUtilityClasses();
|
44 | const {
|
45 | getRootProps,
|
46 | onClickAway
|
47 | } = useSnackbar(_extends({}, props, {
|
48 | autoHideDuration,
|
49 | disableWindowBlurListener,
|
50 | onClose,
|
51 | open,
|
52 | resumeHideDuration
|
53 | }));
|
54 | const ownerState = props;
|
55 | const Root = slots.root || 'div';
|
56 | const rootProps = useSlotProps({
|
57 | elementType: Root,
|
58 | getSlotProps: getRootProps,
|
59 | externalForwardedProps: other,
|
60 | externalSlotProps: slotProps.root,
|
61 | additionalProps: {
|
62 | ref: forwardedRef
|
63 | },
|
64 | ownerState,
|
65 | className: classes.root
|
66 | });
|
67 | const clickAwayListenerProps = useSlotProps({
|
68 | elementType: ClickAwayListener,
|
69 | externalSlotProps: slotProps.clickAwayListener,
|
70 | additionalProps: {
|
71 | onClickAway
|
72 | },
|
73 | ownerState
|
74 | });
|
75 |
|
76 |
|
77 | delete clickAwayListenerProps.ownerState;
|
78 |
|
79 |
|
80 | if (!open && exited) {
|
81 | return null;
|
82 | }
|
83 | return _jsx(ClickAwayListener, _extends({}, clickAwayListenerProps, {
|
84 | children: _jsx(Root, _extends({}, rootProps, {
|
85 | children: children
|
86 | }))
|
87 | }));
|
88 | });
|
89 | process.env.NODE_ENV !== "production" ? Snackbar.propTypes = {
|
90 |
|
91 |
|
92 |
|
93 |
|
94 | |
95 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 |
|
101 | autoHideDuration: PropTypes.number,
|
102 | |
103 |
|
104 |
|
105 | children: PropTypes.node,
|
106 | |
107 |
|
108 |
|
109 |
|
110 | disableWindowBlurListener: PropTypes.bool,
|
111 | |
112 |
|
113 |
|
114 |
|
115 | exited: PropTypes.bool,
|
116 | |
117 |
|
118 |
|
119 |
|
120 |
|
121 |
|
122 |
|
123 |
|
124 |
|
125 |
|
126 | onClose: PropTypes.func,
|
127 | |
128 |
|
129 |
|
130 | open: PropTypes.bool,
|
131 | |
132 |
|
133 |
|
134 |
|
135 |
|
136 |
|
137 | resumeHideDuration: PropTypes.number,
|
138 | |
139 |
|
140 |
|
141 |
|
142 | slotProps: PropTypes.shape({
|
143 | clickAwayListener: PropTypes.oneOfType([PropTypes.func, PropTypes.shape({
|
144 | children: PropTypes.element.isRequired,
|
145 | disableReactTree: PropTypes.bool,
|
146 | mouseEvent: PropTypes.oneOf(['onClick', 'onMouseDown', 'onMouseUp', 'onPointerDown', 'onPointerUp', false]),
|
147 | onClickAway: PropTypes.func,
|
148 | touchEvent: PropTypes.oneOf(['onTouchEnd', 'onTouchStart', false])
|
149 | })]),
|
150 | root: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
|
151 | }),
|
152 | |
153 |
|
154 |
|
155 |
|
156 |
|
157 | slots: PropTypes.shape({
|
158 | root: PropTypes.elementType
|
159 | })
|
160 | } : void 0;
|
161 | export default Snackbar; |
\ | No newline at end of file |