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, childProps) => {
|
118 | return React.cloneElement(children, {
|
119 | style: {
|
120 | opacity: 0,
|
121 | visibility: state === 'exited' && !inProp ? 'hidden' : undefined,
|
122 | ...styles[state],
|
123 | ...style,
|
124 | ...children.props.style
|
125 | },
|
126 | ref: handleRef,
|
127 | ...childProps
|
128 | });
|
129 | }
|
130 | });
|
131 | });
|
132 | process.env.NODE_ENV !== "production" ? Fade.propTypes = {
|
133 |
|
134 |
|
135 |
|
136 |
|
137 | |
138 |
|
139 |
|
140 |
|
141 |
|
142 | addEndListener: PropTypes.func,
|
143 | |
144 |
|
145 |
|
146 |
|
147 |
|
148 | appear: PropTypes.bool,
|
149 | |
150 |
|
151 |
|
152 | children: elementAcceptingRef.isRequired,
|
153 | |
154 |
|
155 |
|
156 |
|
157 | easing: PropTypes.oneOfType([PropTypes.shape({
|
158 | enter: PropTypes.string,
|
159 | exit: PropTypes.string
|
160 | }), PropTypes.string]),
|
161 | |
162 |
|
163 |
|
164 | in: PropTypes.bool,
|
165 | |
166 |
|
167 |
|
168 | onEnter: PropTypes.func,
|
169 | |
170 |
|
171 |
|
172 | onEntered: PropTypes.func,
|
173 | |
174 |
|
175 |
|
176 | onEntering: PropTypes.func,
|
177 | |
178 |
|
179 |
|
180 | onExit: PropTypes.func,
|
181 | |
182 |
|
183 |
|
184 | onExited: PropTypes.func,
|
185 | |
186 |
|
187 |
|
188 | onExiting: PropTypes.func,
|
189 | |
190 |
|
191 |
|
192 | style: PropTypes.object,
|
193 | |
194 |
|
195 |
|
196 |
|
197 |
|
198 |
|
199 |
|
200 |
|
201 | timeout: PropTypes.oneOfType([PropTypes.number, PropTypes.shape({
|
202 | appear: PropTypes.number,
|
203 | enter: PropTypes.number,
|
204 | exit: PropTypes.number
|
205 | })])
|
206 | } : void 0;
|
207 | export default Fade; |
\ | No newline at end of file |