The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
import { useIsNavigationDrawerContentExpanded } from '@/ui/navigation/navigation-drawer/hooks/useIsNavigationDrawerContentExpanded';
import { NavigationDrawerSection } from '@/ui/navigation/navigation-drawer/components/NavigationDrawerSection';
import { NavigationDrawerSectionTitle } from '@/ui/navigation/navigation-drawer/components/NavigationDrawerSectionTitle';
import { useNavigationSection } from '@/ui/navigation/navigation-drawer/hooks/useNavigationSection';
import { styled } from '@linaria/react';
import { type ReactNode } from 'react';
import { Collapsible } from 'twenty-ui/primitives/layout';
import { themeCssVariables } from 'twenty-ui/theme';
const StyledItems = styled.div`
display: flex;
flex-direction: column;
gap: ${themeCssVariables.betweenSiblingsGap};
`;
type CollapsibleNavigationDrawerSectionProps = {
// Namespaced id (e.g. 'settings/User') used to persist open/closed state.
sectionId: string;
label: string;
children: ReactNode;
rightIcon?: ReactNode;
alwaysShowRightIcon?: boolean;
};
export const CollapsibleNavigationDrawerSection = ({
sectionId,
label,
children,
rightIcon,
alwaysShowRightIcon,
}: CollapsibleNavigationDrawerSectionProps) => {
const isNavigationDrawerExpanded = useIsNavigationDrawerContentExpanded();
const { toggleNavigationSection, isNavigationSectionOpen } =
useNavigationSection(sectionId);
return (
<NavigationDrawerSection>
{isNavigationDrawerExpanded && (
<NavigationDrawerSectionTitle
label={label}
rightIcon={rightIcon}
alwaysShowRightIcon={alwaysShowRightIcon}
onClick={toggleNavigationSection}
isOpen={isNavigationSectionOpen}
/>
)}
<Collapsible.Root
open={!isNavigationDrawerExpanded || isNavigationSectionOpen}
>
<Collapsible.Panel dimension="height" containAnimation>
<StyledItems>{children}</StyledItems>
</Collapsible.Panel>
</Collapsible.Root>
</NavigationDrawerSection>
);
};