jellyfish-web/src/components/toast/toast.js

35 lines
693 B
JavaScript
Raw Normal View History

2020-10-18 14:19:41 +01:00
import './toast.css';
2018-10-23 01:05:09 +03:00
function remove(elem) {
setTimeout(function () {
elem.parentNode.removeChild(elem);
}, 300);
}
2018-10-23 01:05:09 +03:00
function animateRemove(elem) {
setTimeout(function () {
elem.classList.remove('toastVisible');
remove(elem);
}, 3300);
}
export default function (options) {
if (typeof options === 'string') {
options = {
text: options
};
}
2020-07-27 10:30:24 +01:00
const elem = document.createElement('div');
2020-09-08 15:43:19 -04:00
elem.classList.add('toast');
elem.innerHTML = options.text;
document.body.appendChild(elem);
setTimeout(function () {
elem.classList.add('toastVisible');
animateRemove(elem);
}, 300);
}