mirror of
https://github.com/Unleash/unleash.git
synced 2025-05-03 01:18:43 +02:00
Adds a Biome rule for "no unused imports", which is something we sometimes have trouble catching. We're adding this as a warning for now. It is safely and easily fixable with `yarn lint:fix`.  
66 lines
1.6 KiB
TypeScript
66 lines
1.6 KiB
TypeScript
import { CSSProperties, useEffect, useState, useRef, FC } from 'react';
|
|
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
|
|
|
|
interface IAnimateOnMountProps {
|
|
mounted: boolean;
|
|
enter: CSSProperties;
|
|
start: CSSProperties;
|
|
leave?: CSSProperties;
|
|
onStart?: () => void;
|
|
onEnd?: () => void;
|
|
}
|
|
|
|
const AnimateOnMount: FC<IAnimateOnMountProps> = ({
|
|
mounted,
|
|
enter,
|
|
start,
|
|
leave,
|
|
children,
|
|
onStart,
|
|
onEnd,
|
|
}) => {
|
|
const [show, setShow] = useState(mounted);
|
|
const [styles, setStyles] = useState<CSSProperties>({});
|
|
const mountedRef = useRef<null | boolean>(null);
|
|
|
|
useEffect(() => {
|
|
if (mountedRef.current !== mounted || mountedRef === null) {
|
|
if (mounted) {
|
|
setShow(true);
|
|
onStart?.();
|
|
setTimeout(() => {
|
|
setStyles(enter);
|
|
}, 50);
|
|
} else {
|
|
if (!leave) {
|
|
setShow(false);
|
|
}
|
|
setStyles(leave || {});
|
|
}
|
|
}
|
|
}, [mounted, enter, onStart, leave]);
|
|
|
|
const onTransitionEnd = () => {
|
|
if (!mounted) {
|
|
setShow(false);
|
|
onEnd?.();
|
|
}
|
|
};
|
|
|
|
return (
|
|
<ConditionallyRender
|
|
condition={show}
|
|
show={
|
|
<div
|
|
onTransitionEnd={onTransitionEnd}
|
|
style={{ ...start, ...styles }}
|
|
>
|
|
{children}
|
|
</div>
|
|
}
|
|
/>
|
|
);
|
|
};
|
|
|
|
export default AnimateOnMount;
|