HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux WebLive 5.15.0-79-generic #86-Ubuntu SMP Mon Jul 10 16:07:21 UTC 2023 x86_64
User: ubuntu (1000)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/html/wpmuhibbah_err/wp-content/plugins/give/src/Views/Components/AdminUI/Toast/index.tsx
import {MouseEventHandler, useEffect} from 'react';
import cx from 'classnames';
import {__} from '@wordpress/i18n';
import {ExitIcon, CheckCircle, AlertTriangle} from '@givewp/components/AdminUI/Icons';
import styles from './style.module.scss';

export interface ToastProps {
    children: string | JSX.Element | JSX.Element[];
    handleClose: MouseEventHandler;
    type?: 'info' | 'error' | 'warning' | 'success';
    show?: boolean;
    position?: 'top-right' | 'bottom-right' | 'top-left' | 'bottom-left';
    autoClose?: number;
    showCloseIcon?: boolean;
}

export default function Toast({children, type, handleClose, position = 'top-right', show = true, autoClose = 0, showCloseIcon = true}: ToastProps) {
    const getIcon = type => {
        switch (type) {
            case 'info':
                return <></>
            case 'error':
                return <></>
            case 'warning':
                return <AlertTriangle />
            case 'success':
                return <CheckCircle />
        }

        return null;
    }

    useEffect(() => {
        if(autoClose) {
            setTimeout(handleClose, autoClose)
        }
    }, []);

    if (!show) return null;

    return (
        <div className={cx(styles.toastContainer, {
            [styles.topLeft]: position === 'top-left',
            [styles.topRight]: position === 'top-right',
            [styles.bottomLeft]: position === 'bottom-left',
            [styles.bottomRight]: position === 'bottom-right',
            [styles.success]: type === 'success',
            [styles.warning]: type === 'warning',
            [styles.error]: type === 'error',
            [styles.info]: type === 'info',
        })}>
            {type && (
                <div className={styles.icon}>
                    {getIcon(type)}
                </div>
            )}
            <div className={styles.content}>
                {children}
            </div>
            {showCloseIcon && handleClose && (
                <div>
                    <button
                        aria-label={__('Close', 'give')}
                        className={styles.close}
                        onClick={handleClose}
                    >
                        <ExitIcon aria-label={__('Close icon', 'give')} className={styles.closeIconSize} />
                    </button>
                </div>
            )}
        </div>
    )
}