diff --git a/packages/react-navigation-visualizer/webui/src/NavigationTree.tsx b/packages/react-navigation-visualizer/webui/src/NavigationTree.tsx index 4c34de1..e08584e 100644 --- a/packages/react-navigation-visualizer/webui/src/NavigationTree.tsx +++ b/packages/react-navigation-visualizer/webui/src/NavigationTree.tsx @@ -25,14 +25,26 @@ export function NavigationTree({ logs }: Props) { Previous state - {hasPreviousItem && } + {hasPreviousItem && ( + + )} Current state - {hasCurrentItem && } + {hasCurrentItem && ( + + )} @@ -89,9 +101,17 @@ const LeafTitle = styled(Typography.Text)({ color: 'white', }); -const Leaf = ({ title, isSelectedTab }: { title: string; isSelectedTab?: boolean }) => { +const Leaf = ({ + title, + isSelectedTab, + color, +}: { + title: string; + isSelectedTab?: boolean; + color: string; +}) => { return ( - + {title} @@ -114,31 +134,62 @@ const NodeTitle = styled(Typography)(({ theme }) => ({ alignSelf: 'flex-start', })); -const Node = ({ name, state }: { name: string; state: NavigationState }) => { +const Node = ({ + name, + state, + parentColor, +}: { + name: string; + state: NavigationState; + parentColor: string; +}) => { const routes = state.routes; if (!routes || !routes.length) { - return ; + return ; } + const color = generateColor(state.key); + return ( - + {routes.toReversed().map((route, index) => ( {route.state?.routes && route.state.routes.length ? ( - + ) : ( )} ))} - {name} + {name} ); }; + +const colorMap: Record = {}; +let currentHue = 0; + +const generateColor = (key: string) => { + if (colorMap[key]) { + console.log(key); + + return colorMap[key]; + } + + currentHue = (currentHue + 9) % 360; + const newColor = `hsl(${currentHue}, 70%, 50%)`; + + colorMap[key] = newColor; + + console.log(newColor); + + return newColor; +};