1 | 'use client';
|
2 |
|
3 | import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
4 | import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
5 | import _extends from "@babel/runtime/helpers/esm/extends";
|
6 | import * as React from 'react';
|
7 | import clsx from 'clsx';
|
8 | import PropTypes from 'prop-types';
|
9 | import { Transition } from 'react-transition-group';
|
10 | import useTimeout from '@mui/utils/useTimeout';
|
11 | import elementTypeAcceptingRef from '@mui/utils/elementTypeAcceptingRef';
|
12 | import composeClasses from '@mui/utils/composeClasses';
|
13 | import styled from '../styles/styled';
|
14 | import { useDefaultProps } from '../DefaultPropsProvider';
|
15 | import { duration } from '../styles/createTransitions';
|
16 | import { getTransitionProps } from '../transitions/utils';
|
17 | import useTheme from '../styles/useTheme';
|
18 | import { useForkRef } from '../utils';
|
19 | import { getCollapseUtilityClass } from './collapseClasses';
|
20 | import { jsx as _jsx } from "react/jsx-runtime";
|
21 | var useUtilityClasses = function useUtilityClasses(ownerState) {
|
22 | var orientation = ownerState.orientation,
|
23 | classes = ownerState.classes;
|
24 | var slots = {
|
25 | root: ['root', "".concat(orientation)],
|
26 | entered: ['entered'],
|
27 | hidden: ['hidden'],
|
28 | wrapper: ['wrapper', "".concat(orientation)],
|
29 | wrapperInner: ['wrapperInner', "".concat(orientation)]
|
30 | };
|
31 | return composeClasses(slots, getCollapseUtilityClass, classes);
|
32 | };
|
33 | var CollapseRoot = styled('div', {
|
34 | name: 'MuiCollapse',
|
35 | slot: 'Root',
|
36 | overridesResolver: function overridesResolver(props, styles) {
|
37 | var ownerState = props.ownerState;
|
38 | return [styles.root, styles[ownerState.orientation], ownerState.state === 'entered' && styles.entered, ownerState.state === 'exited' && !ownerState.in && ownerState.collapsedSize === '0px' && styles.hidden];
|
39 | }
|
40 | })(function (_ref) {
|
41 | var theme = _ref.theme,
|
42 | ownerState = _ref.ownerState;
|
43 | return _extends({
|
44 | height: 0,
|
45 | overflow: 'hidden',
|
46 | transition: theme.transitions.create('height')
|
47 | }, ownerState.orientation === 'horizontal' && {
|
48 | height: 'auto',
|
49 | width: 0,
|
50 | transition: theme.transitions.create('width')
|
51 | }, ownerState.state === 'entered' && _extends({
|
52 | height: 'auto',
|
53 | overflow: 'visible'
|
54 | }, ownerState.orientation === 'horizontal' && {
|
55 | width: 'auto'
|
56 | }), ownerState.state === 'exited' && !ownerState.in && ownerState.collapsedSize === '0px' && {
|
57 | visibility: 'hidden'
|
58 | });
|
59 | });
|
60 | var CollapseWrapper = styled('div', {
|
61 | name: 'MuiCollapse',
|
62 | slot: 'Wrapper',
|
63 | overridesResolver: function overridesResolver(props, styles) {
|
64 | return styles.wrapper;
|
65 | }
|
66 | })(function (_ref2) {
|
67 | var ownerState = _ref2.ownerState;
|
68 | return _extends({
|
69 |
|
70 | display: 'flex',
|
71 | width: '100%'
|
72 | }, ownerState.orientation === 'horizontal' && {
|
73 | width: 'auto',
|
74 | height: '100%'
|
75 | });
|
76 | });
|
77 | var CollapseWrapperInner = styled('div', {
|
78 | name: 'MuiCollapse',
|
79 | slot: 'WrapperInner',
|
80 | overridesResolver: function overridesResolver(props, styles) {
|
81 | return styles.wrapperInner;
|
82 | }
|
83 | })(function (_ref3) {
|
84 | var ownerState = _ref3.ownerState;
|
85 | return _extends({
|
86 | width: '100%'
|
87 | }, ownerState.orientation === 'horizontal' && {
|
88 | width: 'auto',
|
89 | height: '100%'
|
90 | });
|
91 | });
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 | var Collapse = React.forwardRef(function Collapse(inProps, ref) {
|
99 | var props = useDefaultProps({
|
100 | props: inProps,
|
101 | name: 'MuiCollapse'
|
102 | });
|
103 | var addEndListener = props.addEndListener,
|
104 | _children = props.children,
|
105 | className = props.className,
|
106 | _props$collapsedSize = props.collapsedSize,
|
107 | collapsedSizeProp = _props$collapsedSize === void 0 ? '0px' : _props$collapsedSize,
|
108 | component = props.component,
|
109 | easing = props.easing,
|
110 | inProp = props.in,
|
111 | onEnter = props.onEnter,
|
112 | onEntered = props.onEntered,
|
113 | onEntering = props.onEntering,
|
114 | onExit = props.onExit,
|
115 | onExited = props.onExited,
|
116 | onExiting = props.onExiting,
|
117 | _props$orientation = props.orientation,
|
118 | orientation = _props$orientation === void 0 ? 'vertical' : _props$orientation,
|
119 | style = props.style,
|
120 | _props$timeout = props.timeout,
|
121 | timeout = _props$timeout === void 0 ? duration.standard : _props$timeout,
|
122 | _props$TransitionComp = props.TransitionComponent,
|
123 | TransitionComponent = _props$TransitionComp === void 0 ? Transition : _props$TransitionComp,
|
124 | other = _objectWithoutProperties(props, ["addEndListener", "children", "className", "collapsedSize", "component", "easing", "in", "onEnter", "onEntered", "onEntering", "onExit", "onExited", "onExiting", "orientation", "style", "timeout", "TransitionComponent"]);
|
125 | var ownerState = _extends({}, props, {
|
126 | orientation: orientation,
|
127 | collapsedSize: collapsedSizeProp
|
128 | });
|
129 | var classes = useUtilityClasses(ownerState);
|
130 | var theme = useTheme();
|
131 | var timer = useTimeout();
|
132 | var wrapperRef = React.useRef(null);
|
133 | var autoTransitionDuration = React.useRef();
|
134 | var collapsedSize = typeof collapsedSizeProp === 'number' ? "".concat(collapsedSizeProp, "px") : collapsedSizeProp;
|
135 | var isHorizontal = orientation === 'horizontal';
|
136 | var size = isHorizontal ? 'width' : 'height';
|
137 | var nodeRef = React.useRef(null);
|
138 | var handleRef = useForkRef(ref, nodeRef);
|
139 | var normalizedTransitionCallback = function normalizedTransitionCallback(callback) {
|
140 | return function (maybeIsAppearing) {
|
141 | if (callback) {
|
142 | var node = nodeRef.current;
|
143 |
|
144 |
|
145 | if (maybeIsAppearing === undefined) {
|
146 | callback(node);
|
147 | } else {
|
148 | callback(node, maybeIsAppearing);
|
149 | }
|
150 | }
|
151 | };
|
152 | };
|
153 | var getWrapperSize = function getWrapperSize() {
|
154 | return wrapperRef.current ? wrapperRef.current[isHorizontal ? 'clientWidth' : 'clientHeight'] : 0;
|
155 | };
|
156 | var handleEnter = normalizedTransitionCallback(function (node, isAppearing) {
|
157 | if (wrapperRef.current && isHorizontal) {
|
158 |
|
159 | wrapperRef.current.style.position = 'absolute';
|
160 | }
|
161 | node.style[size] = collapsedSize;
|
162 | if (onEnter) {
|
163 | onEnter(node, isAppearing);
|
164 | }
|
165 | });
|
166 | var handleEntering = normalizedTransitionCallback(function (node, isAppearing) {
|
167 | var wrapperSize = getWrapperSize();
|
168 | if (wrapperRef.current && isHorizontal) {
|
169 |
|
170 | wrapperRef.current.style.position = '';
|
171 | }
|
172 | var _getTransitionProps = getTransitionProps({
|
173 | style: style,
|
174 | timeout: timeout,
|
175 | easing: easing
|
176 | }, {
|
177 | mode: 'enter'
|
178 | }),
|
179 | transitionDuration = _getTransitionProps.duration,
|
180 | transitionTimingFunction = _getTransitionProps.easing;
|
181 | if (timeout === 'auto') {
|
182 | var duration2 = theme.transitions.getAutoHeightDuration(wrapperSize);
|
183 | node.style.transitionDuration = "".concat(duration2, "ms");
|
184 | autoTransitionDuration.current = duration2;
|
185 | } else {
|
186 | node.style.transitionDuration = typeof transitionDuration === 'string' ? transitionDuration : "".concat(transitionDuration, "ms");
|
187 | }
|
188 | node.style[size] = "".concat(wrapperSize, "px");
|
189 | node.style.transitionTimingFunction = transitionTimingFunction;
|
190 | if (onEntering) {
|
191 | onEntering(node, isAppearing);
|
192 | }
|
193 | });
|
194 | var handleEntered = normalizedTransitionCallback(function (node, isAppearing) {
|
195 | node.style[size] = 'auto';
|
196 | if (onEntered) {
|
197 | onEntered(node, isAppearing);
|
198 | }
|
199 | });
|
200 | var handleExit = normalizedTransitionCallback(function (node) {
|
201 | node.style[size] = "".concat(getWrapperSize(), "px");
|
202 | if (onExit) {
|
203 | onExit(node);
|
204 | }
|
205 | });
|
206 | var handleExited = normalizedTransitionCallback(onExited);
|
207 | var handleExiting = normalizedTransitionCallback(function (node) {
|
208 | var wrapperSize = getWrapperSize();
|
209 | var _getTransitionProps2 = getTransitionProps({
|
210 | style: style,
|
211 | timeout: timeout,
|
212 | easing: easing
|
213 | }, {
|
214 | mode: 'exit'
|
215 | }),
|
216 | transitionDuration = _getTransitionProps2.duration,
|
217 | transitionTimingFunction = _getTransitionProps2.easing;
|
218 | if (timeout === 'auto') {
|
219 |
|
220 |
|
221 | var duration2 = theme.transitions.getAutoHeightDuration(wrapperSize);
|
222 | node.style.transitionDuration = "".concat(duration2, "ms");
|
223 | autoTransitionDuration.current = duration2;
|
224 | } else {
|
225 | node.style.transitionDuration = typeof transitionDuration === 'string' ? transitionDuration : "".concat(transitionDuration, "ms");
|
226 | }
|
227 | node.style[size] = collapsedSize;
|
228 | node.style.transitionTimingFunction = transitionTimingFunction;
|
229 | if (onExiting) {
|
230 | onExiting(node);
|
231 | }
|
232 | });
|
233 | var handleAddEndListener = function handleAddEndListener(next) {
|
234 | if (timeout === 'auto') {
|
235 | timer.start(autoTransitionDuration.current || 0, next);
|
236 | }
|
237 | if (addEndListener) {
|
238 |
|
239 | addEndListener(nodeRef.current, next);
|
240 | }
|
241 | };
|
242 | return _jsx(TransitionComponent, _extends({
|
243 | in: inProp,
|
244 | onEnter: handleEnter,
|
245 | onEntered: handleEntered,
|
246 | onEntering: handleEntering,
|
247 | onExit: handleExit,
|
248 | onExited: handleExited,
|
249 | onExiting: handleExiting,
|
250 | addEndListener: handleAddEndListener,
|
251 | nodeRef: nodeRef,
|
252 | timeout: timeout === 'auto' ? null : timeout
|
253 | }, other, {
|
254 | children: function children(state, childProps) {
|
255 | return _jsx(CollapseRoot, _extends({
|
256 | as: component,
|
257 | className: clsx(classes.root, className, {
|
258 | 'entered': classes.entered,
|
259 | 'exited': !inProp && collapsedSize === '0px' && classes.hidden
|
260 | }[state]),
|
261 | style: _extends(_defineProperty({}, isHorizontal ? 'minWidth' : 'minHeight', collapsedSize), style),
|
262 | ref: handleRef
|
263 | }, childProps, {
|
264 |
|
265 |
|
266 | ownerState: _extends({}, ownerState, {
|
267 | state: state
|
268 | }),
|
269 | children: _jsx(CollapseWrapper, {
|
270 | ownerState: _extends({}, ownerState, {
|
271 | state: state
|
272 | }),
|
273 | className: classes.wrapper,
|
274 | ref: wrapperRef,
|
275 | children: _jsx(CollapseWrapperInner, {
|
276 | ownerState: _extends({}, ownerState, {
|
277 | state: state
|
278 | }),
|
279 | className: classes.wrapperInner,
|
280 | children: _children
|
281 | })
|
282 | })
|
283 | }));
|
284 | }
|
285 | }));
|
286 | });
|
287 | process.env.NODE_ENV !== "production" ? Collapse.propTypes = {
|
288 |
|
289 |
|
290 |
|
291 |
|
292 | |
293 |
|
294 |
|
295 |
|
296 |
|
297 | addEndListener: PropTypes.func,
|
298 | |
299 |
|
300 |
|
301 | children: PropTypes.node,
|
302 | |
303 |
|
304 |
|
305 | classes: PropTypes.object,
|
306 | |
307 |
|
308 |
|
309 | className: PropTypes.string,
|
310 | |
311 |
|
312 |
|
313 |
|
314 | collapsedSize: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
315 | |
316 |
|
317 |
|
318 |
|
319 | component: elementTypeAcceptingRef,
|
320 | |
321 |
|
322 |
|
323 |
|
324 | easing: PropTypes.oneOfType([PropTypes.shape({
|
325 | enter: PropTypes.string,
|
326 | exit: PropTypes.string
|
327 | }), PropTypes.string]),
|
328 | |
329 |
|
330 |
|
331 | in: PropTypes.bool,
|
332 | |
333 |
|
334 |
|
335 | onEnter: PropTypes.func,
|
336 | |
337 |
|
338 |
|
339 | onEntered: PropTypes.func,
|
340 | |
341 |
|
342 |
|
343 | onEntering: PropTypes.func,
|
344 | |
345 |
|
346 |
|
347 | onExit: PropTypes.func,
|
348 | |
349 |
|
350 |
|
351 | onExited: PropTypes.func,
|
352 | |
353 |
|
354 |
|
355 | onExiting: PropTypes.func,
|
356 | |
357 |
|
358 |
|
359 |
|
360 | orientation: PropTypes.oneOf(['horizontal', 'vertical']),
|
361 | |
362 |
|
363 |
|
364 | style: PropTypes.object,
|
365 | |
366 |
|
367 |
|
368 | sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
|
369 | |
370 |
|
371 |
|
372 |
|
373 |
|
374 |
|
375 |
|
376 | timeout: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number, PropTypes.shape({
|
377 | appear: PropTypes.number,
|
378 | enter: PropTypes.number,
|
379 | exit: PropTypes.number
|
380 | })])
|
381 | } : void 0;
|
382 | Collapse.muiSupportAuto = true;
|
383 | export default Collapse; |
\ | No newline at end of file |