2020-09-01 00:57:59 +02:00
|
|
|
import React, { useEffect } from 'react';
|
2021-02-16 14:10:04 +01:00
|
|
|
import PropTypes from 'prop-types';
|
2020-09-01 00:57:59 +02:00
|
|
|
import ReactDOM from 'react-dom';
|
|
|
|
import { useSpring, animated } from 'react-spring';
|
|
|
|
import styles from './Toast.module.css';
|
|
|
|
import Icon from 'components/common/Icon';
|
|
|
|
import Close from 'assets/times.svg';
|
|
|
|
|
2021-02-16 14:10:04 +01:00
|
|
|
function Toast({ message, timeout = 3000, onClose }) {
|
2020-09-01 00:57:59 +02:00
|
|
|
const props = useSpring({
|
|
|
|
opacity: 1,
|
|
|
|
transform: 'translate3d(0,0px,0)',
|
|
|
|
from: { opacity: 0, transform: 'translate3d(0,-40px,0)' },
|
|
|
|
});
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
setTimeout(onClose, timeout);
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
return ReactDOM.createPortal(
|
|
|
|
<animated.div className={styles.toast} style={props} onClick={onClose}>
|
|
|
|
<div className={styles.message}>{message}</div>
|
|
|
|
<Icon className={styles.close} icon={<Close />} size="small" />
|
|
|
|
</animated.div>,
|
|
|
|
document.getElementById('__modals'),
|
|
|
|
);
|
|
|
|
}
|
2021-02-16 14:10:04 +01:00
|
|
|
|
|
|
|
Toast.propTypes = {
|
|
|
|
message: PropTypes.node,
|
|
|
|
timeout: PropTypes.number,
|
|
|
|
onClose: PropTypes.func,
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Toast;
|