Skip to content

Commit

Permalink
Active Nav Link
Browse files Browse the repository at this point in the history
* Added active nav link component and styles
  • Loading branch information
Elkrival committed Nov 2, 2023
1 parent b52866e commit b86cd69
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 21 deletions.
12 changes: 0 additions & 12 deletions views/components/Sidebar/NavItem.css

This file was deleted.

15 changes: 6 additions & 9 deletions views/components/Sidebar/NavItem.jsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import React from 'react'
import { Link } from 'react-router-dom'
import { ListItem, ListItemIcon, ListItemText } from '@mui/material'
import './NavItem.css'
import SidebarLink from './SidebarLink'

const NavItem = ({ to, Icon, label }) => {
return (
<ListItem>
<Link to={to} className="sidenav_link">
<ListItemIcon className="sidenav_icon_container">
<Icon />
</ListItemIcon>
<ListItemText primary={label} sx={{ color: 'text.primary' }} />
</Link>
<ListItem component={SidebarLink} to={to} sx={{ width: 228 }}>
<ListItemIcon sx={{ minWidth: 40 }}>
<Icon />
</ListItemIcon>
<ListItemText primary={label} sx={{ color: 'text.primary' }} />
</ListItem>
)
}
Expand Down
21 changes: 21 additions & 0 deletions views/components/Sidebar/SidebarLink.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.sidenav_link {
text-decoration: none;
padding: 6px 12px 6px 12px;
display: flex;
flex-direction: row;
&:visited&:focus {
text-decoration: none;
}
}

.sidenav_link-active {
text-decoration: none;
display: flex;
flex-direction: row;
background-color: #addbff;
border-radius: 8px;
padding: 6px 12px 6px 12px;
&:visited&:focus {
text-decoration: none;
}
}
17 changes: 17 additions & 0 deletions views/components/Sidebar/SidebarLink.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { forwardRef } from 'react'
import { NavLink } from 'react-router-dom'
import './SidebarLink.css'

const SidebarLink = forwardRef((props, ref) => (
<NavLink
ref={ref}
to={props.to}
className={({ isActive }) =>
isActive ? 'sidenav_link-active' : 'sidenav_link'
}
>
{props.children}
</NavLink>
))

export default SidebarLink

0 comments on commit b86cd69

Please sign in to comment.