import { useStyles } from './Toast.styles'; import classnames from 'classnames'; import { useContext } from 'react'; import { IconButton } from '@material-ui/core'; import CheckMarkBadge from '../../CheckmarkBadge/CheckMarkBadge'; import UIContext from '../../../../contexts/UIContext'; import ConditionallyRender from '../../ConditionallyRender'; import Close from '@material-ui/icons/Close'; import { IToast } from '../../../../interfaces/toast'; const Toast = ({ title, text, type, confetti }: IToast) => { const { setToast } = useContext(UIContext); const styles = useStyles(); const confettiColors = ['#d13447', '#ffbf00', '#263672']; const confettiAmount = 200; const getRandomNumber = (input: number) => { return Math.floor(Math.random() * input) + 1; }; const renderConfetti = () => { const elements = new Array(confettiAmount).fill(1); const styledElements = elements.map((el, index) => { const width = getRandomNumber(8); const length = getRandomNumber(100); const style = { position: 'absolute' as 'absolute', width: `${width}px`, height: `${width * 0.4}px`, backgroundColor: confettiColors[getRandomNumber(2)], left: `${length}%`, transform: `rotate(${getRandomNumber(101)}deg)`, animationDelay: `${getRandomNumber(5)}s`, animationDuration: `${getRandomNumber(3)}s`, animationEase: `${getRandomNumber(2)}s`, }; return (
); }); return styledElements; }; const hide = () => { setToast((prev: IToast) => ({ ...prev, show: false })); }; return (
{confetti && renderConfetti()}

{title}

{text}

} />
); }; export default Toast;