@@ -2,6 +2,7 @@ import { CSSMotionList } from '@rc-component/motion';
22import type { CSSMotionProps } from '@rc-component/motion' ;
33import { clsx } from 'clsx' ;
44import * as React from 'react' ;
5+ import type { StackConfig } from './interface' ;
56import { NotificationContext } from './legacy/NotificationProvider' ;
67import useStack from './legacy/hooks/useStack' ;
78import Notification , {
@@ -13,14 +14,7 @@ import useListPosition from './hooks/useListPosition';
1314import useListScroll from './hooks/useListScroll' ;
1415
1516export type Placement = 'top' | 'topLeft' | 'topRight' | 'bottom' | 'bottomLeft' | 'bottomRight' ;
16-
17- export type StackConfig =
18- | boolean
19- | {
20- threshold ?: number ;
21- offset ?: number ;
22- gap ?: number ;
23- } ;
17+ export type { StackConfig } from './interface' ;
2418
2519export interface NotificationListConfig extends NotificationProps {
2620 key : React . Key ;
@@ -35,7 +29,7 @@ export interface NotificationListProps {
3529 pauseOnHover ?: boolean ;
3630 classNames ?: NotificationClassNames ;
3731 styles ?: NotificationStyles ;
38- stack ?: StackConfig ;
32+ stack ?: boolean | StackConfig ;
3933 motion ?: CSSMotionProps | ( ( placement : Placement ) => CSSMotionProps ) ;
4034 className ?: string ;
4135 style ?: React . CSSProperties ;
@@ -83,28 +77,26 @@ const NotificationList: React.FC<NotificationListProps> = (props) => {
8377
8478 // ========================= Motion =========================
8579 const placementMotion = typeof motion === 'function' ? motion ( placement ) : motion ;
86- const [ stack , { threshold } ] = useStack ( stackConfig ) ;
87- const [ hoverKeys , setHoverKeys ] = React . useState < string [ ] > ( [ ] ) ;
88- const expanded = stack && ( hoverKeys . length > 0 || keys . length <= threshold ) ;
80+ const [ stackEnabled , { offset, threshold } ] = useStack ( stackConfig ) ;
81+ const [ listHovering , setListHovering ] = React . useState ( false ) ;
82+ const expanded = stackEnabled && ( listHovering || keys . length <= threshold ) ;
83+ const stackPosition = React . useMemo < StackConfig | undefined > ( ( ) => {
84+ if ( ! stackEnabled || expanded ) {
85+ return undefined ;
86+ }
87+
88+ return {
89+ offset,
90+ threshold,
91+ } ;
92+ } , [ expanded , offset , stackEnabled , threshold ] ) ;
8993
90- const [ notificationPosition , setNodeSize ] = useListPosition ( mergedConfigList ) ;
94+ const [ notificationPosition , setNodeSize ] = useListPosition ( mergedConfigList , stackPosition ) ;
9195 const { contentRef, onWheel, scrollOffset, viewportRef } = useListScroll (
9296 keyList ,
9397 notificationPosition ,
9498 ) ;
9599
96- React . useEffect ( ( ) => {
97- if ( stack && hoverKeys . length > 1 ) {
98- setHoverKeys ( ( originKeys ) => {
99- const nextKeys = originKeys . filter ( ( key ) =>
100- keyList . some ( ( existingKey ) => existingKey === key ) ,
101- ) ;
102-
103- return nextKeys . length === originKeys . length ? originKeys : nextKeys ;
104- } ) ;
105- }
106- } , [ hoverKeys , keyList , stack ] ) ;
107-
108100 // ========================= Render =========================
109101 const listPrefixCls = `${ prefixCls } -list` ;
110102 const itemPrefixCls = `${ listPrefixCls } -item` ;
@@ -120,11 +112,17 @@ const NotificationList: React.FC<NotificationListProps> = (props) => {
120112 contextClassNames ?. list ,
121113 className ,
122114 {
123- [ `${ prefixCls } -stack` ] : stack ,
115+ [ `${ prefixCls } -stack` ] : stackEnabled ,
124116 [ `${ prefixCls } -stack-expanded` ] : expanded ,
125117 } ,
126118 ) }
127119 onWheel = { onWheel }
120+ onMouseEnter = { ( ) => {
121+ setListHovering ( true ) ;
122+ } }
123+ onMouseLeave = { ( ) => {
124+ setListHovering ( false ) ;
125+ } }
128126 ref = { viewportRef }
129127 style = { style }
130128 >
@@ -169,14 +167,6 @@ const NotificationList: React.FC<NotificationListProps> = (props) => {
169167 ...styles ?. wrapper ,
170168 ...config . styles ?. wrapper ,
171169 } }
172- onMouseEnter = { ( ) =>
173- setHoverKeys ( ( originKeys ) =>
174- originKeys . includes ( strKey ) ? originKeys : [ ...originKeys , strKey ] ,
175- )
176- }
177- onMouseLeave = { ( ) =>
178- setHoverKeys ( ( originKeys ) => originKeys . filter ( ( key ) => key !== strKey ) )
179- }
180170 >
181171 < Notification
182172 key = { config . times }
@@ -209,7 +199,7 @@ const NotificationList: React.FC<NotificationListProps> = (props) => {
209199 ...config . styles ?. progress ,
210200 } ,
211201 } }
212- hovering = { stack && hoverKeys . length > 0 }
202+ hovering = { stackEnabled && listHovering }
213203 pauseOnHover = { config . pauseOnHover ?? pauseOnHover }
214204 onCloseInternal = { ( ) => {
215205 onNoticeClose ?.( key ) ;
0 commit comments