MCPcopy Create free account
hub / github.com/adobe/react-spectrum / SpectrumToastList

Function SpectrumToastList

packages/@react-spectrum/s2/src/Toast.tsx:455–493  ·  view source on GitHub ↗
({placement, align, reduceMotion})

Source from the content-addressed store, hash-verified

453}
454
455function SpectrumToastList({placement, align, reduceMotion}) {
456 let {isExpanded, toggleExpanded} = useContext(ToastContainerContext)!;
457
458 // Attach click handler to ref since ToastList doesn't pass through onClick/onPress.
459 let toastListRef = useRef(null);
460 useEvent(toastListRef, 'click', e => {
461 // Have to check if this is a button because stopPropagation in react events doesn't affect native events.
462 if (!isExpanded && !(getEventTarget(e) as Element)?.closest('button')) {
463 toggleExpanded();
464 }
465 });
466
467 return (
468 <ToastList<SpectrumToastValue>
469 ref={toastListRef}
470 style={({isHovered}) => {
471 let origin = isHovered ? 95 : 55;
472 return {
473 perspective: 80,
474 perspectiveOrigin:
475 'center ' + (placement === 'top' ? `calc(100% + ${origin}px)` : `${-origin}px`),
476 transition: 'perspective-origin 400ms'
477 };
478 }}
479 className={
480 toastCss[isExpanded ? 'toast-list-expanded' : 'toast-list-collapsed'] +
481 toastList({placement, align, isExpanded})
482 }>
483 {({toast}) => (
484 <SpectrumToast
485 toast={toast}
486 placement={placement}
487 align={align}
488 reduceMotion={reduceMotion}
489 />
490 )}
491 </ToastList>
492 );
493}
494
495interface SpectrumToastProps extends ToastProps<SpectrumToastValue> {
496 placement?: 'top' | 'bottom';

Callers

nothing calls this directly

Calls 3

useEventFunction · 0.90
getEventTargetFunction · 0.90
toggleExpandedFunction · 0.85

Tested by

no test coverage detected