in beta/src/components/Layout/Sidebar/SidebarRouteTree.tsx [20:70]
function CollapseWrapper({
isExpanded,
duration,
children,
}: {
isExpanded: boolean;
duration: number;
children: any;
}) {
const ref = React.useRef<HTMLDivElement | null>(null);
const timeoutRef = React.useRef<number | null>(null);
const {getCollapseProps} = useCollapse({
isExpanded,
duration,
});
// Disable pointer events while animating.
const isExpandedRef = React.useRef(isExpanded);
if (typeof window !== 'undefined') {
// eslint-disable-next-line react-hooks/rules-of-hooks
useLayoutEffect(() => {
const wasExpanded = isExpandedRef.current;
if (wasExpanded === isExpanded) {
return;
}
isExpandedRef.current = isExpanded;
if (ref.current !== null) {
const node: HTMLDivElement = ref.current;
node.style.pointerEvents = 'none';
if (timeoutRef.current !== null) {
window.clearTimeout(timeoutRef.current);
}
timeoutRef.current = window.setTimeout(() => {
node.style.pointerEvents = '';
}, duration + 100);
}
});
}
return (
<div
ref={ref}
style={{
opacity: isExpanded ? 1 : 0.5,
transition: `opacity ${duration}ms ease-in-out`,
animation: `nav-fadein ${duration}ms ease-in-out`,
}}>
<div {...getCollapseProps()}>{children}</div>
</div>
);
}