Skip to content

Instantly share code, notes, and snippets.

@jsmanifest
Created February 20, 2020 05:24
Show Gist options
  • Save jsmanifest/5b60d421219e186538e81705bc655efe to your computer and use it in GitHub Desktop.
Save jsmanifest/5b60d421219e186538e81705bc655efe to your computer and use it in GitHub Desktop.
import React from 'react'
import List from '@material-ui/core/List'
import ListItem from '@material-ui/core/ListItem'
import Button from '@material-ui/core/Button'
function SidebarItem({ children, ...rest }) {
return (
<ListItem
component={Button}
style={{ textTransform: 'none' }}
variant="outlined"
color="primary"
{...rest}
>
{children}
</ListItem>
)
}
function Sidebar({ items, defaultDepth = 0, step = 6, ...props }) {
const nextDepth = defaultDepth + step
return (
<List
style={{ marginLeft: defaultDepth === 0 ? 0 : nextDepth }}
disablePadding
dense
>
{items.map((item) => (
<React.Fragment key={item.title}>
<div style={{ marginBottom: 4 }}>
<SidebarItem {...item}>{item.title}</SidebarItem>
</div>
{item.items && (
<Sidebar items={item.items} defaultDepth={nextDepth} step={step} />
)}
</React.Fragment>
))}
</List>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment