Skip to content

Commit

Permalink
Code for 5-sidebar
Browse files Browse the repository at this point in the history
  • Loading branch information
tylermcginnis committed May 24, 2020
1 parent e3e8f26 commit 90d9877
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -5,7 +5,8 @@
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-router-dom": "^5.2.0",
"react-scripts": "3.4.1"
"react-scripts": "3.4.1",
"slug": "^3.0.1"
},
"scripts": {
"start": "react-scripts start",
Expand Down
41 changes: 41 additions & 0 deletions src/components/Sidebar.js
@@ -0,0 +1,41 @@
import * as React from 'react'
import {
Link,
useRouteMatch,
useLocation
} from 'react-router-dom'
import slug from 'slug'

function CustomLink ({ to, children }) {
const match = useRouteMatch(to.pathname)

return (
<li style={{fontWeight: match ? 900 : 'normal'}}>
<Link to={to}>{children}</Link>
</li>
)
}

export default function Sidebar ({ title, list }) {
const { url } = useRouteMatch()
const location = useLocation()

return (
<div>
<h3 className='header'>{title}</h3>
<ul className='sidebar-list'>
{list.map((item) => (
<CustomLink
key={item}
to={{
pathname: `${url}/${slug(item)}`,
search: location.search
}}
>
{item.toUpperCase()}
</CustomLink>
))}
</ul>
</div>
)
}

0 comments on commit 90d9877

Please sign in to comment.