Spaces:
Sleeping
Sleeping
File size: 12,782 Bytes
56fda74 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 |
'use client';
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
import _extends from "@babel/runtime/helpers/esm/extends";
const _excluded = ["addEndListener", "children", "className", "collapsedSize", "component", "easing", "in", "onEnter", "onEntered", "onEntering", "onExit", "onExited", "onExiting", "orientation", "style", "timeout", "TransitionComponent"];
import * as React from 'react';
import clsx from 'clsx';
import PropTypes from 'prop-types';
import { Transition } from 'react-transition-group';
import useTimeout from '@mui/utils/useTimeout';
import elementTypeAcceptingRef from '@mui/utils/elementTypeAcceptingRef';
import composeClasses from '@mui/utils/composeClasses';
import styled from '../styles/styled';
import { useDefaultProps } from '../DefaultPropsProvider';
import { duration } from '../styles/createTransitions';
import { getTransitionProps } from '../transitions/utils';
import useTheme from '../styles/useTheme';
import { useForkRef } from '../utils';
import { getCollapseUtilityClass } from './collapseClasses';
import { jsx as _jsx } from "react/jsx-runtime";
const useUtilityClasses = ownerState => {
const {
orientation,
classes
} = ownerState;
const slots = {
root: ['root', `${orientation}`],
entered: ['entered'],
hidden: ['hidden'],
wrapper: ['wrapper', `${orientation}`],
wrapperInner: ['wrapperInner', `${orientation}`]
};
return composeClasses(slots, getCollapseUtilityClass, classes);
};
const CollapseRoot = styled('div', {
name: 'MuiCollapse',
slot: 'Root',
overridesResolver: (props, styles) => {
const {
ownerState
} = props;
return [styles.root, styles[ownerState.orientation], ownerState.state === 'entered' && styles.entered, ownerState.state === 'exited' && !ownerState.in && ownerState.collapsedSize === '0px' && styles.hidden];
}
})(({
theme,
ownerState
}) => _extends({
height: 0,
overflow: 'hidden',
transition: theme.transitions.create('height')
}, ownerState.orientation === 'horizontal' && {
height: 'auto',
width: 0,
transition: theme.transitions.create('width')
}, ownerState.state === 'entered' && _extends({
height: 'auto',
overflow: 'visible'
}, ownerState.orientation === 'horizontal' && {
width: 'auto'
}), ownerState.state === 'exited' && !ownerState.in && ownerState.collapsedSize === '0px' && {
visibility: 'hidden'
}));
const CollapseWrapper = styled('div', {
name: 'MuiCollapse',
slot: 'Wrapper',
overridesResolver: (props, styles) => styles.wrapper
})(({
ownerState
}) => _extends({
// Hack to get children with a negative margin to not falsify the height computation.
display: 'flex',
width: '100%'
}, ownerState.orientation === 'horizontal' && {
width: 'auto',
height: '100%'
}));
const CollapseWrapperInner = styled('div', {
name: 'MuiCollapse',
slot: 'WrapperInner',
overridesResolver: (props, styles) => styles.wrapperInner
})(({
ownerState
}) => _extends({
width: '100%'
}, ownerState.orientation === 'horizontal' && {
width: 'auto',
height: '100%'
}));
/**
* The Collapse transition is used by the
* [Vertical Stepper](/material-ui/react-stepper/#vertical-stepper) StepContent component.
* It uses [react-transition-group](https://github.com/reactjs/react-transition-group) internally.
*/
const Collapse = /*#__PURE__*/React.forwardRef(function Collapse(inProps, ref) {
const props = useDefaultProps({
props: inProps,
name: 'MuiCollapse'
});
const {
addEndListener,
children,
className,
collapsedSize: collapsedSizeProp = '0px',
component,
easing,
in: inProp,
onEnter,
onEntered,
onEntering,
onExit,
onExited,
onExiting,
orientation = 'vertical',
style,
timeout = duration.standard,
// eslint-disable-next-line react/prop-types
TransitionComponent = Transition
} = props,
other = _objectWithoutPropertiesLoose(props, _excluded);
const ownerState = _extends({}, props, {
orientation,
collapsedSize: collapsedSizeProp
});
const classes = useUtilityClasses(ownerState);
const theme = useTheme();
const timer = useTimeout();
const wrapperRef = React.useRef(null);
const autoTransitionDuration = React.useRef();
const collapsedSize = typeof collapsedSizeProp === 'number' ? `${collapsedSizeProp}px` : collapsedSizeProp;
const isHorizontal = orientation === 'horizontal';
const size = isHorizontal ? 'width' : 'height';
const nodeRef = React.useRef(null);
const handleRef = useForkRef(ref, nodeRef);
const normalizedTransitionCallback = callback => maybeIsAppearing => {
if (callback) {
const node = nodeRef.current;
// onEnterXxx and onExitXxx callbacks have a different arguments.length value.
if (maybeIsAppearing === undefined) {
callback(node);
} else {
callback(node, maybeIsAppearing);
}
}
};
const getWrapperSize = () => wrapperRef.current ? wrapperRef.current[isHorizontal ? 'clientWidth' : 'clientHeight'] : 0;
const handleEnter = normalizedTransitionCallback((node, isAppearing) => {
if (wrapperRef.current && isHorizontal) {
// Set absolute position to get the size of collapsed content
wrapperRef.current.style.position = 'absolute';
}
node.style[size] = collapsedSize;
if (onEnter) {
onEnter(node, isAppearing);
}
});
const handleEntering = normalizedTransitionCallback((node, isAppearing) => {
const wrapperSize = getWrapperSize();
if (wrapperRef.current && isHorizontal) {
// After the size is read reset the position back to default
wrapperRef.current.style.position = '';
}
const {
duration: transitionDuration,
easing: transitionTimingFunction
} = getTransitionProps({
style,
timeout,
easing
}, {
mode: 'enter'
});
if (timeout === 'auto') {
const duration2 = theme.transitions.getAutoHeightDuration(wrapperSize);
node.style.transitionDuration = `${duration2}ms`;
autoTransitionDuration.current = duration2;
} else {
node.style.transitionDuration = typeof transitionDuration === 'string' ? transitionDuration : `${transitionDuration}ms`;
}
node.style[size] = `${wrapperSize}px`;
node.style.transitionTimingFunction = transitionTimingFunction;
if (onEntering) {
onEntering(node, isAppearing);
}
});
const handleEntered = normalizedTransitionCallback((node, isAppearing) => {
node.style[size] = 'auto';
if (onEntered) {
onEntered(node, isAppearing);
}
});
const handleExit = normalizedTransitionCallback(node => {
node.style[size] = `${getWrapperSize()}px`;
if (onExit) {
onExit(node);
}
});
const handleExited = normalizedTransitionCallback(onExited);
const handleExiting = normalizedTransitionCallback(node => {
const wrapperSize = getWrapperSize();
const {
duration: transitionDuration,
easing: transitionTimingFunction
} = getTransitionProps({
style,
timeout,
easing
}, {
mode: 'exit'
});
if (timeout === 'auto') {
// TODO: rename getAutoHeightDuration to something more generic (width support)
// Actually it just calculates animation duration based on size
const duration2 = theme.transitions.getAutoHeightDuration(wrapperSize);
node.style.transitionDuration = `${duration2}ms`;
autoTransitionDuration.current = duration2;
} else {
node.style.transitionDuration = typeof transitionDuration === 'string' ? transitionDuration : `${transitionDuration}ms`;
}
node.style[size] = collapsedSize;
node.style.transitionTimingFunction = transitionTimingFunction;
if (onExiting) {
onExiting(node);
}
});
const handleAddEndListener = next => {
if (timeout === 'auto') {
timer.start(autoTransitionDuration.current || 0, next);
}
if (addEndListener) {
// Old call signature before `react-transition-group` implemented `nodeRef`
addEndListener(nodeRef.current, next);
}
};
return /*#__PURE__*/_jsx(TransitionComponent, _extends({
in: inProp,
onEnter: handleEnter,
onEntered: handleEntered,
onEntering: handleEntering,
onExit: handleExit,
onExited: handleExited,
onExiting: handleExiting,
addEndListener: handleAddEndListener,
nodeRef: nodeRef,
timeout: timeout === 'auto' ? null : timeout
}, other, {
children: (state, childProps) => /*#__PURE__*/_jsx(CollapseRoot, _extends({
as: component,
className: clsx(classes.root, className, {
'entered': classes.entered,
'exited': !inProp && collapsedSize === '0px' && classes.hidden
}[state]),
style: _extends({
[isHorizontal ? 'minWidth' : 'minHeight']: collapsedSize
}, style),
ref: handleRef
}, childProps, {
// `ownerState` is set after `childProps` to override any existing `ownerState` property in `childProps`
// that might have been forwarded from the Transition component.
ownerState: _extends({}, ownerState, {
state
}),
children: /*#__PURE__*/_jsx(CollapseWrapper, {
ownerState: _extends({}, ownerState, {
state
}),
className: classes.wrapper,
ref: wrapperRef,
children: /*#__PURE__*/_jsx(CollapseWrapperInner, {
ownerState: _extends({}, ownerState, {
state
}),
className: classes.wrapperInner,
children: children
})
})
}))
}));
});
process.env.NODE_ENV !== "production" ? Collapse.propTypes /* remove-proptypes */ = {
// βββββββββββββββββββββββββββββββ Warning βββββββββββββββββββββββββββββββ
// β These PropTypes are generated from the TypeScript type definitions. β
// β To update them, edit the d.ts file and run `pnpm proptypes`. β
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
/**
* Add a custom transition end trigger. Called with the transitioning DOM
* node and a done callback. Allows for more fine grained transition end
* logic. Note: Timeouts are still used as a fallback if provided.
*/
addEndListener: PropTypes.func,
/**
* The content node to be collapsed.
*/
children: PropTypes.node,
/**
* Override or extend the styles applied to the component.
*/
classes: PropTypes.object,
/**
* @ignore
*/
className: PropTypes.string,
/**
* The width (horizontal) or height (vertical) of the container when collapsed.
* @default '0px'
*/
collapsedSize: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
/**
* The component used for the root node.
* Either a string to use a HTML element or a component.
*/
component: elementTypeAcceptingRef,
/**
* The transition timing function.
* You may specify a single easing or a object containing enter and exit values.
*/
easing: PropTypes.oneOfType([PropTypes.shape({
enter: PropTypes.string,
exit: PropTypes.string
}), PropTypes.string]),
/**
* If `true`, the component will transition in.
*/
in: PropTypes.bool,
/**
* @ignore
*/
onEnter: PropTypes.func,
/**
* @ignore
*/
onEntered: PropTypes.func,
/**
* @ignore
*/
onEntering: PropTypes.func,
/**
* @ignore
*/
onExit: PropTypes.func,
/**
* @ignore
*/
onExited: PropTypes.func,
/**
* @ignore
*/
onExiting: PropTypes.func,
/**
* The transition orientation.
* @default 'vertical'
*/
orientation: PropTypes.oneOf(['horizontal', 'vertical']),
/**
* @ignore
*/
style: PropTypes.object,
/**
* The system prop that allows defining system overrides as well as additional CSS styles.
*/
sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
/**
* The duration for the transition, in milliseconds.
* You may specify a single timeout for all transitions, or individually with an object.
*
* Set to 'auto' to automatically calculate transition time based on height.
* @default duration.standard
*/
timeout: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number, PropTypes.shape({
appear: PropTypes.number,
enter: PropTypes.number,
exit: PropTypes.number
})])
} : void 0;
Collapse.muiSupportAuto = true;
export default Collapse; |