import clsx from 'clsx'; import { PropsWithChildren, useState } from 'react'; import { AutomationTestingProps } from '@/types'; import { Icon } from '@@/Icon'; import { Link } from '@@/Link'; import { CollapseExpandButton } from '@@/CollapseExpandButton'; import { useSidebarState } from '../useSidebarState'; import { Wrapper } from './Wrapper'; import { PathOptions, useSidebarSrefActive } from './useSidebarSrefActive'; import { SidebarTooltip } from './SidebarTooltip'; type Props = { label: string; icon: React.ReactNode; to: string; pathOptions?: PathOptions; params?: object; listId: string; }; export function SidebarParent({ children, icon, label: title, to, params, pathOptions, listId, 'data-cy': dataCy, }: PropsWithChildren) { const anchorProps = useSidebarSrefActive( to, undefined, params, {}, pathOptions ); const hasActiveChild = !!anchorProps.className; const { isOpen: isSidebarOpen } = useSidebarState(); const [isExpanded, setIsExpanded] = useState(hasActiveChild); const parentItem = (
{isSidebarOpen && ( setIsExpanded((isExpanded) => !isExpanded)} isExpanded={isExpanded} listId={listId} /> )}
); const childList = ( ); if (isSidebarOpen) return ( <> {parentItem} {childList} ); return (
  • {title}
  • {children}
    } > {parentItem}
    ); } function SidebarExpandButton({ isExpanded, listId, onClick, }: { onClick(): void; isExpanded: boolean; listId: string; }) { return ( ); }