mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-21 14:50:08 +03:00
M #~: Add color to sidebar selected item when not fixed (#1853)
(cherry picked from commit 8ab421fb1dfaa0c6ea17983c65a86ad8bcff4315)
This commit is contained in:
parent
86cefb1bec
commit
ad6ea644c0
@ -13,8 +13,7 @@
|
||||
* See the License for the specific language governing permissions and *
|
||||
* limitations under the License. *
|
||||
* ------------------------------------------------------------------------- */
|
||||
/* eslint-disable jsdoc/require-jsdoc */
|
||||
import { useEffect, useState } from 'react'
|
||||
import { useEffect, useState, useMemo, ReactElement } from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import { useLocation } from 'react-router-dom'
|
||||
import clsx from 'clsx'
|
||||
@ -34,26 +33,43 @@ import { useGeneral } from 'client/features/General'
|
||||
import SidebarLink from 'client/components/Sidebar/SidebarLink'
|
||||
import sidebarStyles from 'client/components/Sidebar/styles'
|
||||
|
||||
/**
|
||||
* Renders nested list options for sidebar.
|
||||
*
|
||||
* @param {object} props - Props
|
||||
* @param {string} props.label - Label
|
||||
* @param {object[]} props.routes - Nested list of routes
|
||||
* @param {ReactElement} props.icon - Icon
|
||||
* @returns {ReactElement} Sidebar option that includes other list of routes
|
||||
*/
|
||||
const SidebarCollapseItem = ({ label = '', routes = [], icon: Icon }) => {
|
||||
const classes = sidebarStyles()
|
||||
const { pathname } = useLocation()
|
||||
const { isFixMenu } = useGeneral()
|
||||
const isUpLg = useMediaQuery((theme) => theme.breakpoints.up('lg'))
|
||||
|
||||
const [expanded, setExpanded] = useState(() => false)
|
||||
|
||||
const hasRouteSelected = useMemo(
|
||||
() => routes.some(({ path }) => pathname === path),
|
||||
[routes, pathname]
|
||||
)
|
||||
|
||||
const handleExpand = () => setExpanded(!expanded)
|
||||
|
||||
useEffect(() => {
|
||||
if (isFixMenu && !expanded) {
|
||||
const hasRouteSelected = routes.some(({ path }) => pathname === path)
|
||||
hasRouteSelected && setExpanded(true)
|
||||
}
|
||||
}, [isFixMenu])
|
||||
// force expanded
|
||||
isFixMenu && !expanded && hasRouteSelected && setExpanded(true)
|
||||
}, [isFixMenu, expanded, hasRouteSelected])
|
||||
|
||||
console.log({ expanded, hasRouteSelected })
|
||||
|
||||
return (
|
||||
<>
|
||||
<ListItemButton onClick={handleExpand}>
|
||||
<ListItemButton
|
||||
className={classes.parentSubItem}
|
||||
onClick={handleExpand}
|
||||
selected={(!isFixMenu || !expanded) && hasRouteSelected}
|
||||
>
|
||||
{Icon && (
|
||||
<ListItemIcon>
|
||||
<Icon />
|
||||
|
@ -14,6 +14,7 @@
|
||||
* limitations under the License. *
|
||||
* ------------------------------------------------------------------------- */
|
||||
import makeStyles from '@mui/styles/makeStyles'
|
||||
import { alpha } from '@mui/material'
|
||||
import { sidebar, toolbar } from 'client/theme/defaults'
|
||||
|
||||
export default makeStyles((theme) => ({
|
||||
@ -43,6 +44,14 @@ export default makeStyles((theme) => ({
|
||||
easing: theme.transitions.easing.sharp,
|
||||
duration: theme.transitions.duration.enteringScreen,
|
||||
}),
|
||||
'& $parentSubItem': {
|
||||
'&.Mui-selected': {
|
||||
backgroundColor: alpha(theme.palette.secondary.main, 0.2),
|
||||
},
|
||||
'&.Mui-selected:hover': {
|
||||
backgroundColor: alpha(theme.palette.secondary.main, 0.3),
|
||||
},
|
||||
},
|
||||
'& #logo__text': {
|
||||
visibility: 'visible',
|
||||
},
|
||||
@ -120,5 +129,6 @@ export default makeStyles((theme) => ({
|
||||
color: theme.palette.secondary.light,
|
||||
},
|
||||
},
|
||||
parentSubItem: {},
|
||||
subItemWrapper: {},
|
||||
}))
|
||||
|
Loading…
x
Reference in New Issue
Block a user