@@ -2,6 +2,11 @@ import * as React from 'react';
22import type { StackConfig } from '../useStack' ;
33import useSizes from './useSizes' ;
44
5+ export interface NoticeBounds {
6+ top : number ;
7+ bottom : number ;
8+ }
9+
510/**
611 * Calculates each notification's position and the full list height.
712 */
@@ -12,11 +17,12 @@ export default function useListPosition(
1217) {
1318 const [ sizeMap , setNodeSize ] = useSizes ( ) ;
1419
15- const [ notificationPosition , totalHeight ] = React . useMemo ( ( ) => {
20+ const [ notificationPosition , totalHeight , topNoticeBounds ] = React . useMemo ( ( ) => {
1621 let offsetY = 0 ;
1722 let nextTotalHeight = 0 ;
1823 const stackThreshold = stack ?. threshold ?? 0 ;
1924 const nextNotificationPosition = new Map < string , number > ( ) ;
25+ let nextTopNoticeBounds : NoticeBounds | undefined ;
2026
2127 configList
2228 . slice ( )
@@ -29,6 +35,13 @@ export default function useListPosition(
2935
3036 nextNotificationPosition . set ( key , y ) ;
3137
38+ if ( index === 0 ) {
39+ nextTopNoticeBounds = {
40+ top : y ,
41+ bottom : y + height ,
42+ } ;
43+ }
44+
3245 if ( ! stack || index < stackThreshold ) {
3346 nextTotalHeight = Math . max ( nextTotalHeight , y + height ) ;
3447 }
@@ -40,8 +53,8 @@ export default function useListPosition(
4053 }
4154 } ) ;
4255
43- return [ nextNotificationPosition , nextTotalHeight ] as const ;
56+ return [ nextNotificationPosition , nextTotalHeight , nextTopNoticeBounds ] as const ;
4457 } , [ configList , gap , sizeMap , stack ] ) ;
4558
46- return [ notificationPosition , setNodeSize , totalHeight ] as const ;
59+ return [ notificationPosition , setNodeSize , totalHeight , topNoticeBounds ] as const ;
4760}
0 commit comments