import PropTypes from 'prop-types' import React, { useEffect, useState } from 'react' import { BGColor, PColor } from '../../../assets/colors' import { IconClose } from './../../../assets/icons/index' import styles from './styles.module.css' export const Toast = (props) => { const { toastList, position, autoDelete, autoDeleteTime } = props const [list, setList] = useState(toastList) useEffect(() => { setList([...toastList]) }, [toastList]) useEffect(() => { const interval = setInterval(() => { if (autoDelete && toastList.length && list.length) { deleteToast(toastList[0].id) } }, autoDeleteTime) return () => { clearInterval(interval) } // eslint-disable-next-line react-hooks/exhaustive-deps }, [toastList, autoDelete, autoDeleteTime, list]) const deleteToast = (id) => { const listItemIndex = list.findIndex((e) => {return e.id === id}) const toastListItem = toastList.findIndex((e) => {return e.id === id}) list.splice(listItemIndex, 1) toastList.splice(toastListItem, 1) setList([...list]) } const [divPosition, setDivPosition] = useState(0) const handleDrag = (event) => { setDivPosition(event.clientX) } const handleDragEnd = (event, id) => { if (window.innerWidth - event.clientX > window.innerWidth / 2) { deleteToast(id) } } const backgroundColor = { success: '#50a773', warning: '#ebbc26', error: `${PColor}69` } return (
{toast.title}
{toast.description}