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

Function SpectrumToastList

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

Source from the content-addressed store, hash-verified

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