Enforce front project structure through ESLINT (#7863)

Fixes: https://github.com/twentyhq/twenty/issues/7329
This commit is contained in:
Charles Bochet
2024-10-20 20:20:19 +02:00
committed by GitHub
parent f801f3aa9f
commit eccf0bf8ba
260 changed files with 500 additions and 290 deletions

View File

@ -0,0 +1,52 @@
import { useEffect, useRef, useState } from 'react';
import { isDefined } from 'twenty-ui';
const transitionValues = {
transition: {
opacity: { duration: 0.2 },
height: { duration: 0.4 },
},
};
const commonStyles = {
opacity: 0,
height: 0,
...transitionValues,
};
const advancedSectionAnimationConfig = (
isExpanded: boolean,
measuredHeight: number,
) => ({
initial: {
...commonStyles,
},
animate: {
opacity: 1,
height: isExpanded ? measuredHeight : 0,
...transitionValues,
},
exit: {
...commonStyles,
},
});
export const useExpandedHeightAnimation = (isExpanded: boolean) => {
const contentRef = useRef<HTMLDivElement>(null);
const [measuredHeight, setMeasuredHeight] = useState(0);
useEffect(() => {
if (isDefined(contentRef.current)) {
setMeasuredHeight(contentRef.current.scrollHeight);
}
}, [isExpanded]);
return {
contentRef,
measuredHeight,
motionAnimationVariants: advancedSectionAnimationConfig(
isExpanded,
measuredHeight,
),
};
};