You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
portainer/app/react/sidebar/SidebarItem/utils.ts

25 lines
571 B

import { ReactNode, ReactElement, Children } from 'react';
function isReactElement(element: ReactNode): element is ReactElement {
return (
!!element &&
typeof element === 'object' &&
'type' in element &&
'props' in element
);
}
export function getPaths(element: ReactNode, paths: string[]): string[] {
if (!isReactElement(element)) {
return paths;
}
if (typeof element.props.to === 'undefined') {
return Children.map(element.props.children, (child) =>
getPaths(child, paths)
);
}
return [element.props.to, ...paths];
}