Files
twenty/packages/twenty-front/src/modules/ui/navigation/navigation-drawer/components/NavigationDrawerItemsCollapsableContainer.tsx
T
Thomas des Francs e609320666 Squirclesssss 🟦🔵 (#22535)
2026-07-04 07:07:29 +02:00

62 lines
1.8 KiB
TypeScript

import { useIsSettingsPage } from '@/navigation/hooks/useIsSettingsPage';
import { isNavigationDrawerExpandedState } from '@/ui/navigation/states/isNavigationDrawerExpanded';
import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
import { styled } from '@linaria/react';
import { type ReactNode, useContext } from 'react';
import {
type AnimationControls,
motion,
type TargetAndTransition,
} from 'framer-motion';
import { ThemeContext, themeCssVariables } from 'twenty-ui/theme-constants';
const StyledAnimationGroupContainerBase = styled.div``;
const StyledAnimationGroupContainer = motion.create(
StyledAnimationGroupContainerBase,
);
type NavigationDrawerItemsCollapsableContainerProps = {
isGroup?: boolean;
children: ReactNode;
};
export const NavigationDrawerItemsCollapsableContainer = ({
isGroup = false,
children,
}: NavigationDrawerItemsCollapsableContainerProps) => {
const { theme } = useContext(ThemeContext);
const isSettingsPage = useIsSettingsPage();
const isNavigationDrawerExpanded = useAtomStateValue(
isNavigationDrawerExpandedState,
);
const isExpanded = isNavigationDrawerExpanded || isSettingsPage;
let animate: AnimationControls | TargetAndTransition = {
width: 'auto',
backgroundColor: 'transparent',
border: 'none',
};
if (!isExpanded) {
animate = { width: 24 };
if (isGroup) {
animate = {
width: 24,
backgroundColor: theme.background.transparent.lighter,
border: `1px solid ${theme.background.transparent.lighter}`,
borderRadius: themeCssVariables.border.radius.md,
};
}
}
return (
<StyledAnimationGroupContainer
initial={false}
animate={animate}
transition={{
duration: theme.animation.duration.normal,
}}
>
{children}
</StyledAnimationGroupContainer>
);
};