@@ -39,6 +39,7 @@ export interface NotificationProps {
3939 x : number ;
4040 y : number ;
4141 } ;
42+ props ?: React . HTMLAttributes < HTMLDivElement > & Record < string , any > ;
4243
4344 // Behavior
4445 duration ?: number | false | null ;
@@ -49,8 +50,9 @@ export interface NotificationProps {
4950
5051 // Function
5152 onClick ?: React . MouseEventHandler < HTMLDivElement > ;
53+ onMouseEnter ?: React . MouseEventHandler < HTMLDivElement > ;
54+ onMouseLeave ?: React . MouseEventHandler < HTMLDivElement > ;
5255 onClose ?: ( ) => void ;
53- onCloseInternal ?: VoidFunction ;
5456}
5557
5658const Notification = React . forwardRef < HTMLDivElement , NotificationProps > ( ( props , ref ) => {
@@ -68,6 +70,7 @@ const Notification = React.forwardRef<HTMLDivElement, NotificationProps>((props,
6870 close,
6971 closable,
7072 offset,
73+ props : rootProps ,
7174
7275 // Behavior
7376 duration = 4.5 ,
@@ -77,16 +80,16 @@ const Notification = React.forwardRef<HTMLDivElement, NotificationProps>((props,
7780
7881 // Function
7982 onClick,
83+ onMouseEnter,
84+ onMouseLeave,
8085 onClose,
81- onCloseInternal,
8286 } = props ;
83- const [ hovering , setHovering ] = React . useState ( false ) ;
87+
8488 const [ percent , setPercent ] = React . useState ( 0 ) ;
8589 const noticePrefixCls = `${ prefixCls } -notice` ;
8690
8791 // ========================= Close ==========================
8892 const onEventClose = useEvent ( onClose ) ;
89- const onEventCloseInternal = useEvent ( onCloseInternal ) ;
9093 const offsetRef = React . useRef ( offset ) ;
9194 const closableObj = React . useMemo ( ( ) => {
9295 if ( typeof closable === 'object' && closable !== null ) {
@@ -104,12 +107,13 @@ const Notification = React.forwardRef<HTMLDivElement, NotificationProps>((props,
104107 }
105108
106109 // ======================== Duration ========================
110+ const [ hovering , setHovering ] = React . useState ( false ) ;
111+
107112 const [ onResume , onPause ] = useNoticeTimer (
108113 duration ,
109114 ( ) => {
110115 closableObj . onClose ?.( ) ;
111116 onEventClose ( ) ;
112- onEventCloseInternal ( ) ;
113117 } ,
114118 setPercent ,
115119 ! ! showProgress ,
@@ -130,6 +134,23 @@ const Notification = React.forwardRef<HTMLDivElement, NotificationProps>((props,
130134 }
131135 } , [ forcedHovering , hovering , onPause , onResume , pauseOnHover ] ) ;
132136
137+ // ========================= Hover ==========================
138+ function onInternalMouseEnter ( event : React . MouseEvent < HTMLDivElement > ) {
139+ setHovering ( true ) ;
140+ if ( pauseOnHover ) {
141+ onPause ( ) ;
142+ }
143+ onMouseEnter ?.( event ) ;
144+ }
145+
146+ function onInternalMouseLeave ( event : React . MouseEvent < HTMLDivElement > ) {
147+ setHovering ( false ) ;
148+ if ( pauseOnHover && ! forcedHovering ) {
149+ onResume ( ) ;
150+ }
151+ onMouseLeave ?.( event ) ;
152+ }
153+
133154 // ========================= Render =========================
134155 return (
135156 < div
@@ -151,20 +172,8 @@ const Notification = React.forwardRef<HTMLDivElement, NotificationProps>((props,
151172 } }
152173 // Events
153174 onClick = { onClick }
154- onMouseEnter = { ( event ) => {
155- setHovering ( true ) ;
156- if ( pauseOnHover ) {
157- onPause ( ) ;
158- }
159- rootProps ?. onMouseEnter ?.( event ) ;
160- } }
161- onMouseLeave = { ( event ) => {
162- setHovering ( false ) ;
163- if ( pauseOnHover && ! forcedHovering ) {
164- onResume ( ) ;
165- }
166- rootProps ?. onMouseLeave ?.( event ) ;
167- } }
175+ onMouseEnter = { onInternalMouseEnter }
176+ onMouseLeave = { onInternalMouseLeave }
168177 >
169178 < div
170179 className = { clsx ( `${ noticePrefixCls } -content` , classNames ?. content ) }
@@ -183,15 +192,13 @@ const Notification = React.forwardRef<HTMLDivElement, NotificationProps>((props,
183192 if ( event . key === 'Enter' || event . code === 'Enter' ) {
184193 closableObj . onClose ?.( ) ;
185194 onEventClose ( ) ;
186- onEventCloseInternal ( ) ;
187195 }
188196 } }
189197 onClick = { ( e ) => {
190198 e . preventDefault ( ) ;
191199 e . stopPropagation ( ) ;
192200 closableObj . onClose ?.( ) ;
193201 onEventClose ( ) ;
194- onEventCloseInternal ( ) ;
195202 } }
196203 >
197204 { closeContent }
0 commit comments