Skip to content

Commit 63037ce

Browse files
EtienneLtthangqp
andauthored
add Nested menu used in gridexplore and gridstudy (#757)
Signed-off-by: Etienne LESOT <[email protected]> Co-authored-by: Thang PHAM <[email protected]>
1 parent be224e6 commit 63037ce

File tree

5 files changed

+84
-0
lines changed

5 files changed

+84
-0
lines changed

package-lock.json

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"@react-querybuilder/material": "^8.2.0",
4242
"autosuggest-highlight": "^3.3.4",
4343
"clsx": "^2.1.1",
44+
"mui-nested-menu": "^4.0.0",
4445
"jwt-decode": "^4.0.0",
4546
"localized-countries": "^2.0.0",
4647
"oidc-client": "^1.11.5",

src/components/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ export * from './topBar';
2121
export * from './treeViewFinder';
2222
export * from './notifications';
2323
export * from './icons';
24+
export * from './menus';
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**
2+
* Copyright (c) 2025, RTE (http://www.rte-france.com)
3+
* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
*/
7+
import { PropsWithChildren, useState } from 'react';
8+
import { NestedMenuItem, NestedMenuItemProps } from 'mui-nested-menu';
9+
import { Box, MenuItem, MenuItemProps, SxProps, Theme } from '@mui/material';
10+
import { mergeSx } from '../../utils';
11+
12+
const styles = {
13+
highlightedParentLine: {
14+
backgroundColor: 'action.hover',
15+
color: 'primary.main',
16+
transition: 'all 300ms ease',
17+
},
18+
highlightedLine: {
19+
transition: 'all 300ms ease',
20+
'&:hover': {
21+
backgroundColor: 'action.hover',
22+
color: 'primary.main',
23+
},
24+
},
25+
};
26+
27+
interface CustomNestedMenuItemProps extends PropsWithChildren, Omit<NestedMenuItemProps, 'parentMenuOpen'> {
28+
sx?: SxProps<Theme>;
29+
}
30+
31+
export function CustomNestedMenuItem({ sx, children, ...other }: Readonly<CustomNestedMenuItemProps>) {
32+
const [subMenuActive, setSubMenuActive] = useState(false);
33+
34+
return (
35+
<NestedMenuItem
36+
{...other}
37+
parentMenuOpen
38+
sx={mergeSx(subMenuActive ? styles.highlightedParentLine : styles.highlightedLine, sx)}
39+
>
40+
<Box onMouseEnter={() => setSubMenuActive(true)} onMouseLeave={() => setSubMenuActive(false)}>
41+
{children}
42+
</Box>
43+
</NestedMenuItem>
44+
);
45+
}
46+
47+
export function CustomMenuItem({ sx, ...other }: Readonly<MenuItemProps>) {
48+
return <MenuItem sx={mergeSx(styles.highlightedLine, sx)} {...other} />;
49+
}

src/components/menus/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* Copyright (c) 2021, RTE (http://www.rte-france.com)
3+
* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
*/
7+
export * from './custom-nested-menu';

0 commit comments

Comments
 (0)