From cd33471159a52c22fe1912212d0cb8f15360a909 Mon Sep 17 00:00:00 2001 From: Ali Elamir Date: Tue, 6 Aug 2024 12:28:06 +0300 Subject: [PATCH] Animate the Sidebar Objects Tree view opening (#6521) @Bonapara Issue https://github.com/twentyhq/twenty/issues/6485 Introduced the animation when opening the menu. Please let me know if this is fine or I need to make further changes. Thank you. --------- Co-authored-by: bosiraphael --- .../components/ObjectMetadataNavItems.tsx | 73 +++++++++++++------ 1 file changed, 50 insertions(+), 23 deletions(-) diff --git a/packages/twenty-front/src/modules/object-metadata/components/ObjectMetadataNavItems.tsx b/packages/twenty-front/src/modules/object-metadata/components/ObjectMetadataNavItems.tsx index f6d9544411..1c6193313b 100644 --- a/packages/twenty-front/src/modules/object-metadata/components/ObjectMetadataNavItems.tsx +++ b/packages/twenty-front/src/modules/object-metadata/components/ObjectMetadataNavItems.tsx @@ -1,5 +1,4 @@ -import React from 'react'; - +import { AnimatePresence, motion } from 'framer-motion'; import { useLocation } from 'react-router-dom'; import { useRecoilValue } from 'recoil'; import { isDefined, useIcons } from 'twenty-ui'; @@ -17,6 +16,20 @@ import { NavigationDrawerSubItem } from '@/ui/navigation/navigation-drawer/compo import { useNavigationSection } from '@/ui/navigation/navigation-drawer/hooks/useNavigationSection'; import { View } from '@/views/types/View'; import { getObjectMetadataItemViews } from '@/views/utils/getObjectMetadataItemViews'; +import { Theme, useTheme } from '@emotion/react'; + +const navItemsAnimationVariants = (theme: Theme) => ({ + hidden: { + height: 0, + opacity: 0, + marginTop: 0, + }, + visible: { + height: 'auto', + opacity: 1, + marginTop: theme.spacing(1), + }, +}); export const ObjectMetadataNavItems = ({ isRemote }: { isRemote: boolean }) => { const currentUser = useRecoilValue(currentUserState); @@ -36,6 +49,8 @@ export const ObjectMetadataNavItems = ({ isRemote }: { isRemote: boolean }) => { const { records: views } = usePrefetchedData(PrefetchKey.AllViews); const loading = useIsPrefetchLoading(); + const theme = useTheme(); + if (loading && isDefined(currentUser)) { return ; } @@ -96,7 +111,7 @@ export const ObjectMetadataNavItems = ({ isRemote }: { isRemote: boolean }) => { objectMetadataViews.length > 1; return ( - +
{ currentPath === `/objects/${objectMetadataItem.namePlural}` } /> - {shouldSubItemsBeDisplayed && - objectMetadataViews - .sort((viewA, viewB) => - viewA.key === 'INDEX' - ? -1 - : viewA.position - viewB.position, - ) - .map((view) => ( - - ))} - + + {shouldSubItemsBeDisplayed && ( + + {objectMetadataViews + .sort((viewA, viewB) => + viewA.key === 'INDEX' + ? -1 + : viewA.position - viewB.position, + ) + .map((view) => ( +
+ +
+ ))} +
+ )} +
+
); })}