import clsx from 'clsx'; import React, { PropsWithChildren, useCallback } from 'react'; import styles from './Popup.module.scss'; interface Props { testId?: string; style?: React.CSSProperties; className?: string; /** Should it display a subtle dark overlay over the rest of the screen */ overlay?: boolean; onClose?: () => void; } /** * A reusable popup component that can be used to display content on the page * @returns */ export default function Popup({ onClose, children, className, style, testId, overlay }: PropsWithChildren) { const containerRef = React.useRef(null); const bodyRef = React.useRef(null); const handleClickOutside = useCallback( (event: MouseEvent) => { if (!bodyRef.current) return; if (!bodyRef.current.contains(event.target as Node)) { onClose?.(); } }, [onClose, bodyRef] ); React.useEffect(() => { const shadowRoot = document.getElementById('ut-registration-plus-container')?.shadowRoot; if (!shadowRoot) return; shadowRoot.addEventListener('mousedown', handleClickOutside); return () => { shadowRoot.removeEventListener('mousedown', handleClickOutside); }; }, [handleClickOutside]); return (
{children}
); }