@@ -3,37 +3,31 @@ import styles from '@system/HamburgerMenuButton.module.scss';
3
3
import * as React from 'react' ;
4
4
import * as Utilities from '@common/utilities' ;
5
5
6
- import { useModal } from '@system/providers/ModalContextProvider' ;
6
+ import ModalHamburgerMenu from '@root/demos/modals/ModalHamburgerMenu' ;
7
+
8
+ import { useModalV2 } from './modals/GlobalModalManagerV2' ;
7
9
8
10
export default function HamburgerMenuButton ( props ) {
9
- const { modalContent , showModal } = useModal ( ) ;
11
+ const modal = useModalV2 ( ModalHamburgerMenu ) ;
10
12
11
- const [ menuActive , setMenuActive ] = React . useState ( false ) ;
12
13
const [ isAnimating , setIsAnimating ] = React . useState ( false ) ;
13
14
14
15
const hamburgerRef = React . useRef < HTMLDivElement > ( null ) ;
15
16
16
- // (@xBalbinus) The hamburger menu is a modal, and can get closed by other modals
17
- // Handle the case where the hamburger menu is closed by another modal or gets clicked outside of.
18
- React . useEffect ( ( ) => {
19
- if ( modalContent ?. name === 'HAMBURGER_MENU' ) {
20
- setMenuActive ( true ) ;
21
- } else if ( modalContent ?. name !== 'HAMBURGER_MENU' ) {
22
- setMenuActive ( false ) ;
23
- }
24
- } , [ modalContent ] ) ;
25
-
26
17
// (@xBalbinus): The hamburger menu gets closed on click to any outside HTML element if we only use
27
18
// onOutsideEvent, we need to check if the click is coming from the hamburger button specifically.
28
19
function toggleModal ( ) {
29
20
if ( isAnimating ) return ;
30
21
31
22
setIsAnimating ( true ) ;
32
- setMenuActive ( ( prev ) => ! prev ) ;
33
- showModal ( {
34
- name : 'HAMBURGER_MENU' ,
35
- data : { navItems : props . navItems , isActive : menuActive , triggerElement : hamburgerRef . current } ,
36
- } ) ;
23
+
24
+ if ( ! modal . isActive ) {
25
+ modal . open ( {
26
+ content : { data : { navItems : props . navItems } } ,
27
+ } ) ;
28
+ } else {
29
+ modal . close ( ) ;
30
+ }
37
31
setTimeout ( ( ) => {
38
32
setIsAnimating ( false ) ;
39
33
} , 300 ) ;
@@ -43,7 +37,7 @@ export default function HamburgerMenuButton(props) {
43
37
< div className = { styles . body } >
44
38
< div
45
39
ref = { hamburgerRef }
46
- className = { Utilities . classNames ( styles . hamburger , { [ styles . active ] : menuActive } ) }
40
+ className = { Utilities . classNames ( styles . hamburger , { [ styles . active ] : modal . isActive } ) }
47
41
onMouseDown = { toggleModal }
48
42
>
49
43
< span className = { styles . bar } > </ span >
0 commit comments