22import styles from './DropdownMenu.module.css'
33
44import { useRouter } from 'next/navigation'
5- import React , { useState } from 'react'
5+ import React from 'react'
66
7- import { Link , Menu , MenuItem } from '@mui/material'
7+ import { Link } from '@mui/material'
88import KeyboardArrowDownIcon from '@mui/icons-material/KeyboardArrowDown'
99
1010type DropDownMenuProps = {
@@ -13,77 +13,21 @@ type DropDownMenuProps = {
1313}
1414
1515export default function DropdownMenu ( { title, items } : DropDownMenuProps ) : React . ReactElement {
16- const [ anchorEl , setAnchorEl ] = useState < null | HTMLElement > ( null ) ;
17- let currentlyHovering = false ;
1816 const router = useRouter ( )
1917
20- const handleMouseOver = ( event : React . MouseEvent < HTMLElement > ) => {
21- handleHover ( ) ;
22- if ( anchorEl !== event . currentTarget ) {
23- setAnchorEl ( event . currentTarget ) ;
24- }
25- } ;
26-
27- const handleClose = ( ) => {
28- setAnchorEl ( null ) ;
29- } ;
30-
31- const handleHover = ( ) => {
32- currentlyHovering = true ;
33- }
34-
35- const handleCloseHover = ( ) => {
36- currentlyHovering = false ;
37- setTimeout ( ( ) => {
38- if ( ! currentlyHovering ) {
39- handleClose ( ) ;
40- }
41- } , 50 ) ;
42- }
43-
4418 const handleClick = ( path : string ) => {
45- handleClose ( ) ;
4619 router . push ( path ) ;
4720 }
4821
4922 return (
50- < div >
51- < Link
52- className = { `flex-horizontal ${ styles . dropdownLink } ` }
53- onClick = { ( ) => handleClick ( title . path ) }
54- onMouseOver = { handleMouseOver }
55- onMouseLeave = { handleCloseHover } >
56- { title . text }
57- < KeyboardArrowDownIcon fontSize = 'small' />
23+ < div className = { styles . dropdown } >
24+ < Link className = { `flex-horizontal ${ styles . dropdownLink } ` } >
25+ { title . text } < KeyboardArrowDownIcon fontSize = 'small' />
5826 </ Link >
5927
60- < Menu
61- id = "simple-menu"
62- anchorEl = { anchorEl }
63- open = { Boolean ( anchorEl ) }
64- onClose = { handleClose }
65- autoFocus = { false }
66- slotProps = { {
67- paper : {
68- style : {
69- borderTopLeftRadius : 0 ,
70- borderTopRightRadius : 0
71- }
72- } ,
73- list : {
74- onMouseLeave : handleCloseHover ,
75- onMouseEnter : handleHover ,
76- style : {
77- pointerEvents : 'auto' ,
78- backgroundColor : 'var(--primary)'
79- }
80- }
81- } }
82- PopoverClasses = { {
83- root : styles . popOverRoot
84- } } >
85- { items . map ( ( item , i ) => < MenuItem key = { i } className = { styles . menuItem } onClick = { ( ) => handleClick ( item . path ) } > { item . text } </ MenuItem > ) }
86- </ Menu >
28+ < div className = { styles . dropdownMenu } >
29+ { items . map ( ( item , i ) => < div key = { i } className = { styles . menuItem } onClick = { ( ) => handleClick ( item . path ) } > { item . text } </ div > ) }
30+ </ div >
8731 </ div >
8832 )
8933}
0 commit comments