1 | 'use client';
|
2 |
|
3 | import * as React from 'react';
|
4 | import PropTypes from 'prop-types';
|
5 | import { Transition } from 'react-transition-group';
|
6 | import elementAcceptingRef from '@mui/utils/elementAcceptingRef';
|
7 | import getReactElementRef from '@mui/utils/getReactElementRef';
|
8 | import { useTheme } from "../zero-styled/index.js";
|
9 | import { reflow, getTransitionProps } from "../transitions/utils.js";
|
10 | import useForkRef from "../utils/useForkRef.js";
|
11 | import { jsx as _jsx } from "react/jsx-runtime";
|
12 | const styles = {
|
13 | entering: {
|
14 | opacity: 1
|
15 | },
|
16 | entered: {
|
17 | opacity: 1
|
18 | }
|
19 | };
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 | const Fade = React.forwardRef(function Fade(props, ref) {
|
26 | const theme = useTheme();
|
27 | const defaultTimeout = {
|
28 | enter: theme.transitions.duration.enteringScreen,
|
29 | exit: theme.transitions.duration.leavingScreen
|
30 | };
|
31 | const {
|
32 | addEndListener,
|
33 | appear = true,
|
34 | children,
|
35 | easing,
|
36 | in: inProp,
|
37 | onEnter,
|
38 | onEntered,
|
39 | onEntering,
|
40 | onExit,
|
41 | onExited,
|
42 | onExiting,
|
43 | style,
|
44 | timeout = defaultTimeout,
|
45 |
|
46 | TransitionComponent = Transition,
|
47 | ...other
|
48 | } = props;
|
49 | const enableStrictModeCompat = true;
|
50 | const nodeRef = React.useRef(null);
|
51 | const handleRef = useForkRef(nodeRef, getReactElementRef(children), ref);
|
52 | const normalizedTransitionCallback = callback => maybeIsAppearing => {
|
53 | if (callback) {
|
54 | const node = nodeRef.current;
|
55 |
|
56 |
|
57 | if (maybeIsAppearing === undefined) {
|
58 | callback(node);
|
59 | } else {
|
60 | callback(node, maybeIsAppearing);
|
61 | }
|
62 | }
|
63 | };
|
64 | const handleEntering = normalizedTransitionCallback(onEntering);
|
65 | const handleEnter = normalizedTransitionCallback((node, isAppearing) => {
|
66 | reflow(node);
|
67 |
|
68 | const transitionProps = getTransitionProps({
|
69 | style,
|
70 | timeout,
|
71 | easing
|
72 | }, {
|
73 | mode: 'enter'
|
74 | });
|
75 | node.style.webkitTransition = theme.transitions.create('opacity', transitionProps);
|
76 | node.style.transition = theme.transitions.create('opacity', transitionProps);
|
77 | if (onEnter) {
|
78 | onEnter(node, isAppearing);
|
79 | }
|
80 | });
|
81 | const handleEntered = normalizedTransitionCallback(onEntered);
|
82 | const handleExiting = normalizedTransitionCallback(onExiting);
|
83 | const handleExit = normalizedTransitionCallback(node => {
|
84 | const transitionProps = getTransitionProps({
|
85 | style,
|
86 | timeout,
|
87 | easing
|
88 | }, {
|
89 | mode: 'exit'
|
90 | });
|
91 | node.style.webkitTransition = theme.transitions.create('opacity', transitionProps);
|
92 | node.style.transition = theme.transitions.create('opacity', transitionProps);
|
93 | if (onExit) {
|
94 | onExit(node);
|
95 | }
|
96 | });
|
97 | const handleExited = normalizedTransitionCallback(onExited);
|
98 | const handleAddEndListener = next => {
|
99 | if (addEndListener) {
|
100 |
|
101 | addEndListener(nodeRef.current, next);
|
102 | }
|
103 | };
|
104 | return _jsx(TransitionComponent, {
|
105 | appear: appear,
|
106 | in: inProp,
|
107 | nodeRef: enableStrictModeCompat ? nodeRef : undefined,
|
108 | onEnter: handleEnter,
|
109 | onEntered: handleEntered,
|
110 | onEntering: handleEntering,
|
111 | onExit: handleExit,
|
112 | onExited: handleExited,
|
113 | onExiting: handleExiting,
|
114 | addEndListener: handleAddEndListener,
|
115 | timeout: timeout,
|
116 | ...other,
|
117 | children: (state, {
|
118 | ownerState,
|
119 | ...restChildProps
|
120 | }) => {
|
121 | return React.cloneElement(children, {
|
122 | style: {
|
123 | opacity: 0,
|
124 | visibility: state === 'exited' && !inProp ? 'hidden' : undefined,
|
125 | ...styles[state],
|
126 | ...style,
|
127 | ...children.props.style
|
128 | },
|
129 | ref: handleRef,
|
130 | ...restChildProps
|
131 | });
|
132 | }
|
133 | });
|
134 | });
|
135 | process.env.NODE_ENV !== "production" ? Fade.propTypes = {
|
136 |
|
137 |
|
138 |
|
139 |
|
140 | |
141 |
|
142 |
|
143 |
|
144 |
|
145 | addEndListener: PropTypes.func,
|
146 | |
147 |
|
148 |
|
149 |
|
150 |
|
151 | appear: PropTypes.bool,
|
152 | |
153 |
|
154 |
|
155 | children: elementAcceptingRef.isRequired,
|
156 | |
157 |
|
158 |
|
159 |
|
160 | easing: PropTypes.oneOfType([PropTypes.shape({
|
161 | enter: PropTypes.string,
|
162 | exit: PropTypes.string
|
163 | }), PropTypes.string]),
|
164 | |
165 |
|
166 |
|
167 | in: PropTypes.bool,
|
168 | |
169 |
|
170 |
|
171 | onEnter: PropTypes.func,
|
172 | |
173 |
|
174 |
|
175 | onEntered: PropTypes.func,
|
176 | |
177 |
|
178 |
|
179 | onEntering: PropTypes.func,
|
180 | |
181 |
|
182 |
|
183 | onExit: PropTypes.func,
|
184 | |
185 |
|
186 |
|
187 | onExited: PropTypes.func,
|
188 | |
189 |
|
190 |
|
191 | onExiting: PropTypes.func,
|
192 | |
193 |
|
194 |
|
195 | style: PropTypes.object,
|
196 | |
197 |
|
198 |
|
199 |
|
200 |
|
201 |
|
202 |
|
203 |
|
204 | timeout: PropTypes.oneOfType([PropTypes.number, PropTypes.shape({
|
205 | appear: PropTypes.number,
|
206 | enter: PropTypes.number,
|
207 | exit: PropTypes.number
|
208 | })])
|
209 | } : void 0;
|
210 | export default Fade; |
\ | No newline at end of file |