@mui/base
Version:
MUI Base is a library of headless ('unstyled') React components and low-level hooks. You gain complete control over your app's CSS and accessibility features.
61 lines (60 loc) • 1.69 kB
JavaScript
'use client';
import * as React from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import { useTransitionStateManager } from "../useTransition/index.js";
import { jsx as _jsx } from "react/jsx-runtime";
/**
*
* Demos:
*
* - [Transitions](https://mui.com/base-ui/react-transitions/)
*
* API:
*
* - [CssAnimation API](https://mui.com/base-ui/react-transitions/components-api/#css-animation)
*/
function CssAnimation(props) {
const {
children,
className,
enterAnimationName,
enterClassName,
exitAnimationName,
exitClassName,
...other
} = props;
const {
requestedEnter,
onExited
} = useTransitionStateManager();
const hasExited = React.useRef(true);
React.useEffect(() => {
if (requestedEnter && hasExited.current) {
hasExited.current = false;
}
}, [requestedEnter]);
const handleAnimationEnd = React.useCallback(event => {
if (event.animationName === exitAnimationName) {
onExited();
hasExited.current = true;
} else if (event.animationName === enterAnimationName) {
hasExited.current = false;
}
}, [onExited, exitAnimationName, enterAnimationName]);
return /*#__PURE__*/_jsx("div", {
onAnimationEnd: handleAnimationEnd,
className: clsx(className, requestedEnter ? enterClassName : exitClassName),
...other,
children: children
});
}
process.env.NODE_ENV !== "production" ? CssAnimation.propTypes = {
children: PropTypes.node,
className: PropTypes.string,
enterAnimationName: PropTypes.string,
enterClassName: PropTypes.string,
exitAnimationName: PropTypes.string,
exitClassName: PropTypes.string
} : void 0;
export { CssAnimation };