Skip to content

Instantly share code, notes, and snippets.

@bautistaaa
Created May 4, 2020 16:30
Show Gist options
  • Save bautistaaa/56f98c6c419e0ce3888f6c559b8c3cb7 to your computer and use it in GitHub Desktop.
Save bautistaaa/56f98c6c419e0ce3888f6c559b8c3cb7 to your computer and use it in GitHub Desktop.
const SidebarItem = ({
link,
handleMenuSelection,
selectedMenus,
depth = 0,
}) => {
const { label, path, children = [] } = link;
return (
<>
{children.length > 0 ? (
<SidebarItem.Item>
<SidebarItem.Label
onMouseEnter={() => handleMenuSelection(label, depth)}
>
{label}
</SidebarItem.Label>
{selectedMenus[depth] === label && (
<SidebarItem.List depth={depth}>
{children.map((child, i) => {
const { label } = child;
const childDepth = depth + 1;
return (
<SidebarItem
link={child}
handleMenuSelection={handleMenuSelection}
key={`child-${label}-${i}`}
depth={childDepth}
selectedMenus={selectedMenus}
/>
);
})}
</SidebarItem.List>
)}
</SidebarItem.Item>
) : (
<SidebarItem.Item onMouseEnter={() => handleMenuSelection('', depth)}>
<SidebarItem.Anchor href={path}>{label}</SidebarItem.Anchor>
</SidebarItem.Item>
)}
</>
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment