Skip to content

Instantly share code, notes, and snippets.

@treyhuffine
Last active February 12, 2020 21:40
Show Gist options
  • Save treyhuffine/92a90e3820a425daa40f82ccfc235de8 to your computer and use it in GitHub Desktop.
Save treyhuffine/92a90e3820a425daa40f82ccfc235de8 to your computer and use it in GitHub Desktop.
import React from 'react';
import { Link, useLocation } from 'react-router-dom';
import { SideNavItems, SideNavLink } from 'carbon-components-react/lib/components/UIShell';
import { StyledSideNav } from './styles';
const items = [
{ name: 'Me', path: '/' },
{ name: 'Projects', path: '/projects' },
{ name: 'Work', path: '/work' },
{ name: 'Education', path: '/education' },
];
const Sidebar = () => {
const location = useLocation();
return (
<StyledSideNav isFixedNav expanded isChildOfHeader={false} aria-label="Side navigation">
<SideNavItems>
{items.map(i => (
<SideNavLink
isActive={
location.pathname === '/' && i.path === '/' ? true : location.pathname === i.path
}
element={Link}
to={i.path}
key={i.name}
>
{i.name}
</SideNavLink>
))}
</SideNavItems>
</StyledSideNav>
);
};
export default Sidebar;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment