// Copyright 2021 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only import type { KeyboardEvent, MouseEvent, ReactNode } from 'react'; import React, { memo, useEffect } from 'react'; import classNames from 'classnames'; import { useRestoreFocus } from '../hooks/useRestoreFocus'; import { clearTimeoutIfNecessary } from '../util/clearTimeoutIfNecessary'; export type PropsType = { autoDismissDisabled?: boolean; children: ReactNode; className?: string; disableCloseOnClick?: boolean; onClose: () => unknown; timeout?: number; toastAction?: { label: string; onClick: () => unknown; }; style?: React.CSSProperties; }; export const Toast = memo(function ToastInner({ autoDismissDisabled = false, children, className, disableCloseOnClick = false, onClose, style, timeout = 8000, toastAction, }: PropsType): JSX.Element | null { const [focusRef] = useRestoreFocus(); useEffect(() => { if (autoDismissDisabled) { return; } const timeoutId = setTimeout(onClose, timeout); return () => { clearTimeoutIfNecessary(timeoutId); }; }, [autoDismissDisabled, onClose, timeout]); return (