import clsx from 'clsx'; import { ChevronDown } from 'lucide-react'; import { PropsWithChildren, useState } from 'react'; import { Icon } from '@@/Icon'; import { Link } from '@@/Link'; 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; 'data-cy': string; pathOptions?: PathOptions; params?: object; }; export function SidebarParent({ children, icon, label: title, to, params, pathOptions, '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 && ( )}
); const childList = ( ); if (isSidebarOpen) return ( <> {parentItem} {childList} ); return (
  • {title}
  • {children}
    } > {parentItem}
    ); }