Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Animated the Sidebar Objects Tree view opening/closing #9287

Merged
merged 13 commits into from
Jan 8, 2025
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { NavigationDrawerInput } from '@/ui/navigation/navigation-drawer/compone
import { NavigationDrawerItem } from '@/ui/navigation/navigation-drawer/components/NavigationDrawerItem';
import { NavigationDrawerItemsCollapsableContainer } from '@/ui/navigation/navigation-drawer/components/NavigationDrawerItemsCollapsableContainer';
import { NavigationDrawerSubItem } from '@/ui/navigation/navigation-drawer/components/NavigationDrawerSubItem';
import { NavigationDrawerSubItemAnimatedExpandableContainer } from '@/ui/navigation/navigation-drawer/components/NavigationDrawerSubItemAnimatedExpandableContainer';
import { getNavigationSubItemLeftAdornment } from '@/ui/navigation/navigation-drawer/utils/getNavigationSubItemLeftAdornment';
import { Droppable } from '@hello-pangea/dnd';
import { useContext, useState } from 'react';
Expand Down Expand Up @@ -158,7 +159,10 @@ export const CurrentWorkspaceMemberFavorites = ({
</FavoritesDroppable>
)}

{isOpen && (
<NavigationDrawerSubItemAnimatedExpandableContainer
isOpen={isOpen}
key={`folder-${folder.folderId}`}
>
<Droppable droppableId={`folder-${folder.folderId}`}>
{(provided) => (
<div
Expand Down Expand Up @@ -202,7 +206,7 @@ export const CurrentWorkspaceMemberFavorites = ({
</div>
)}
</Droppable>
)}
</NavigationDrawerSubItemAnimatedExpandableContainer>
</NavigationDrawerItemsCollapsableContainer>

{createPortal(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { PrefetchKey } from '@/prefetch/types/PrefetchKey';
import { NavigationDrawerItem } from '@/ui/navigation/navigation-drawer/components/NavigationDrawerItem';
import { NavigationDrawerItemsCollapsableContainer } from '@/ui/navigation/navigation-drawer/components/NavigationDrawerItemsCollapsableContainer';
import { NavigationDrawerSubItem } from '@/ui/navigation/navigation-drawer/components/NavigationDrawerSubItem';
import { NavigationDrawerSubItemAnimatedExpandableContainer } from '@/ui/navigation/navigation-drawer/components/NavigationDrawerSubItemAnimatedExpandableContainer';
import { getNavigationSubItemLeftAdornment } from '@/ui/navigation/navigation-drawer/utils/getNavigationSubItemLeftAdornment';
import { View } from '@/views/types/View';
import { getObjectMetadataItemViews } from '@/views/utils/getObjectMetadataItemViews';
Expand Down Expand Up @@ -66,8 +67,11 @@ export const NavigationDrawerItemForObjectMetadataItem = ({
Icon={getIcon(objectMetadataItem.icon)}
active={isActive}
/>
{shouldSubItemsBeDisplayed &&
sortedObjectMetadataViews.map((view, index) => (

<NavigationDrawerSubItemAnimatedExpandableContainer
isOpen={shouldSubItemsBeDisplayed}
>
{sortedObjectMetadataViews.map((view, index) => (
<NavigationDrawerSubItem
label={view.name}
to={`/objects/${objectMetadataItem.namePlural}?view=${view.id}`}
Expand All @@ -81,6 +85,7 @@ export const NavigationDrawerItemForObjectMetadataItem = ({
key={view.id}
/>
))}
</NavigationDrawerSubItemAnimatedExpandableContainer>
</NavigationDrawerItemsCollapsableContainer>
);
};
ehconitin marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,19 @@ const advancedSectionAnimationConfig = (
isExpanded: boolean,
dimension: AnimationDimension,
measuredValue?: number,
ehconitin marked this conversation as resolved.
Show resolved Hide resolved
fitContent?: boolean,
) => ({
initial: {
...commonStyles(dimension),
},
animate: {
opacity: 1,
[dimension]: isExpanded
? dimension === 'width'
? '100%'
: measuredValue
? fitContent
ehconitin marked this conversation as resolved.
Show resolved Hide resolved
? 'fit-content'
: dimension === 'width'
? '100%'
: measuredValue
: 0,
...getTransitionValues(dimension),
},
Expand All @@ -42,6 +45,7 @@ const advancedSectionAnimationConfig = (
export const useExpandedAnimation = (
isExpanded: boolean,
dimension: AnimationDimension = 'height',
fitContent?: boolean,
) => {
const contentRef = useRef<HTMLDivElement>(null);
const [measuredValue, setMeasuredValue] = useState(0);
Expand All @@ -58,6 +62,7 @@ export const useExpandedAnimation = (
isExpanded,
dimension,
dimension === 'height' ? measuredValue : undefined,
fitContent,
),
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { useExpandedAnimation } from '@/settings/hooks/useExpandedAnimation';
import styled from '@emotion/styled';
import { AnimatePresence, motion } from 'framer-motion';
import { ReactNode } from 'react';

const StyledAnimatedContainer = styled(motion.div)`
display: flex;
flex-direction: column;
overflow: hidden;
width: 100%;
`;

type NavigationDrawerSubItemAnimatedExpandableContainerProps = {
children: ReactNode;
isOpen?: boolean;
};

export const NavigationDrawerSubItemAnimatedExpandableContainer = ({
ehconitin marked this conversation as resolved.
Show resolved Hide resolved
ehconitin marked this conversation as resolved.
Show resolved Hide resolved
children,
isOpen = false,
}: NavigationDrawerSubItemAnimatedExpandableContainerProps) => {
const { contentRef, motionAnimationVariants } = useExpandedAnimation(
isOpen,
'height',
true,
);

return (
<AnimatePresence>
{isOpen && (
<StyledAnimatedContainer
ref={contentRef}
initial="initial"
animate="animate"
exit="exit"
variants={motionAnimationVariants}
ehconitin marked this conversation as resolved.
Show resolved Hide resolved
>
{children}
</StyledAnimatedContainer>
)}
</AnimatePresence>
);
};
Loading