mirror of
https://github.com/portainer/portainer.git
synced 2025-07-25 00:09:40 +02:00
feat(sidebar): implement new design [EE-3447] (#7118)
This commit is contained in:
parent
e5e57978af
commit
ed8f9b5931
54 changed files with 1928 additions and 857 deletions
28
app/react/sidebar/SidebarItem/utils.ts
Normal file
28
app/react/sidebar/SidebarItem/utils.ts
Normal file
|
@ -0,0 +1,28 @@
|
|||
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 getPathsForChildren(children: ReactNode): string[] {
|
||||
return Children.map(children, (child) => getPaths(child, []))?.flat() || [];
|
||||
}
|
||||
|
||||
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];
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue