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