import * as React from 'react' ; import { MenuContext } from '../context/MenuContext' ; import type { MenuHoverEventHandler } from '../interface' ; interface ActiveObj { active : boolean ; onMouseEnter ? : React . MouseEventHandler < HTMLElement > ; onMouseLeave ? : React . MouseEventHandler < HTMLElement > ; } export default function useActive ( eventKey , disabled , onMouseEnter ? , onMouseLeave ? ) { const { activeKey , onActive , onInactive , } = React . useContext ( MenuContext ) ; const ret = { active : activeKey === eventKey , } ; if ( ! disabled ) { ret . onMouseEnter = domEvent => { onMouseEnter ?. ( { key : eventKey , domEvent , } ) ; onActive ( eventKey ) ; } ; ret . onMouseLeave = domEvent => { onMouseLeave ?. ( { key : eventKey , domEvent , } ) ; onInactive ( eventKey ) ; } ; } return ret ; }