Use your personal coding best practices to create a component or set of components that can load and display an expandable tree menu.
- Write your code as if it will go to production. Do not hack together a solution.
- You may not use any additional frameworks.
- Use proper Typescript types, do not use "any", implied any or "unknown".
- Your implementation must be able to support a tree of infinite depth. Don't assume it only needs to work with the examples.
- Nodes with children are initially displayed collapsed.
- Clicking a node with children toggles expand/collapse.
- Collapsed nodes display a "+" next the label.
- Expanded nodes display a "-" next the label.
- Nodes that contain a url display a "#" next to th label. The "#" should not be clickable.
- Nodes that contain a url open the url in a separate tab when clicked. The same tab must always be used. It should not create a new tab on every click.
- Child nodes are consistently indented from their parents.
- Multiple menus can be displayed at once, each displaying a different set of menu items.
- All nodes will have a label.
- All nodes will have either a url or children, but never both.
- For your initial implementation, styling does not matter. If time permits styling can be added later.
- main 1 <-- expanded menu
+ child 1 <-- collapsed menu
# link a <-- link item
- child 3
# link b
# link c
+ main 2
- main 3
+ child 4
# link d