import React, { Component } from 'react'; import ReactDOM from 'react-dom'; import classnames from 'classnames'; import uuidv4 from 'uuid/v4'; import { TransitionGroup, CSSTransition } from 'react-transition-group'; import PropTypes from 'prop-types'; import Icon from './Icon'; import styles from './Toast.cm.styl'; const TOAST_TYPES = { SUCCESS: 1, ERROR: 2, INFO: 3, }; class Toast extends Component { constructor(props) { super(props); this.state = { toasts: [], }; } add(type, title) { const newId = uuidv4(); const toast = { id: newId, type, title, }; setTimeout(() => { this.setState(state => { const nextToasts = state.toasts.filter(t => t.id !== newId); return { toasts: nextToasts, }; }); }, 2000); this.setState(state => { return { toasts: [...state.toasts, toast], }; }); } render() { const { toasts = [], } = this.state; const iconNames = { [TOAST_TYPES.SUCCESS]: 'check', [TOAST_TYPES.ERROR]: 'close', [TOAST_TYPES.INFO]: 'info', }; const classNamesOfToastType = { [TOAST_TYPES.SUCCESS]: styles.success, [TOAST_TYPES.ERROR]: styles.error, [TOAST_TYPES.INFO]: styles.info, }; return (