11import { InfoIcon } from "lucide-react" ;
2- import { useId , useLayoutEffect , useRef , useState , type ReactNode } from "react" ;
2+ import { useEffect , useId , useLayoutEffect , useRef , useState , type ReactNode } from "react" ;
33import { flushSync } from "react-dom" ;
44
55import { cn } from "~/lib/utils" ;
@@ -10,11 +10,15 @@ import { observeResize } from "~/lib/observeResize";
1010
1111// Match the duration-220 exit transition before removing a dismissed notice.
1212const DISMISS_TRANSITION_MS = 220 ;
13+ // How long a revealed notice stays open before tucking behind the front banner.
14+ const REVEAL_MS = 5_000 ;
1315
1416export interface ComposerBannerStackItem {
1517 readonly id : string ;
1618 readonly variant : ComposerBannerVariant ;
1719 readonly priority ?: "urgent" | "activity" | "notice" ;
20+ /** The user asked for this notice, so it opens the stack when it lands behind another banner. */
21+ readonly reveal ?: boolean ;
1822 readonly icon : ReactNode ;
1923 readonly title : ReactNode ;
2024 readonly description ?: ReactNode ;
@@ -73,6 +77,26 @@ export function ComposerBannerStack({ className, items, attachedAbove }: Compose
7377 } ;
7478
7579 const orderedItems = items . toSorted ( ( a , b ) => bannerPriority ( a ) - bannerPriority ( b ) ) ;
80+ const stackedItems = orderedItems . slice ( 1 ) ;
81+ const revealItemId =
82+ stackedItems . find ( ( item ) => "reveal" in item && item . reveal === true ) ?. id ?? null ;
83+ const [ revealedItemId , setRevealedItemId ] = useState < string | null > ( null ) ;
84+ if ( revealItemId !== null && revealItemId !== revealedItemId ) {
85+ setRevealedItemId ( revealItemId ) ;
86+ setStackExpanded ( true ) ;
87+ }
88+
89+ // Tuck the revealed notice away unless the user is reading it; leaving it collapses as usual.
90+ useEffect ( ( ) => {
91+ if ( revealedItemId === null ) return ;
92+ const timeout = setTimeout ( ( ) => {
93+ const notices = noticesRef . current ;
94+ if ( notices ?. matches ( ":hover" ) || notices ?. contains ( document . activeElement ) ) return ;
95+ setStackExpanded ( false ) ;
96+ } , REVEAL_MS ) ;
97+ return ( ) => clearTimeout ( timeout ) ;
98+ } , [ revealedItemId ] ) ;
99+
76100 const frontItem = orderedItems [ 0 ] ;
77101 if ( ! frontItem ) {
78102 return (
@@ -83,7 +107,6 @@ export function ComposerBannerStack({ className, items, attachedAbove }: Compose
83107 </ >
84108 ) ;
85109 }
86- const stackedItems = orderedItems . slice ( 1 ) ;
87110 const hasStack = stackedItems . length > 0 ;
88111 const showCollapsedStackCap = hasStack && exitingItemId !== frontItem . id ;
89112 const firstStackedItem = stackedItems [ 0 ] ;
0 commit comments