Above: Short animation of proposed dropdown menu. You can view a compiled version of the page, here.
This is a short post intended to just demonstrate a potential format for hosting a dynamic list of analytical modules in a drop down menu. The goal was to just roughly mock something out in React, and, hackiness aside, just demonstrate a possible data schema that would allow for navigable, nested module lists.
Inspiration was me noticing that a component of the frontend on the app I work on at my job could be better sorted into a menu of some sort. I played around with some ideas here, and took notes since nested lists do not appear to be a common component when looking around at published React components.
This is a very straightforward static page with just a few components developed to represent the different parts of the drop down menu. To see the whole related files to create this page, I’ve placed the content in this repo on Github.
I propose a structure such as the following for passing through a dynamic nested list (in this case a list where there are a set of modules you can choose from). Each is grouped under a category, and each category gets some custom styling themes.
Each nested array element will be handled in this top level component,
ModuleGroupSelector, which creates drop downs for each group. Then, within each group, the list of modules is passed through.
Note that toggle bindings are made for each element. This will be the case for both the menu item here that shows the groups, as well as the group components that house each of their subset of modules.
So, when a user hovers over the menu component to show the groups, it triggers the rendering of the list of groups as components:
Each group div above is designed to by styled slightly based on that groups meta attributes. Those styles are also passed down to the element’s child components, which in this case are the modules themselves:
That gets us consistent group styles paired through to the subcomponents of a group of modules.
Note that the styling (if you view the CSS) is pretty hacky (also apologies for not using Scss or Sass). The location of the div for the group elements is hard set with absolute positioning. But, I think the design pattern for the modules themselves works, wherein relative positioning based on the location of the parent group selector is used. This gets the rightward-cascading menu pattern that allows for a more legible, nested drop down list.