import React, { useRef } from 'react'; import { createPortal } from 'react-dom'; import Icon from '../Icon'; import './Toast.scss'; interface ToasterProps { /** * toaster to open */ isOpen: boolean; /** * Type of toaster eg: success | warning | info | danger */ variant: 'success' | 'warning' | 'danger' | 'info'; /** * Options for where to show toaster */ displayPosition: | 'top' | 'bottom' | 'top-right' | 'bottom-right' | 'top-left' | 'bottom-left'; /** * Header Title */ toastTitle: string; /** * Actual content to be shown in toaster, eg: warning toastMessage or success */ toastMessage?: string; /** * Event for Cancel button */ onCancelClick?: () => void; /** * Event for Cancel button */ onMouseOverOnButton?: () => void; /** * Number of milliseconds Toaster need to display */ displayDuration?: number; /** * label for close button */ closeButtonLabel?: React.ReactNode; } const Toaster: React.FC = ({ isOpen = false, variant = 'success', displayPosition = 'top-right', toastTitle = 'Success', onCancelClick = () => { isOpen = false; }, toastMessage = 'Hello this is child element', }) => { const getToasterIcon = (variant: string) => { let name = ''; if (variant === 'success') { name = 'toast_sucess'; } else if (variant === 'info') { name = 'toast_info'; } else if (variant === 'warning') { name = 'warning_icon'; } else { name = 'danger_icon'; } return ; }; if (!isOpen) return null; return createPortal(
{getToasterIcon(variant)}
{toastTitle}
{toastMessage}
, document.body ); }; export default Toaster;