Change icon on active menu item (#903)

* add icons

* add logic to change the icon

* make the active menu bold

* Encapsulate the dynamic icon behaviour into a self-contained component

Co-authored-by: Deluan <deluan@navidrome.org>
This commit is contained in:
Ruchi Kushwaha
2021-04-17 10:10:07 +05:30
committed by GitHub
parent 16a5ac323b
commit b441260186
8 changed files with 173 additions and 21 deletions
+23
View File
@@ -0,0 +1,23 @@
import PropTypes from 'prop-types'
import { useLocation } from 'react-router-dom'
import { createElement } from 'react'
const DynamicMenuIcon = ({ icon, activeIcon, path }) => {
const location = useLocation()
if (!activeIcon) {
return createElement(icon, { 'data-testid': 'icon' })
}
return location.pathname.startsWith('/' + path)
? createElement(activeIcon, { 'data-testid': 'activeIcon' })
: createElement(icon, { 'data-testid': 'icon' })
}
DynamicMenuIcon.propTypes = {
path: PropTypes.string.isRequired,
icon: PropTypes.object.isRequired,
activeIcon: PropTypes.object,
}
export default DynamicMenuIcon